feat(kwin): survive restarts of the daemon and KWin

kglobalaccel keeps the actions of a client that died, and their keys: a daemon
that is killed leaves its keys swallowed and running nothing until they are
unregistered. And kglobalaccel runs inside KWin, so a KWin that restarts forgets
every key komorebi registered. Neither should leave a user without keys.

kwin::hotkeys::release unregisters every action of the component, whatever
registered it, and komorebic hotkeys release runs it, with or without a daemon.
The NixOS module's unit runs it after the daemon stops (ExecStopPost), however
it stops, and a start already takes over what is left. The KWin backend's
NameOwnerChanged watch now also follows org.kde.kglobalaccel: when it has an
owner again, kwin::hotkeys::rebind loads the key bindings into the new one,
trying for 15 seconds.

Loading moves from the daemon's main into kwin::hotkeys::load, which keeps its
settings (Keybindings: file, format, plan mode, engine options), so that reload
can read the file again: the message ReloadHotkeys, komorebic hotkeys reload. A
new engine replaces the running one without unregistering its keys, and takes
them over as a start does, so the keys both files have stay grabbed. The message
HotkeysState answers with the engine's mode, the combos it holds and whether a
chain is pending (null without an engine); komorebic hotkeys state prints it
with the actions kglobalaccel has for the component. komorebic now depends on
komorebi for the two calls to kglobalaccel, and on serde_json for the state.

Tests: the socket messages without key bindings, state and release without a
session bus, reload without a daemon, and a nixos-module-eval check of
ExecStopPost. The VM test vm-restart-survival runs the module's unit in a Plasma
session: a key works, hotkeys state shows it; with the daemon stopped by SIGSTOP
the key runs nothing until hotkeys release gives it back; after SIGKILL the
unit's journal shows the release and the restarted daemon has the key; after the
KWin process is killed, the daemon registers the key with the new KWin; and a
reload of a changed file swaps the key.

vm-keys-engine asks the engine and does not sleep. A key that is not grabbed yet
reaches the focused window, which showed as a binding that does not run, so the
suite presses one once komorebic hotkeys state answers, which it does when the
engine has made the calls of its last event: for a mode, for a chord chain
beginning and ending, and for the keys of the application that takes the focus.
It waits for the old daemon to exit before it starts the next (a daemon started
meanwhile failed to load its KWin script), and activates a window until KWin has
it (KWin lists a window before it can have the focus). The last check reloads
the key bindings with komorebic hotkeys reload while wev has the focus and every
binding is for the terminal, a start with no key to grab.
This commit is contained in:
LGUG2Z committed 2026-10-28 07:39:49 -07:00
1 parent 47d3a471d7
commit 2f61b62276
25 files changed
+771 -150

No files matched your search

+23 -2
View File
@@ -1196,6 +1196,8 @@ With `services.komorebi.enable`, the module:
- runs `execStart` in it, with `Restart=on-failure`, the exit status of a `SIGTERM` (130)
counted as success, and a `PATH` of `/run/wrappers/bin`, `/etc/profiles/per-user/%u/bin` and
`/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.
The VM tests run on machines built with it ([vm-tests.md](vm-tests.md)). Their headless node
@@ -1217,6 +1219,7 @@ module's unit.
| The animation effect is installed with komorebi, and not loaded until komorebi asks | the module installs `effects.animation.package` when `effects.animation.enable` is set, and the package's metadata says `EnabledByDefault` false | `nixos-module-eval` ("the animation effect is installed in the system profile", "with the animation effect off, ..."), the `kwin-effect-geometry-change-komorebi-install` check, `vm-look` | `effects.animation.enable = false` |
| Every Plasma session starts komorebi, once KWin's service has started | systemd: the user unit is wanted by `plasma-workspace.target`, after `plasma-core.target` | `nixos-module-eval`, `vm-module` | `systemctl --user mask komorebi` |
| A daemon that fails or is killed is started again | systemd: `Restart=on-failure` | `vm-module` (`SIGKILL`) | none |
| 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 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) |
@@ -1687,7 +1690,19 @@ plan needs no engine. A failure to start is logged, and the window manager runs
unless the default mode wants them; the others are unregistered. The engine starts in the
default mode.
- **Stop**: every key is released and every action unregistered, from
`KWinBackend::shutdown`, which every way the daemon stops goes through.
`KWinBackend::shutdown`, which every way the daemon stops goes through. A daemon that is
killed cannot: `kwin::hotkeys::release` (`komorebic hotkeys release`, the module's
`ExecStopPost`) unregisters every action of the component, with or without a daemon.
- **Reload**: `kwin::hotkeys::load` reads the file, plans it and starts the engine, and keeps
its settings; `reload` (the message `ReloadHotkeys`, `komorebic hotkeys reload`) does it again.
A new engine replaces the running one without unregistering its keys first, and takes them
over as a start does.
- **KWin restarting**: kglobalaccel runs in KWin. The KWin backend's watch of
`NameOwnerChanged` also follows `org.kde.kglobalaccel`, and when it has an owner again,
`kwin::hotkeys::rebind` loads the key bindings into it, trying for 15 seconds.
- **State**: the message `HotkeysState` is answered with the engine's mode, the combos it
holds and whether a chain is pending, or `null` when no engine runs; `komorebic hotkeys
state` adds the actions kglobalaccel has for the component.
### What is guaranteed, and by what
@@ -1724,6 +1739,10 @@ plan needs no engine. A failure to start is logged, and the window manager runs
| After the prefix of a chain only its next keys and Escape are grabbed, until a key ends the chain or its deadline passes, and the keys of the mode come back then | test, of the calls; VM test | `a_chain_grabs_its_next_keys_until_its_deadline`, the `Engine::deadline` doctest, `vm-keys-engine` | none |
| The application of the focus is the one of the window KWin activated, a dialog included, and none once that window is gone | test | `the_focused_application_is_the_one_of_the_window_kwin_activated` | none |
| A per-application key is grabbed only while the focused application (or an alias of it) has an action for it, and reaches the application otherwise | test, of the calls; VM test | `a_scoped_key_is_grabbed_only_while_its_application_has_the_focus`, `vm-keys-engine` | none |
| A key of a daemon that stopped answering is given back by `hotkeys release`, and a new daemon registers it again | VM test | `vm-restart-survival` | none |
| After KWin restarts, the keys are registered with the new kglobalaccel | framework path: the KWin backend's name-owner watch calls `kwin::hotkeys::rebind`; VM test | `vm-restart-survival` | none |
| A reload reads the file again, and the keys both files have stay grabbed | framework path: `start` replaces an engine without unregistering, and `Registry::startup` takes over; VM test | `a_start_takes_over_the_keys_of_a_killed_komorebi_and_drops_the_rest`, `vm-restart-survival` | none |
| Without key bindings, the daemon shows no engine and refuses a reload | test | `without_key_bindings_there_is_no_engine_to_show_or_reload` | none |
| Holding a key runs its binding once | convention only: the transport listens to `globalShortcutPressed` and not to `globalShortcutRepeated` | none (measured in PLATFORM.md) | none |
## Where to look in the code
@@ -1916,7 +1935,9 @@ plan needs no engine. A failure to start is logged, and the window manager runs
- [`komorebi/src/kwin/hotkeys.rs`](../../komorebi/src/kwin/hotkeys.rs): the engine against
kglobalaccel, and
[`nix/tests/vm/suites/keys-engine`](../../nix/tests/vm/suites/keys-engine/test.py), keys
pressed in a real KWin with the daemon running.
pressed in a real KWin with the daemon running;
[`nix/tests/vm/suites/restart-survival`](../../nix/tests/vm/suites/restart-survival/test.py),
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/nixos-module.nix`](../../nix/nixos-module.nix): the NixOS module;
+10
View File
@@ -772,3 +772,13 @@ engine acts on the pressed signal only, so holding a key runs its binding once.
The engine itself does no I/O: it returns what to do, and the daemon does it. This entry
needs the reason for that split.
## Why does the unit release the keys after the daemon stops?
Because nothing else does when a daemon dies. kglobalaccel keeps the actions of a client
that was killed, and their keys with them: on KWin 6.8.1 (2026-10-27) a killed client's key
stayed swallowed, and its signal was sent to nobody, until the action was unregistered. A
daemon that stops on its own unregisters its keys, but one that crashes or is killed cannot,
and the next start may never come. So the NixOS module's unit runs `komorebic hotkeys
release` after the daemon stops, however it stops (`ExecStopPost`), and a start takes over
what is still registered.
+9 -4
View File
@@ -190,7 +190,11 @@ of the old KWin out of its layout, as if each had been closed: the bridge went w
nothing reports them closing. When the name has an owner again, komorebi loads the bridge into
the new KWin, trying again for up to 15 seconds while KWin is not ready for it, and the bridge
reports the new KWin's windows and outputs as it does at start. A window that opens in the new
KWin is tiled. In the spikes the bridge was loaded again 1.0 to 1.1 seconds after the name had
KWin is tiled. kglobalaccel runs in KWin, so the keys of the engine go with the old KWin:
komorebi watches `org.kde.kglobalaccel` the same way, and when it has an owner again, it reads
its key binding file again and registers the keys with the new one, trying for up to 15
seconds. The VM test `vm-restart-survival` kills the KWin of a Plasma session under the
daemon and presses a key afterwards. In the spikes the bridge was loaded again 1.0 to 1.1 seconds after the name had
an owner again; the VM test `vm-kwin-restart` restarts KWin twice under a running daemon.
#### What komorebi leaves behind
@@ -210,8 +214,9 @@ on, and the parking desktop with the hidden windows on it, until the next start
script and the socket, sends the windows on the parking desktop to the first workspace's desktop
and removes the desktop, and its stop puts the setting back (the backup in the runtime
directory keeps the user's value), or the session ends. It also leaves the keys of its engine
grabbed: they are swallowed, and run nothing, until the next start takes them over and unregisters
those its key bindings no longer have.
grabbed: they are swallowed, and run nothing, until `komorebic hotkeys release` unregisters them, or
the next start takes them over and unregisters those its key bindings no longer have. The NixOS
module's unit runs `komorebic hotkeys release` after the daemon stops, however it stops.
### A headless KWin
@@ -255,7 +260,7 @@ What komorebi calls:
|---|---|---|---|---|
| `org.kde.KWin` | `/Scripting` | `org.kde.kwin.Scripting` | `unloadScript(s)`, `loadScript(ss) -> i` | at start, and when KWin is back after a restart; `unloadScript` again at exit |
| `org.kde.KWin` | `/Scripting/Script<id>` | `org.kde.kwin.Script` | `run()` | after `loadScript` |
| `org.freedesktop.DBus` | `/org/freedesktop/DBus` | `org.freedesktop.DBus` | `AddMatch(s)`, for the signal `NameOwnerChanged` | at start, to see KWin leave the bus and come back |
| `org.freedesktop.DBus` | `/org/freedesktop/DBus` | `org.freedesktop.DBus` | `AddMatch(s)`, for the signal `NameOwnerChanged` | at start, to see KWin (`org.kde.KWin`, and `org.kde.kglobalaccel`, which it owns too) leave the bus and come back |
| `org.kde.kglobalaccel` | `/component/kwin` | `org.kde.kglobalaccel.Component` | `invokeShortcut(s)`, with `MoveMouseToFocus` | when the pointer follows the focus |
| `org.kde.KWin` | `/Effects` | `org.kde.kwin.Effects` | `isEffectSupported(s)`, `isEffectLoaded(s)`, `loadEffect(s)`, `unloadEffect(s)`, `reconfigureEffect(s)`, with `kwin4_effect_shapecorners` and `kwin4_effect_geometry_change` | when the look changes (the border is turned on, off or changed), and at exit |
| `org.kde.KWin` | `/org/komorebi/BorderColours` | `org.komorebi.BorderColours1` | `SetColours(asau)`: the UUID of each window and its color, `0xRRGGBB` | when the color of a window's border changes; the object is komorebi's build of the border effect ([The patches](#the-patches)) |