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
modmask
that need to be taken into consideration if we can’t properly ignore the modifiers inignored
. (Typically NumLock and CapsLock)- Parameters
modmask (
int
) – An integer orGdk.ModifierType
bitfield to be combinatorically grown.ignored (
Iterable
[int
]) – Integer orGdk.ModifierType
modifiers to be combined withmodmask
.
- Return type
- Returns
The
power set
ofignored
withmodmask
bitwise ORed onto each entry.
-
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 satisfyGIOFunc
signature.cond (
GLib.IOCondition
) – Not used. Just to needed to satisfyGIOFunc
signature.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
True
to prevent GLib from unsetting the watch.
-
handle_keypress
(xevent)[source]¶ Resolve
Xlib.protocol.event.KeyPress
events to thequicktile.commands.CommandRegistry
commands 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
KeyBinder
orNone
ifwinman
didn’t already have an X connection and attempting to open a new one met with failure.