feat(wm): more than one monitor

Every monitor has workspaces of its own, which KWin's per-output desktops show
independently, so a second monitor is mostly the window manager's business:
which monitor has the focus, and how a window gets from one to the other.

At the edge of a monitor, focus and move now cross to the monitor on that side,
where they used to fail with "there is no container in this direction": the
focus lands on the container nearest the monitor it came from, and a move swaps
with the container at that edge (cross-monitor-move-behaviour insert puts it in
among the containers there, no-op keeps it). A window that opens or gets the
focus on a monitor that is not the focused one focuses that monitor, which also
makes the scrolling test of a strip next to another monitor guard real code.

The monitor commands come with it: focusing a monitor by index, in order or
under the pointer, a workspace of another monitor, moving and sending the
focused window to another monitor, to a workspace of it or to a named workspace
(in the window manager these are moves between monitors, so they were left out
of the workspace commands), moving and swapping workspaces between monitors, and
a display index preference that keeps a monitor at the index the user gives it.
eager-focus focuses the first window of an executable on any workspace of any
monitor; its window is found in a container or among the floating windows, the
two places a window can be until stacks, monocle and maximize exist.
This commit is contained in:
LGUG2Z committed 2026-10-28 07:20:37 -07:00
1 parent 8467b03ac2
commit 189aeb1005
41 files changed
+3172 -28

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
```text
Set the behaviour when moving windows across monitor boundaries
Usage: cross-monitor-move-behaviour <MOVE_BEHAVIOUR>
Arguments:
<MOVE_BEHAVIOUR>
Possible values:
- swap: Swap the window container with the window container at the edge of the adjacent
monitor
- insert: Insert the window container into the focused workspace on the adjacent monitor
- no-op: Do nothing if trying to move a window container in the direction of an adjacent
monitor
Options:
-h, --help
Print help (see a summary with '-h')
```
+14
View File
@@ -0,0 +1,14 @@
```text
Focus the monitor in the given cycle direction
Usage: cycle-monitor <CYCLE_DIRECTION>
Arguments:
<CYCLE_DIRECTION>
[possible values: previous, next]
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Move the focused window to the monitor in the given cycle direction
Usage: cycle-move-to-monitor <CYCLE_DIRECTION>
Arguments:
<CYCLE_DIRECTION>
[possible values: previous, next]
Options:
-h, --help
Print help
```
@@ -0,0 +1,14 @@
```text
Move the focused workspace monitor in the given cycle direction
Usage: cycle-move-workspace-to-monitor <CYCLE_DIRECTION>
Arguments:
<CYCLE_DIRECTION>
[possible values: previous, next]
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Send the focused window to the monitor in the given cycle direction
Usage: cycle-send-to-monitor <CYCLE_DIRECTION>
Arguments:
<CYCLE_DIRECTION>
[possible values: previous, next]
Options:
-h, --help
Print help
```
+17
View File
@@ -0,0 +1,17 @@
```text
Set the display index preference for a monitor identified using its display name
Usage: display-index-preference <INDEX_PREFERENCE> <DISPLAY>
Arguments:
<INDEX_PREFERENCE>
Preferred monitor index (zero-indexed)
<DISPLAY>
Display name as identified in komorebic state
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Focus the first managed window matching the given executable
Usage: eager-focus <EXE>
Arguments:
<EXE>
Case-sensitive exe identifier
Options:
-h, --help
Print help
```
+10
View File
@@ -0,0 +1,10 @@
```text
Focus the monitor at the current cursor location
Usage: focus-monitor-at-cursor
Options:
-h, --help
Print help
```
+17
View File
@@ -0,0 +1,17 @@
```text
Focus the specified workspace on the target monitor
Usage: focus-monitor-workspace <TARGET_MONITOR> <TARGET_WORKSPACE>
Arguments:
<TARGET_MONITOR>
Target monitor index (zero-indexed)
<TARGET_WORKSPACE>
Workspace index on the target monitor (zero-indexed)
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Focus the specified monitor
Usage: focus-monitor <TARGET>
Arguments:
<TARGET>
Target index (zero-indexed)
Options:
-h, --help
Print help
```
+17
View File
@@ -0,0 +1,17 @@
```text
Move the focused window to the specified monitor workspace
Usage: move-to-monitor-workspace <TARGET_MONITOR> <TARGET_WORKSPACE>
Arguments:
<TARGET_MONITOR>
Target monitor index (zero-indexed)
<TARGET_WORKSPACE>
Workspace index on the target monitor (zero-indexed)
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Move the focused window to the specified monitor
Usage: move-to-monitor <TARGET>
Arguments:
<TARGET>
Target index (zero-indexed)
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Move the focused window to the specified workspace
Usage: move-to-named-workspace <WORKSPACE>
Arguments:
<WORKSPACE>
Target workspace name
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Move the focused workspace to the specified monitor
Usage: move-workspace-to-monitor <TARGET>
Arguments:
<TARGET>
Target index (zero-indexed)
Options:
-h, --help
Print help
```
+17
View File
@@ -0,0 +1,17 @@
```text
Send the focused window to the specified monitor workspace
Usage: send-to-monitor-workspace <TARGET_MONITOR> <TARGET_WORKSPACE>
Arguments:
<TARGET_MONITOR>
Target monitor index (zero-indexed)
<TARGET_WORKSPACE>
Workspace index on the target monitor (zero-indexed)
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Send the focused window to the specified monitor
Usage: send-to-monitor <TARGET>
Arguments:
<TARGET>
Target index (zero-indexed)
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Send the focused window to the specified workspace
Usage: send-to-named-workspace <WORKSPACE>
Arguments:
<WORKSPACE>
Target workspace name
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Swap focused monitor workspaces with specified monitor
Usage: swap-workspaces-with-monitor <TARGET>
Arguments:
<TARGET>
Target index (zero-indexed)
Options:
-h, --help
Print help
```
@@ -0,0 +1,10 @@
```text
Toggle the behaviour when moving windows across monitor boundaries
Usage: toggle-cross-monitor-move-behaviour
Options:
-h, --help
Print help
```
+38 -5
View File
@@ -304,7 +304,10 @@ direction, both from `komorebi-layouts`:
`FocusWindow` and `CycleFocusWindow` focus another container of the focused workspace and give
its window the focus with the backend's `focus` ([`WindowManager::focus_container_in_direction`],
[`WindowManager::focus_container_in_cycle_direction`]). They retile nothing. When there is no
container in that direction, the message fails and changes nothing. Whether the pointer follows
container in that direction, the focus goes to the monitor in that direction
([`WindowManager::monitor_idx_in_direction`], from the bounds of the monitors), to its container
nearest the monitor the focus came from (the leftmost one going right); with no monitor there
either, the message fails and changes nothing. Whether the pointer follows
the focus is [`WindowManager::mouse_follows_focus`], which `MouseFollowsFocus` and
`ToggleMouseFollowsFocus` set.
@@ -313,8 +316,13 @@ direction ([`WindowManager::move_container_in_direction`],
[`WindowManager::move_container_in_cycle_direction`]), and tile the workspace again: the window
that moved takes the other's tile, keeps the focus, and the pointer follows it. The swap goes
through `LockableSequence`, so a lock stays with its index: the container swapped onto a locked
index is locked in its place. When there is no container in that direction, the message fails
and nothing moves.
index is locked in its place. When there is no container in that direction, the container goes
to the monitor in that direction ([`WindowManager::move_container_to_monitor`]), and
[`WindowManager::cross_monitor_move_behaviour`] says what it does there: by default (`Swap`) the
container at that edge of the other monitor comes back in its place, `Insert` puts it in among
the containers there, and `NoOp` keeps it where it is. With no monitor in that direction, the
message fails and nothing moves. [`WindowManager::cross_boundary_behaviour`] can make both cross
to the next workspace of the same monitor instead.
`ChangeLayout` and `CycleLayout` set the focused workspace's [`Layout`], and `FlipLayout`
mirrors it along an axis, on top of the flip it has ([`Workspace::layout_flip`]); each tiles
@@ -438,6 +446,21 @@ gives a monitor workspaces up to a number, and `CloseWorkspace` removes the work
when it has no window and no name and is not the monitor's last. A name is komorebi's: the
compositor's desktops keep theirs.
A window the compositor reports shown or focused on a monitor that is not the focused one
focuses that monitor ([`WindowManager::monitor_idx_from_window`]). The monitor commands work on
the ring of monitors: `FocusMonitorNumber`, `CycleFocusMonitor` and `FocusMonitorAtCursor` focus
one ([`WindowManager::focus_monitor`]), and `FocusMonitorWorkspaceNumber` a workspace of it;
`MoveContainerToMonitorNumber`, `SendContainerToMonitorNumber`, their cycle and monitor-workspace
forms, and `MoveContainerToNamedWorkspace` and `SendContainerToNamedWorkspace` take the focused
container to another monitor, put its windows on the desktop of the workspace they go to, and tile
both monitors ([`WindowManager::move_container_to_monitor`]); `MoveWorkspaceToMonitorNumber` and
`CycleMoveWorkspaceToMonitor` take the workspace in front to another monitor, and
`SwapWorkspacesToMonitorNumber` exchanges the workspaces of two monitors.
`DisplayIndexPreference` gives a monitor, by its serial number id, the index the window manager
puts it at when it loads the monitors, with placeholders before it while the monitors in between
are not connected. `EagerFocus` focuses the first window of an executable, searching every
workspace of every monitor, and shows its workspace.
`PreselectDirection` reserves the index on one side of the focused container for the next
window ([`WindowManager::preselect_container_in_direction`]). The workspace inserts an empty
container there ([`Container::preselect`]), which [`Workspace::update`] keeps and the layout
@@ -499,7 +522,8 @@ module's unit.
promote the focused container, float a window, lock a container, set the padding of a
workspace, manage and unmanage a window, show a workspace, move a container to another
workspace, follow a workspace switch made by something else, name a workspace and find
it by its name, set the layout of a workspace that is not in front).
it by its name, set the layout of a workspace that is not in front, focus another monitor,
and move containers and workspaces between monitors).
- [`desktop`](../../komorebi/src/desktop.rs): loads the monitors and the open windows from
the backend.
- [`window_manager_event`](../../komorebi/src/window_manager_event.rs) and
@@ -602,6 +626,8 @@ the fake. The window manager is its only caller, through [`backend`]. The contra
| komorebi's own switch or move, reported back by KWin, changes nothing | framework path: the table records a switch and a move when it makes their commands | `the_compositor_reporting_komorebis_own_switch_changes_nothing`, `komorebis_own_move_coming_back_as_an_event_moves_nothing`, `komorebi_switching_a_monitor_comes_back_as_a_change_to_what_it_already_knows` | none |
| The user's `kwinrc` gets back the value komorebi changed, also after a crash | framework path: [`Kwinrc`] records the first value of a key in a backup file, and the backend's `shutdown` puts it back | `what_komorebi_changed_is_put_back_exactly_and_what_it_added_is_removed`, `a_backup_left_by_a_crash_keeps_the_values_from_before_the_first_run`, `vm-workspace-switch` ("back as they were") | `SIGKILL`: the next run puts it back when it stops |
| A workspace is closed only when it has no window and no name and is not the monitor's last | framework path: the `CloseWorkspace` arm of [`WindowManager::process_command`] checks all three | `new_workspace_adds_one_and_close_workspace_removes_it_when_it_is_empty_and_unnamed` | none |
| The focus and a move at the edge of a monitor go to the monitor on that side, and fail only when there is none | framework path: the `None` arms of [`WindowManager::focus_container_in_direction`] and [`WindowManager::move_container_in_direction`] | `the_focus_crosses_to_the_monitor_on_that_side`, `a_move_at_the_edge_of_a_monitor_swaps_with_the_window_on_the_next_one_by_default`, `focus_towards_a_side_with_no_window_is_an_error_and_changes_nothing` | `NoOp` keeps a move on its monitor |
| A window shown or focused on another monitor focuses that monitor, and nothing else does | framework path: `handle_event` focuses the monitor of a `Show` or `FocusChange` before it acts on it | `a_window_that_opens_on_the_monitor_that_is_not_focused_focuses_it`, `a_scrolling_strip_on_the_next_monitor_over_does_not_take_focus_with_it` | none |
| Moving the focus moves no window | test | `focus_gives_the_focus_to_the_window_on_that_side_and_moves_nothing`, `vm-core-e2e` ("moving the focus moved no window") | none |
| A subscriber that is gone is dropped, not retried | test | `a_subscriber_that_is_gone_is_dropped_and_not_tried_again` | none |
| The bridge holds no window manager logic | convention, with every decision about an event in the table, which the `kwin::state` unit tests pin | the unit tests in `komorebi/src/kwin/state.rs` | none |
@@ -735,7 +761,9 @@ A window is shown, and ends up on a tile:
- [`komorebi/tests/workspaces.rs`](../../komorebi/tests/workspaces.rs): workspaces as the
fake's desktops;
[`komorebi/tests/workspace_commands.rs`](../../komorebi/tests/workspace_commands.rs), naming,
cycling and the other workspace commands; [`komorebi/src/kwin/kwinrc.rs`](../../komorebi/src/kwin/kwinrc.rs), the
cycling and the other workspace commands;
[`komorebi/tests/monitors.rs`](../../komorebi/tests/monitors.rs), two monitors: crossing from
one to the other, the monitor commands and `EagerFocus`; [`komorebi/src/kwin/kwinrc.rs`](../../komorebi/src/kwin/kwinrc.rs), the
`kwinrc` editor and its tests.
- [`nix/tests/vm/suites/workspace-switch`](../../nix/tests/vm/suites/workspace-switch/test.py):
workspaces as a real KWin's desktops, switched by `komorebic` and by KWin;
@@ -832,6 +860,11 @@ A window is shown, and ends up on a tile:
[`WindowManager::move_container_to_workspace`]: ../../komorebi/src/window_manager.rs
[`WindowManager::monitor_workspace_index_by_name`]: ../../komorebi/src/window_manager.rs
[`WindowManager::focus_monitor`]: ../../komorebi/src/window_manager.rs
[`WindowManager::monitor_idx_in_direction`]: ../../komorebi/src/window_manager.rs
[`WindowManager::monitor_idx_from_window`]: ../../komorebi/src/window_manager.rs
[`WindowManager::move_container_to_monitor`]: ../../komorebi/src/window_manager.rs
[`WindowManager::cross_monitor_move_behaviour`]: ../../komorebi/src/window_manager.rs
[`WindowManager::cross_boundary_behaviour`]: ../../komorebi/src/window_manager.rs
[`Monitor::focus_workspace`]: ../../komorebi/src/monitor.rs
[`bridge.js`]: ../../komorebi/src/kwin/bridge.js
[`kwin-api.d.ts`]: ../../komorebi/src/kwin/kwin-api.d.ts
+15 -2
View File
@@ -18,8 +18,21 @@ komorebic focus up
komorebic focus right
```
When there is no tile on that side, nothing happens, and the daemon logs "there is no container
in this direction".
When there is no tile on that side, the focus goes to the monitor on that side, if there is one,
to the tile nearest the monitor the focus came from: `focus right` lands on the leftmost tile of
the monitor on the right. With no monitor there either, nothing happens, and the daemon logs
"there is no container or monitor in this direction".
[`komorebic focus-monitor`](../cli/focus-monitor.md) focuses a monitor by its index,
[`komorebic cycle-monitor`](../cli/cycle-monitor.md) the next or the previous one, and
[`komorebic focus-monitor-at-cursor`](../cli/focus-monitor-at-cursor.md) the one the pointer is
on. [`komorebic eager-focus`](../cli/eager-focus.md) focuses the first window komorebi manages of
an executable, whichever workspace of whichever monitor it is on, and shows its workspace.
```sh
komorebic focus-monitor 1
komorebic eager-focus firefox
```
## In order
+28 -2
View File
@@ -18,8 +18,34 @@ komorebic move up
komorebic move right
```
When there is no tile on that side, nothing moves, and the daemon logs "there is no container
in this direction".
When there is no tile on that side, the window goes to the monitor on that side, if there is one,
and takes the place nearest the monitor it came from. What it does there is
[`komorebic cross-monitor-move-behaviour`](../cli/cross-monitor-move-behaviour.md): `swap`, the
default, sends the window it takes the place of back to where it came from; `insert` puts it in
among the windows there; `no-op` keeps it where it is.
[`komorebic toggle-cross-monitor-move-behaviour`](../cli/toggle-cross-monitor-move-behaviour.md)
switches between `insert` and `swap`. With no monitor on that side, nothing moves, and the daemon
logs "there is no container or monitor in this direction".
## To another monitor
[`komorebic move-to-monitor`](../cli/move-to-monitor.md) takes the focused window to a monitor, by
its index, and focuses it there; [`komorebic send-to-monitor`](../cli/send-to-monitor.md) does the
same and leaves the focus on the monitor it came from. Their `cycle-` forms take the next or the
previous monitor. [`komorebic move-to-monitor-workspace`](../cli/move-to-monitor-workspace.md) and
[`komorebic send-to-monitor-workspace`](../cli/send-to-monitor-workspace.md) name a workspace of
that monitor too, and [`komorebic move-to-named-workspace`](../cli/move-to-named-workspace.md) and
[`komorebic send-to-named-workspace`](../cli/send-to-named-workspace.md) find it by its name.
```sh
komorebic move-to-monitor 1
komorebic send-to-monitor-workspace 1 2
```
[`komorebic move-workspace-to-monitor`](../cli/move-workspace-to-monitor.md) takes the whole
workspace in front to another monitor, and
[`komorebic swap-workspaces-with-monitor`](../cli/swap-workspaces-with-monitor.md) exchanges the
workspaces of the focused monitor with those of another.
## In order