def parse(self, spec): """ Splits an emacs keydef into modifiers and keys. For example: "M-S-a" -> ['mod4', 'shift'], 'a' "A-<minus>" -> ['mod1'], 'minus' "C-<Tab>" -> ['control'], 'Tab' """ mods = [] keys = [] for key in spec.split("-"): if not key: break if key in self.modifier_keys: if keys: msg = "Modifiers must always come before key/btn: %s" raise utils.QtileError(msg % spec) mods.append(self.modifier_keys[key]) continue if len(key) == 1: keys.append(key) continue if len(key) > 3 and key[0] == "<" and key[-1] == ">": keys.append(key[1:-1]) continue if not keys: msg = "Invalid key/btn specifier: %s" raise utils.QtileError(msg % spec) if len(keys) > 1: msg = "Key chains are not supported: %s" % spec raise utils.QtileError(msg) return mods, keys[0]
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._root.grab_button( mouse.button_code, modmask | amask, True, eventmask, grabmode, xcffib.xproto.GrabMode.Async, )
def _subscribe(self, event, func): lst = subscriptions.setdefault(event, []) try: lst.remove(func) except ValueError: raise utils.QtileError("Tried to unsubscribe a hook that was not" " currently subscribed")
def __init__( self, title=None, wm_class=None, role=None, wm_type=None, wm_instance_class=None, net_wm_pid=None, func: Callable[[base.WindowType], bool] | None = None, wid=None, ): self._rules = {} if title is not None: self._rules["title"] = title if wm_class is not None: self._rules["wm_class"] = wm_class if wm_instance_class is not None: self._rules["wm_instance_class"] = wm_instance_class if wid is not None: self._rules["wid"] = wid if net_wm_pid is not None: try: self._rules["net_wm_pid"] = int(net_wm_pid) except ValueError: error = 'Invalid rule for net_wm_pid: "%s" only int allowed' % str( net_wm_pid) raise utils.QtileError(error) if func is not None: self._rules["func"] = func if role is not None: self._rules["role"] = role if wm_type is not None: self._rules["wm_type"] = wm_type
def __init__(self, title=None, wm_class=None, role=None, wm_type=None, wm_instance_class=None, net_wm_pid=None): if not title: title = [] if not wm_class: wm_class = [] if not role: role = [] if not wm_type: wm_type = [] if not wm_instance_class: wm_instance_class = [] if not net_wm_pid: net_wm_pid = [] try: net_wm_pid = list(map(int, net_wm_pid)) except ValueError: error = 'Invalid rule for net_wm_pid: "%s" '\ 'only ints allowed' % str(net_wm_pid) raise utils.QtileError(error) self._rules = [('title', t) for t in title] self._rules += [('wm_class', w) for w in wm_class] self._rules += [('role', r) for r in role] self._rules += [('wm_type', r) for r in wm_type] self._rules += [('wm_instance_class', w) for w in wm_instance_class] self._rules += [('net_wm_pid', w) for w in net_wm_pid]
def __init__(self, title=None, wm_class=None, role=None, wm_type=None, wm_instance_class=None, net_wm_pid=None): self._rules = {} if title is not None: self._rules["title"] = title if wm_class is not None: self._rules["wm_class"] = wm_class if role is not None: self._rules["role"] = role if wm_type is not None: self._rules["wm_type"] = wm_type if wm_instance_class is not None: self._rules["wm_instance_class"] = wm_instance_class if net_wm_pid is not None: try: self._rules["net_wm_pid"] = int(net_wm_pid) except ValueError: error = 'Invalid rule for net_wm_pid: "%s" only int allowed' % \ str(net_wm_pid) raise utils.QtileError(error)
def lookup_key(self, key: config.Key) -> Tuple[int, 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, modmask & self._valid_mask
def fire(event, *args, **kwargs): if event not in subscribe.hooks: raise utils.QtileError("Unknown event: %s" % event) if event not in SKIPLOG: logger.debug("Internal event: %s(%s, %s)", event, args, kwargs) for i in subscriptions.get(event, []): try: i(*args, **kwargs) except: # noqa: E722 logger.exception("Error in hook %s", event)