Internal Global Hotkey Support (keybinder.py)¶
Xlib-based global hotkey-binding code
- class KeyBinder(x_display=None)[source]¶
A convenience class for wrapping XGrabKey.
- Parameters:
x_display (
Optional[Display]) – An Xlib display handle. IfNone, a new connection will be opened.- Raises:
XInitError – Failed to open a new X connection.
- static _vary_modmask(modmask, ignored)[source]¶
Generate all possible variations on
modmaskthat need to be taken into consideration if we can’t properly ignore the modifiers inignored. (Typically NumLock and CapsLock)- Parameters:
modmask (
Union[int,Gdk.ModifierType]) – An integer orGdk.ModifierTypebitfield to be combinatorically grown.ignored (
Iterable[Union[int,Gdk.ModifierType]]) – Integer orGdk.ModifierTypemodifiers to be combined withmodmask.
- Return type:
- Returns:
The
power setofignoredwithmodmaskbitwise ORed onto each entry.
>>> list(KeyBinder._vary_modmask(Gdk.ModifierType.MOD1_MASK, [])) [8] >>> list(KeyBinder._vary_modmask(Gdk.ModifierType.MOD1_MASK, ... [Gdk.ModifierType.MOD2_MASK, ... Gdk.ModifierType.LOCK_MASK])) [8, 24, 10, 26]
- bind(accel, callback)[source]¶
Bind a global key combination to a callback.
- Parameters:
accel (
str) – An accelerator as either a string to be parsed byGtk.accelerator_parse()or a tuple as returned by it.)callback (
Callable[[],None]) – The function to call when the key is pressed.
- Return type:
- Returns:
A boolean indicating whether the provided keybinding was parsed successfully and didn’t provoke an error from XGrabKey.
- cb_xerror(err, request)[source]¶
Callback used to identify when attempts to bind keys fail.
- Parameters:
err (
XError) – The error that was asynchronously returned.request (
Any) – Unused. Just to match the required function signature.
- cb_xevent(src, cond, handle=None)[source]¶
GLib.io_add_watch()callback to dispatch X events to more specific handlers.- Parameters:
src (
GLib.IOChannel) – Not used. Just needed to satisfyGIOFuncsignature.cond (
GLib.IOCondition) – Not used. Just to needed to satisfyGIOFuncsignature.handle (
Optional[Display]) – A handle to the Xlib display object with pending events. A cached reference will be used if it isNone.
- Return type:
- Returns:
Always returns
Trueto prevent GLib from unsetting the watch.
- handle_keypress(xevent)[source]¶
Resolve
Xlib.protocol.event.KeyPressevents to thequicktile.commands.CommandRegistrycommands associated with them and then call the commands.- Parameters:
xevent (
KeyPress)
- ignored_modifiers = ['Mod2Mask', 'LockMask']¶
Modifiers whose state should not affect whether a binding fires
- keybind_failed = False¶
Used in concert with
Xlib.display.Display.sync()to pass state fromcb_xerror()tobind()so XGrabKey failure can be reported.
- init(modmask, mappings, commands, winman)[source]¶
Initialize the keybinder and bind the requested mappings
- Parameters:
modmask (
Optional[str]) – A valid set of modifiers as accepted byGtk.accelerator_parse(),none, an empty string, orNone.mappings (
Dict[str,str]) – A dict mapping accelerator strings to command names.commands (
CommandRegistry) – The command registry used to map command names to functions.winman (
WindowManager) – The interface commands should use to take action.
- Return type:
- Returns:
An instance of
KeyBinderorNoneifwinmandidn’t already have an X connection and attempting to open a new one met with failure.


Install Dependencies