@@ -12,11 +12,22 @@ import fcntl
1212import platform
1313import math
1414import hashlib
15+ import threading
1516from time import monotonic
1617from collections import OrderedDict
1718from pathlib import Path
1819from 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+
2031PROGPATH = Path (sys .argv [0 ])
2132PROGNAME = 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+
612642def 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