def grab_button(self, mouse: config.Mouse) -> None: """Grab the given mouse button for events""" try: modmask = xcbq.translate_masks(mouse.modifiers) except xcbq.XCBQError as err: raise utils.QtileError(err) if isinstance(mouse, config.Click) and mouse.focus: # Make a freezing grab on mouse button to gain focus # Event will propagate to target window grabmode = xcffib.xproto.GrabMode.Sync else: grabmode = xcffib.xproto.GrabMode.Async eventmask = xcffib.xproto.EventMask.ButtonPress if isinstance(mouse, config.Drag): eventmask |= xcffib.xproto.EventMask.ButtonRelease for amask in self._auto_modmasks(): self.conn.conn.core.GrabButton( True, self._root.wid, eventmask, grabmode, xcffib.xproto.GrabMode.Async, xcffib.xproto.Atom._None, xcffib.xproto.Atom._None, mouse.button_code, modmask | amask, )
def lookup_key(self, key: config.Key) -> Tuple[int, int]: """Find the keysym and the modifier mask for the given key""" try: keysym = xcbq.get_keysym(key.key) modmask = xcbq.translate_masks(key.modifiers) except xcbq.XCBQError as err: raise utils.QtileError(err) return keysym, modmask
def simulate_keypress(self, modifiers, key): """Simulates a keypress on the focused window.""" # FIXME: This needs to be done with sendevent, once we have that fixed. modmasks = xcbq.translate_masks(modifiers) keysym = xcbq.keysyms.get(key) class DummyEv: pass d = DummyEv() d.detail = self.conn.keysym_to_keycode(keysym)[0] d.state = modmasks self.handle_KeyPress(d)
def grab_button(self, mouse: config.Mouse) -> int: """Grab the given mouse button for events""" modmask = xcbq.translate_masks(mouse.modifiers) eventmask = EventMask.ButtonPress if isinstance(mouse, config.Drag): eventmask |= EventMask.ButtonRelease for amask in self._auto_modmasks(): self.conn.conn.core.GrabButton( True, self._root.wid, eventmask, xcffib.xproto.GrabMode.Async, xcffib.xproto.GrabMode.Async, xcffib.xproto.Atom._None, xcffib.xproto.Atom._None, mouse.button_code, modmask | amask, ) return modmask & self._valid_mask
def test_translate_masks(): assert xcbq.translate_masks(["shift", "control"]) assert xcbq.translate_masks([]) == 0