1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- try:
- import Xlib.X
- import Xlib.protocol.event
- except ImportError:
- pass
- class SelectGagAction:
- def __init__(self, factor_x, factor_y):
- self._button = Xlib.X.Button1
- self._factor_x = factor_x
- self._factor_y = factor_y
- def execute(self, extended_controls, xkeyevent):
- engine_geometry = extended_controls._engine_window.get_geometry()
- smaller_dimension = min(engine_geometry.width, engine_geometry.height)
- attr = dict(
- window=extended_controls.engine_window,
- detail=self._button,
- state=xkeyevent.state,
- event_x=int(engine_geometry.width/2+smaller_dimension*self._factor_x),
- event_y=int(engine_geometry.height/2+smaller_dimension*self._factor_y),
- # apparently root_x & root_y do not need to correspond with event_x/y.
- # attributes are still required to be set.
- root_x=0, # xkeyevent.root_x,
- root_y=0, # xkeyevent.root_y,
- child=xkeyevent.child,
- root=xkeyevent.root,
- time=xkeyevent.time, # X.CurrentTime
- same_screen=xkeyevent.same_screen,
- )
- if isinstance(xkeyevent, Xlib.protocol.event.KeyPress):
- e = Xlib.protocol.event.ButtonPress(**attr)
- else:
- e = Xlib.protocol.event.ButtonRelease(**attr)
- extended_controls.engine_window.send_event(e)
- class RewriteKeyEventAction:
- def __init__(self, keysym=None):
- self._keysym = keysym
- def execute(self, extended_controls, xkeyevent):
- attr = dict(
- window=extended_controls.engine_window,
- detail=xkeyevent.detail,
- state=xkeyevent.state,
- root_x=xkeyevent.root_x,
- root_y=xkeyevent.root_y,
- event_x=xkeyevent.event_x,
- event_y=xkeyevent.event_y,
- child=xkeyevent.child,
- root=xkeyevent.root,
- time=xkeyevent.time, # X.CurrentTime
- same_screen=xkeyevent.same_screen,
- )
- if self._keysym:
- attr['detail'] = extended_controls.xdisplay.keysym_to_keycode(
- self._keysym)
- extended_controls.engine_window.send_event(
- type(xkeyevent)(**attr),
- )
- class ForwardKeyEventAction(RewriteKeyEventAction):
- def __init__(self):
- super().__init__(keysym=None)
- class ToggleExtendedControlsAction:
- def execute(self, extended_controls, xkeyevent):
- if isinstance(xkeyevent, Xlib.protocol.event.KeyPress):
- extended_controls.toggle()
|