mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-29 20:02:46 +01:00
feat(hotkeys): plan the bindings and write the plain ones as KDE shortcut files
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.
This commit is contained in:
1 parent
e713d77272
commit
8f5d4a32ef
7 files changed
+969
-4
No files matched your search
@@ -1585,6 +1585,13 @@ daemons: skhd (macOS), whkd (Windows) and sxhkd (X11).
|
||||
its severity (error, warning, note) and how faithfully the construct is realized (exactly,
|
||||
approximated, not at all).
|
||||
- **Parsed**: a file, read: the keymap and the diagnostics.
|
||||
- **Static shortcut**: a binding KDE realizes from a `.desktop` file, with no komorebi process:
|
||||
one combo, pressed, the same in every application, in a file without modes, blacklist or pause
|
||||
binding.
|
||||
- **Engine**: the part of komorebi that registers keys with KDE and decides what each press does,
|
||||
for everything a static shortcut cannot be.
|
||||
- **Plan**: the bindings of a keymap sorted into static shortcuts and the engine's keymap, with
|
||||
notes on why each binding goes where it goes.
|
||||
|
||||
### The parts
|
||||
|
||||
@@ -1604,6 +1611,13 @@ daemons: skhd (macOS), whkd (Windows) and sxhkd (X11).
|
||||
a chain that stays open (`a : b`) is a mode named after its prefix, entered by the prefix and
|
||||
left by Escape.
|
||||
- [`parse`](../../komorebi-hotkeys/src/lib.rs) picks the reader by format.
|
||||
- [`plan`](../../komorebi-hotkeys/src/plan.rs): sorts a keymap into static shortcuts and the
|
||||
engine's keymap, by mode: `Auto` (static where it can be), `Engine` (the default: everything
|
||||
through the engine) or `Static` (no engine; what needs it is left out with a warning).
|
||||
- [`kde`](../../komorebi-hotkeys/src/kde.rs): writes static shortcuts as `.desktop` files for
|
||||
kglobalacceld (`X-KDE-Shortcuts`, `X-KDE-GlobalAccel-CommandShortcut`, an `Exec` line quoted as
|
||||
the desktop entry specification requires), and replaces the files it wrote before, and no
|
||||
other.
|
||||
- [`text`](../../komorebi-hotkeys/src/text.rs): what the readers share: line numbers, comments,
|
||||
continued lines and the diagnostics' wording.
|
||||
- [`tests/fixtures`](../../komorebi-hotkeys/tests/fixtures): the corpus, `<case>.skhdrc`,
|
||||
@@ -1620,6 +1634,10 @@ daemons: skhd (macOS), whkd (Windows) and sxhkd (X11).
|
||||
| Text that is left out has a diagnostic that points at it | test | `what_cannot_be_read_is_reported_and_left_out`, `reading_goes_on_after_an_error`, `diagnostics_point_at_the_text_they_are_about` | none |
|
||||
| A fixture reads, without errors, into the keymap of its case | test | `every_file_reads_without_errors_into_the_keymap_of_its_case` | none |
|
||||
| The files of a case read into the same keymap, apart from where each binding was written | test | `the_files_of_a_case_read_into_the_same_keymap` | none |
|
||||
| A static shortcut is a single combo, pressed, the same in every application, in the default mode of a file with no modes, blacklist or pause binding | test | `a_plain_binding_is_static_and_the_rest_goes_through_the_engine`, `modes_a_blacklist_or_a_pause_binding_send_every_binding_through_the_engine` | `PlanMode::Engine` sends every binding through the engine |
|
||||
| A rewrite of the shortcut files removes only the files it generated | test | `rewriting_replaces_our_files_and_nothing_else` | none |
|
||||
| An `Exec` line runs the command as written (quoting, `%%`) | test | `exec_lines_are_quoted_for_the_desktop_entry_spec` | none |
|
||||
| The sample configuration plans into the same 50 shortcut files from each format | test | `the_sample_plans_into_the_same_shortcut_files_in_every_format` | none |
|
||||
| The whkd reader reads a whkdrc as whkd does | test, on the files it is given | `every_whkdrc_of_the_corpus_reads_as_whkd_reads_it`, `the_example_of_whkds_readme_reads_as_whkd_reads_it` | none |
|
||||
|
||||
## Where to look in the code
|
||||
@@ -1800,7 +1818,9 @@ daemons: skhd (macOS), whkd (Windows) and sxhkd (X11).
|
||||
[`komorebi-hotkeys/src/qt.rs`](../../komorebi-hotkeys/src/qt.rs) the keys, and one module per
|
||||
format, [`skhd.rs`](../../komorebi-hotkeys/src/skhd.rs),
|
||||
[`whkd.rs`](../../komorebi-hotkeys/src/whkd.rs) and
|
||||
[`sxhkd.rs`](../../komorebi-hotkeys/src/sxhkd.rs).
|
||||
[`sxhkd.rs`](../../komorebi-hotkeys/src/sxhkd.rs);
|
||||
[`plan.rs`](../../komorebi-hotkeys/src/plan.rs) and [`kde.rs`](../../komorebi-hotkeys/src/kde.rs)
|
||||
for the shortcuts.
|
||||
- [`komorebi-hotkeys/tests`](../../komorebi-hotkeys/tests): the corpus test and the comparison
|
||||
with `whkd-parser`.
|
||||
- [`nix/nixos-module.nix`](../../nix/nixos-module.nix): the NixOS module;
|
||||
|
||||
@@ -722,3 +722,27 @@ recorded; this entry needs one.
|
||||
What is not plain syntax is expanded while the file is read: sxhkd's braces become one binding
|
||||
per alternative, and skhd's `.define` templates and application groups are replaced where
|
||||
they are used, so the model has only expanded bindings in it.
|
||||
|
||||
## Why are some bindings shortcut files, and the others the engine's?
|
||||
|
||||
A KDE global shortcut can be a `.desktop` file that KDE reads by itself. Such a static
|
||||
shortcut is robust: it shows in System Settings, where it can be changed, and it survives a
|
||||
komorebi process that has died. But it is one combo that runs one command: it cannot be in a
|
||||
mode, wait for the second key of a chord, fire on release, or do something else in each
|
||||
application. So a binding is a static shortcut when it is in the default mode, a single combo,
|
||||
unscoped and a press binding, and the file declares no modes; everything else goes through
|
||||
the engine, in which komorebi registers the keys itself and decides what each press does. A
|
||||
blacklist and a pause binding apply to every binding, so a file with either is the engine's
|
||||
too.
|
||||
|
||||
## Why does the engine handle every binding by default?
|
||||
|
||||
The plan was to make static shortcuts the default and to switch the default if a static
|
||||
shortcut turned out to be slow to start its command. It did: on KWin 6.8.1 (in a virtual
|
||||
machine, on 2026-10-27) a static shortcut ran its command 165 to 436 ms after the key, 233 ms
|
||||
at the median, while the engine was told of the key 3 ms after it. So the default is
|
||||
`PlanMode::Engine`, and `PlanMode::Auto` and `PlanMode::Static` stay selectable.
|
||||
|
||||
The cost is the robustness of static shortcuts: the engine works only while komorebi runs,
|
||||
and a komorebi process that was killed leaves its keys registered and dead until they are
|
||||
released.
|
||||
Reference in new issue
Block a user