Commits

A2K committed 3976b33

Better hotkeys handling

  • Participants
  • Parent commits 5098fbd

Comments (0)

Files changed (1)

File shortcuts.py

         self.keys = [ play_st, stop_st, pause_st, prev_st, next_st ]
         self.disp = Display()
         self.root = self.disp.screen().root
+        self.root.change_attributes(event_mask = X.PropertyChangeMask| X.KeyPressMask)
         QtCore.QThread.__init__(self)
 
     def bind_keys(self):
         self.root.change_attributes(event_mask = X.KeyPressMask)
         for key in self.keys:
             try:
-                self.root.grab_key(key[0], key[1], True,
-                                        X.GrabModeAsync, X.GrabModeAsync)
-                self.root.grab_key(key[0], key[1] | 1<<4, True,
-                                        X.GrabModeAsync, X.GrabModeAsync)
-            except:
+                self.root.grab_key(key[0], key[1] & ~(X.AnyModifier << 1),
+                                   True, X.GrabModeAsync, X.GrabModeAsync)
+            except Exception as e:
+                print dir(e)
                 log.error('could not register hotkey ' + str(key))
 
+
     def run(self):
         self.active = True
         self.bind_keys()
 
     def handle(self):
         while self.active:
-            for x in range(0, self.root.display.pending_events()):
-                xevent = self.root.display.next_event()
-                if xevent.type == X.KeyPress:
-                    keycode = xevent.detail
-                    for key in self.keys:
-                        if key[0] == keycode:
-                            self.emit(QtCore.SIGNAL("control"), key[2])
-            time.sleep(0.5)
+            event = self.root.display.next_event()
+            if event.type == X.KeyPress:
+                keycode = event.detail
+                for key in self.keys:
+                    if key[0] == keycode:
+                        self.emit(QtCore.SIGNAL("control"), key[2])
 
     def stop(self):
         self.active = False