feat(cli): komorebic

The daemon answers on its socket, but a person has no way to write a message on
it. komorebic is that way: each subcommand that asks something of the daemon is
one message, sent with komorebi-client, and a question's answer is printed.
komorebic is a separate program because the daemon takes no input but its
socket, so a key binding, a script and a terminal all drive it the same way.

It has what the daemon can answer so far: state, monitor-information, query,
retile and stop. Around them, start runs the komorebi on the PATH in the
background and passes it what follows a --, such as --fake-backend to try it
without a compositor; log follows the daemon's log, which the daemon now writes
to a file a day in LOG_DIR as well as to stdout; data-directory shows where the
socket is; completions prints a shell completion script. The hidden docgen
writes each subcommand's help to docs/cli, in fences that name their language
and wrapped at 100 columns whatever the width of the terminal, so that the pages
are the same wherever they are generated; just docgen runs it.

The user guide starts here: docs/index.md for KDE Plasma, and a page on running
komorebi. tests/cli.rs runs each subcommand against a socket the test serves in
place of the daemon. In the VM tests the guests get komorebic next to the
daemon, and vm-core-e2e reads the daemon's state with it (the windows it
manages, the one it focuses, after KWin restarts too) and stops it with
komorebic stop, which unloads the bridge and removes the socket.

In the VM test library, Kde.state asks again, a second (times the scale) after
an empty answer or a failed command, up to 10 times. The daemon drops a query
when it cannot take hold of the window manager within a second, and komorebic
then prints an empty line and succeeds; komorebic itself gives the daemon a
second to answer and fails when that is not enough. A daemon busy with the first
windows does either on a machine that is loaded or slow, and a suite that polled
the state died on JSONDecodeError. An answer that is not JSON still fails at
once.
This commit is contained in:
LGUG2Z committed 2026-10-28 07:20:37 -07:00
1 parent 88aa78b874
commit 6f657e53e3
36 files changed
+1320 -39

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
```text
Generate komorebic CLI completions for the target shell
Usage: completions <SHELL>
Arguments:
<SHELL>
[possible values: bash, elvish, fish, powershell, zsh]
Options:
-h, --help
Print help
```
+10
View File
@@ -0,0 +1,10 @@
```text
Show the path to komorebi's data directory, which has its socket
Usage: data-directory
Options:
-h, --help
Print help
```
+10
View File
@@ -0,0 +1,10 @@
```text
Tail komorebi's process logs (cancel with Ctrl-C)
Usage: log
Options:
-h, --help
Print help
```
+10
View File
@@ -0,0 +1,10 @@
```text
Show information about connected monitors
Usage: monitor-information
Options:
-h, --help
Print help
```
+15
View File
@@ -0,0 +1,15 @@
```text
Query the current window manager state
Usage: query <STATE_QUERY>
Arguments:
<STATE_QUERY>
[possible values: focused-monitor-index, focused-workspace-index, focused-container-index,
focused-window-index, focused-workspace-layout, focused-container-kind, version]
Options:
-h, --help
Print help
```
+10
View File
@@ -0,0 +1,10 @@
```text
Force the retiling of all managed windows
Usage: retile
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Start komorebi as a background process
Usage: start [-- <KOMOREBI_ARGS>...]
Arguments:
[KOMOREBI_ARGS]...
Arguments to pass to komorebi, after a `--`: `komorebic start -- --log-level debug`
Options:
-h, --help
Print help
```
+10
View File
@@ -0,0 +1,10 @@
```text
Show a JSON representation of the current window manager state
Usage: state
Options:
-h, --help
Print help
```
+10
View File
@@ -0,0 +1,10 @@
```text
Stop the komorebi process
Usage: stop
Options:
-h, --help
Print help
```
+12 -5
View File
@@ -223,6 +223,10 @@ status 0. `SIGINT` and `SIGTERM` do the same from `main.rs`, with the exit statu
- [`state`](../../komorebi/src/state.rs): the [`State`] a `State` message is answered with.
- [`komorebi-client`](../../komorebi-client/src/lib.rs): a library that writes messages on
the socket and reads the answers, for programs that talk to the daemon.
- [`komorebic`](../../komorebic/src/main.rs): the command line. A subcommand that asks
something of the daemon is one message, sent with `komorebi-client`; `start` runs the
daemon, `log` follows its log file in [`LOG_DIR`], and the hidden `docgen` writes
`docs/cli`.
- [`main.rs`](../../komorebi/src/main.rs): the daemon. It connects to KWin, or installs the
fake with `--fake-backend`, makes the window manager, which binds the socket, loads and
tiles the desktop, starts the threads that listen on the socket and handle events, and
@@ -325,10 +329,10 @@ A window is shown, and ends up on a tile:
## One message, end to end
A client asks for the state of the window manager:
`komorebic state` asks for the state of the window manager:
1. [`send_query`] connects to `komorebi.sock` in [`DATA_DIR`], writes
`{"type":"State"}`, and shuts down its side of the connection for writing.
1. `komorebic` calls [`send_query`], which connects to `komorebi.sock` in [`DATA_DIR`],
writes `{"type":"State"}`, and shuts down its side of the connection for writing.
2. The thread that [`listen_for_commands`] started accepts the connection and starts a
thread for it, which calls [`read_commands_uds`].
3. `read_commands_uds` reads the line, parses it into [`SocketMessage`]`::State`, and locks
@@ -339,7 +343,7 @@ A client asks for the state of the window manager:
5. The state is written to the connection as pretty-printed JSON, and the index of managed
windows is rebuilt, as after every message.
6. There are no more lines, so `read_commands_uds` returns and the connection is closed.
`send_query` has read to the end, and returns the JSON.
`send_query` has read to the end, and returns the JSON, which `komorebic` prints.
## Where to look in the code
@@ -358,6 +362,8 @@ A client asks for the state of the window manager:
each message does, and the tests that send messages through a real socket.
- [`komorebi-client/src/lib.rs`](../../komorebi-client/src/lib.rs): the client side of the
socket.
- [`komorebic/src/main.rs`](../../komorebic/src/main.rs): the subcommands, and
[`komorebic/tests/cli.rs`](../../komorebic/tests/cli.rs), what each writes on the socket.
- [`komorebi/src/kwin/mod.rs`](../../komorebi/src/kwin/mod.rs): the KWin backend, its D-Bus
service and the held call.
- [`komorebi/src/kwin/state.rs`](../../komorebi/src/kwin/state.rs): the table, with the
@@ -369,7 +375,7 @@ A client asks for the state of the window manager:
- [`nix/tests/vm/suites/kwin-events`](../../nix/tests/vm/suites/kwin-events/test.py): the
events of a real KWin, through the daemon.
- [`nix/tests/vm/suites/core-e2e`](../../nix/tests/vm/suites/core-e2e/test.py): the daemon
tiling a real KWin, checked against what KWin has.
tiling a real KWin, checked against what KWin has, and read and stopped with `komorebic`.
- [`nix/tests/vm/suites/kwin-restart`](../../nix/tests/vm/suites/kwin-restart/test.py): KWin
restarting under the daemon.
- [`komorebi/tests/wm_events.rs`](../../komorebi/tests/wm_events.rs): the window manager
@@ -411,6 +417,7 @@ A client asks for the state of the window manager:
[`bridge.test.js`]: ../../komorebi/src/kwin/bridge.test.js
[`fixtures`]: ../../komorebi/src/kwin/fixtures
[`DATA_DIR`]: ../../komorebi/src/lib.rs
[`LOG_DIR`]: ../../komorebi/src/lib.rs
[`SocketMessage`]: ../../komorebi/src/core/mod.rs
[`StateQuery`]: ../../komorebi/src/core/mod.rs
[`State`]: ../../komorebi/src/state.rs
+7
View File
@@ -164,3 +164,10 @@ an action is the job of another program, which runs a command that writes a mess
socket. This is the architecture that bspwm made popular on Linux and yabai on macOS, and
the one komorebi has on Windows and on macOS
([the design notes of komorebi for Mac](https://github.com/LGUG2Z/komorebi-for-mac/blob/master/docs/design.md)).
## Why is `komorebic` a separate program?
Because the daemon takes no input but its socket. `komorebic` turns a command line into one
message on the socket and, for a question, prints the answer. A key binding, a script and a
person at a terminal all drive komorebi the same way, by running `komorebic` (the design
notes of komorebi for Mac, linked above).
+11 -6
View File
@@ -144,9 +144,11 @@ What komorebi calls:
|---|---|---|
| `$XDG_RUNTIME_DIR/komorebi/bridge.js` | the script KWin loads, with its configuration (the D-Bus names and the hold time of `Poll`) on its first line | written at every start; the directory is removed at logout |
| `$XDG_RUNTIME_DIR/komorebi/komorebi.sock` | the command socket | bound once the daemon is connected to KWin, after a file left there is removed; removed when the daemon stops |
| `$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 |
Without `XDG_RUNTIME_DIR` the directory is `komorebi` in the local data directory instead
(see [`XDG_DATA_HOME`](#xdg_data_home)).
Without `XDG_RUNTIME_DIR` the bridge and the socket are in `komorebi` in the local data
directory instead, with the logs (see [`XDG_DATA_HOME`](#xdg_data_home)).
## Environment variables
@@ -163,8 +165,10 @@ the `komorebi` directory in it, and binds its command socket there.
### `XDG_DATA_HOME`
Read only when `XDG_RUNTIME_DIR` is not set: the bridge and the socket then go to
`$XDG_DATA_HOME/komorebi` (`~/.local/share/komorebi` if `XDG_DATA_HOME` is not set either).
The logs are written to `$XDG_DATA_HOME/komorebi` (`~/.local/share/komorebi` if
`XDG_DATA_HOME` is not set), which the daemon makes before anything else: a home it cannot
write to stops it at once. When `XDG_RUNTIME_DIR` is not set, the bridge and the socket go
there too.
### `RUST_LOG`
@@ -178,8 +182,9 @@ Whether an error carries a backtrace. komorebi sets it to `1` when it is not set
### `NO_COLOR`
When set to anything but the empty string, the log has no ANSI colors, which is what a log
written to a file wants. The VM tests set it.
When set to anything but the empty string, the log the daemon prints on its standard output
has no ANSI colors, which is what standard output redirected to a file wants. The VM tests
set it. The log files are not affected: one has colors and the other none.
## The bridge's environment
+7 -2
View File
@@ -54,8 +54,8 @@ own Wayland socket), so a test can run several sessions side by side and none
touches another. A virtual KWin has no real output, so it cannot draw: it can
place windows and answer questions about them, but it cannot take a screenshot.
A third unit, `komorebi@NAME`, runs the daemon in a session, built from the
commit under test and installed on the node; it is not bound to KWin's unit, so
a test can restart KWin under a running daemon.
commit under test and installed on the node with `komorebic`; it is not bound to
KWin's unit, so a test can restart KWin under a running daemon.
KWin wants a DRM render node, which needs a GPU. The test driver gives every aarch64 guest one
`virtio-gpu-pci`; on x86_64 the node adds it, unless `komorebi.vm.renderNode` is false.
@@ -105,6 +105,11 @@ the run.
started, and `script_loaded()` asks KWin whether it runs the bridge.
`restart_kwin()` stops the session's KWin and starts a new one on the same
bus, as when the compositor of a running session crashes, and waits for it.
- `komorebic(*args)` runs `komorebic` in the session and returns what it
printed, failing the test if it fails. `state()` is the daemon's state as
`komorebic state` prints it, `managed(workspace)` the number of windows the
daemon has on a workspace of the first monitor, and `focused_title(workspace)`
the title of the window it has focused there.
- `daemon` reads the daemon's view of the desktop from that log, started with
`--log-level debug`: `daemon.events(log)` lists the window events it handled,
in order, `daemon.window_ids(log)` maps a window's title to the daemon's id
+94
View File
@@ -0,0 +1,94 @@
# komorebi for KDE
## Overview
`komorebi` is a tiling window manager for KDE Plasma on Wayland. It decides where each window
goes, and KWin, the window manager of Plasma, moves and draws the windows.
`komorebi` is a daemon that runs in the background, and it is controlled with a CLI,
`komorebic`. Every `komorebic` command that asks something of the daemon is a message on its
socket, so anything that can run a command can drive `komorebi`: a terminal, a script, or a
program that binds keys, which is how a key is given an action.
`komorebi` aims to make _as few modifications as possible_ to the operating system and desktop
environment by default. Users are free to make such modifications in their own configuration
files for `komorebi`, but these will always remain opt-in and off-by-default.
## How it fits together
_komorebi_ only responds to the events KWin reports about windows and to the messages it
receives on a dedicated socket. _komorebic_ is a CLI that writes messages on _komorebi_'s
socket. _komorebi_ doesn't handle any keyboard or mouse inputs: a program that binds keys,
such as the custom shortcuts in Plasma's System Settings, runs _komorebic_ commands.
```text
PROCESS SOCKET
key bindings --------> komorebic <------> komorebi
```
## Getting started
[Running komorebi](usage/running-komorebi.md) explains how to get the two programs, start and
stop the daemon, ask it what it is doing and read its log. The [CLI reference](cli/start.md)
has a page for every `komorebic` command, generated from its help.
## Community
There is a [Discord server](https://discord.gg/mGkn66PHkx) available for
`komorebi`-related discussion, help, troubleshooting etc.
There is a [YouTube
channel](https://www.youtube.com/channel/UCeai3-do-9O4MNy9_xjO6mg) where I post
`komorebi` development videos, feature previews and release overviews. Subscribing
to the channel (which is monetized as part of the YouTube Partner Program) and
watching videos is a really simple and passive way to contribute financially to
the development and maintenance of `komorebi`.
There is an [Awesome List](https://github.com/LGUG2Z/awesome-komorebi) which
showcases the many awesome projects that exist in the `komorebi` ecosystem.
## Licensing for Personal Use
`komorebi` is licensed under the [Komorebi 2.0.0 license](https://github.com/LGUG2Z/komorebi-license), which is a fork
of the [PolyForm Strict 1.0.0 license](https://polyformproject.org/licenses/strict/1.0.0). On a high level this means
that you are free to do whatever you want with `komorebi` for personal use other than redistribution, or distribution of
new works (i.e. hard-forks) based on the software.
Anyone is free to make their own fork of `komorebi` with changes intended either for personal use or for integration
back upstream via pull requests.
The [Komorebi 2.0.0 License](https://github.com/LGUG2Z/komorebi-license) does not permit any kind of commercial use (
i.e. using `komorebi` at work).
## Sponsorship for Personal Use
`komorebi` is a free and educational source project, and one that encourages you
to make charitable donations if you find the software to be useful and have the
financial means.
I encourage you to make a charitable donation to the [Palestine Children's
Relief Fund](https://pcrf1.app.neoncrm.com/forms/gaza-recovery) or to contribute
to a [Gaza Funds campaign](https://gazafunds.com) before you consider sponsoring
me on GitHub.
[GitHub Sponsors is enabled for this
project](https://github.com/sponsors/LGUG2Z). Sponsors can claim custom roles on
the Discord server, get shout-outs at the end of _komorebi_-related videos on
YouTube, and gain the ability to submit feature requests on the issue tracker.
If you would like to tip or sponsor the project but are unable to use GitHub
Sponsors, you may also sponsor through [Ko-fi](https://ko-fi.com/lgug2z), or
make an anonymous Bitcoin donation to `bc1qv73wzspc77k46uty4vp85x8sdp24mphvm58f6q`.
## Licensing for Commercial Use
A dedicated Individual Commercial Use License is available for those who want to
use `komorebi` at work.
The Individual Commercial Use License adds “Commercial Use” as a “Permitted Use”
for the licensed individual only, for the duration of a valid paid license
subscription only. All provisions and restrictions enumerated in the [Komorebi
License](https://github.com/LGUG2Z/komorebi-license) continue to apply.
More information, pricing and purchase links for Individual Commercial Use
Licenses [can be found here](https://lgug2z.com/software/komorebi).
+98
View File
@@ -0,0 +1,98 @@
# Running komorebi
`komorebi` is the daemon that tiles your windows, and `komorebic` is the command line you
control it with. This page covers starting and stopping the daemon, asking it what it is
doing, and reading its log.
## Getting the two programs
On Linux, the flake's default package has both: in a checkout of the repository,
`nix build` leaves them in `result/bin`, and `nix profile install .` puts them on your
`PATH`. Without nix, build them with the Rust toolchain that `rust-toolchain.toml`
selects:
```sh
cargo build --release --locked
export PATH="$PWD/target/release:$PATH"
```
## Starting and stopping
[`komorebic start`](../cli/start.md) runs the `komorebi` on your `PATH` in the background,
and checks three seconds later that it is running. It tries three times. If `komorebi` has
not started by then, `komorebic start` runs it once more in the foreground and prints what
it wrote on its standard error, which explains why it did not start. When a `komorebi` is
running already, `komorebic start` does nothing.
`komorebi` manages the windows of the Plasma Wayland session it is started in: it connects
to KWin on the session bus and loads a script into it, so start it from a terminal in that
session. Outside a Plasma session it exits with an error that says what is missing, which
`komorebic start` prints.
Everything after a `--` is passed to `komorebi`. `--fake-backend` runs it against an
in-memory desktop with one monitor and no windows instead of KWin, which is a way to try the
daemon and `komorebic` without a compositor:
```sh
komorebic start
komorebic start -- --log-level debug
komorebic start -- --fake-backend
```
[`komorebic stop`](../cli/stop.md) tells the daemon to stop. It asks KWin to unload its
script, removes its socket and exits. Stopping the process with `SIGINT` or `SIGTERM` does
the same.
## Asking komorebi what it is doing
The daemon answers questions on its socket, and these commands print the answers:
- [`komorebic state`](../cli/state.md): every monitor, with its workspaces, their
containers and the windows in them, as JSON.
- [`komorebic monitor-information`](../cli/monitor-information.md): the id, the name and
the bounds of every monitor, as JSON.
- [`komorebic query`](../cli/query.md): one value, the answer to one question: the index of
the focused monitor, workspace, container or window, the layout of the focused workspace,
whether the focused container is a single window or a stack, or the version of the
daemon.
```sh
komorebic query focused-workspace-index
komorebic state | jq '.monitors.elements[0].workspaces.elements[0].containers.elements | length'
```
[`komorebic retile`](../cli/retile.md) tiles the windows of every monitor again, which puts
a window that was moved by hand back on its tile.
When the daemon is not running, these commands fail: there is no socket to write to.
## The socket and the data directory
The daemon listens on `komorebi.sock` in its data directory, `$XDG_RUNTIME_DIR/komorebi`
(the local data directory, `~/.local/share/komorebi`, when there is no runtime directory).
[`komorebic data-directory`](../cli/data-directory.md) prints the directory, if it exists.
## The log
The daemon logs to its standard output and to a file a day in `~/.local/share/komorebi`
(`$XDG_DATA_HOME/komorebi` when that is set): `komorebi.log.YYYY-MM-DD`, with colors, and
`komorebi_plaintext.log.YYYY-MM-DD`, without. The day is the UTC date.
[`komorebic log`](../cli/log.md) follows the file of the current day, with colors, until
you press Ctrl-C. The `--log-level` of `komorebi` sets how much is logged: `error`, `warn`,
`info` (the default), `debug` or `trace`.
## Shell completions
[`komorebic completions`](../cli/completions.md) prints a completion script for bash,
elvish, fish, PowerShell or zsh:
```sh
komorebic completions fish > ~/.config/fish/completions/komorebic.fish
komorebic completions bash > ~/.local/share/bash-completion/completions/komorebic
```
## Every command
[`docs/cli`](../cli/start.md) has a page for every `komorebic` command, generated from its
help with `just docgen`.