build(nix): keybindings in the module

On NixOS the key bindings belong in the configuration, with the rest of
komorebi. services.komorebi.keybindings takes the format (skhd, whkd or sxhkd),
the bindings as text or as a file (exactly one of the two, asserted), the mode
(auto, engine or static; engine by default, as PlanMode::default() is),
chordTimeout (3000 ms), layout (us, the only one), strict and appAliases. skhd's
.load is refused by an assertion: the file it reads would not be in the store.

At build time the module runs komorebic hotkeys compile on the file in the
package komorebi-keybindings, whose share/kglobalaccel goes into the system
profile, where KWin finds the static shortcuts when the session starts. Its
diagnostics are in the build log and in diagnostics.txt, and strict passes
--strict, which fails the build on a warning or an error. execStart gains
--keybindings with the same store file, its format and mode, --chord-timeout and
an --app-alias per alias, so the daemon plans the file as the build did and runs
the bindings the build left to the engine. The unit already releases the keys
after the daemon stops.

The check keybindings-fixtures runs every file of the fixture corpus through
komorebic hotkeys compile --mode auto --dry-run, the command the module runs,
and diffs what it prints against nix/tests/keybindings.expected; it also checks
that docs/{skhdrc,whkdrc,sxhkdrc}.sample are the corpus's sample case.
nixos-module-eval gains the key binding scenarios: text, file, both, no format,
.load and a layout that is not us, and one with the typed config together with
key bindings, whose execStart has the checked file and then the keys. The corpus
gains the case vm, in the three formats: a binding a shortcut file can hold, and
one on the comma key, which X-KDE-Shortcuts cannot, so that the engine runs it
in auto mode. The VM suites vm-keys-skhd, vm-keys-whkd and vm-keys-sxhkd
configure the module with that case in their format and press both keys; they
share one script through the generator's script attribute.

For strict, nixos-module-eval has two scenarios with the same skhd text, which
has a line komorebic cannot read: strict = true and the default. Evaluation
never reads the key bindings, so the checks read the script of the build: with
strict it runs hotkeys compile --strict and exits 1 when that fails, without it
there is no --strict and the diagnostics are only printed to the build log. A
third check says the daemon gets the same command line either way. ARCHITECTURE
names them in the row for strict.

komorebic quickstart writes the sample skhdrc next to komorebi.json and
applications.json, from docs/skhdrc.sample, where the daemon and hotkeys compile
read it; the flake's source filter keeps that file for the build.

Docs: the user guide docs/usage/keybindings.md, the three sample files,
docs/example-configurations.md for KDE and NixOS, the options in
docs/installation.md, and the module's section of ARCHITECTURE. Whether the
engine or static shortcuts should be the default stays open in DESIGN: a static
shortcut took 233 ms to run its command at the median on KWin 6.8.1, the engine
3 ms, but only the static shortcut survives a dead daemon.
This commit is contained in:
LGUG2Z committed 2026-10-28 07:39:49 -07:00
1 parent 2f61b62276
commit 9cb26daf38
31 files changed
+1392 -32

No files matched your search

+23 -6
View File
@@ -929,8 +929,9 @@ reads as a [`StaticConfig`], pauses the old window manager and brings back the w
([`StaticConfig::preload`], [`WindowManager::init`], [`StaticConfig::reload`]) over the same command
socket, and puts it where the old one was, so the daemon starts over from the file, with the
windows the backend has, all of them in view, and a watcher on the new file. A file that does not read is logged and the old window manager stays.
`komorebic quickstart` writes the example file of the docs and `komorebic/applications.json` into
the config home, compiled into the binary, and asks before it writes over a file;
`komorebic quickstart` writes the example file of the docs, `komorebic/applications.json` and the
sample `skhdrc` of the docs into the config home, compiled into the binary, and asks before it
writes over a file;
`komorebic enable-autostart` writes the XDG autostart entry that has Plasma start the daemon at login.
The same types describe the file as a JSON Schema, which `schemars` derives: `komorebic
@@ -1176,9 +1177,11 @@ The flake exports one module under two names, `nixosModules.default` and
`configFile`, `config`, `applicationSpecificConfiguration`, `effects.borders.enable` and
`effects.borders.package` (by default `pkgs.kde-rounded-corners-komorebi`, from the overlay),
`effects.animation.enable` and `effects.animation.package`
(`pkgs.kwin-effect-geometry-change-komorebi`), and `execStart`, which is read-only: the module
sets it to `bin/komorebi` of the package with `--log-level`, and `--config` with a
`komorebi.json` when `configFile` or `config` is set. `config` is typed from
(`pkgs.kwin-effect-geometry-change-komorebi`), `keybindings` (`format`, `text` or `file`, `mode`,
`chordTimeout`, `layout`, `strict`, `appAliases`), and `execStart`, which is read-only: the module
sets it to `bin/komorebi` of the package with `--log-level`, `--config` with a `komorebi.json`
when `configFile` or `config` is set, and `--keybindings` and the options of the engine when there
are key bindings. `config` is typed from
`nix/komorebi-options.nix`, the options `schemars-nixgen` makes from the schema of `komorebi.json`;
the module writes it as JSON, with no null in it, and `configFile` and the written file both go
through `check-jsonschema` against `schema.json` when the system is built (comment lines taken out
@@ -1198,7 +1201,14 @@ With `services.komorebi.enable`, the module:
`/run/current-system/sw/bin` instead of the store paths NixOS gives a unit;
- runs `komorebic hotkeys release` after the daemon has stopped (`ExecStopPost`), which
unregisters the keys a daemon that was killed left in kglobalaccel;
- asserts that Plasma 6 is enabled.
- asserts that Plasma 6 is enabled;
- with key bindings, asserts that exactly one of `text` and `file` is set, that `format` is,
and that an skhdrc has no `.load`; runs `komorebic hotkeys compile` on them at build time in
the package `komorebi-keybindings` (`--strict` with `strict`), whose
`share/kglobalaccel/*.desktop` (the static shortcuts) it installs in the system profile, with
the diagnostics in its `diagnostics.txt` and in the build log; and passes the file (a store
path), its format and mode, the chord timeout and the aliases to the daemon in `execStart`,
so that the daemon plans the file as the build did and runs the rest.
The VM tests run on machines built with it ([vm-tests.md](vm-tests.md)). Their headless node
runs the daemon in test sessions, with a template unit, `komorebi@NAME`, that runs the module's
@@ -1222,6 +1232,10 @@ module's unit.
| The keys of a daemon that was killed are given back | systemd: `ExecStopPost` runs `komorebic hotkeys release` | `nixos-module-eval` ("the unit releases the keys of the daemon when it stops"), `vm-restart-survival` | none |
| A daemon that is told to stop stays stopped, and the unit is not failed | systemd: the exit statuses of `Stop` (0) and of `SIGTERM` (130) are successes | `vm-module` | none |
| The daemon has the `PATH` of a terminal in the session | the unit's environment, with NixOS's default `PATH` turned off | `nixos-module-eval`, `vm-module` | none |
| The static shortcuts the module installs and the bindings its daemon runs are one plan of one file | framework path: the build and `execStart` get the same store file, format and mode, and `plan` is deterministic | `nixos-module-eval` (the key binding scenarios), `vm-keys-skhd`, `vm-keys-whkd`, `vm-keys-sxhkd` | none |
| Key bindings have one source, a format, and no skhd `.load` | evaluation error: assertions of the module | `nixos-module-eval` ("text and file together", "without a format", "skhd's .load") | none |
| `strict` fails the build on a warning or an error | `komorebic hotkeys compile --strict` exits non-zero before it writes anything, and the module's build of the key bindings passes `--strict` only when `strict` is set and fails when `komorebic` does | `strict_refuses_a_file_with_a_warning_and_writes_nothing`, `nixos-module-eval` ("with strict, the build of the key bindings runs komorebic hotkeys compile --strict", "without strict ... no --strict") | none |
| What `hotkeys compile` prints for every file of the corpus is what was reviewed | test: a diff against `nix/tests/keybindings.expected` | `keybindings-fixtures` | writing the file again |
| The VM suites run komorebi as the module installs it | framework path: the test nodes import the module, and `komorebi@NAME` runs its `execStart` | every VM suite | a suite's `node` can set `services.komorebi.enable = false` (`vm-render-smoke` does) |
## The parts
@@ -1940,6 +1954,9 @@ plan needs no engine. A failure to start is logged, and the window manager runs
the keys when the daemon and KWin go away.
- [`komorebi-hotkeys/tests`](../../komorebi-hotkeys/tests): the corpus test and the comparison
with `whkd-parser`.
- [`nix/tests/keybindings.nix`](../../nix/tests/keybindings.nix): `keybindings-fixtures`, and
[`nix/tests/vm/keys-corpus.py`](../../nix/tests/vm/keys-corpus.py), the corpus case `vm`
pressed in the three formats on a machine the module configured.
- [`nix/nixos-module.nix`](../../nix/nixos-module.nix): the NixOS module;
[`nix/tests/nixos-module.nix`](../../nix/tests/nixos-module.nix), its scenarios, evaluated in
real NixOS systems; and [`nix/tests/vm/suites/module`](../../nix/tests/vm/suites/module/test.py),
+2 -1
View File
@@ -748,7 +748,8 @@ and a komorebi process that was killed leaves its keys registered and dead until
released.
Which of the two is the default is still open for a decision. `PlanMode::default()` is the
one place it is set, and `komorebic hotkeys compile` takes its default from there.
one place it is set, and `komorebic hotkeys compile` and the daemon's `--keybindings-mode`
take their default from there; the NixOS module's `keybindings.mode` repeats it, `"engine"`.
## Why does the engine grab and give back keys, instead of using KDE's own key sequences?
+1
View File
@@ -372,6 +372,7 @@ named after the combo (`Alt+H`); an action's id is `["komorebi", "Alt+H", "komor
| `$XDG_CACHE_HOME/komorebi` (`~/.cache/komorebi`) | the palettes made from wallpapers, a file for each picture and variant, `NAME-HASH.base16.VARIANT.json` | never removed by komorebi; made again when the picture's path, size or time of last change differ |
| `$XDG_DATA_HOME/komorebi/komorebi.log.YYYY-MM-DD` | the daemon's log, with colors, which `komorebic log` follows | a file a day (the UTC date), never removed by komorebi |
| `$XDG_DATA_HOME/komorebi/komorebi_plaintext.log.YYYY-MM-DD` | the same log without colors | as above |
| `/run/current-system/sw/share/kglobalaccel/komorebi-*.desktop` | on NixOS, the static shortcuts of `services.komorebi.keybindings`, which the module compiles at build time into the package `komorebi-keybindings` | the system's: KWin reads them when the session starts |
| `$XDG_DATA_HOME/kglobalaccel/komorebi-*.desktop` | the static shortcuts `komorebic hotkeys compile` and `komorebic export-kde-shortcuts` write, each with `X-Komorebi-Generated=true` | replaced at every write: the files with that key are removed, and no other |
| `$KOMOREBI_CONFIG_HOME/{skhdrc,whkdrc,sxhkdrc}` | the key binding file `komorebic hotkeys compile` and the daemon read when they are given none (the first that exists), and the skhdrc of `export-kde-shortcuts` | the user's; the daemon reads it once, at start |
+4 -1
View File
@@ -41,7 +41,10 @@ A suite has two files:
`services.komorebi`).
- `test.py` is the test, a Python script for the NixOS test driver. It is
prefixed with `SCALE = <number>`, how many times slower than KVM the machine
is.
is. Suites that run the same test on different nodes set `script` to a file
they share instead, relative to their directory: `vm-keys-skhd`,
`vm-keys-whkd` and `vm-keys-sxhkd` run `../../keys-corpus.py`, each with the
key bindings of its format in its `node`.
## Nodes