feat(wm): transparency for the windows without the focus

The window in front of every container is see-through, unless its container has
the focus on the focused monitor, so that the window being worked in stands out.
The opacity of a window is a property KWin has: komorebi sets it through the
bridge, as a fraction of 255, and KWin draws the window so. The window manager
keeps the opacity it gave each window and, after every event and message, sends
only the difference, makes a window opaque again when it should no longer be
see-through, and makes every one opaque when it stops. Windows an ignore rule
covers, and workspaces that do not tile, are left as they are.

The patched border effect already draws a window again when its opacity changes,
so the border follows it. komorebic gets transparency, transparency-alpha and
toggle-transparency, and the state of the daemon says what the settings are.
vm-features checks the pixels in the middle of a focused window and of one that
is not.

A monocled window is opaque on the focused monitor and see-through on another.
komorebi.json takes transparency, transparency_alpha and
transparency_ignore_rules.
This commit is contained in:
LGUG2Z committed 2026-10-28 07:20:49 -07:00
1 parent abfa8c6a5c
commit fa1e822e44
36 files changed
+974 -30

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
```text
Toggle transparency for unfocused windows
Usage: toggle-transparency
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Set the alpha value for unfocused window transparency
Usage: transparency-alpha <ALPHA>
Arguments:
<ALPHA>
Alpha
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Enable or disable transparency for unfocused windows
Usage: transparency <BOOLEAN_STATE>
Arguments:
<BOOLEAN_STATE>
[possible values: enable, disable]
Options:
-h, --help
Print help
```
+36 -1
View File
@@ -70,6 +70,8 @@ grows with the code: each part of the daemon that is added has its place here.
- **Look**: how the compositor is asked to dress the windows, which it draws ([`Look`]):
a border, with its width, its corner radius and two colors, and the animation of windows going
to their places, with its duration and its easing curve.
- **Opacity**: how opaque a window is drawn, 0 to 255, a property of the window in the compositor,
which [`transparency_manager`] sets for the windows that do not have the focus.
- **Effect**: a plugin of the compositor that changes how windows are drawn. KDE Rounded Corners
is the effect that draws the border, and Geometry Change the one that animates windows.
- **Compositor**: the program that owns the screen and the windows. On KDE Plasma it is
@@ -822,6 +824,25 @@ 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.
## Transparency
The opacity of a window is a property KWin has, so komorebi sets it ([`Backend::set_opacity`],
which the KWin backend sends the bridge as an `opacity` command: `alpha / 255`) and the compositor
draws the window so. [`transparency_manager`] holds the settings, as statics that `Transparency`,
`ToggleTransparency` and `TransparencyAlpha` set and the `transparency` and `transparency_alpha`
keys of the file give a value, and the rules for the ignored windows (`TRANSPARENCY_BLACKLIST`, set
by the `transparency_ignore_rules` of the file). [`transparency_manager::apply`] is called
before the first layout and after every event and every message: it works out
[`transparency_manager::transparent_windows`], on the workspace each monitor shows (the window in
front in every container, unless the container has the focus on the focused monitor; a monocled
window only on a monitor that is not the focused one; none on a workspace that does not tile; none
that a rule ignores), and sends the backend only what differs
from what the window manager kept in [`WindowManager::opacity_applied`]. A window that should not
be see-through any more is made opaque, and with transparency off every window is. When komorebi
stops, [`transparency_manager::restore`] makes every window it changed opaque again. The border
effect draws a window from a texture that has its opacity in it, and the build komorebi installs
draws it again when the opacity changes ([PLATFORM.md](PLATFORM.md#the-patches)).
## The NixOS module
The flake exports one module under two names, `nixosModules.default` and
@@ -918,6 +939,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.
- [`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,
its settings and the state komorebi keeps of it.
- [`process_command`](../../komorebi/src/process_command.rs): the thread that listens on the
@@ -1067,6 +1090,10 @@ the fake. The window manager is its only caller, through [`backend`]. The contra
| A command that changes a stack is carried out with the animation off, and the animation is on again after it | framework path: the arms of [`WindowManager::process_command`] for the stack messages swap `ANIMATION_ENABLED_GLOBAL` for false and put the value back | `the_animation_is_on_again_after_a_command_that_changes_a_stack` | none |
| The `animation` key of the file is the animation settings, and a file without it leaves them | framework path: `StaticConfig::apply_globals` sets them only when the key is there, and `duration` and `style` only when the key has one | `the_animation_key_of_the_file_is_the_animation_settings` | none |
| 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 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 effect komorebi loaded is unloaded, and the user's settings of it are put back, when komorebi stops using it or exits | framework path: the effect's state unloads what komorebi loaded, and [`Kwinrc`] puts the group back | `one_group_can_be_put_back_while_the_others_stay_changed`, `vm-look` | `SIGKILL`: the next run puts the settings back when it stops |
| Queries never block on the compositor | convention only | none | the KWin backend's `cursor_pos` waits up to 250 ms |
| Only the backend module reaches the compositor | convention only | none | none |
@@ -1202,7 +1229,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/border_colours.rs`](../../komorebi/tests/border_colours.rs) and
the stack commands that turn it off; [`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
[`komorebi/tests/borders_off.rs`](../../komorebi/tests/borders_off.rs), the color of each
window's border, and none with borders off;
[`nix/tests/vm/suites/look`](../../nix/tests/vm/suites/look/test.py), the border in a real
@@ -1293,6 +1322,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
[`transparency_manager`]: ../../komorebi/src/transparency_manager.rs
[`transparency_manager::apply`]: ../../komorebi/src/transparency_manager.rs
[`transparency_manager::transparent_windows`]: ../../komorebi/src/transparency_manager.rs
[`transparency_manager::restore`]: ../../komorebi/src/transparency_manager.rs
[`Backend::set_opacity`]: ../../komorebi/src/backend/mod.rs
[`WindowManager::opacity_applied`]: ../../komorebi/src/window_manager.rs
[`animation::movement_animation`]: ../../komorebi/src/animation/mod.rs
[`animation::movement_style`]: ../../komorebi/src/animation/mod.rs
[`AnimationStyle::qt_curve`]: ../../komorebi/src/core/animation.rs
+9
View File
@@ -460,6 +460,15 @@ one of Qt's curves, and is drawn as an ease out, the kind of curve a window movi
wants. The stock Geometry Change has one curve, an exponential ease out, so komorebi's build of
it reads a `Curve` setting ([PLATFORM.md](PLATFORM.md#the-patches)).
## Why does the window manager keep the opacity it gave each window?
So that the backend is told only what changed. `transparency_manager::apply`
([`transparency_manager.rs`](../../komorebi/src/transparency_manager.rs)) is called after every
event and every message, and most of them change no window's opacity: the window manager keeps
the opacity it gave each window that is not opaque (`WindowManager::opacity_applied`), sends the
difference, makes a window opaque again when it should no longer be see-through (and only if it is
still there), and makes every one opaque when it stops.
## Why are the effects patched?
Because the stock effects lack what komorebi needs of them. Each patch leaves the effect
+4
View File
@@ -345,6 +345,10 @@ What the KWin scripting API offers a script, and what it does not, at time of wr
uses, which `tsc` checks it against with ECMAScript 2016's library and nothing else. Node and
TypeScript are needed only for those checks: in the session the bridge needs KWin alone.
- A window's `opacity` is a number from 0 to 1 that a script may set: `Window.opacity` is KWin's
own property, so komorebi sets the opacity of a window by setting it, and the effect that
draws the border has to draw the window again when it changes
([The patches](#the-patches)).
- `callDBus` sends a JavaScript number as a 32-bit integer, and a call whose arguments do not
match the method's signature fails without a word. The bridge sends every argument as a
JSON string.
+4 -2
View File
@@ -59,8 +59,10 @@ explains the files of rules for particular applications it can name.
[Quickstart and autostart](usage/quickstart-and-autostart.md) explains how to write an example
configuration, how to start komorebi with Plasma without the module, and how to replace the
configuration of a running daemon.
[Borders](usage/borders.md) explains how komorebi has KWin draw a border around each window, and
[Animation](usage/animation.md) how it has KWin animate the windows going to their places.
[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.
[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.
+11
View File
@@ -120,6 +120,17 @@ runs.
settings as they are, and one that has it and leaves out `duration` or `style` leaves that one as it
is; a value given for every kind of animation takes the settings of single kinds away.
### Transparency
| Key | Default | What it does |
|---|---|---|
| `transparency` | `false` | Whether the windows that do not have the focus are see-through |
| `transparency_alpha` | `200` | How opaque they are, from 0 to 255 |
| `transparency_ignore_rules` | none | Rules for the windows that are never see-through |
[Transparency](transparency.md) explains which windows are see-through. `transparency_ignore_rules`
is a list of rules, which [Rules](#rules) describes, and has no command.
### Rules
| Key | What it does |
+63
View File
@@ -0,0 +1,63 @@
# Transparency
komorebi can make the windows that do not have the focus see-through, so that the one you are
working in stands out. It does not draw anything itself: the opacity of a window is a property
KWin has, which komorebi sets. Transparency is off by default.
## Turning it on
[`komorebic transparency`](../cli/transparency.md) turns transparency on or off,
[`komorebic toggle-transparency`](../cli/toggle-transparency.md) switches it, and
[`komorebic transparency-alpha`](../cli/transparency-alpha.md) sets how opaque a see-through window
is, from 0 (not there at all) to 255 (not see-through): 200 by default.
```sh
komorebic transparency enable
komorebic transparency-alpha 150
komorebic toggle-transparency
```
## In komorebi.json
The same settings are keys of [`komorebi.json`](configuration.md#transparency): `transparency`,
`transparency_alpha` and `transparency_ignore_rules`, a list of rules, as [Rules](rules.md)
explains them, for the windows that are never see-through.
```json
{
"transparency": true,
"transparency_alpha": 150,
"transparency_ignore_rules": [
{ "kind": "Exe", "id": "mpv", "matching_strategy": "Equals" }
]
}
```
The file sets them when the daemon starts and when the file changes. A file that leaves out
`transparency` or `transparency_alpha` has the defaults, off and 200, so a change made with a
command does not survive the file changing. The ignore rules add up, as the other rules do.
## Which windows are see-through
On the workspace each monitor shows, the window in front in every container is see-through unless
its container has the focus on the focused monitor. A window on a monitor that is not the focused
one is see-through, whatever its container. On a workspace with a monocle the monocled window is
the only one that counts: it is opaque on the focused monitor and see-through on another. A
workspace that does not tile has no see-through windows, and neither does a window that a rule
keeps out of it: the rules are the `transparency_ignore_rules` of
[`komorebi.json`](configuration.md#transparency), which no command sets.
Windows that are not in front, such as the other windows of a stack, are not on the screen and
are left as they are. With transparency off, every window is opaque.
## What is put back
When komorebi exits, every window it made see-through is opaque again. A window that closes needs
nothing.
## The border
The border effect draws a window from a texture that has the window's opacity in it. The build
of the effect that the flake installs draws a window again when its opacity changes, so the border
and the window change together. With the stock effect a change of opacity alone does not show
until the window changes.