feat(wm): themes for the borders

A theme gives the borders their colors, in place of choosing the color of each
kind of window: a Catppuccin theme, a Base16 theme or a palette of one's own,
with the color it gives each of the six kinds of border and its default for the
ones it does not name. The Theme message puts the six colors where the border
manager keeps them and asks for the look again. The palette of a picture is made
by the same generator as komorebi for Windows, which takes seconds for a large
picture, so each one is kept in the cache directory, in a file named for the
picture, a hash of its path, size and time of last change, and the variant: the
palette of a picture painted over, or of one of the same name in another folder,
is made again and not mistaken.

The themes come from komorebi-themes at the revision komorebi-layouts is at. It
pulls egui for its types, which the license list, the sources and the advisories
of deny.toml now have to allow, and the colors the border manager keeps are the
themes' own again.

A subscriber that asks for the changes of the state only is sent a Theme message
all the same: the colors of the borders are not part of the state, so a theme
never changes it, and the subscriber would not hear of the colors at all.

komorebi.json takes border_colours, a color for each kind of window as red,
green and blue or as a hex color, and a theme, which wins over them.
This commit is contained in:
LGUG2Z committed 2026-10-28 07:20:49 -07:00
1 parent 9a0693f5d1
commit e6ddb5a7c9
27 files changed
+7051 -154

No files matched your search

+38 -7
View File
@@ -363,12 +363,13 @@ notified.
its socket, writes the JSON and closes the connection, all on the thread that handled the
event or the message, with the window manager still locked. A subscriber with
`filter_state_changes` is skipped when the state did not change, unless the notification is
about a window being shown or a subscriber being added. A subscriber that cannot be
connected to is removed, with its socket file, after the loop. Writing to a subscriber that
was connected to has no timeout, and a failed write returns an error from the call that
handled the event or the message. A subscriber that stops reading therefore holds the window
manager, and with it the thread that handles events: the backend's events wait in the
channel of [`window_manager_event_listener`], and past 20 the backend drops them.
about a window being shown, a subscriber being added, a theme being set (the colors of the
borders are not part of the state) or the configuration being reloaded. A subscriber that
cannot be connected to is removed, with its socket file, after the loop. Writing to a
subscriber that was connected to has no timeout, and a failed write returns an error from the
call that handled the event or the message. A subscriber that stops reading therefore holds
the window manager, and with it the thread that handles events: the backend's events wait in
the channel of [`window_manager_event_listener`], and past 20 the backend drops them.
When the daemon stops ([`WindowManager::stop`], or `SIGINT` and `SIGTERM` in `main.rs`), it
connects to each subscriber and shuts the connection down without writing anything.
@@ -824,6 +825,23 @@ once, when the effect is the stock one: every border is then the focused or the
the look.
[PLATFORM.md](PLATFORM.md#kwin-effects) has the effect, its settings and what was measured.
## Themes
A theme gives the borders their colors. The `Theme` message carries a [`KomorebiTheme`]: a
Catppuccin theme, a Base16 theme or a Base16 palette, each with the color it gives to each of the
six kinds of border, and a default for the ones it does not name.
[`theme_manager::send_notification`] puts the six colors into the statics of [`border_manager`],
keeps the theme as [`theme_manager::CURRENT_THEME`] and asks the backend for the look again, on
the thread that handled the message; [`border_manager::update_colours`] hands them to the border
effect with the next event or message. The palette of a picture is made by
`komorebi-themes` ([`komorebi_themes::generate_base16_palette`]), which takes seconds, so
[`theme_manager::wallpaper_palette`] keeps each palette it makes in `komorebi` in the user's cache
directory, in a file named by [`theme_manager::palette_file`] for the picture, a hash of its path,
size and time of last change, and the variant: a picture that was painted over, or one of the same
name in another folder, has a palette of its own. A picture it cannot make a palette from (it
cannot be read, or has fewer than eight colors) has none, and the borders keep their colors.
[DESIGN.md](DESIGN.md#why-is-a-palette-kept-by-the-hash-of-its-picture) has the reason.
## Transparency
The opacity of a window is a property KWin has, so komorebi sets it ([`Backend::set_opacity`],
@@ -953,6 +971,8 @@ module's unit.
- [`border_manager`](../../komorebi/src/border_manager/mod.rs): the border settings, and the
[`Look`] they make, which it asks the backend for.
- [`animation`](../../komorebi/src/animation/mod.rs): the animation settings, which the look has.
- [`theme_manager`](../../komorebi/src/theme_manager.rs): a theme's colors for the borders, and the
palettes made from pictures.
- [`transparency_manager`](../../komorebi/src/transparency_manager.rs): which windows are
see-through, and the opacity they are given.
- [`kwin::effects`](../../komorebi/src/kwin/effects.rs): the KWin effect that draws the border,
@@ -1106,6 +1126,9 @@ the fake. The window manager is its only caller, through [`backend`]. The contra
| Every style is a curve Qt has | test: [`AnimationStyle::qt_curve`] is a `match` of every style, and the test checks each against its name without the "Ease" | `every_style_is_a_curve_qt_has`, the doctest of `qt_curve`, `vm-features` (section D: two curves are in different places at the same moment) | a cubic Bézier is an ease out |
| Only the windows the rules make see-through are, and only while transparency is on | framework path: [`transparency_manager::apply`] asks [`transparency_manager::transparent_windows`] and sends the difference from [`WindowManager::opacity_applied`] | `unfocused_windows_are_transparent_and_the_focused_one_is_not`, `turning_transparency_off_makes_everything_opaque_again`, `a_monocled_window_is_not_transparent`, `windows_the_rules_ignore_keep_their_opacity`, `vm-features` (section B) | none |
| The `transparency` keys of the file are the settings, and a key the file leaves out has the default | framework path: `StaticConfig::apply_globals` stores `transparency` and `transparency_alpha` whether the file has them or not, and adds the ignore rules to `TRANSPARENCY_BLACKLIST` | `the_transparency_keys_of_the_file_are_the_transparency_settings` | none |
| A theme gives every kind of border a color, the one it names or the theme's default | framework path: [`theme_manager::send_notification`] stores a color for each of the six kinds, from the theme's own defaults for the ones the message does not name | `a_named_theme_colours_every_kind_of_border` | none |
| The `border_colours` of the file are the border colors, and a theme in the file wins over them | framework path: `StaticConfig::apply_globals` stores each color the file names, and then calls [`theme_manager::send_notification`] for the `theme` | `the_colour_and_theme_keys_of_the_file_are_the_border_colours` | none |
| A picture's palette is made again when the picture changes, and is not mistaken for another picture's | framework path: [`theme_manager::palette_file`] names the file by a hash of the picture's path, size and time of last change, and the variant | the doctest of `palette_file` | the hash is not a proof of identity |
| A window komorebi made see-through is opaque again when komorebi exits | framework path: [`WindowManager::stop`] and `main.rs` call [`transparency_manager::restore`] | `what_komorebi_made_see_through_is_opaque_again_when_it_exits` | `SIGKILL`: the windows stay as they were drawn |
| What the backend sends for an opacity is what the bridge sets | tests: the `opacity` command of [`fixtures`] is what the backend's test sends and what the bridge's test answers with, checking the window's `opacity` | `the_commands_of_a_session_go_to_the_bridge_as_the_bridges_tests_answer_it`, `what the bridge sends for a session is what the daemon's tests read`, `a window is given the opacity it is asked for, and one KWin has not got is given back` | none |
| The user's focus policy is put back when focus follows mouse is turned off and when komorebi exits | framework path: [`Kwinrc`] records the first value of each key it sets, `set_focus_follows_mouse(false)` puts the two keys back with [`Kwinrc::restore_keys`] and `shutdown` puts back all | `one_key_can_be_put_back_while_the_others_in_its_group_stay_changed`, `what_komorebi_changed_is_put_back_exactly_and_what_it_added_is_removed`, `vm-focus-follows-mouse` | `SIGKILL`: the next run puts it back when it stops |
@@ -1247,7 +1270,9 @@ A window is shown, and ends up on a tile:
[`komorebi/tests/animation.rs`](../../komorebi/tests/animation.rs), the messages that set the
animation, [`komorebi/tests/animation_config.rs`](../../komorebi/tests/animation_config.rs), its
key of the file, and [`komorebi/tests/animation_stack.rs`](../../komorebi/tests/animation_stack.rs),
the stack commands that turn it off; [`komorebi/tests/focus_follows_mouse.rs`](../../komorebi/tests/focus_follows_mouse.rs),
the stack commands that turn it off; [`komorebi/tests/themes.rs`](../../komorebi/tests/themes.rs),
a named theme and [`komorebi/tests/theme_config.rs`](../../komorebi/tests/theme_config.rs), the
colors and the theme of the file; [`komorebi/tests/focus_follows_mouse.rs`](../../komorebi/tests/focus_follows_mouse.rs),
focus follows mouse; [`komorebi/tests/transparency.rs`](../../komorebi/tests/transparency.rs)
and [`komorebi/tests/transparency_config.rs`](../../komorebi/tests/transparency_config.rs),
transparency and its keys of the file; [`komorebi/tests/border_colours.rs`](../../komorebi/tests/border_colours.rs) and
@@ -1343,6 +1368,12 @@ A window is shown, and ends up on a tile:
[`border_manager::send_notification`]: ../../komorebi/src/border_manager/mod.rs
[`BORDER_DRAWN`]: ../../komorebi/src/border_manager/mod.rs
[`animation`]: ../../komorebi/src/animation/mod.rs
[`KomorebiTheme`]: ../../komorebi/src/core/mod.rs
[`theme_manager::send_notification`]: ../../komorebi/src/theme_manager.rs
[`theme_manager::CURRENT_THEME`]: ../../komorebi/src/theme_manager.rs
[`theme_manager::wallpaper_palette`]: ../../komorebi/src/theme_manager.rs
[`theme_manager::palette_file`]: ../../komorebi/src/theme_manager.rs
[`komorebi_themes::generate_base16_palette`]: https://github.com/LGUG2Z/komorebi/tree/f08aa55511d77ca56ab0e789efabeb0a237a463e/komorebi-themes
[`WindowManager::focus_follows_mouse`]: ../../komorebi/src/window_manager.rs
[`Backend::set_focus_follows_mouse`]: ../../komorebi/src/backend/mod.rs
[`Kwinrc::restore_keys`]: ../../komorebi/src/kwin/kwinrc.rs
+9
View File
@@ -481,6 +481,15 @@ which is KWin's setting for no delay between the pointer entering a window and t
given the focus; why 0 and not the delay KWin has by default is not written down, and needs a
reason.
## Why is a palette kept by the hash of its picture?
Because the name of a picture alone does not say which picture it is: two folders can each have a
`wallpaper.png`, and one wallpaper can be painted over. A palette takes seconds to make for a
large picture, so it is kept, in the user's cache directory (`~/.cache/komorebi`), where it
outlives a login; the runtime directory, where the socket is, does not. The file is named after the
picture, a hash of its path, size and time of last change, and the variant. A palette that cannot
be kept is made again the next time. komorebi for Windows keeps them by file name alone.
## Why are the effects patched?
Because the stock effects lack what komorebi needs of them. Each patch leaves the effect
+3 -2
View File
@@ -62,8 +62,9 @@ configuration of a running daemon.
[Borders](usage/borders.md) explains how komorebi has KWin draw a border around each window,
[Animation](usage/animation.md) how it has KWin animate the windows going to their places, and
[Transparency](usage/transparency.md) how it makes the windows that do not have the focus
see-through, and [Focus follows mouse](usage/focus-follows-mouse.md) how it has KWin give the focus
to the window under the pointer.
see-through, [Focus follows mouse](usage/focus-follows-mouse.md) how it has KWin give the focus
to the window under the pointer, and [Themes](usage/themes.md) how a theme gives the borders their
colors.
[Subscribing to notifications](usage/subscribing-to-notifications.md) explains how a program
such as a status bar follows what komorebi does. The [CLI reference](cli/start.md) has a page
for every `komorebic` command, generated from its help.
+13
View File
@@ -90,6 +90,19 @@ starts and when the file changes; a key it leaves out leaves the setting as it i
}
```
`border_colours` sets the colors of the kinds of window above, each as red, green and blue or as
a hex color, and leaves out the kinds it does not name. A [theme](themes.md), which the
`theme` key of the file gives too, replaces them.
```json
{
"border_colours": {
"single": { "r": 255, "g": 128, "b": 0 },
"unfocused": "#404040"
}
}
```
## What is put back
The effect keeps its settings in the user's `kwinrc`, in the group `[Round-Corners]`. komorebi
+5 -2
View File
@@ -38,8 +38,9 @@ trailing commas.
Reading the file again sets every setting of the daemon from it, and a key the file leaves out is
the default of the setting: a `resize-delta` given with a command is gone when the file changes.
These stay as they were when the file leaves them out: `default_workspace_padding`,
`default_container_padding`, `display_index_preferences`, the four settings of the borders and the
animation, when the file has no `animation`. The rules add up, as
`default_container_padding`, `display_index_preferences`, the four settings of the borders, each
color of `border_colours` the file does not name, the theme and the animation, when the file has no
`animation`. The rules add up, as
[Rules](#rules) says. A workspace the file lists gets its name, padding, offsets and rules from
its entry, and its layout when the entry names one; a workspace the file does not list is left as
it is.
@@ -101,6 +102,8 @@ can have values of their own, which come before the default.
| `border_width` | `10` | How thick the border is, in pixels (`active_window_border_width`) |
| `border_offset` | `0` | How much more room than the width the layout leaves around each window (`active_window_border_offset`) |
| `border_radius` | `10` | How round the corners of the border are, in pixels |
| `border_colours` | see [Borders](borders.md#colors) | The color of the border of each kind of window: `single`, `stack`, `monocle`, `floating`, `unfocused` and `unfocused_locked`, each as `{ "r": 66, "g": 165, "b": 245 }` or `"#42A5F5"` (`active_window_border_colours`). A theme replaces them |
| `theme` | none | A theme that gives every kind of border its color: a Catppuccin theme, a Base16 scheme or a palette of your own ([Themes](themes.md)). It wins over `border_colours` |
[Borders](borders.md) explains what the compositor draws and what the layout leaves room for.
`komorebic border`, `border-width` and `border-offset` change the first three while the daemon
+3 -2
View File
@@ -50,8 +50,9 @@ sent.
A subscriber can ask to be sent a notification only when the event or the message changed
the state, with the `filter_state_changes` option. It is still sent the notification of a
window that is shown, of every new subscription, so it receives the state as soon as it
subscribes, and of every reload of `komorebi.json`. `komorebic subscribe-socket` has no option for it; a program writes the message
on the daemon's socket itself:
subscribes, of a theme, which changes the colors of the borders and nothing in the state,
and of every reload of `komorebi.json`. `komorebic subscribe-socket` has no option for it; a
program writes the message on the daemon's socket itself:
```sh
printf '%s' '{"type":"AddSubscriberSocketWithOptions","content":["bar.sock",{"filter_state_changes":true}]}' |
+68
View File
@@ -0,0 +1,68 @@
# Themes
A theme gives the borders their colors. Instead of choosing the color of each kind of window with
[`komorebic border-colour`](../cli/border-colour.md), a program tells the daemon to take a theme,
and the six kinds of border (`single`, `stack`, `monocle`, `floating`, `unfocused` and
`unfocused-locked`) take the colors the theme gives them: a Catppuccin theme, a Base16 theme, or a
Base16 palette of your own.
There is no `komorebic` command for it: the daemon takes it from the `theme` key of
[`komorebi.json`](configuration.md#borders), or as a message on its socket, the `Theme` message,
which a program sends with [`komorebi-client`](../../komorebi-client/src/lib.rs) or a script writes
as a line of JSON.
```rust
use komorebi_client::SocketMessage;
use komorebi_client::send_message;
let theme: SocketMessage = r#"{
"type": "Theme",
"content": { "palette": "Catppuccin", "name": "Mocha" }
}"#
.parse()?;
send_message(&theme)?;
```
The key has the same fields as the message, and wins over `border_colours` of the file, which has
no effect while a theme is set:
```json
{
"theme": { "palette": "Catppuccin", "name": "Mocha" }
}
```
The file sets the theme when the daemon starts and when the file changes. A file without `theme`
leaves the one the daemon has.
## What a theme gives
`palette` is the kind of theme (`Catppuccin`, `Base16` or `Custom`), and `name` the theme: one of
Catppuccin's four, `Latte`, `Frappe`, `Macchiato` and `Mocha`, or one of the Base16 schemes
(`Custom` has a `colours` of the sixteen Base16 colors instead). A kind of border that the message
does not name takes the theme's default for it:
| Border | Catppuccin | Base16 |
|---|---|---|
| `single_border` | Blue | Base0D |
| `stack_border` | Green | Base0B |
| `monocle_border` | Pink | Base0F |
| `floating_border` | Yellow | Base09 |
| `unfocused_border` | Base | Base01 |
| `unfocused_locked_border` | Red | Base08 |
The message can name another color of the theme for any of them, as `"single_border": "Mauve"`
for Catppuccin or `"single_border": "Base0E"` for Base16.
A theme sets the colors that `border-colour` sets, and replaces them, and the colors set after it
replace the theme's. The theme is kept as the current one. The border has to be on and drawn by
the effect for any of it to show ([Borders](borders.md)).
## Palettes from a picture
The Base16 palette of a picture can be made from the picture itself: the same palette generator as
komorebi for Windows takes the picture's colors and gives a light or a dark variant. A palette
takes seconds to make for a large picture, so each one is kept in `$XDG_CACHE_HOME/komorebi`
(`~/.cache/komorebi`), in a file named for the picture, a hash of its path, size and time of last
change, and the variant. It is made again when the path, the size or the time of change differ. A
picture with fewer than eight colors has no palette.