@@ -12,11 +12,22 @@ import fcntl
12
12
import platform
13
13
import math
14
14
import hashlib
15
+ import threading
15
16
from time import monotonic
16
17
from collections import OrderedDict
17
18
from pathlib import Path
18
19
from distutils .version import LooseVersion as Version
19
20
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
+
20
31
PROGPATH = Path (sys .argv [0 ])
21
32
PROGNAME = PROGPATH .stem
22
33
@@ -609,6 +620,25 @@ def read_conf(conffile, defname):
609
620
get_conf (confpath , confname )
610
621
return confname
611
622
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
+
612
642
def main ():
613
643
global args , abzsquare
614
644
@@ -715,13 +745,22 @@ def main():
715
745
devstr = ' --device {}' .format (device .get ('_path' )) if device else ''
716
746
command = 'stdbuf -oL -- {}{}' .format (cmd_debug_events , devstr )
717
747
748
+ if dbus_imported :
749
+ t = threading .Thread (target = lockcheck )
750
+ t .daemon = True
751
+ t .start ()
752
+
718
753
cmd = subprocess .Popen (shlex .split (command ), stdout = subprocess .PIPE ,
719
754
bufsize = 1 , universal_newlines = True )
720
755
721
756
# Sit in a loop forever reading the libinput messages ..
722
757
handler = None
723
758
for line in cmd .stdout :
724
759
760
+ # Ignore gestures if this session is locked
761
+ if session_locked :
762
+ continue
763
+
725
764
# Just output raw messages if in that mode
726
765
if args .raw :
727
766
print (line .strip ())
0 commit comments