actions.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. try:
  2. import Xlib.protocol.event
  3. except ImportError:
  4. pass
  5. class RewriteKeyEventAction:
  6. def __init__(self, keysym=None):
  7. self._keysym = keysym
  8. def execute(self, extended_controls, xkeyevent):
  9. attr = dict(
  10. window=extended_controls.engine_window,
  11. detail=xkeyevent.detail,
  12. state=xkeyevent.state,
  13. root_x=xkeyevent.root_x,
  14. root_y=xkeyevent.root_y,
  15. event_x=xkeyevent.event_x,
  16. event_y=xkeyevent.event_y,
  17. child=xkeyevent.child,
  18. root=xkeyevent.root,
  19. time=xkeyevent.time, # X.CurrentTime
  20. same_screen=xkeyevent.same_screen,
  21. )
  22. if self._keysym:
  23. attr['detail'] = extended_controls.xdisplay.keysym_to_keycode(
  24. self._keysym)
  25. extended_controls.engine_window.send_event(
  26. type(xkeyevent)(**attr),
  27. )
  28. class ForwardKeyEventAction(RewriteKeyEventAction):
  29. def __init__(self):
  30. super().__init__(keysym=None)
  31. class ToggleExtendedControlsAction:
  32. def execute(self, extended_controls, xkeyevent):
  33. if isinstance(xkeyevent, Xlib.protocol.event.KeyPress):
  34. extended_controls.toggle()