Skip to content

Commit 1ae7339

Browse files
committed
Inhibit actions if user session is locked
1 parent 115dd64 commit 1ae7339

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
22
ignore = E126,E127,E128,E302,E305,E401
33
max-line-length = 80
4-
max-complexity = 30
4+
max-complexity = 36

libinput-gestures

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@ import fcntl
1212
import platform
1313
import math
1414
import hashlib
15+
import threading
1516
from time import monotonic
1617
from collections import OrderedDict
1718
from pathlib import Path
1819
from distutils.version import LooseVersion as Version
1920

21+
dbus_imported = True
22+
try:
23+
import dbus
24+
from dbus.mainloop.glib import DBusGMainLoop
25+
from gi.repository import GLib
26+
except ImportError:
27+
dbus_imported = False
28+
29+
session_locked = False
30+
2031
PROGPATH = Path(sys.argv[0])
2132
PROGNAME = PROGPATH.stem
2233

@@ -609,6 +620,25 @@ def read_conf(conffile, defname):
609620
get_conf(confpath, confname)
610621
return confname
611622

623+
def lockcheck():
624+
'Listen on DBus to set session_locked state'
625+
def proc(busname, vals, _):
626+
global session_locked
627+
if busname == 'org.freedesktop.login1.Session':
628+
val = vals.get('LockedHint')
629+
if val is not None:
630+
session_locked = bool(val)
631+
632+
DBusGMainLoop(set_as_default=True)
633+
dbus.SystemBus().add_signal_receiver(
634+
proc,
635+
'PropertiesChanged',
636+
'org.freedesktop.DBus.Properties',
637+
'org.freedesktop.login1',
638+
)
639+
640+
GLib.MainLoop().run()
641+
612642
def main():
613643
global args, abzsquare
614644

@@ -715,13 +745,22 @@ def main():
715745
devstr = ' --device {}'.format(device.get('_path')) if device else ''
716746
command = 'stdbuf -oL -- {}{}'.format(cmd_debug_events, devstr)
717747

748+
if dbus_imported:
749+
t = threading.Thread(target=lockcheck)
750+
t.daemon = True
751+
t.start()
752+
718753
cmd = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE,
719754
bufsize=1, universal_newlines=True)
720755

721756
# Sit in a loop forever reading the libinput messages ..
722757
handler = None
723758
for line in cmd.stdout:
724759

760+
# Ignore gestures if this session is locked
761+
if session_locked:
762+
continue
763+
725764
# Just output raw messages if in that mode
726765
if args.raw:
727766
print(line.strip())

0 commit comments

Comments
 (0)