What a static shortcut file cannot be (modes, chord chains, release bindings,
per-application bindings, a blacklist, a pause binding) komorebi realizes
itself, with keys it registers in kglobalacceld. The engine is the logic of
that, with no I/O and no clock: it takes the press and the release of an active
combo, a change of the focused window and the time, and returns effects: combos
to activate or deactivate, and commands to run (komorebic's to dispatch
in-process, the others through `sh -c`).
After every event it computes the set of combos it wants from its state (the
mode, the chord chain being typed, the focused application, whether it is
paused) and returns the difference with the active set, so that a key it does
not want reaches the application. That is how everything works, because of what
KWin 6.8.1 was measured to do: KDE's own multi-key sequences never fire, while a
single combo can be grabbed and given back (`setShortcutKeys`, `setInactive`) in
well under a millisecond each. A chain's first combo is an active key, and
pressing it leaves only the next combos and Escape active until one is pressed
or the chord timeout (3 s by default) passes. A scoped key is active only while
the focused application, matched without regard to case on its executable,
app_id or desktop entry and on the configured aliases, has an action for it.
Autorepeat arrives as a separate signal the engine has no input for, so a held
key runs its binding once.
The D-Bus side (registering the component, carrying out the effects, feeding the
signals in) belongs to the daemon and is not here.
The crate documentation now ends with what is emulated and what is not, across
the readers, the plan and the engine.
A binding can reach KDE in two ways. A `.desktop` file in a kglobalaccel
directory is a static shortcut that KDE runs by itself: it shows in System
Settings and survives a dead komorebi, but it is one combo that runs one
command. Modes, chord chains, release bindings, per-application bindings, a
blacklist and a pause binding need the engine, where komorebi registers the keys
and decides what each press does. `plan::plan` sorts a keymap into the two: a
binding is static when it is in the default mode, a single combo, unscoped and
pressed, in a file with no modes, blacklist or pause binding. Notes say why each
other binding goes through the engine.
The static shortcut was meant to be the default unless it proved slow, and it
did: on KWin 6.8.1 a static shortcut ran its command 233 ms after the key at the
median, while the engine heard of it after 3 ms. `PlanMode::Engine` is therefore
the default, and `Auto` and `Static` (no engine; what needs it is left out with
a warning) stay selectable.
`kde` is the skhdrc exporter of the first KDE prototype, moved: the same file
names, the same `Exec` quoting for the desktop entry specification (`%%`
included), the same `X-KDE-GlobalAccel-CommandShortcut` and `X-KDE-Shortcuts`
keys, and `write` and `diff`, which replace the generated files and leave every
other file alone. For the sample configuration the files are byte for byte the
prototype's; its tests come along, and the corpus test checks that the sample
plans into the same 50 files from each format.
The third format is sxhkd's, the hotkey daemon users of tiling window managers
on X11 bind keys with. `sxhkd::parse` reads a hotkey line and the indented
command below it, with comments and continued lines, X keysyms (XF86 media keys
included) and the modifiers sxhkd shares with KDE.
Braces are expanded while reading, in the hotkey and the command together:
`{a,b}`, ranges such as `1-9`, `_` for nothing and `\{` for a literal brace,
with every combination of several pairs, the last changing fastest. A chord
chain (`super + w ; h`) is one binding with two combos, and a chain that stays
open after its last chord (`super + r : {h,l}`) is a mode named after its
prefix, entered by the prefix and left with Escape. `@` makes a release binding.
The diagnostics say what differs from sxhkd: a wrong key does not end a chain
(only Escape and the chord timeout do), a release binding fires on the first
key-up of any key of its combo, `~` does not pass the key on, and the modifiers
KDE has no equivalent for, mouse buttons and keypad keys are left out.
`parse` now picks the reader by format, and the corpus test reads every fixture
with it: the files of each case, in all three formats, read into the same
keymap.
komorebi for Windows' users bind komorebic in a whkdrc. `whkd::parse` reads it
into the same model as an skhdrc: `keys : command` bindings with the Windows
virtual key names whkd takes, per-application lists with `Ignore` and `Default`,
`.pause` and `.pause_hook`. A `#` starts a comment wherever it is, as in whkd.
whkd requires its sections in a fixed order; the reader takes them in any.
`.shell` is noted, since commands run through `sh -c`, side-specific modifiers
are approximated, and keys KDE has no key for (the keypad's) are left out with a
warning.
whkd's own parser, `whkd-parser`, is not used to read: it requires `.shell` to
be pwsh, powershell or cmd and panics on anything else, and it matches Windows
process names. It is under the same license as komorebi, so it is a
dev-dependency at v0.2.10, and a test reads every whkdrc of the corpus and the
example of whkd's README with both parsers and requires the same bindings.
deny.toml allows its git source.
The corpus test now also reads the whkdrc fixtures, and checks that the files of
a case read into the same keymap, apart from where each binding was written.
komorebi for Mac's users bind komorebic in an skhdrc, so that is the first file
the crate reads. `skhd::parse` reads the whole syntax into the model: bindings
with every modifier skhd has, literal keys and macOS keycodes, mode declarations
(with `@` and an entry command), mode switches and bindings in one or more
modes, per-application lists with `~` and `*`, `.blacklist`, and skhd.zig's
`.define` command templates and application groups, which are expanded where
they are used. A mode may be used before it is declared, so bindings are put in
their modes at the end of the file.
Reading never fails. Text that is not valid skhd is an error with its span and
is skipped, up to the end of the line or of the list it opened, and reading goes
on. What is valid but not realized the way skhd does it has a warning that says
so: side-specific modifiers are the modifier, a capturing mode lets unbound keys
through, `->` does not pass the key on, and `fn`, `.load`, `.alias`, key
forwarding and key sequences are left out. Comments, continued lines and the
line numbers of diagnostics are shared with the readers that follow.
The tests cover the modifiers, macOS keycodes and the shifted symbol rule,
comments and continued lines, modes, lists, defines, spans and recovery after an
error, and the corpus test now checks that every skhdrc fixture reads into the
keymap of its case. The keymaps of the other cases are written down too, for the
readers to be written against.
komorebi users keep their bindings to komorebic in the file of a hotkey daemon:
an skhdrc on macOS, a whkdrc on Windows, an sxhkdrc on X11. On KDE Plasma the
program that runs a command on a key is KDE's global shortcut daemon, so the
bindings have to be read and turned into shortcuts. This adds
`komorebi-hotkeys`, a crate of its own that does not depend on the daemon, with
the model all three formats are read into: a `Keymap` of modes of bindings, each
a chord, an edge and a body (a command, a mode switch, or one action per
application), and `Diagnostic`s with spans.
A key is a Qt key code with the modifier flags or'ed in, which is what
kglobalacceld stores, so the same key is the same value whatever file named it.
`qt::key_to_qt` knows the three vocabularies: skhd's literals and macOS
keycodes, whkd's virtual key names and sxhkd's X keysyms, including the XF86
media keys. `Combo` applies the shifted symbol rule measured on KWin 6.8.1
(Alt+Shift+1 arrives as Alt+!), and its fields are private so that no combo
skips it; a `compile_fail` example proves it. Positions are read as on a US
layout.
The fixture corpus writes each case in every format that can express it; the
parsers are written against it. The flake's source filter keeps the fixtures, so
that the nix checks can read them.