mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-30 20:24:09 +01:00
feat(kwin): focus follows mouse through KWin's focus policy
KWin has a focus policy that gives the focus to the window under the pointer, so komorebi asks for it and follows where the focus goes, as it does for any change of focus. Both implementations komorebi for Windows names are the same thing here. The KWin backend sets the focus policy and no delay in the user's kwinrc and has KWin read it, and puts the two keys back as the user had them when it is turned off and, with every other setting, when komorebi exits. The state of the daemon says whether it is on. komorebic gets focus-follows-mouse and toggle-focus-follows-mouse. The session node gets a pointer that a test drives from inside the guest: the program komorebi-pointer makes an absolute device with uinput, and komorebi_vm.Pointer sends it commands. vm-focus-follows-mouse moves it over each of two windows and checks the focus, then the policy that is put back. komorebi.json takes focus_follows_mouse, which is on with Windows or Komorebi, and a file that leaves it out turns it off and gives the user's focus policy back. Loading a configuration asks the backend for the focus policy now, so the tests that load one do it with a backend installed.
This commit is contained in:
1 parent
fa1e822e44
commit
9a0693f5d1
37 files changed
+1140
-25
No files matched your search
@@ -843,6 +843,20 @@ stops, [`transparency_manager::restore`] makes every window it changed opaque ag
|
||||
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)).
|
||||
|
||||
## Focus follows mouse
|
||||
|
||||
The window under the pointer has the focus when the compositor's focus policy says so, and the
|
||||
compositor does it. `FocusFollowsMouse` and `ToggleFocusFollowsMouse` set
|
||||
[`WindowManager::focus_follows_mouse`] (the implementation that was asked for, or none) and ask the
|
||||
backend ([`Backend::set_focus_follows_mouse`]); whichever of the two implementations is named, on
|
||||
KDE it is the compositor's own policy. The KWin backend writes `FocusPolicy=1` and
|
||||
`DelayFocusInterval=0` into the `[Windows]` group of the user's `kwinrc` through [`Kwinrc`], which
|
||||
records the first value of each key, and asks KWin to reload; turning it off puts those two keys
|
||||
back ([`Kwinrc::restore_keys`]) and leaves `PerOutputVirtualDesktops`, which is in the same group,
|
||||
as it is. `shutdown` puts back everything. The focus the compositor gives is an event like the
|
||||
others: the window manager follows it, and [`State`] says whether focus follows mouse is on.
|
||||
[DESIGN.md](DESIGN.md#why-is-focus-follows-mouse-kwins-own-focus-policy) has the reasons.
|
||||
|
||||
## The NixOS module
|
||||
|
||||
The flake exports one module under two names, `nixosModules.default` and
|
||||
@@ -1094,6 +1108,10 @@ the fake. The window manager is its only caller, through [`backend`]. The contra
|
||||
| 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 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 |
|
||||
| Focus follows mouse is the compositor's, whichever implementation is named | framework path: the `FocusFollowsMouse` and `ToggleFocusFollowsMouse` arms ask the backend the same thing for both | `focus_follows_mouse_is_asked_of_the_compositor_and_toggles` | none |
|
||||
| The `focus_follows_mouse` key of the file turns it on, and a file that leaves it out turns it off | framework path: `StaticConfig::postload` and `StaticConfig::reload` set the window manager's field from the file and ask the backend for it | `the_file_turns_focus_follows_mouse_on_and_a_file_that_leaves_it_out_turns_it_off` | none |
|
||||
| The window under the pointer has the focus, and komorebi follows | the compositor's focus policy; the window manager follows the focus event as any other | `vm-focus-follows-mouse` (a real pointer over each window) | 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 |
|
||||
@@ -1229,7 +1247,8 @@ 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/transparency.rs`](../../komorebi/tests/transparency.rs)
|
||||
the stack commands that turn it off; [`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
|
||||
[`komorebi/tests/borders_off.rs`](../../komorebi/tests/borders_off.rs), the color of each
|
||||
@@ -1237,7 +1256,9 @@ A window is shown, and ends up on a tile:
|
||||
[`nix/tests/vm/suites/look`](../../nix/tests/vm/suites/look/test.py), the border in a real
|
||||
Plasma session, read from the pixels of a screenshot, and
|
||||
[`nix/tests/vm/suites/features`](../../nix/tests/vm/suites/features/test.py), the colors of the
|
||||
kinds of window.
|
||||
kinds of window; [`nix/tests/vm/suites/focus-follows-mouse`](../../nix/tests/vm/suites/focus-follows-mouse/test.py),
|
||||
focus follows mouse with a real pointer, which [`Pointer`](../../nix/tests/vm/lib/komorebi_vm/pointer.py)
|
||||
moves from inside the guest.
|
||||
- [`komorebi/tests/wm_events.rs`](../../komorebi/tests/wm_events.rs): the window manager
|
||||
driven end to end against the fake.
|
||||
- [`komorebi/tests/socket.rs`](../../komorebi/tests/socket.rs): the daemon over its socket,
|
||||
@@ -1322,6 +1343,9 @@ 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
|
||||
[`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
|
||||
[`transparency_manager`]: ../../komorebi/src/transparency_manager.rs
|
||||
[`transparency_manager::apply`]: ../../komorebi/src/transparency_manager.rs
|
||||
[`transparency_manager::transparent_windows`]: ../../komorebi/src/transparency_manager.rs
|
||||
|
||||
@@ -469,6 +469,18 @@ the opacity it gave each window that is not opaque (`WindowManager::opacity_appl
|
||||
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 is focus follows mouse KWin's own focus policy?
|
||||
|
||||
Because KWin has one, and gives the focus to the window under the pointer by itself. komorebi
|
||||
asks for it by changing the user's `FocusPolicy` and follows the focus, as it follows any change
|
||||
of focus, and puts the policy back when focus follows mouse is turned off and when it exits
|
||||
([PLATFORM.md](PLATFORM.md#files-and-directories)). Both implementations komorebi for Windows
|
||||
names, `Windows` and `Komorebi`, ask KWin for the same thing. Upstream marks the Windows key
|
||||
end-of-life in favor of masir, a separate program. The code also sets `DelayFocusInterval` to 0,
|
||||
which is KWin's setting for no delay between the pointer entering a window and the window being
|
||||
given the focus; why 0 and not the delay KWin has by default is not written down, and needs a
|
||||
reason.
|
||||
|
||||
## Why are the effects patched?
|
||||
|
||||
Because the stock effects lack what komorebi needs of them. Each patch leaves the effect
|
||||
|
||||
+10
-7
@@ -142,7 +142,9 @@ sends another window there.
|
||||
When borders are on, it also asks KWin to load KDE Rounded Corners, the effect that draws them,
|
||||
after writing the effect's settings into `kwinrc`, and asks it to read them again
|
||||
([KWin effects](#kwin-effects)). It does the same with Geometry Change, the effect that animates
|
||||
windows, when animation is on. An effect KWin did not find is reported once in the log.
|
||||
windows, when animation is on. An effect KWin did not find is reported once in the log. When focus
|
||||
follows mouse is turned on, it sets KWin's focus policy in `kwinrc` (`[Windows] FocusPolicy=1`,
|
||||
`DelayFocusInterval=0`) and asks KWin to reload its configuration.
|
||||
|
||||
Every command of the window manager (move and resize, focus, raise, hide or restore, minimize,
|
||||
bring back, maximize, unmaximize or close a window, show a workspace on an output, put a window
|
||||
@@ -171,12 +173,12 @@ an owner again; the VM test `vm-kwin-restart` restarts KWin twice under a runnin
|
||||
When it is stopped with `SIGINT`, `SIGTERM` or a `Stop` message on its socket, it brings back
|
||||
the windows it hid, waits until the commands that do so have reached the bridge, removes the
|
||||
parking desktop, unloads the effects it loaded, puts back the values the keys it set in `kwinrc`
|
||||
had (`PerOutputVirtualDesktops`, and the keys of the effects), or removes a key the user had not
|
||||
set, and asks KWin to reload its configuration, asks KWin to unload the script, closes an empty
|
||||
connection to each subscriber, and removes the socket. The desktops it created for workspaces
|
||||
stay: they are the user's desktops from then on. A `StopIgnoreRestore` message stops it the same
|
||||
way, except that it does not bring the windows back: the parking desktop is removed all the same.
|
||||
The file `bridge.js` stays in the runtime
|
||||
had (`PerOutputVirtualDesktops`, the focus policy, and the keys of the effects), or removes a key
|
||||
the user had not set, and asks KWin to reload its configuration, asks KWin to unload the script,
|
||||
closes an empty connection to each subscriber, and removes the socket. The desktops it created for
|
||||
workspaces stay: they are the user's desktops from then on. A `StopIgnoreRestore` message stops it
|
||||
the same way, except that it does not bring the windows back: the parking desktop is removed all
|
||||
the same. The file `bridge.js` stays in the runtime
|
||||
directory, which is removed at logout. A daemon that is killed leaves the script running in
|
||||
KWin, reporting to nobody, the socket file in the runtime directory, per-output desktops
|
||||
on, and the parking desktop with the hidden windows on it, until the next start replaces the
|
||||
@@ -243,6 +245,7 @@ since a read right after `createDesktop` has to see the new desktop.
|
||||
| `$KOMOREBI_CONFIG_HOME/komorebi.json` (`~/.config/komorebi/komorebi.json`) | komorebi's configuration, which komorebi never writes: read when the daemon starts, and again when it changes. `--config` names another file | the user's |
|
||||
| `$XDG_CONFIG_HOME/autostart/komorebi.desktop` (`~/.config/autostart/komorebi.desktop`) | the XDG autostart entry `komorebic enable-autostart` writes: `Exec=komorebi`, or `komorebi --config "FILE"`, and `X-KDE-autostart-after=plasma-workspace`, which a Plasma session starts komorebi from at login | the user's; `komorebic disable-autostart` removes it |
|
||||
| `$XDG_CONFIG_HOME/kwinrc` (`~/.config/kwinrc`) | KWin's configuration: komorebi sets `PerOutputVirtualDesktops=true` in `[Windows]`, changing that line or adding it and nothing else, and writes the file beside it first and renames it over it | put back as it was when the daemon stops |
|
||||
| `$XDG_CONFIG_HOME/kwinrc`, group `[Windows]`, keys `FocusPolicy` and `DelayFocusInterval` | `1` and `0` while focus follows mouse is on: KWin's "focus follows mouse" policy, which KWin takes when it is asked to reconfigure | put back, without the other keys of the group, when focus follows mouse is turned off, and with everything else when the daemon stops |
|
||||
| `$XDG_CONFIG_HOME/kwinrc`, group `[Round-Corners]` | the settings of the border effect, written when borders are on ([KWin effects](#kwin-effects)) | put back, with the rest of `kwinrc`, when borders are turned off and when the daemon stops |
|
||||
| `$XDG_CONFIG_HOME/kwinrc`, group `[Effect-kwin4_effect_geometry_change]` | the settings of the animation effect, written when animation is on | put back as above, when animation is turned off and when the daemon stops |
|
||||
| `$XDG_RUNTIME_DIR/komorebi/kwinrc-backup.json` | the value each key of `kwinrc` had before komorebi first changed it | removed when the values are put back; one a crash left behind is used by the next run |
|
||||
|
||||
@@ -88,6 +88,9 @@ display device: the `virtio-gpu-pci` that the test driver adds to every aarch64
|
||||
guest, and the default VGA of an x86_64 one. The node sets
|
||||
`komorebi.vm.renderNode` to false, so that an x86_64 guest does not get a second
|
||||
device: KWin would draw on it, and the screenshot would show the other one.
|
||||
The node also has uinput, with the test user in the group `uinput`, and the
|
||||
program `komorebi-pointer`, which makes a pointer device with it: a test drives
|
||||
the pointer from inside the guest, and KWin takes it as a tablet.
|
||||
|
||||
On aarch64 under HVF, at time of writing (2026-10-27), the session has the
|
||||
Wayland socket after 11 to 19 seconds and a painted desktop after 35 seconds.
|
||||
@@ -166,6 +169,15 @@ the run.
|
||||
- `monitor_bridge(path)` records the bridge's traffic on the session bus with
|
||||
`dbus-monitor`, and `latency.rounds` times each batch of commands in it, from
|
||||
the daemon's answer to the last frame KWin reports for the windows it moved.
|
||||
- `Pointer.start(machine, (width, height), scale=)` starts `komorebi-pointer` on
|
||||
a session node, for a screen of that size, and `move(x, y)`, `down()`, `up()`,
|
||||
`glide(x, y, steps, ms)` and `drag(start, end)` move and click it. Each
|
||||
returns once the program has done it, and a glide's moves are made in the
|
||||
guest, milliseconds apart: moves that each wait for the test are seconds
|
||||
apart, and KWin was seen to lose the horizontal part of such a drag. The
|
||||
pointer lands within a pixel of where it is asked. The program itself is
|
||||
[`komorebi_vm/uinput.py`](../../nix/tests/vm/lib/komorebi_vm/uinput.py),
|
||||
whose arithmetic the `vm-lib` check tests.
|
||||
|
||||
Poll for what the test needs with `wait_for`. A fixed sleep is too long on
|
||||
KVM and too short on TCG.
|
||||
|
||||
Reference in new issue
Block a user