mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-17 06:11:21 +01:00
feat(wm): monocle
A workspace could show its windows only side by side. Monocle gives one container the whole work area: the focused container is taken out of the workspace's containers, so the layout gives no container a tile, and the next tiling puts its window on the work area less the padding. Turning it off puts the container back at the index it came from, and the tiles come back as they were resized: the container keeps its resize adjustment, and the workspace does not shorten the list of adjustments while a monocle is on. The windows of the other containers are hidden on the parking desktop, as the windows behind the front one of a stack are, and the front window of each is shown again when the monocle is turned off or the window in monocle closes. A stack in monocle stays a stack. `komorebic toggle-monocle` turns it on and off. What focusing in a direction does meanwhile is set with `monocle-focus-behaviour` or switched with `toggle-monocle-focus-behaviour`: with `cycle` the monocle goes to the previous or the next container, with `no-op`, the default, no container is on any side and the focus falls through to the monitor on that side, where the monocle window of its workspace, if it has one, is given the focus, and the command fails where there is no monitor. A container that is moved to a monitor or sent to a workspace in monocle turns that monocle off first. `cycle-focus` always carries the monocle along. Giving the focus to another window gives it back to the monocle window, so that it stays in front. `move` and `cycle-move` are refused and `toggle-float` is ignored while a window is in monocle, since the focused container is not the window in front. The monocle container is in the state, with the index it goes back to, and a window in it that closes takes the monocle with it. komorebi/tests/monocle.rs drives it against the fake desktop, with one monitor and with two. vm-core-e2e checks in a real KWin that the focused window fills the work area, that the state has the monocle container, that toggling back restores the tile, that the cycle behavior gives another window the work area, and that the windows behind a monocle are parked, which a clean stop and the next start after a crash put right; vm-stacks checks a monocle over a stack; the vm-commands sweep runs the new commands.
This commit is contained in:
1 parent
2e439414db
commit
0d21dd332c
28 files changed
+1927
-101
No files matched your search
@@ -38,7 +38,8 @@ While it runs, the daemon takes messages on a Unix socket, `komorebi.sock` in
|
||||
directory): a message can ask for the state of the window manager, ask which
|
||||
monitor, workspace or container has the focus, give the focus to another
|
||||
window, move the focused window to another tile, change the layout, resize a
|
||||
tile, float a window, retile every monitor, or stop the daemon. [`komorebi-client`](komorebi-client) writes them, and `komorebic`,
|
||||
tile, float a window, give one window the whole work area, retile every monitor, or stop the
|
||||
daemon. [`komorebi-client`](komorebi-client) writes them, and `komorebic`,
|
||||
the command line, is how a person sends them. `komorebic start` runs the
|
||||
`komorebi` on the `PATH`, and passes it what follows a `--`. In a Plasma
|
||||
session:
|
||||
@@ -67,7 +68,7 @@ without a checkout of the toolchain.
|
||||
through which it reaches a compositor and the in-memory desktop the tests use
|
||||
(`backend`), the backend that reaches KWin through a script it runs and edits
|
||||
the one setting of KWin's it needs in the user's `kwinrc` and the parking desktop
|
||||
it hides the back of a stack on (`kwin`),
|
||||
it hides the back of a stack and the windows behind a monocle on (`kwin`),
|
||||
the model of what it tiles (`monitor`, `workspace`, `container`, `window`), the
|
||||
window manager that keeps the model (`window_manager`), loads it from the
|
||||
backend (`desktop`) and changes it when the compositor reports an event
|
||||
@@ -144,7 +145,8 @@ A container with more than one window is a stack: the layout gives it one tile,
|
||||
and the window in front is in sight. The others are hidden, which on KWin means
|
||||
moved to one more virtual desktop, `komorebi-park`, that nobody looks at and that
|
||||
is not a workspace. The daemon makes it when it first needs it, removes it when
|
||||
it stops, and removes one that a run that did not stop left behind.
|
||||
it stops, and removes one that a run that did not stop left behind. A monocle
|
||||
hides the windows of the other containers there too.
|
||||
|
||||
Everything else reaches the daemon as a message on its socket: one JSON
|
||||
`SocketMessage` per line, handled one at a time with the window manager
|
||||
@@ -159,7 +161,8 @@ another layout, `layout-ratios` and `scrolling-layout-columns` tune it,
|
||||
`preselect-direction` reserves a tile for the next window, `resize-edge` and
|
||||
`resize-axis` move the edges of the focused tile, `promote` brings the
|
||||
focused window to the largest tile, `toggle-float` takes it out of the
|
||||
layout, and `toggle-lock` keeps its container at its place. The scrolling layout
|
||||
layout, `toggle-monocle` gives its container the whole work area, hiding the
|
||||
others, and puts it back, and `toggle-lock` keeps its container at its place. The scrolling layout
|
||||
is a strip of columns that runs past the edges of the monitor and scrolls to
|
||||
the window that has the focus. `minimize` and `close` ask KWin to minimize or
|
||||
close the focused window, `unmanage` takes it out of the layout until `manage`
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
```text
|
||||
Set the behavior when focusing in a direction while a monocle container is active
|
||||
|
||||
Usage: monocle-focus-behaviour <BEHAVIOUR>
|
||||
|
||||
Arguments:
|
||||
<BEHAVIOUR>
|
||||
Desired monocle focus behavior
|
||||
|
||||
Possible values:
|
||||
- cycle: Cycle the monocle container to the next/previous container in the workspace
|
||||
- no-op: Do nothing, allowing focus to fall through to cross-monitor logic
|
||||
|
||||
Options:
|
||||
-h, --help
|
||||
Print help (see a summary with '-h')
|
||||
|
||||
```
|
||||
@@ -0,0 +1,10 @@
|
||||
```text
|
||||
Toggle the behavior when focusing in a direction while a monocle container is active
|
||||
|
||||
Usage: toggle-monocle-focus-behaviour
|
||||
|
||||
Options:
|
||||
-h, --help
|
||||
Print help
|
||||
|
||||
```
|
||||
@@ -0,0 +1,10 @@
|
||||
```text
|
||||
Toggle monocle mode for the focused container
|
||||
|
||||
Usage: toggle-monocle
|
||||
|
||||
Options:
|
||||
-h, --help
|
||||
Print help
|
||||
|
||||
```
|
||||
+65
-13
@@ -29,13 +29,16 @@ daemon. It grows with the code: each part of the daemon that is added has its pl
|
||||
that tile.
|
||||
- **Stack**: a container with more than one window. It has one tile, and the window in front
|
||||
(the container's focused window) is in sight; the others are hidden.
|
||||
- **Hidden window**: a window of a stack that is not in front, which komorebi has taken out of
|
||||
sight ([`Backend::hide`]) and recorded in [`HIDDEN_WINDOWS`]. It is alive, not minimized, and
|
||||
on its workspace.
|
||||
- **Hidden window**: a window of a stack that is not in front, or of a container a monocle
|
||||
leaves out, which komorebi has taken out of sight ([`Backend::hide`]) and recorded in
|
||||
[`HIDDEN_WINDOWS`]. It is alive, not minimized, and on its workspace.
|
||||
- **Parking desktop**: the virtual desktop, named `komorebi-park`, that the KWin backend hides
|
||||
windows on. It is not a workspace.
|
||||
- **Layout**: the arrangement (BSP, columns, rows, ...) that turns a work area and a
|
||||
number of containers into one rectangle, a **tile**, for each container.
|
||||
- **Monocle**: a workspace's one container that has the whole work area. It is held out of the
|
||||
workspace's containers, so the layout gives no container a tile, and the windows of the
|
||||
containers are hidden, until it is put back where it was ([`Workspace::monocle_container`]).
|
||||
- **Event**: what the compositor reports about a window: it was shown, destroyed, given
|
||||
the focus, minimized or restored, or put on another workspace's desktop; and that a monitor
|
||||
shows another workspace ([`WindowManagerEvent`]). Two events come from komorebi itself: a
|
||||
@@ -107,8 +110,9 @@ the same thing at every level.
|
||||
its padding, an optional work area offset, an optional window-based offset with the number of
|
||||
windows up to which it applies, and its workspaces. It shows the focused one.
|
||||
- A **workspace** ([`Workspace`]) has a layout, its padding, an optional work area offset of its
|
||||
own, whether it takes the monitor's window-based offset, its containers, in order, and its
|
||||
floating windows, which are in no container and which the layout does not tile.
|
||||
own, whether it takes the monitor's window-based offset, its containers, in order, its
|
||||
monocle container, if it has one, and its floating windows, which are in no container and
|
||||
which the layout does not tile.
|
||||
- A **container** ([`Container`]) has its windows. A new window gets a container of its
|
||||
own, unless the window container behavior says to put it in the focused one. With more than
|
||||
one window it is a stack: the focused window is in front and the others are hidden. A
|
||||
@@ -252,6 +256,12 @@ window is in, end with that call: stacking and unstacking ([`Workspace::move_win
|
||||
is floated, a focus change to a window that is behind ([`Workspace::focus_container_by_window`]),
|
||||
and cycling the stack or focusing a window of it by its index.
|
||||
|
||||
A monocle hides the other containers in the same way. Turning it on hides every window of each
|
||||
of them ([`Container::hide`]), turning it off restores the window in front of each
|
||||
([`Container::restore`]), and cycling it hides the container it gave up. While a monocle is on,
|
||||
[`Workspace::restore`] restores its window and no other, and [`Workspace::hide`] hides it with
|
||||
the rest.
|
||||
|
||||
[`Window::hide`] puts the window's id in [`HIDDEN_WINDOWS`] before it asks the backend, and
|
||||
[`Window::restore`] takes it out, so that when the compositor reports something about the window
|
||||
because of the hide the window manager knows who did it. A `Minimize` for a window in the set is
|
||||
@@ -450,6 +460,25 @@ manager's, and `Append` on an empty workspace is `Create`. `ToggleWindowContaine
|
||||
`ToggleWorkspaceFloatOverride` the focused workspace's, which starts from the opposite of the
|
||||
window manager's value the first time.
|
||||
|
||||
`ToggleMonocle` takes the focused container out of the workspace's containers and makes it the
|
||||
monocle container, which [`Workspace::update`] puts on the whole work area, less the padding, and
|
||||
hides the windows of the other containers; turned off, their windows are restored and the
|
||||
container is put back at the index it came from ([`WindowManager::toggle_monocle`],
|
||||
[`Workspace::new_monocle_container`], [`Workspace::reintegrate_monocle_container`]). The container's resize adjustment is kept
|
||||
meanwhile, and so is the whole of [`Workspace::resize_dimensions`], so that the tiles come back
|
||||
as they were resized. While there is a monocle container, the window in front of it is the one
|
||||
that has the focus: a `FocusChange` to another window gives the focus back to it, and
|
||||
[`WindowManager::update_focused_workspace`] focuses it, not the focused container's window, which
|
||||
is one of the tiles behind. `MoveWindow` and `CycleMoveWindow` are refused, and `ToggleFloat` is
|
||||
ignored, for the focused container is not the window in front. What `FocusWindow` does is
|
||||
[`WindowManager::monocle_focus_behaviour`]: with `Cycle`, it makes the next or the previous
|
||||
container the monocle ([`WindowManager::cycle_monocle`]); with `NoOp`, the default, there is no
|
||||
container on any side, so the focus goes to the monitor on that side, and it fails where there
|
||||
is none. `CycleFocusWindow` always carries the monocle to the next or the previous container.
|
||||
`MonocleFocusBehaviour` sets the behavior, and `ToggleMonocleFocusBehaviour` switches it. A focus
|
||||
that crosses to a monitor whose workspace has a monocle container gives the focus to its window,
|
||||
and a container moved to a workspace with one turns that monocle off first.
|
||||
|
||||
`ToggleLock` locks the focused container, or unlocks it ([`WindowManager::toggle_lock`]), and
|
||||
`LockMonitorWorkspaceContainer` and `UnlockMonitorWorkspaceContainer` do the same for a
|
||||
container given by its indices. A lock changes nothing until containers are inserted, removed or
|
||||
@@ -608,12 +637,12 @@ module's unit.
|
||||
- [`window_manager`](../../komorebi/src/window_manager.rs): the [`WindowManager`] and the
|
||||
operations on it (tile the workspace in front, tile every monitor, take a minimized
|
||||
window out, move the focus, move the focused container, change the layout, resize or
|
||||
promote the focused container, float a window, lock a container, set the padding of a
|
||||
workspace, manage and unmanage a window, stack and unstack windows and choose the one in
|
||||
front, 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, focus another monitor, and move containers and workspaces
|
||||
between monitors).
|
||||
promote the focused container, float a window, put a container in monocle, lock a
|
||||
container, set the padding of a workspace, manage and unmanage a window, stack and unstack
|
||||
windows and choose the one in front, 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, 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
|
||||
@@ -675,7 +704,8 @@ the fake. The window manager is its only caller, through [`backend`]. The contra
|
||||
- A hidden window (`hide`) is out of sight, alive, not minimized, and on the workspace it was
|
||||
on until `restore`: `window_workspace` still names that workspace, and
|
||||
`set_window_workspace` changes where it comes back to, not where it is hidden. Only the back of
|
||||
a stack is hidden: nothing is hidden to leave a workspace.
|
||||
a stack and the containers behind a monocle are hidden: nothing is hidden to leave a
|
||||
workspace.
|
||||
- `shutdown`, `is_window`, `window_rect` and `monitor_from_point` have defaults, written in
|
||||
terms of the queries. An implementor should not need to override them, except `shutdown`
|
||||
when it created something in the compositor that has to be given up.
|
||||
@@ -690,6 +720,13 @@ the fake. The window manager is its only caller, through [`backend`]. The contra
|
||||
| A test's backend does not outlive the test | framework path: [`with_backend`] restores the previous one on drop | `with_backend_puts_the_previous_backend_back_when_the_closure_panics` | none |
|
||||
| A command about a missing window is an error, not a panic | test | `a_command_about_a_window_nobody_opened_is_an_error`, `a_command_about_a_closed_window_is_an_error` and `hiding_or_restoring_a_window_nobody_opened_is_an_error` against the fake, `a_command_about_a_window_the_table_does_not_know_is_an_error_and_sends_nothing` against the KWin backend | none |
|
||||
| A locked container keeps its index | framework path: a [`Workspace`] inserts, removes and swaps its containers through `LockableSequence` | `test_locked_containers_with_new_window`, `test_locked_containers_remove_window`, `a_window_that_opens_does_not_push_a_locked_container_from_its_index` | `containers_mut()` is the `VecDeque` itself |
|
||||
| A container in monocle goes back to the index it came from, and the tiles come back as they were resized | framework path: [`Workspace::new_monocle_container`] keeps the index and [`Workspace::reintegrate_monocle_container`] inserts at it, and [`Workspace::update`] does not shorten the resize adjustments while there is a monocle container | `test_toggle_monocle`, `a_monocle_goes_back_to_its_index_even_when_a_window_opens_meanwhile`, `a_tile_that_was_resized_is_the_size_it_was_after_a_monocle` | none |
|
||||
| The window in monocle keeps the focus | framework path: `handle_event` gives the focus back to the monocle window on a `FocusChange`, and [`WindowManager::update_focused_workspace`] focuses it | `a_window_that_takes_the_focus_from_the_monocle_is_made_to_give_it_back` | none |
|
||||
| What is about the tiles does nothing while a window is in monocle | framework path: [`WindowManager::move_container_in_direction`] and [`WindowManager::move_container_in_cycle_direction`] bail, and [`WindowManager::toggle_float`] returns, when the window in front is in monocle | `what_is_about_the_tiles_is_refused_or_ignored_while_a_monocle_is_on` | none |
|
||||
| A focus that crosses to a monitor in monocle gives its monocle window the focus, and a container moved or sent to a workspace in monocle turns the monocle off | framework path: the `None` arm of [`WindowManager::focus_container_in_direction`], [`WindowManager::move_container_in_direction`], [`WindowManager::move_container_to_monitor`] and [`Monitor::move_container_to_workspace`] | `focusing_towards_a_monitor_in_monocle_gives_the_focus_to_its_monocle_window`, `a_container_moved_to_a_monitor_in_monocle_turns_the_monocle_off_there`, `a_container_sent_to_a_workspace_in_monocle_turns_the_monocle_off_there` | none |
|
||||
| A window in monocle that closes takes the monocle with it | framework path: [`Workspace::remove_window`] looks in the monocle container, which the index of managed windows lists | `closing_the_window_in_monocle_tiles_the_others_again` | none |
|
||||
| In a real KWin, the window in monocle fills the work area and goes back to its tile | VM test | `vm-core-e2e` ("in monocle the focused window fills the work area", "toggling back puts it on its tile") | none |
|
||||
| A clean stop, and the next start after a crash, bring back the windows a monocle hid | VM test | `vm-core-e2e` ("and every window is on a workspace's desktop", "after a crash and a restart a monocle still hides the other window") | none |
|
||||
| A window komorebi does not manage is never moved | framework path: `handle_event` asks [`Window::should_manage`] before it acts on any event but a destroy | `dialogs_and_other_non_normal_windows_are_left_alone`, `an_ignore_rule_keeps_a_window_unmanaged` | `ManageRule` |
|
||||
| A window the user unmanaged stays out of the layout until it is managed again | framework path: `handle_event` checks the list of unmanaged windows before it acts on any event but a removal | `unmanage_takes_the_focused_window_out_until_manage_takes_it_back` | none |
|
||||
| A paused window manager moves no window | framework path: `handle_event` returns before anything else, and [`read_commands_uds`] drops every message but `TogglePause`, `State`, `GlobalState` and `Stop` | `while_paused_no_event_changes_the_layout_and_manage_takes_in_a_window_it_missed`, `while_paused_only_toggle_pause_state_and_stop_are_handled` | none |
|
||||
@@ -726,6 +763,7 @@ the fake. The window manager is its only caller, through [`backend`]. The contra
|
||||
| Only the window in front of a stack is in sight | framework path: [`Container::add_window`] and [`Container::load_focused_window`] hide every window of the container but the focused one, and every operation that changes the front ends with the call | `a_window_added_to_a_container_is_in_front_and_the_others_are_hidden`, `loading_the_focused_window_shows_it_and_hides_the_rest`, `stacking_puts_two_windows_in_one_container_and_hides_the_one_behind`, `vm-stacks` ("exactly one window is on it") | none |
|
||||
| A hidden window is still on its workspace, and is not reported as moved | framework path: the table keeps the desktop a window came from, and a move to the parking desktop is its own | `parking_a_window_hides_it_without_unmanaging_it`, `komorebis_own_move_and_its_park_and_restore_raise_nothing_new`, `a_window_is_put_on_a_workspace_by_putting_it_on_its_desktop` | none |
|
||||
| What the compositor reports about a window komorebi hid is not taken for the user's doing | framework path: [`Window::hide`] records the window in [`HIDDEN_WINDOWS`] before it asks the backend, and the `Minimize` arm of `handle_event` checks it | `a_minimize_komorebi_asked_for_is_not_mistaken_for_the_user`, `a_minimize_the_user_asked_for_takes_the_window_out_of_the_layout` | none |
|
||||
| While a window is in monocle the windows of the other containers are hidden, and they are shown again when it is turned off | framework path: [`WindowManager::monocle_on`], [`WindowManager::cycle_monocle`] and [`WindowManager::monocle_off`] hide and restore the containers, and [`Workspace::remove_window`] restores them when the window in monocle closes | `a_monocle_hides_the_other_windows_until_it_is_turned_off`, `a_window_in_monocle_that_leaves_shows_the_containers_behind_it`, `the_back_of_a_stack_stays_hidden_in_monocle_and_after_it`, `vm-stacks` ("the window in monocle fills the work area and the other one is out of sight") | none |
|
||||
| The window the compositor focuses in a stack comes to the front | framework path: the `FocusChange` arm of `handle_event` focuses the container by the window, which loads it ([`Workspace::focus_container_by_window`]) | `focusing_a_hidden_window_of_a_stack_brings_it_to_the_front`, `the_window_the_user_focuses_in_the_back_of_a_stack_comes_to_the_front` | none |
|
||||
| Cycling a stack changes which window is in front and nothing else | framework path: [`Container::load_focused_window`] shows the focused window and hides the rest; a cycle by index only swaps two places | `cycling_the_stack_brings_the_next_window_to_the_front_and_hides_the_one_that_was`, `cycling_the_index_moves_the_front_window_along_the_stack_and_keeps_it_in_front`, `focus_stack_window_brings_the_window_at_an_index_to_the_front`, `vm-stacks` ("cycle the stack") | none |
|
||||
| A stack with one window cannot be cycled, and an index it lacks is refused | runtime error: the window manager's functions return it before they change anything | `cycling_a_window_that_is_alone_is_an_error`, `focus_stack_window_refuses_an_index_the_stack_does_not_have` | none |
|
||||
@@ -838,7 +876,8 @@ A window is shown, and ends up on a tile:
|
||||
- [`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, and read and stopped with `komorebic`.
|
||||
tiling a real KWin, checked against what KWin has, with a window in monocle, 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
|
||||
@@ -855,6 +894,7 @@ A window is shown, and ends up on a tile:
|
||||
[`komorebi/tests/promote.rs`](../../komorebi/tests/promote.rs), promoting;
|
||||
[`komorebi/tests/float.rs`](../../komorebi/tests/float.rs), floating;
|
||||
[`komorebi/tests/lock.rs`](../../komorebi/tests/lock.rs), locking;
|
||||
[`komorebi/tests/monocle.rs`](../../komorebi/tests/monocle.rs), the monocle;
|
||||
[`komorebi/tests/manage.rs`](../../komorebi/tests/manage.rs), minimizing, closing,
|
||||
unmanaging and managing the focused window, and pausing;
|
||||
[`komorebi/tests/padding.rs`](../../komorebi/tests/padding.rs), the paddings and the work area
|
||||
@@ -911,12 +951,15 @@ A window is shown, and ends up on a tile:
|
||||
[`Window::restore`]: ../../komorebi/src/window.rs
|
||||
[`HIDDEN_WINDOWS`]: ../../komorebi/src/lib.rs
|
||||
[`Container::add_window`]: ../../komorebi/src/container.rs
|
||||
[`Container::hide`]: ../../komorebi/src/container.rs
|
||||
[`Container::load_focused_window`]: ../../komorebi/src/container.rs
|
||||
[`Container::restore`]: ../../komorebi/src/container.rs
|
||||
[`Workspace::move_window_to_container`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::new_container_for_focused_window`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::remove_window`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::focus_container_by_window`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::restore`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::hide`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::window_container_behaviour`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::float_override`]: ../../komorebi/src/workspace.rs
|
||||
[`WindowManager::add_window_to_container`]: ../../komorebi/src/window_manager.rs
|
||||
@@ -950,6 +993,14 @@ A window is shown, and ends up on a tile:
|
||||
[`WindowManager::resize_window`]: ../../komorebi/src/window_manager.rs
|
||||
[`WindowManager::toggle_float`]: ../../komorebi/src/window_manager.rs
|
||||
[`WindowManager::toggle_lock`]: ../../komorebi/src/window_manager.rs
|
||||
[`WindowManager::toggle_monocle`]: ../../komorebi/src/window_manager.rs
|
||||
[`WindowManager::monocle_on`]: ../../komorebi/src/window_manager.rs
|
||||
[`WindowManager::monocle_off`]: ../../komorebi/src/window_manager.rs
|
||||
[`WindowManager::cycle_monocle`]: ../../komorebi/src/window_manager.rs
|
||||
[`WindowManager::monocle_focus_behaviour`]: ../../komorebi/src/window_manager.rs
|
||||
[`Workspace::monocle_container`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::new_monocle_container`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::reintegrate_monocle_container`]: ../../komorebi/src/workspace.rs
|
||||
[`WindowManager::adjust_workspace_padding`]: ../../komorebi/src/window_manager.rs
|
||||
[`Workspace::apply_window_based_work_area_offset`]: ../../komorebi/src/workspace.rs
|
||||
[`Monitor::update_workspace_globals`]: ../../komorebi/src/monitor.rs
|
||||
@@ -1004,6 +1055,7 @@ A window is shown, and ends up on a tile:
|
||||
[`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
|
||||
[`Monitor::move_container_to_workspace`]: ../../komorebi/src/monitor.rs
|
||||
[`bridge.js`]: ../../komorebi/src/kwin/bridge.js
|
||||
[`kwin-api.d.ts`]: ../../komorebi/src/kwin/kwin-api.d.ts
|
||||
[`bridge.test.js`]: ../../komorebi/src/kwin/bridge.test.js
|
||||
|
||||
@@ -296,3 +296,22 @@ records a window in it before it asks the backend to hide it. What the composito
|
||||
hidden window (a minimize, a move to another desktop) is the echo of a command komorebi sent, and
|
||||
the window manager has to be able to tell that from the user's own: a window that the user
|
||||
minimizes leaves the layout, and one komorebi hid does not.
|
||||
|
||||
## Why is the monocle container not one of the containers?
|
||||
|
||||
Because a layout gives every container a tile, and the monocle container is the one that has the
|
||||
whole work area. [`Workspace::new_monocle_container`](../../komorebi/src/workspace.rs) takes the
|
||||
focused container out of the workspace's containers and remembers its index, and
|
||||
[`Workspace::update`](../../komorebi/src/workspace.rs) puts the window of the monocle container on
|
||||
the work area and gives the other containers no tile. The container is taken out and put back
|
||||
with the plain remove and insert of the ring, and not the ones that respect locked containers:
|
||||
the comments of the code say that a monocle, like a maximize, takes over the whole screen before
|
||||
it is reinserted at the same index, which is what respecting the indexes of locked containers
|
||||
needs.
|
||||
|
||||
The container keeps its resize adjustment, "because when this container is inevitably
|
||||
reintegrated, it would be weird if it doesn't go back to the dimensions it had before", and for
|
||||
the same reason `update` does not shorten the list of adjustments while there is a monocle
|
||||
container: with two containers, one of them in monocle, the list would be cut to one, and the
|
||||
adjustment of the container in monocle would be lost when it came back (the comments in
|
||||
`new_monocle_container` and `update`).
|
||||
@@ -22,7 +22,7 @@ was measured with KWin 6.8.1, Plasma 6.8.1 and Qt 6.12.0 from nixpkgs `d3b13ad`
|
||||
- **Desktop**: one of KWin's virtual desktops. Each output shows one; komorebi's workspace `i`
|
||||
is desktop `i`.
|
||||
- **Parking desktop**: the desktop named `komorebi-park`, which komorebi makes to hide the back of
|
||||
a stack on. It is not a workspace.
|
||||
a stack, and the windows behind a monocle, on. It is not a workspace.
|
||||
- **Headless KWin**: `kwin_wayland --virtual`, a KWin with virtual outputs and no display,
|
||||
which the VM tests run ([vm-tests.md](vm-tests.md)).
|
||||
|
||||
@@ -132,11 +132,12 @@ reload its configuration. If a workspace has no desktop, it creates the missing
|
||||
`org.kde.KWin.VirtualDesktopManager`, named "Workspace 1", "Workspace 2" and so on. A desktop
|
||||
that is already there keeps its name.
|
||||
|
||||
When a stack hides a window for the first time, it makes one more desktop, named `komorebi-park`,
|
||||
after the desktops of the workspaces (the missing workspace desktops are made by position, so that
|
||||
it stays last), and moves the window there. The desktop is not a workspace: komorebi counts the
|
||||
workspaces without it, and a window on it is on the workspace it will come back to. It checks that
|
||||
KWin still lists the desktop before it sends another window there.
|
||||
When komorebi hides a window for the first time (the back of a stack, or a window behind a
|
||||
monocle), it makes one more desktop, named `komorebi-park`, after the desktops of the workspaces
|
||||
(the missing workspace desktops are made by position, so that it stays last), and moves the window
|
||||
there. The desktop is not a workspace: komorebi counts the workspaces without it, and a window on
|
||||
it is on the workspace it will come back to. It checks that KWin still lists the desktop before it
|
||||
sends another window there.
|
||||
|
||||
Every command of the window manager (move and resize, focus, raise, hide or restore, minimize,
|
||||
bring back or close a window, show a workspace on an output, put a window on a workspace) is
|
||||
|
||||
@@ -127,9 +127,10 @@ the run.
|
||||
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, `managed_all()` the number it
|
||||
has on every workspace of every monitor (floating windows too),
|
||||
`containers(workspace)` the titles of the windows of each of its containers,
|
||||
and `focused_title(workspace)` the title of the window it has focused there.
|
||||
has on every workspace of every monitor (floating windows and monocle
|
||||
containers too), `containers(workspace)` the titles of the windows of each of
|
||||
its containers, `monocle(workspace)` those of its monocle container, 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, at the debug
|
||||
level the nodes set: `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
|
||||
|
||||
@@ -39,6 +39,7 @@ out of sight and bring one of them to the front,
|
||||
[Layouts](usage/layouts.md) how to change the arrangement of the tiles,
|
||||
[Resizing windows](usage/resizing-windows.md) how to change the size of one,
|
||||
[Floating windows](usage/floating-windows.md) how to take a window out of the layout,
|
||||
[Monocle](usage/monocle.md) how to give one window the whole work area,
|
||||
[Managing windows](usage/managing-windows.md) how to minimize, close and unmanage the focused
|
||||
window and pause the daemon, and
|
||||
[Padding and work area offsets](usage/padding-and-offsets.md) how to put gaps around the tiles
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
# Monocle
|
||||
|
||||
A workspace in monocle shows one window: the container that has the focus takes the whole work
|
||||
area, and the layout gives the other containers no tile, and their windows are out of sight,
|
||||
until the monocle is turned off.
|
||||
|
||||
[`komorebic toggle-monocle`](../cli/toggle-monocle.md) turns the monocle of the focused workspace
|
||||
on, for the container that has the focus, and off. The window is put where a window alone in the
|
||||
workspace would be: the work area less the panels, the workspace padding and the container
|
||||
padding. Turned off, the container goes back to the place in the order of the workspace it was
|
||||
taken from, and the layout tiles every container again.
|
||||
|
||||
```sh
|
||||
komorebic toggle-monocle
|
||||
```
|
||||
|
||||
The windows of the other containers are hidden while the monocle is on, the way the windows behind
|
||||
the front one of a [stack](stacking-windows.md) are, and the front window of each is shown again
|
||||
when the monocle is turned off. A window that opens meanwhile is added to the layout after the
|
||||
focused container, and has its tile when the monocle is turned off. When the window in monocle
|
||||
closes, the monocle is gone and the other windows are shown and tiled again.
|
||||
|
||||
## Focusing
|
||||
|
||||
Giving the focus to another window does not take the monocle with it: komorebi gives the focus
|
||||
back to the window in monocle, so that it is the one in front. What focusing in a direction
|
||||
does meanwhile is set with
|
||||
[`komorebic monocle-focus-behaviour`](../cli/monocle-focus-behaviour.md):
|
||||
|
||||
- `no-op`, the default: no container is on any side of the window in monocle, so
|
||||
[`komorebic focus`](../cli/focus.md) goes to the monitor on that side, as it does at the edge of
|
||||
a layout, and gives the focus to the window in monocle there if its workspace has one. Where
|
||||
there is no monitor on that side it fails, and the daemon logs "there is no container or
|
||||
monitor in this direction".
|
||||
- `cycle`: `komorebic focus left` or `down` makes the previous container the monocle, and
|
||||
`right` or `up` the next one.
|
||||
|
||||
[`komorebic toggle-monocle-focus-behaviour`](../cli/toggle-monocle-focus-behaviour.md) switches
|
||||
between the two. [`komorebic cycle-focus`](../cli/cycle-focus.md) always carries the monocle to
|
||||
the next or the previous container, whatever the behavior is.
|
||||
|
||||
```sh
|
||||
komorebic monocle-focus-behaviour cycle
|
||||
komorebic toggle-monocle-focus-behaviour
|
||||
```
|
||||
|
||||
## What is left alone
|
||||
|
||||
While a window is in monocle, [`komorebic move`](../cli/move.md) and
|
||||
[`komorebic cycle-move`](../cli/cycle-move.md) are refused, and
|
||||
[`komorebic toggle-float`](../cli/toggle-float.md) does nothing: the daemon logs that it ignores
|
||||
them. Turn the monocle off first.
|
||||
|
||||
In the daemon's state, a workspace in monocle has the container as `monocle_container`, which
|
||||
is not one of its `containers`, and the index it goes back to as `monocle_container_restore_idx`.
|
||||
@@ -45,10 +45,10 @@ komorebic start -- --log-level debug
|
||||
komorebic start -- --fake-backend
|
||||
```
|
||||
|
||||
[`komorebic stop`](../cli/stop.md) tells the daemon to stop. It brings back the windows it hid
|
||||
(the back of a stack, [stacking windows](stacking-windows.md)), removes the desktop they were
|
||||
hidden on, asks KWin to unload its script, removes its socket and exits. Stopping the process with
|
||||
`SIGINT` or `SIGTERM` does the same.
|
||||
[`komorebic stop`](../cli/stop.md) tells the daemon to stop. It brings back the windows it hid (the
|
||||
back of a stack, [stacking windows](stacking-windows.md), and the windows behind a
|
||||
[monocle](monocle.md)), removes the desktop they were hidden on, 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
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ where
|
||||
/// # let daemon = std::thread::spawn(move || -> std::io::Result<()> {
|
||||
/// # let (mut stream, _) = listener.accept()?;
|
||||
/// # BufReader::new(stream.try_clone()?).read_line(&mut String::new())?;
|
||||
/// # let state = r#"{"monitors":{"elements":[],"focused":0},"monitor_usr_idx_map":{},"is_paused":false,"resize_delta":50,"new_window_behaviour":"Create","float_override":false,"cross_monitor_move_behaviour":"Swap","unmanaged_window_operation_behaviour":"Op","work_area_offset":null,"mouse_follows_focus":true}"#;
|
||||
/// # let state = r#"{"monitors":{"elements":[],"focused":0},"monitor_usr_idx_map":{},"is_paused":false,"resize_delta":50,"new_window_behaviour":"Create","float_override":false,"cross_monitor_move_behaviour":"Swap","monocle_focus_behaviour":"NoOp","unmanaged_window_operation_behaviour":"Op","work_area_offset":null,"mouse_follows_focus":true}"#;
|
||||
/// # stream.write_all(state.as_bytes())
|
||||
/// # });
|
||||
/// use komorebi_client::SocketMessage;
|
||||
@@ -260,7 +260,7 @@ pub fn send_query(message: &SocketMessage) -> std::io::Result<String> {
|
||||
/// # let mut message = String::new();
|
||||
/// # BufReader::new(stream).read_line(&mut message)?;
|
||||
/// # let subscriber = komorebi_client::DATA_DIR.join("bar.sock");
|
||||
/// # let state = r#"{"monitors":{"elements":[],"focused":0},"monitor_usr_idx_map":{},"is_paused":false,"resize_delta":50,"new_window_behaviour":"Create","float_override":false,"cross_monitor_move_behaviour":"Swap","unmanaged_window_operation_behaviour":"Op","work_area_offset":null,"mouse_follows_focus":true}"#;
|
||||
/// # let state = r#"{"monitors":{"elements":[],"focused":0},"monitor_usr_idx_map":{},"is_paused":false,"resize_delta":50,"new_window_behaviour":"Create","float_override":false,"cross_monitor_move_behaviour":"Swap","monocle_focus_behaviour":"NoOp","unmanaged_window_operation_behaviour":"Op","work_area_offset":null,"mouse_follows_focus":true}"#;
|
||||
/// # let notification = format!(r#"{{"event":{message},"state":{state}}}"#);
|
||||
/// # std::os::unix::net::UnixStream::connect(subscriber)?.write_all(notification.as_bytes())?;
|
||||
/// # Ok(message)
|
||||
|
||||
@@ -385,10 +385,13 @@ pub enum SocketMessage {
|
||||
UnlockMonitorWorkspaceContainer(usize, usize, usize),
|
||||
ToggleLock,
|
||||
ToggleFloat,
|
||||
ToggleMonocle,
|
||||
ToggleWindowContainerBehaviour,
|
||||
ToggleFloatOverride,
|
||||
ToggleCrossMonitorMoveBehaviour,
|
||||
CrossMonitorMoveBehaviour(MoveBehaviour),
|
||||
ToggleMonocleFocusBehaviour,
|
||||
MonocleFocusBehaviour(MonocleFocusBehaviour),
|
||||
UnmanagedWindowOperationBehaviour(OperationBehaviour),
|
||||
// Current Workspace Commands
|
||||
ManageFocusedWindow,
|
||||
|
||||
+2
-2
@@ -174,7 +174,7 @@ pub enum NotificationEvent {
|
||||
/// use komorebi::core::SocketMessage;
|
||||
/// use komorebi::window_manager_event::WindowManagerEvent;
|
||||
///
|
||||
/// let state = r#"{"monitors":{"elements":[],"focused":0},"monitor_usr_idx_map":{},"is_paused":false,"resize_delta":50,"new_window_behaviour":"Create","float_override":false,"cross_monitor_move_behaviour":"Swap","unmanaged_window_operation_behaviour":"Op","work_area_offset":null,"mouse_follows_focus":true}"#;
|
||||
/// let state = r#"{"monitors":{"elements":[],"focused":0},"monitor_usr_idx_map":{},"is_paused":false,"resize_delta":50,"new_window_behaviour":"Create","float_override":false,"cross_monitor_move_behaviour":"Swap","monocle_focus_behaviour":"NoOp","unmanaged_window_operation_behaviour":"Op","work_area_offset":null,"mouse_follows_focus":true}"#;
|
||||
///
|
||||
/// let shown = format!(
|
||||
/// r#"{{"event":{{"type":"Show","content":[{{"type":"KWin","content":"WindowAdded"}},{{"id":7}}]}},"state":{state}}}"#
|
||||
@@ -249,7 +249,7 @@ pub struct Notification {
|
||||
/// ]);
|
||||
///
|
||||
/// let state: State = serde_json::from_str(
|
||||
/// r#"{"monitors":{"elements":[],"focused":0},"monitor_usr_idx_map":{},"is_paused":false,"resize_delta":50,"new_window_behaviour":"Create","float_override":false,"cross_monitor_move_behaviour":"Swap","unmanaged_window_operation_behaviour":"Op","work_area_offset":null,"mouse_follows_focus":true}"#,
|
||||
/// r#"{"monitors":{"elements":[],"focused":0},"monitor_usr_idx_map":{},"is_paused":false,"resize_delta":50,"new_window_behaviour":"Create","float_override":false,"cross_monitor_move_behaviour":"Swap","monocle_focus_behaviour":"NoOp","unmanaged_window_operation_behaviour":"Op","work_area_offset":null,"mouse_follows_focus":true}"#,
|
||||
/// )?;
|
||||
/// let event = NotificationEvent::Socket(SocketMessage::Retile);
|
||||
/// notify_subscribers(Notification { event, state }, false)?;
|
||||
|
||||
+21
-2
@@ -243,7 +243,13 @@ impl Monitor {
|
||||
.containers()
|
||||
.iter()
|
||||
.flat_map(|c| c.windows().iter())
|
||||
.chain(workspace.floating_windows().iter());
|
||||
.chain(workspace.floating_windows().iter())
|
||||
.chain(
|
||||
workspace
|
||||
.monocle_container
|
||||
.iter()
|
||||
.flat_map(|c| c.windows().iter()),
|
||||
);
|
||||
|
||||
for window in windows {
|
||||
if backend().window_workspace(window.id) != Some(idx)
|
||||
@@ -267,7 +273,8 @@ impl Monitor {
|
||||
/// the ones before it) if it does not exist, and focuses that workspace when `follow` is set.
|
||||
///
|
||||
/// With a `direction`, the container goes where a container moved across a boundary in that
|
||||
/// direction goes ([`Monitor::add_container_with_direction`]).
|
||||
/// direction goes ([`Monitor::add_container_with_direction`]). A container that moves to a
|
||||
/// workspace with a monocle container first turns the monocle off there.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn move_container_to_workspace(
|
||||
&mut self,
|
||||
@@ -322,6 +329,18 @@ impl Monitor {
|
||||
Some(workspace) => workspace,
|
||||
};
|
||||
|
||||
if target_workspace.monocle_container.is_some() {
|
||||
for container in target_workspace.containers_mut() {
|
||||
container.restore()?;
|
||||
}
|
||||
|
||||
for window in target_workspace.floating_windows_mut() {
|
||||
window.restore();
|
||||
}
|
||||
|
||||
target_workspace.reintegrate_monocle_container()?;
|
||||
}
|
||||
|
||||
if let Some(direction) = direction {
|
||||
self.add_container_with_direction(
|
||||
container,
|
||||
|
||||
@@ -69,6 +69,10 @@
|
||||
//! - **ToggleFloat** takes the focused window out of the layout into the floating windows of the
|
||||
//! workspace, which komorebi does not move, or puts a floating window back
|
||||
//! ([`WindowManager::toggle_float`]).
|
||||
//! - **ToggleMonocle** gives the focused container the whole work area, with the others out of
|
||||
//! the layout and out of sight, or puts it back ([`WindowManager::toggle_monocle`]).
|
||||
//! **MonocleFocusBehaviour** sets what focusing in a direction does meanwhile, cycle the
|
||||
//! monocle or nothing, and **ToggleMonocleFocusBehaviour** switches between the two.
|
||||
//! - **WorkspacePadding** and **ContainerPadding** set the paddings of a workspace given by the
|
||||
//! index of its monitor and its own, **NamedWorkspacePadding** and
|
||||
//! **NamedWorkspaceContainerPadding** those of the workspace with a name
|
||||
@@ -156,6 +160,7 @@ use crate::core::ApplicationIdentifier;
|
||||
use crate::core::Axis;
|
||||
use crate::core::Layout;
|
||||
use crate::core::LayoutOptions;
|
||||
use crate::core::MonocleFocusBehaviour;
|
||||
use crate::core::MoveBehaviour;
|
||||
use crate::core::OperationDirection;
|
||||
use crate::core::Rect;
|
||||
@@ -258,6 +263,8 @@ impl WindowManager {
|
||||
/// `UnlockMonitorWorkspaceContainer` is not there (a container that is not there is ignored).
|
||||
/// - The focused window cannot be floated or put back, for one of the reasons
|
||||
/// [`WindowManager::toggle_float`] gives.
|
||||
/// - The monocle cannot be turned on or off, for one of the reasons
|
||||
/// [`WindowManager::toggle_monocle`] gives.
|
||||
/// - The focused window cannot be stacked, unstacked or cycled, for one of the reasons
|
||||
/// [`WindowManager::add_window_to_container`], [`WindowManager::remove_window_from_container`],
|
||||
/// [`WindowManager::stack_all`], [`WindowManager::unstack_all`],
|
||||
@@ -349,6 +356,9 @@ impl WindowManager {
|
||||
|
||||
if let Some(location) = window_location {
|
||||
match location {
|
||||
WorkspaceWindowLocation::Monocle(window_idx) => {
|
||||
self.focus_container_window(window_idx)?;
|
||||
}
|
||||
WorkspaceWindowLocation::Container(container_idx, window_idx) => {
|
||||
let focused_container_idx = self.focused_container_idx()?;
|
||||
if container_idx != focused_container_idx {
|
||||
@@ -578,6 +588,7 @@ impl WindowManager {
|
||||
&& monitor.workspaces().len() > 1
|
||||
&& workspace.containers().is_empty()
|
||||
&& workspace.floating_windows().is_empty()
|
||||
&& workspace.monocle_container.is_none()
|
||||
&& workspace.name.is_none()
|
||||
{
|
||||
can_close = true;
|
||||
@@ -821,6 +832,7 @@ impl WindowManager {
|
||||
SocketMessage::EnsureNamedWorkspaces(monitor_idx, ref names) => {
|
||||
self.ensure_named_workspaces_for_monitor(monitor_idx, names)?;
|
||||
}
|
||||
SocketMessage::ToggleMonocle => self.toggle_monocle()?,
|
||||
SocketMessage::ToggleFloat => self.toggle_float(false)?,
|
||||
SocketMessage::ResizeWindowEdge(direction, sizing) => {
|
||||
self.resize_window(direction, sizing, self.resize_delta, true)?;
|
||||
@@ -1358,6 +1370,15 @@ impl WindowManager {
|
||||
SocketMessage::ToggleMouseFollowsFocus => {
|
||||
self.mouse_follows_focus = !self.mouse_follows_focus;
|
||||
}
|
||||
SocketMessage::ToggleMonocleFocusBehaviour => {
|
||||
self.monocle_focus_behaviour = match self.monocle_focus_behaviour {
|
||||
MonocleFocusBehaviour::Cycle => MonocleFocusBehaviour::NoOp,
|
||||
MonocleFocusBehaviour::NoOp => MonocleFocusBehaviour::Cycle,
|
||||
};
|
||||
}
|
||||
SocketMessage::MonocleFocusBehaviour(behaviour) => {
|
||||
self.monocle_focus_behaviour = behaviour;
|
||||
}
|
||||
SocketMessage::UnmanagedWindowOperationBehaviour(behaviour) => {
|
||||
self.unmanaged_window_operation_behaviour = behaviour;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
//! komorebi leaves it alone until it is managed again.
|
||||
//! - **FocusChange**: the workspace is tiled again and the container of the window that has the
|
||||
//! focus becomes the focused container. In the scrolling layout the workspace is tiled after
|
||||
//! that instead, so that the strip scrolls to the window that has the focus.
|
||||
//! that instead, so that the strip scrolls to the window that has the focus. While the
|
||||
//! workspace has a monocle container, the focus goes back to its window instead, no matter
|
||||
//! which window was given it.
|
||||
//! - **Minimize**: a window the user minimized leaves its workspace and the rest are tiled
|
||||
//! again; **Restore** brings it back in a container of its own. A minimize of a window komorebi
|
||||
//! hid ([`struct@HIDDEN_WINDOWS`]) is not the user's, and changes nothing.
|
||||
@@ -197,7 +199,11 @@ impl WindowManager {
|
||||
is_on_current_workspace = true;
|
||||
}
|
||||
|
||||
if is_on_current_workspace {
|
||||
if let Some(monocle) = &workspace.monocle_container {
|
||||
if let Some(window) = monocle.focused_window() {
|
||||
window.focus(false)?;
|
||||
}
|
||||
} else if is_on_current_workspace {
|
||||
workspace.focus_container_by_window(window_id)?;
|
||||
}
|
||||
|
||||
@@ -271,6 +277,8 @@ impl WindowManager {
|
||||
let behaviour = self
|
||||
.window_management_behaviour(focused_monitor_idx, focused_workspace_idx);
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
let workspace_contains_window = workspace.contains_window(window_id);
|
||||
let monocle_container = workspace.monocle_container.clone();
|
||||
|
||||
let floating_applications = FLOATING_APPLICATIONS.lock();
|
||||
let mut should_float = false;
|
||||
@@ -340,6 +348,20 @@ impl WindowManager {
|
||||
window.focus(self.mouse_follows_focus)?;
|
||||
}
|
||||
}
|
||||
|
||||
if workspace_contains_window {
|
||||
let mut monocle_window_event = false;
|
||||
if let Some(ref monocle) = monocle_container
|
||||
&& let Some(monocle_window) = monocle.focused_window()
|
||||
&& monocle_window.id == window_id
|
||||
{
|
||||
monocle_window_event = true;
|
||||
}
|
||||
|
||||
if !monocle_window_event && monocle_container.is_some() {
|
||||
window.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
WindowManagerEvent::Destroy(_, _) | WindowManagerEvent::Unmanage(_) => {
|
||||
|
||||
+11
-2
@@ -14,6 +14,7 @@
|
||||
use crate::DATA_DIR;
|
||||
use crate::IGNORE_IDENTIFIERS;
|
||||
use crate::MANAGE_IDENTIFIERS;
|
||||
use crate::core::MonocleFocusBehaviour;
|
||||
use crate::core::MoveBehaviour;
|
||||
use crate::core::OperationBehaviour;
|
||||
use crate::core::Rect;
|
||||
@@ -128,6 +129,7 @@ pub struct State {
|
||||
pub new_window_behaviour: WindowContainerBehaviour,
|
||||
pub float_override: bool,
|
||||
pub cross_monitor_move_behaviour: MoveBehaviour,
|
||||
pub monocle_focus_behaviour: MonocleFocusBehaviour,
|
||||
pub unmanaged_window_operation_behaviour: OperationBehaviour,
|
||||
pub work_area_offset: Option<Rect>,
|
||||
pub mouse_follows_focus: bool,
|
||||
@@ -158,6 +160,8 @@ impl From<&WindowManager> for State {
|
||||
.map(|workspace| Workspace {
|
||||
name: workspace.name.clone(),
|
||||
containers: workspace.containers.clone(),
|
||||
monocle_container: workspace.monocle_container.clone(),
|
||||
monocle_container_restore_idx: workspace.monocle_container_restore_idx,
|
||||
floating_windows: workspace.floating_windows.clone(),
|
||||
layout: workspace.layout.clone(),
|
||||
layout_options: workspace.layout_options,
|
||||
@@ -197,6 +201,7 @@ impl From<&WindowManager> for State {
|
||||
new_window_behaviour: wm.window_management_behaviour.current_behaviour,
|
||||
float_override: wm.window_management_behaviour.float_override,
|
||||
cross_monitor_move_behaviour: wm.cross_monitor_move_behaviour,
|
||||
monocle_focus_behaviour: wm.monocle_focus_behaviour,
|
||||
mouse_follows_focus: wm.mouse_follows_focus,
|
||||
unmanaged_window_operation_behaviour: wm.unmanaged_window_operation_behaviour,
|
||||
}
|
||||
@@ -206,8 +211,8 @@ impl From<&WindowManager> for State {
|
||||
impl State {
|
||||
/// Returns true if and only if the window manager's monitors (with their workspaces,
|
||||
/// containers and windows), whether it is paused, its new window behavior, its float override,
|
||||
/// its unmanaged window operation behavior, its work area offset or its mouse follows focus
|
||||
/// setting differ from this state's
|
||||
/// its monocle focus behavior, its unmanaged window operation behavior, its work area offset
|
||||
/// or its mouse follows focus setting differ from this state's
|
||||
///
|
||||
/// A window is compared by its id only, so a window that moved or was renamed is not a
|
||||
/// change.
|
||||
@@ -234,6 +239,10 @@ impl State {
|
||||
return true;
|
||||
}
|
||||
|
||||
if self.monocle_focus_behaviour != new.monocle_focus_behaviour {
|
||||
return true;
|
||||
}
|
||||
|
||||
if self.unmanaged_window_operation_behaviour != new.unmanaged_window_operation_behaviour {
|
||||
return true;
|
||||
}
|
||||
|
||||
+475
-34
@@ -55,6 +55,7 @@ use crate::core::CrossBoundaryBehaviour;
|
||||
use crate::core::CycleDirection;
|
||||
use crate::core::DefaultLayout;
|
||||
use crate::core::Layout;
|
||||
use crate::core::MonocleFocusBehaviour;
|
||||
use crate::core::MoveBehaviour;
|
||||
use crate::core::OperationBehaviour;
|
||||
use crate::core::OperationDirection;
|
||||
@@ -112,6 +113,9 @@ pub struct WindowManager {
|
||||
/// Where a focus or a move towards a side with no container goes: the monitor on that side
|
||||
/// (`Monitor`, the default), or the next workspace of the same monitor (`Workspace`)
|
||||
pub cross_boundary_behaviour: CrossBoundaryBehaviour,
|
||||
/// What focusing in a direction does while the workspace has a monocle container: cycle the
|
||||
/// monocle to the next or the previous container, or nothing (the default)
|
||||
pub monocle_focus_behaviour: MonocleFocusBehaviour,
|
||||
/// Whether the pointer is moved to the window that is given the focus, which is the default
|
||||
pub mouse_follows_focus: bool,
|
||||
pub work_area_offset: Option<Rect>,
|
||||
@@ -171,6 +175,7 @@ impl WindowManager {
|
||||
window_management_behaviour: WindowManagementBehaviour::default(),
|
||||
cross_monitor_move_behaviour: Default::default(),
|
||||
cross_boundary_behaviour: Default::default(),
|
||||
monocle_focus_behaviour: MonocleFocusBehaviour::default(),
|
||||
mouse_follows_focus: true,
|
||||
work_area_offset: None,
|
||||
incoming_events: incoming,
|
||||
@@ -198,7 +203,7 @@ impl WindowManager {
|
||||
/// that opens on the focused workspace ([`Workspace::preselect_container_idx`])
|
||||
///
|
||||
/// The grid layout has no preselection: there, and where there is no container on that side,
|
||||
/// nothing is reserved.
|
||||
/// or while the workspace has a monocle container, nothing is reserved.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
@@ -218,7 +223,11 @@ impl WindowManager {
|
||||
|
||||
tracing::info!("preselecting container");
|
||||
|
||||
let new_idx = workspace.new_idx_for_direction(direction);
|
||||
let new_idx = if workspace.monocle_container.is_some() {
|
||||
None
|
||||
} else {
|
||||
workspace.new_idx_for_direction(direction)
|
||||
};
|
||||
|
||||
match new_idx {
|
||||
Some(new_idx) => {
|
||||
@@ -253,6 +262,13 @@ impl WindowManager {
|
||||
///
|
||||
/// Nothing is retiled: the focus moves, the windows stay where they are.
|
||||
///
|
||||
/// While the workspace has a monocle container, no container is on any side of the window in
|
||||
/// front. With the monocle focus behaviour `Cycle`, focusing left or down cycles the monocle to
|
||||
/// the previous container and focusing right or up to the next one
|
||||
/// ([`WindowManager::cycle_monocle`]); with `NoOp`, the default, the focus falls through to
|
||||
/// the monitor on that side, and gives the window in front of its monocle container the focus
|
||||
/// if it has one.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - There is no focused workspace, or neither a container nor a monitor on that side of the
|
||||
@@ -272,7 +288,23 @@ impl WindowManager {
|
||||
|
||||
tracing::info!("focusing container");
|
||||
|
||||
let new_idx = workspace.new_idx_for_direction(direction);
|
||||
if workspace.monocle_container.is_some()
|
||||
&& matches!(self.monocle_focus_behaviour, MonocleFocusBehaviour::Cycle)
|
||||
{
|
||||
let cycle_direction = match direction {
|
||||
OperationDirection::Left | OperationDirection::Down => CycleDirection::Previous,
|
||||
OperationDirection::Right | OperationDirection::Up => CycleDirection::Next,
|
||||
};
|
||||
return self.cycle_monocle(cycle_direction);
|
||||
}
|
||||
|
||||
let new_idx = if workspace.monocle_container.is_some() {
|
||||
None
|
||||
} else {
|
||||
workspace.new_idx_for_direction(direction)
|
||||
};
|
||||
|
||||
let mut cross_monitor_monocle_or_max = false;
|
||||
|
||||
// this is for when we are scrolling across workspaces like PaperWM
|
||||
if new_idx.is_none()
|
||||
@@ -305,7 +337,9 @@ impl WindowManager {
|
||||
|
||||
self.focus_workspace(next_idx)?;
|
||||
|
||||
if let Ok(focused_workspace) = self.focused_workspace_mut() {
|
||||
if let Ok(focused_workspace) = self.focused_workspace_mut()
|
||||
&& focused_workspace.monocle_container.is_none()
|
||||
{
|
||||
match direction {
|
||||
OperationDirection::Left => match focused_workspace.layout {
|
||||
Layout::Default(layout) => {
|
||||
@@ -338,23 +372,30 @@ impl WindowManager {
|
||||
self.focus_monitor(monitor_idx)?;
|
||||
|
||||
if let Ok(focused_workspace) = self.focused_workspace_mut() {
|
||||
match direction {
|
||||
OperationDirection::Left => match focused_workspace.layout {
|
||||
Layout::Default(layout) => {
|
||||
let target_index =
|
||||
layout.rightmost_index(focused_workspace.containers().len());
|
||||
focused_workspace.focus_container(target_index);
|
||||
}
|
||||
},
|
||||
OperationDirection::Right => match focused_workspace.layout {
|
||||
Layout::Default(layout) => {
|
||||
let target_index =
|
||||
layout.leftmost_index(focused_workspace.containers().len());
|
||||
focused_workspace.focus_container(target_index);
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
};
|
||||
if let Some(monocle) = &focused_workspace.monocle_container {
|
||||
if let Some(window) = monocle.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
cross_monitor_monocle_or_max = true;
|
||||
}
|
||||
} else {
|
||||
match direction {
|
||||
OperationDirection::Left => match focused_workspace.layout {
|
||||
Layout::Default(layout) => {
|
||||
let target_index = layout
|
||||
.rightmost_index(focused_workspace.containers().len());
|
||||
focused_workspace.focus_container(target_index);
|
||||
}
|
||||
},
|
||||
OperationDirection::Right => match focused_workspace.layout {
|
||||
Layout::Default(layout) => {
|
||||
let target_index =
|
||||
layout.leftmost_index(focused_workspace.containers().len());
|
||||
focused_workspace.focus_container(target_index);
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(idx) => {
|
||||
@@ -363,11 +404,13 @@ impl WindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
let ws = self.focused_workspace_mut()?;
|
||||
if !ws.is_empty()
|
||||
&& let Ok(focused_window) = self.focused_window()
|
||||
{
|
||||
focused_window.focus(mouse_follows_focus)?;
|
||||
if !cross_monitor_monocle_or_max {
|
||||
let ws = self.focused_workspace_mut()?;
|
||||
if !ws.is_empty()
|
||||
&& let Ok(focused_window) = self.focused_window()
|
||||
{
|
||||
focused_window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -388,6 +431,7 @@ impl WindowManager {
|
||||
/// - There is no focused workspace, or neither a container nor a monitor on that side of the
|
||||
/// focused one.
|
||||
/// - [`WindowManager::handle_unmanaged_window_behaviour`] refuses the message.
|
||||
/// - The window in front is in monocle mode, which has no neighbours to swap with.
|
||||
/// - The workspace cannot be tiled, or the backend refuses to focus the window.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn move_container_in_direction(
|
||||
@@ -399,6 +443,12 @@ impl WindowManager {
|
||||
let workspace = self.focused_workspace()?;
|
||||
let workspace_idx = self.focused_workspace_idx()?;
|
||||
|
||||
// the monocle container is not one of the containers, so the index of the focused
|
||||
// container is not the window in front: moving it would move one that is out of sight
|
||||
if workspace.is_focused_window_monocle_or_maximized()? {
|
||||
bail!("ignoring command while active window is in monocle mode or maximized");
|
||||
}
|
||||
|
||||
tracing::info!("moving container");
|
||||
|
||||
let origin_container_idx = workspace.focused_container_idx();
|
||||
@@ -467,6 +517,18 @@ impl WindowManager {
|
||||
// focus the target monitor
|
||||
self.focus_monitor(target_monitor_idx)?;
|
||||
|
||||
// unset monocle container on target workspace if there is one
|
||||
let mut target_workspace_has_monocle = false;
|
||||
if let Ok(target_workspace) = self.focused_workspace()
|
||||
&& target_workspace.monocle_container.is_some()
|
||||
{
|
||||
target_workspace_has_monocle = true;
|
||||
}
|
||||
|
||||
if target_workspace_has_monocle {
|
||||
self.toggle_monocle()?;
|
||||
}
|
||||
|
||||
// get a mutable ref to the focused workspace on the target monitor
|
||||
let target_workspace = self.focused_workspace_mut()?;
|
||||
|
||||
@@ -547,11 +609,22 @@ impl WindowManager {
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.update_focused_workspace(offset)?;
|
||||
|
||||
if follow_focus
|
||||
&& trigger_focus
|
||||
&& let Ok(window) = self.focused_window_mut()
|
||||
{
|
||||
window.focus(mouse_follows_focus)?;
|
||||
if follow_focus && trigger_focus {
|
||||
// When a monocle container is active, workspace.update() already positioned it at
|
||||
// the work area. Focus that window directly: the focused container is one of the
|
||||
// tiles behind it, and the pointer is to follow the window that is in front.
|
||||
let monocle_window = self
|
||||
.focused_workspace_mut()?
|
||||
.monocle_container
|
||||
.as_mut()
|
||||
.and_then(|c| c.focused_window_mut())
|
||||
.cloned();
|
||||
|
||||
if let Some(window) = monocle_window {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
} else if let Ok(window) = self.focused_window_mut() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -978,10 +1051,101 @@ impl WindowManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Turns the monocle of the focused workspace on, for the focused container, or off, and tiles
|
||||
/// the workspace again
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - There is no focused workspace, or it has no container to turn into a monocle.
|
||||
/// - The workspace cannot be tiled, or the backend refuses to focus the window.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn toggle_monocle(&mut self) -> eyre::Result<()> {
|
||||
let workspace = self.focused_workspace()?;
|
||||
match workspace.monocle_container {
|
||||
None => self.monocle_on()?,
|
||||
Some(_) => self.monocle_off()?,
|
||||
}
|
||||
|
||||
self.update_focused_workspace(true, true)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Takes the focused container out of the layout of the focused workspace and makes it the
|
||||
/// monocle container, which the next tiling gives the whole work area, and hides the windows
|
||||
/// of the other containers
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// There is no focused workspace, or it has no container.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn monocle_on(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("enabling monocle");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.new_monocle_container()?;
|
||||
|
||||
for container in workspace.containers_mut() {
|
||||
container.hide(None)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Shows the windows of the other containers again, and puts the monocle container of the
|
||||
/// focused workspace back in the layout, where it was
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// There is no focused workspace, or it has no monocle container.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn monocle_off(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("disabling monocle");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
for container in workspace.containers_mut() {
|
||||
container.restore()?;
|
||||
}
|
||||
|
||||
workspace.reintegrate_monocle_container()
|
||||
}
|
||||
|
||||
/// Puts the monocle container back in the layout and makes the next (or the previous)
|
||||
/// container the monocle, wrapping around at the ends, hides the windows of the containers
|
||||
/// that are left, and tiles the workspace again
|
||||
///
|
||||
/// A workspace where the monocle is the only container is left as it is.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - There is no focused workspace, or it has no monocle container.
|
||||
/// - The workspace cannot be tiled, or the backend refuses to focus the window.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn cycle_monocle(&mut self, direction: CycleDirection) -> eyre::Result<()> {
|
||||
tracing::info!("cycling monocle container");
|
||||
|
||||
if self.focused_workspace()?.containers().is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.focused_workspace_mut()?
|
||||
.cycle_monocle_container(direction)?;
|
||||
|
||||
for container in self.focused_workspace_mut()?.containers_mut() {
|
||||
container.hide(None)?;
|
||||
}
|
||||
|
||||
self.update_focused_workspace(true, true)
|
||||
}
|
||||
|
||||
/// Takes the window that has the focus in the compositor out of the layout of the focused
|
||||
/// workspace, or puts it back when it is one of its floating windows and `force_float` is not
|
||||
/// set, and tiles the workspace again
|
||||
///
|
||||
/// While the workspace has a monocle container nothing is done: the message is logged and
|
||||
/// ignored.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - The compositor reports no focused window.
|
||||
@@ -995,6 +1159,10 @@ impl WindowManager {
|
||||
.ok_or_eyre("no foreground window")?;
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
if workspace.monocle_container.is_some() {
|
||||
tracing::warn!("ignoring toggle-float command while workspace has a monocle container");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut is_floating_window = false;
|
||||
|
||||
@@ -1662,6 +1830,18 @@ impl WindowManager {
|
||||
.focused_workspace_mut()
|
||||
.ok_or_eyre("there is no focused workspace on target monitor")?;
|
||||
|
||||
if target_workspace.monocle_container.is_some() {
|
||||
for container in target_workspace.containers_mut() {
|
||||
container.restore()?;
|
||||
}
|
||||
|
||||
for window in target_workspace.floating_windows_mut() {
|
||||
window.restore();
|
||||
}
|
||||
|
||||
target_workspace.reintegrate_monocle_container()?;
|
||||
}
|
||||
|
||||
if let Some(window) = floating_window {
|
||||
window.move_to_area(¤t_area, &target_monitor_work_area_size)?;
|
||||
target_workspace.floating_windows_mut().push_back(window);
|
||||
@@ -1806,6 +1986,9 @@ impl WindowManager {
|
||||
/// workspace, wrapping around at the ends, and the pointer follows it if
|
||||
/// [`WindowManager::mouse_follows_focus`] is set
|
||||
///
|
||||
/// While the workspace has a monocle container, the monocle goes with the focus: it is turned
|
||||
/// off, the next container is focused, and it is turned on for that one.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - There is no focused workspace, or it has no containers.
|
||||
@@ -1816,9 +1999,15 @@ impl WindowManager {
|
||||
direction: CycleDirection,
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("focusing container");
|
||||
let mut monocle_next = false;
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
|
||||
if self.focused_workspace_mut()?.monocle_container.is_some() {
|
||||
monocle_next = true;
|
||||
self.monocle_off()?;
|
||||
}
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
let new_idx = workspace
|
||||
@@ -1827,7 +2016,11 @@ impl WindowManager {
|
||||
|
||||
workspace.focus_container(new_idx);
|
||||
|
||||
self.focused_window_mut()?.focus(mouse_follows_focus)?;
|
||||
if monocle_next {
|
||||
self.toggle_monocle()?;
|
||||
} else {
|
||||
self.focused_window_mut()?.focus(mouse_follows_focus)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1841,6 +2034,7 @@ impl WindowManager {
|
||||
/// # Errors
|
||||
///
|
||||
/// - There is no focused workspace, or it has no containers.
|
||||
/// - The window in front is in monocle mode, which has no neighbours to swap with.
|
||||
/// - The workspace cannot be tiled, or the backend refuses to focus the window.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn move_container_in_cycle_direction(
|
||||
@@ -1848,6 +2042,9 @@ impl WindowManager {
|
||||
direction: CycleDirection,
|
||||
) -> eyre::Result<()> {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
if workspace.is_focused_window_monocle_or_maximized()? {
|
||||
eyre::bail!("ignoring command while active window is in monocle mode or maximized");
|
||||
}
|
||||
|
||||
tracing::info!("moving container");
|
||||
|
||||
@@ -1879,7 +2076,12 @@ impl WindowManager {
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
|
||||
let container = self.focused_container_mut()?;
|
||||
let container =
|
||||
if let Some(container) = &mut self.focused_workspace_mut()?.monocle_container {
|
||||
container
|
||||
} else {
|
||||
self.focused_container_mut()?
|
||||
};
|
||||
|
||||
let len = NonZeroUsize::new(container.windows().len())
|
||||
.ok_or_eyre("there must be at least one window in a container")?;
|
||||
@@ -1916,7 +2118,12 @@ impl WindowManager {
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
|
||||
let container = self.focused_container_mut()?;
|
||||
let container =
|
||||
if let Some(container) = &mut self.focused_workspace_mut()?.monocle_container {
|
||||
container
|
||||
} else {
|
||||
self.focused_container_mut()?
|
||||
};
|
||||
|
||||
let len = NonZeroUsize::new(container.windows().len())
|
||||
.ok_or_eyre("there must be at least one window in a container")?;
|
||||
@@ -2121,6 +2328,12 @@ impl WindowManager {
|
||||
for window in workspace.floating_windows() {
|
||||
known_window_ids.insert(window.id, (m_idx, w_idx));
|
||||
}
|
||||
|
||||
if let Some(container) = &workspace.monocle_container {
|
||||
for window in container.windows() {
|
||||
known_window_ids.insert(window.id, (m_idx, w_idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2536,6 +2749,37 @@ impl WindowManager {
|
||||
.floating_windows_mut()
|
||||
.push_back(floating_window);
|
||||
}
|
||||
} else if origin_workspace
|
||||
.monocle_container
|
||||
.as_ref()
|
||||
.and_then(|monocle| monocle.focused_window().map(|w| w.id == window_id))
|
||||
.unwrap_or_default()
|
||||
{
|
||||
// Moving monocle container
|
||||
if let Some(monocle_idx) = origin_workspace.monocle_container_restore_idx {
|
||||
let origin_workspace = self
|
||||
.monitors_mut()
|
||||
.get_mut(origin_monitor_idx)
|
||||
.ok_or_eyre("there is no monitor at this idx")?
|
||||
.workspaces_mut()
|
||||
.get_mut(origin_workspace_idx)
|
||||
.ok_or_eyre("there is no workspace for this monitor")?;
|
||||
|
||||
for container in origin_workspace.containers_mut() {
|
||||
container.restore()?;
|
||||
}
|
||||
|
||||
origin_workspace.reintegrate_monocle_container()?;
|
||||
|
||||
self.transfer_container(
|
||||
(origin_monitor_idx, origin_workspace_idx, monocle_idx),
|
||||
(
|
||||
target_monitor_idx,
|
||||
target_workspace_idx,
|
||||
target_container_idx,
|
||||
),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -4240,6 +4484,203 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_monocle_on_and_monocle_off() {
|
||||
let (mut wm, _context) = setup_window_manager();
|
||||
|
||||
{
|
||||
// Create a monitor
|
||||
let mut m = monitor::new(
|
||||
0,
|
||||
Rect::default(),
|
||||
Rect::default(),
|
||||
"TestMonitor".to_string(),
|
||||
"TestDeviceID".to_string(),
|
||||
);
|
||||
|
||||
// Create a container
|
||||
let mut container = Container::default();
|
||||
|
||||
// Add a window to the container
|
||||
container.windows_mut().push_back(Window::from(1));
|
||||
|
||||
// Should have 1 window in the container
|
||||
assert_eq!(container.windows().len(), 1);
|
||||
|
||||
// Add the container to the workspace
|
||||
let workspace = m.focused_workspace_mut().unwrap();
|
||||
workspace.add_container_to_back(container);
|
||||
|
||||
// Add monitor to the window manager
|
||||
wm.monitors_mut().push_back(m);
|
||||
}
|
||||
|
||||
// Move container to monocle container
|
||||
wm.monocle_on().ok();
|
||||
|
||||
{
|
||||
// Container should be a monocle container
|
||||
let monocle_container = wm
|
||||
.focused_workspace()
|
||||
.unwrap()
|
||||
.monocle_container
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
assert_eq!(monocle_container.windows().len(), 1);
|
||||
assert_eq!(monocle_container.windows()[0].id, 1);
|
||||
}
|
||||
|
||||
{
|
||||
// Should not have any containers
|
||||
let container = wm.focused_workspace().unwrap();
|
||||
assert_eq!(container.containers().len(), 0);
|
||||
}
|
||||
|
||||
// Move monocle container to regular container
|
||||
wm.monocle_off().ok();
|
||||
|
||||
{
|
||||
// Should have 1 container in the workspace
|
||||
let container = wm.focused_workspace().unwrap();
|
||||
assert_eq!(container.containers().len(), 1);
|
||||
assert_eq!(container.containers()[0].windows()[0].id, 1);
|
||||
}
|
||||
|
||||
{
|
||||
// No windows should be in the monocle container
|
||||
let monocle_container = &wm.focused_workspace().unwrap().monocle_container;
|
||||
assert_eq!(*monocle_container, None);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_monocle_on_and_off_nonexistent_container() {
|
||||
let (mut wm, _context) = setup_window_manager();
|
||||
|
||||
{
|
||||
// Create a monitor
|
||||
let m = monitor::new(
|
||||
0,
|
||||
Rect::default(),
|
||||
Rect::default(),
|
||||
"TestMonitor".to_string(),
|
||||
"TestDeviceID".to_string(),
|
||||
);
|
||||
|
||||
// Add monitor to the window manager
|
||||
wm.monitors_mut().push_back(m);
|
||||
}
|
||||
|
||||
// Should return an error when trying to move a non-existent container to monocle
|
||||
let result = wm.monocle_on();
|
||||
assert!(
|
||||
result.is_err(),
|
||||
"Expected an error when trying to move a non-existent container to monocle"
|
||||
);
|
||||
|
||||
// Should return an error when trying to restore a non-existent container from monocle
|
||||
let result = wm.monocle_off();
|
||||
assert!(
|
||||
result.is_err(),
|
||||
"Expected an error when trying to restore a non-existent container from monocle"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_toggle_monocle() {
|
||||
let (mut wm, _context) = setup_window_manager();
|
||||
|
||||
{
|
||||
// Create a monitor
|
||||
let mut m = monitor::new(
|
||||
0,
|
||||
Rect::default(),
|
||||
Rect::default(),
|
||||
"TestMonitor".to_string(),
|
||||
"TestDeviceID".to_string(),
|
||||
);
|
||||
|
||||
// Create a container
|
||||
let mut container = Container::default();
|
||||
|
||||
// Add a window to the container
|
||||
container.windows_mut().push_back(Window::from(1));
|
||||
|
||||
// Should have 1 window in the container
|
||||
assert_eq!(container.windows().len(), 1);
|
||||
|
||||
// Add the container to the workspace
|
||||
let workspace = m.focused_workspace_mut().unwrap();
|
||||
workspace.add_container_to_back(container);
|
||||
|
||||
// Add monitor to the window manager
|
||||
wm.monitors_mut().push_back(m);
|
||||
}
|
||||
|
||||
// Toggle monocle on
|
||||
wm.toggle_monocle().ok();
|
||||
|
||||
{
|
||||
// Container should be a monocle container
|
||||
let monocle_container = wm
|
||||
.focused_workspace()
|
||||
.unwrap()
|
||||
.monocle_container
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
assert_eq!(monocle_container.windows().len(), 1);
|
||||
assert_eq!(monocle_container.windows()[0].id, 1);
|
||||
}
|
||||
|
||||
{
|
||||
// Should not have any containers
|
||||
let container = wm.focused_workspace().unwrap();
|
||||
assert_eq!(container.containers().len(), 0);
|
||||
}
|
||||
|
||||
// Toggle monocle off
|
||||
wm.toggle_monocle().ok();
|
||||
|
||||
{
|
||||
// Should have 1 container in the workspace
|
||||
let container = wm.focused_workspace().unwrap();
|
||||
assert_eq!(container.containers().len(), 1);
|
||||
assert_eq!(container.containers()[0].windows()[0].id, 1);
|
||||
}
|
||||
|
||||
{
|
||||
// No windows should be in the monocle container
|
||||
let monocle_container = &wm.focused_workspace().unwrap().monocle_container;
|
||||
assert_eq!(*monocle_container, None);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_toggle_monocle_nonexistent_container() {
|
||||
let (mut wm, _context) = setup_window_manager();
|
||||
|
||||
{
|
||||
// Create a monitor
|
||||
let m = monitor::new(
|
||||
0,
|
||||
Rect::default(),
|
||||
Rect::default(),
|
||||
"TestMonitor".to_string(),
|
||||
"TestDeviceID".to_string(),
|
||||
);
|
||||
|
||||
// Add monitor to the window manager
|
||||
wm.monitors_mut().push_back(m);
|
||||
}
|
||||
|
||||
// Should return an error when trying to toggle monocle on a non-existent container
|
||||
let result = wm.toggle_monocle();
|
||||
assert!(
|
||||
result.is_err(),
|
||||
"Expected an error when trying to toggle monocle on a non-existent container"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ensure_named_workspace_for_monitor() {
|
||||
let (mut wm, _context) = setup_window_manager();
|
||||
|
||||
+302
-11
@@ -30,6 +30,13 @@ use std::num::NonZeroUsize;
|
||||
pub struct Workspace {
|
||||
pub name: Option<String>,
|
||||
pub containers: Ring<Container>,
|
||||
/// The container that has the whole work area, and so is the only one in view: it is not one
|
||||
/// of `containers`, which are not given tiles until it is put back
|
||||
/// ([`Workspace::new_monocle_container`], [`Workspace::reintegrate_monocle_container`])
|
||||
pub monocle_container: Option<Container>,
|
||||
/// The index in `containers` the monocle container goes back to
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub monocle_container_restore_idx: Option<usize>,
|
||||
pub floating_windows: Ring<Window>,
|
||||
pub layout: Layout,
|
||||
pub layout_options: Option<LayoutOptions>,
|
||||
@@ -65,6 +72,8 @@ impl Default for Workspace {
|
||||
Self {
|
||||
name: None,
|
||||
containers: Default::default(),
|
||||
monocle_container: None,
|
||||
monocle_container_restore_idx: None,
|
||||
workspace_padding: None,
|
||||
container_padding: None,
|
||||
resize_dimensions: vec![],
|
||||
@@ -88,6 +97,7 @@ impl Default for Workspace {
|
||||
/// Where a workspace has a window of an application ([`Workspace::location_from_exe`])
|
||||
#[derive(Debug)]
|
||||
pub enum WorkspaceWindowLocation {
|
||||
Monocle(usize), // window_idx
|
||||
Container(usize, usize), // container_idx, window_idx
|
||||
Floating(usize), // idx in floating_windows
|
||||
}
|
||||
@@ -280,6 +290,13 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(container) = &self.monocle_container {
|
||||
for window in container.windows() {
|
||||
let entry = tracker.entry(window.id).or_insert(0);
|
||||
*entry += 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (window_id, count) in &tracker {
|
||||
if *count > 1 {
|
||||
to_prune_from_containers.push(*window_id);
|
||||
@@ -324,6 +341,14 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(container) = &self.monocle_container {
|
||||
for window in container.windows() {
|
||||
if !window.is_valid() {
|
||||
invalid_window_ids.push(window.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for window in self.floating_windows() {
|
||||
if !window.is_valid() {
|
||||
invalid_floating_window_ids.push(window.id);
|
||||
@@ -354,6 +379,28 @@ impl Workspace {
|
||||
///
|
||||
/// No container of the workspace has the window.
|
||||
pub fn remove_window(&mut self, window_id: u32) -> eyre::Result<Window> {
|
||||
if let Some(container) = self.monocle_container.as_mut()
|
||||
&& let Some(window_idx) = container
|
||||
.windows()
|
||||
.iter()
|
||||
.position(|window| window.id == window_id)
|
||||
{
|
||||
let window = container
|
||||
.remove_window_by_idx(window_idx)
|
||||
.ok_or_eyre("there is no window")?;
|
||||
|
||||
if container.windows().is_empty() {
|
||||
self.monocle_container = None;
|
||||
self.monocle_container_restore_idx = None;
|
||||
}
|
||||
|
||||
for c in self.containers_mut() {
|
||||
c.restore()?;
|
||||
}
|
||||
|
||||
return Ok(window);
|
||||
}
|
||||
|
||||
let container_idx = self
|
||||
.container_idx_for_window(window_id)
|
||||
.ok_or_eyre("there is no window")?;
|
||||
@@ -403,8 +450,30 @@ impl Workspace {
|
||||
self.focus_container(focused_idx.saturating_sub(1));
|
||||
}
|
||||
|
||||
/// Returns true if the window that has the focus in the compositor is in the monocle
|
||||
/// container, and so out of the layout
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The compositor reports no focused window.
|
||||
pub fn is_focused_window_monocle_or_maximized(&self) -> eyre::Result<bool> {
|
||||
let window_id = backend()
|
||||
.foreground_window()
|
||||
.ok_or_eyre("no foreground window")?;
|
||||
|
||||
if let Some(container) = &self.monocle_container
|
||||
&& container.contains_window(window_id)
|
||||
{
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.containers().is_empty() && self.floating_windows().is_empty()
|
||||
self.containers().is_empty()
|
||||
&& self.monocle_container.is_none()
|
||||
&& self.floating_windows().is_empty()
|
||||
}
|
||||
|
||||
pub fn contains_window(&self, window_id: u32) -> bool {
|
||||
@@ -414,6 +483,12 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(container) = &self.monocle_container
|
||||
&& container.contains_window(window_id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
for window in self.floating_windows() {
|
||||
if window_id == window.id {
|
||||
return true;
|
||||
@@ -423,8 +498,8 @@ impl Workspace {
|
||||
false
|
||||
}
|
||||
|
||||
/// Where this workspace has a window of the executable `exe`, the first one in a container
|
||||
/// before a floating one
|
||||
/// Where this workspace has a window of the executable `exe`: in a container first, then in
|
||||
/// the monocle container, then floating
|
||||
pub fn location_from_exe(&self, exe: &str) -> Option<WorkspaceWindowLocation> {
|
||||
for (container_idx, container) in self.containers().iter().enumerate() {
|
||||
if let Some(window_idx) = container.idx_from_exe(exe) {
|
||||
@@ -435,6 +510,12 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(container) = &self.monocle_container
|
||||
&& let Some(window_idx) = container.idx_from_exe(exe)
|
||||
{
|
||||
return Some(WorkspaceWindowLocation::Monocle(window_idx));
|
||||
}
|
||||
|
||||
for (window_idx, window) in self.floating_windows().iter().enumerate() {
|
||||
if let Some(window_exe) = window.exe()
|
||||
&& exe == window_exe
|
||||
@@ -446,8 +527,8 @@ impl Workspace {
|
||||
None
|
||||
}
|
||||
|
||||
/// Returns true if and only if the window is in one of the containers, which leaves out the
|
||||
/// floating windows: the windows komorebi tiles
|
||||
/// Returns true if and only if the window is in one of the containers or in the monocle
|
||||
/// container, which leaves out the floating windows: the windows komorebi tiles
|
||||
pub fn contains_managed_window(&self, window_id: u32) -> bool {
|
||||
for container in self.containers() {
|
||||
if container.contains_window(window_id) {
|
||||
@@ -455,6 +536,12 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(container) = &self.monocle_container
|
||||
&& container.contains_window(window_id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
@@ -539,7 +626,7 @@ impl Workspace {
|
||||
}
|
||||
|
||||
/// Hides every window of the workspace, or every one but `omit`: the floating windows and the
|
||||
/// windows of every container. A scrolling workspace is tiled again first without its resize
|
||||
/// windows of every container and of the monocle container. A scrolling workspace is tiled again first without its resize
|
||||
/// adjustments, which are put back after, so that the windows are hidden where the layout
|
||||
/// has them and not where they were dragged.
|
||||
///
|
||||
@@ -581,6 +668,10 @@ impl Workspace {
|
||||
self.resize_dimensions = resize_dimensions;
|
||||
}
|
||||
|
||||
if let Some(container) = &mut self.monocle_container {
|
||||
container.hide(omit)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -590,8 +681,20 @@ impl Workspace {
|
||||
///
|
||||
/// The compositor shows a workspace's windows by itself when the workspace's desktop is shown;
|
||||
/// this is what komorebi does after it has asked for that, and it brings back what komorebi
|
||||
/// itself has hidden (the back of a stack stays hidden).
|
||||
/// itself has hidden (the back of a stack stays hidden). While there is a monocle container
|
||||
/// only its window is restored and focused, for the other containers are out of sight behind
|
||||
/// it.
|
||||
pub fn restore(&mut self, mouse_follows_focus: bool) -> eyre::Result<()> {
|
||||
if let Some(container) = &mut self.monocle_container {
|
||||
container.restore()?;
|
||||
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let idx = self.focused_container_idx();
|
||||
let mut to_focus = None;
|
||||
|
||||
@@ -682,6 +785,106 @@ impl Workspace {
|
||||
self.focus_container(0);
|
||||
}
|
||||
|
||||
/// Takes the focused container out of the containers and makes it the monocle container,
|
||||
/// remembering its index, and focuses the container before it. The window in front of the
|
||||
/// monocle container is shown and the rest of its windows are hidden.
|
||||
///
|
||||
/// The container's resize adjustment stays where it is, so that the container goes back to the
|
||||
/// size it had.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The workspace has no containers.
|
||||
pub fn new_monocle_container(&mut self) -> eyre::Result<()> {
|
||||
let focused_idx = self.focused_container_idx();
|
||||
|
||||
// we shouldn't use remove_container_by_idx here because it doesn't make sense for
|
||||
// monocle and maximized toggles which take over the whole screen before being reinserted
|
||||
// at the same index to respect locked container indexes
|
||||
let container = self
|
||||
.containers_mut()
|
||||
.remove(focused_idx)
|
||||
.ok_or_eyre("there is no container")?;
|
||||
|
||||
// We don't remove any resize adjustments for a monocle, because when this container is
|
||||
// inevitably reintegrated, it would be weird if it doesn't go back to the dimensions
|
||||
// it had before
|
||||
|
||||
self.monocle_container = Option::from(container);
|
||||
self.monocle_container_restore_idx = Option::from(focused_idx);
|
||||
self.focus_previous_container();
|
||||
|
||||
self.monocle_container
|
||||
.as_mut()
|
||||
.ok_or_eyre("there is no monocle container")?
|
||||
.load_focused_window()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Puts the monocle container back and makes the next (or the previous) container the
|
||||
/// monocle, wrapping around at the ends
|
||||
///
|
||||
/// A workspace with no other container is left as it is.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The workspace has no monocle container.
|
||||
pub fn cycle_monocle_container(&mut self, direction: CycleDirection) -> eyre::Result<()> {
|
||||
if self.containers().is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.reintegrate_monocle_container()?;
|
||||
|
||||
let new_idx = self
|
||||
.new_idx_for_cycle_direction(direction)
|
||||
.ok_or_eyre("there is no container to cycle monocle to")?;
|
||||
|
||||
self.focus_container(new_idx);
|
||||
self.new_monocle_container()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Puts the monocle container back in the containers at the index it was taken from, and
|
||||
/// focuses it. The window in front of the container is shown and the rest are hidden.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The workspace has no monocle container.
|
||||
pub fn reintegrate_monocle_container(&mut self) -> eyre::Result<()> {
|
||||
let restore_idx = self
|
||||
.monocle_container_restore_idx
|
||||
.ok_or_eyre("there is no monocle restore index")?;
|
||||
|
||||
let container = self
|
||||
.monocle_container
|
||||
.as_ref()
|
||||
.ok_or_eyre("there is no monocle container")?;
|
||||
|
||||
let container = container.clone();
|
||||
if restore_idx >= self.containers().len() {
|
||||
self.containers_mut()
|
||||
.resize(restore_idx, Container::default());
|
||||
}
|
||||
|
||||
// we shouldn't use insert_container_at_index here because it doesn't make sense for
|
||||
// monocle and maximized toggles which take over the whole screen before being reinserted
|
||||
// at the same index to respect locked container indexes
|
||||
self.containers_mut().insert(restore_idx, container);
|
||||
self.focus_container(restore_idx);
|
||||
|
||||
self.focused_container_mut()
|
||||
.ok_or_eyre("there is no container")?
|
||||
.load_focused_window()?;
|
||||
|
||||
self.monocle_container = None;
|
||||
self.monocle_container_restore_idx = None;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Takes the focused window out of its container, and out of the layout, into the floating
|
||||
/// windows of the workspace; a container that is left with no window is removed, and one that
|
||||
/// is left with windows shows the one in front now
|
||||
@@ -690,7 +893,20 @@ impl Workspace {
|
||||
///
|
||||
/// The workspace has no containers, or the focused one has no window.
|
||||
pub fn new_floating_window(&mut self) -> eyre::Result<()> {
|
||||
let window = {
|
||||
let window = if let Some(monocle_container) = &mut self.monocle_container {
|
||||
let window = monocle_container
|
||||
.remove_focused_window()
|
||||
.ok_or_eyre("there is no window")?;
|
||||
|
||||
if monocle_container.windows().is_empty() {
|
||||
self.monocle_container = None;
|
||||
self.monocle_container_restore_idx = None;
|
||||
} else {
|
||||
monocle_container.load_focused_window()?;
|
||||
}
|
||||
|
||||
window
|
||||
} else {
|
||||
let focused_idx = self.focused_container_idx();
|
||||
|
||||
let container = self
|
||||
@@ -791,6 +1007,11 @@ impl Workspace {
|
||||
/// part of the window is in view is first centered in the work area. A workspace whose tiling
|
||||
/// is off ([`Workspace::tile`] is false) moves no window.
|
||||
///
|
||||
/// While the workspace has a monocle container ([`Workspace::monocle_container`]), the window
|
||||
/// in front of it is put on the work area, less the container padding, and the other containers
|
||||
/// are left where they are. The window-based offset is then applied whatever the number of
|
||||
/// containers, if the monitor has one.
|
||||
///
|
||||
/// The layout applies the resize adjustment of each container ([`Workspace::resize_dimensions`])
|
||||
/// after the parts its layout cannot apply have been cleared. The tiles are kept in
|
||||
/// [`Workspace::latest_layout`], which the scrolling layout scrolls from.
|
||||
@@ -832,7 +1053,8 @@ impl Workspace {
|
||||
},
|
||||
);
|
||||
|
||||
if self.containers().len() <= window_based_work_area_offset_limit as usize
|
||||
if (self.containers().len() <= window_based_work_area_offset_limit as usize
|
||||
|| self.monocle_container.is_some() && window_based_work_area_offset_limit > 0)
|
||||
&& self.apply_window_based_work_area_offset
|
||||
{
|
||||
adjusted_work_area = window_based_work_area_offset.map_or_else(
|
||||
@@ -856,7 +1078,12 @@ impl Workspace {
|
||||
if self.tile {
|
||||
// the backend batches the commands this produces and sends them together
|
||||
let result = (|| -> eyre::Result<()> {
|
||||
if !self.containers().is_empty() {
|
||||
if let Some(container) = self.monocle_container.as_mut() {
|
||||
if let Some(window) = container.focused_window_mut() {
|
||||
adjusted_work_area.add_padding(container_padding);
|
||||
window.set_position(&adjusted_work_area)?;
|
||||
};
|
||||
} else if !self.containers().is_empty() {
|
||||
let mut layouts = self.layout.as_boxed_arrangement().calculate(
|
||||
&adjusted_work_area,
|
||||
NonZeroUsize::new(self.containers().len()).ok_or_eyre(
|
||||
@@ -941,7 +1168,16 @@ impl Workspace {
|
||||
// number of layouts / containers. This should never actually truncate as the remove_window
|
||||
// function takes care of cleaning up resize dimensions when destroying empty containers
|
||||
let container_count = self.containers().len();
|
||||
self.resize_dimensions.resize(container_count, None);
|
||||
|
||||
// since monocle is a toggle, we never want to truncate the resize dimensions since it will
|
||||
// almost always be toggled off and the container will be reintegrated into layout
|
||||
//
|
||||
// without this check, if there are exactly two containers, when one is toggled to monocle
|
||||
// the resize dimensions will be truncated to len == 1, and when it is reintegrated, if it
|
||||
// had a resize adjustment before, that will have been lost
|
||||
if self.monocle_container.is_none() {
|
||||
self.resize_dimensions.resize(container_count, None);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -2220,6 +2456,61 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A workspace with the windows `ids` in containers of their own, and the last of them in
|
||||
/// monocle: the others are hidden
|
||||
fn workspace_in_monocle(ids: &[u32]) -> (Arc<FakeBackend>, Workspace) {
|
||||
let (fake, mut workspace) = workspace_with(ids);
|
||||
with_backend(fake.clone(), || {
|
||||
workspace.new_monocle_container().unwrap();
|
||||
for container in workspace.containers_mut() {
|
||||
container.hide(None).unwrap();
|
||||
}
|
||||
});
|
||||
(fake, workspace)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn showing_a_workspace_in_monocle_restores_the_monocle_window_and_no_other() -> eyre::Result<()>
|
||||
{
|
||||
let (fake, mut workspace) = workspace_in_monocle(&[481, 482, 483]);
|
||||
assert!(fake.is_hidden(481) && fake.is_hidden(482) && !fake.is_hidden(483));
|
||||
with_backend(fake.clone(), || workspace.hide(None))?;
|
||||
assert!(
|
||||
fake.is_hidden(483),
|
||||
"leaving the workspace hides the monocle window too"
|
||||
);
|
||||
|
||||
with_backend(fake.clone(), || workspace.restore(false))?;
|
||||
|
||||
assert!(!fake.is_hidden(483), "the window in monocle is shown");
|
||||
assert!(
|
||||
fake.is_hidden(481) && fake.is_hidden(482),
|
||||
"the containers behind it stay hidden"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hiding_a_workspace_in_monocle_hides_the_monocle_window_too() -> eyre::Result<()> {
|
||||
let (fake, mut workspace) = workspace_in_monocle(&[491, 492]);
|
||||
|
||||
with_backend(fake.clone(), || workspace.hide(None))?;
|
||||
|
||||
assert!(fake.is_hidden(491) && fake.is_hidden(492));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_window_in_monocle_that_leaves_shows_the_containers_behind_it() -> eyre::Result<()> {
|
||||
let (fake, mut workspace) = workspace_in_monocle(&[501, 502, 503]);
|
||||
|
||||
with_backend(fake.clone(), || workspace.remove_window(503))?;
|
||||
|
||||
assert!(workspace.monocle_container.is_none());
|
||||
assert!(!fake.is_hidden(501) && !fake.is_hidden(502));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_drops_a_container_that_has_no_windows_left() -> eyre::Result<()> {
|
||||
let (fake, mut workspace) = workspace_with(&[421]);
|
||||
|
||||
@@ -0,0 +1,595 @@
|
||||
//! The monocle of `toggle-monocle`, against an in-memory desktop: the messages go in through
|
||||
//! [`WindowManager::process_command`] and the events through [`WindowManager::process_event`], and
|
||||
//! what comes out is which containers the layout tiles, which window is the monocle and where the
|
||||
//! backend is asked to put the windows, and which windows are out of sight.
|
||||
//!
|
||||
//! Window ids are in the 35_000s.
|
||||
|
||||
use komorebi::backend::Backend;
|
||||
use komorebi::backend::fake::Command;
|
||||
use komorebi::backend::fake::FakeBackend;
|
||||
use komorebi::backend::with_backend;
|
||||
use komorebi::core::MonocleFocusBehaviour;
|
||||
use komorebi::core::OperationDirection;
|
||||
use komorebi::core::Rect;
|
||||
use komorebi::core::Sizing;
|
||||
use komorebi::core::SocketMessage;
|
||||
use komorebi::state::State;
|
||||
use komorebi::window::Window;
|
||||
use komorebi::window_manager::WindowManager;
|
||||
use komorebi::window_manager_event::KWinNotification;
|
||||
use komorebi::window_manager_event::SystemNotification;
|
||||
use komorebi::window_manager_event::WindowManagerEvent;
|
||||
use std::sync::Arc;
|
||||
|
||||
fn added(id: u32) -> WindowManagerEvent {
|
||||
WindowManagerEvent::Show(
|
||||
SystemNotification::KWin(KWinNotification::WindowAdded),
|
||||
Window::from(id),
|
||||
)
|
||||
}
|
||||
|
||||
fn activated(id: u32) -> WindowManagerEvent {
|
||||
WindowManagerEvent::FocusChange(
|
||||
SystemNotification::KWin(KWinNotification::WindowActivated),
|
||||
Window::from(id),
|
||||
)
|
||||
}
|
||||
|
||||
fn removed(id: u32) -> WindowManagerEvent {
|
||||
WindowManagerEvent::Destroy(
|
||||
SystemNotification::KWin(KWinNotification::WindowRemoved),
|
||||
Window::from(id),
|
||||
)
|
||||
}
|
||||
|
||||
/// A window manager over a fake desktop with one 1920x1080 monitor (1920x1050 without the panel),
|
||||
/// and a window for each of `ids`, opened in that order
|
||||
fn desktop_with(ids: &[u32]) -> (Arc<FakeBackend>, WindowManager) {
|
||||
let fake = Arc::new(FakeBackend::with_one_monitor());
|
||||
let (_sender, receiver) = crossbeam_channel::bounded(1);
|
||||
// unix socket paths are limited to ~104 bytes on macOS, which the temp dir alone can exceed
|
||||
static NEXT: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
||||
let socket = std::path::PathBuf::from(format!(
|
||||
"/tmp/kmm-{}-{}.sock",
|
||||
std::process::id(),
|
||||
NEXT.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
|
||||
));
|
||||
|
||||
let wm = with_backend(fake.clone(), || {
|
||||
let mut wm = WindowManager::new(receiver, Some(socket)).unwrap();
|
||||
wm.init().unwrap();
|
||||
for &id in ids {
|
||||
fake.open_window(id, "foot", "foot", &format!("terminal {id}"));
|
||||
wm.process_event(added(id)).unwrap();
|
||||
}
|
||||
wm
|
||||
});
|
||||
|
||||
(fake, wm)
|
||||
}
|
||||
|
||||
/// The bounds of the monitor on the right of the one of `with_one_monitor`, which is also its work
|
||||
/// area
|
||||
fn right_half() -> Rect {
|
||||
Rect {
|
||||
left: 1920,
|
||||
top: 0,
|
||||
right: 1920,
|
||||
bottom: 1080,
|
||||
}
|
||||
}
|
||||
|
||||
/// A window manager over a fake desktop with two monitors side by side, and a window for each of
|
||||
/// `left` on the one on the left and of `right` on the one on the right, opened in that order
|
||||
fn two_monitors_with(left: &[u32], right: &[u32]) -> (Arc<FakeBackend>, WindowManager) {
|
||||
let fake = FakeBackend::with_one_monitor();
|
||||
fake.add_monitor(2, "Virtual-1", right_half(), right_half());
|
||||
let fake = Arc::new(fake);
|
||||
let (_sender, receiver) = crossbeam_channel::bounded(1);
|
||||
// unix socket paths are limited to ~104 bytes on macOS, which the temp dir alone can exceed
|
||||
static NEXT: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(1000);
|
||||
let socket = std::path::PathBuf::from(format!(
|
||||
"/tmp/kmm-{}-{}.sock",
|
||||
std::process::id(),
|
||||
NEXT.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
|
||||
));
|
||||
|
||||
let wm = with_backend(fake.clone(), || {
|
||||
let mut wm = WindowManager::new(receiver, Some(socket)).unwrap();
|
||||
wm.init().unwrap();
|
||||
for (ids, on_right) in [(left, false), (right, true)] {
|
||||
for &id in ids {
|
||||
fake.open_window(id, "foot", "foot", &format!("terminal {id}"));
|
||||
if on_right {
|
||||
fake.move_window_by_user(
|
||||
id,
|
||||
Rect {
|
||||
left: 2020,
|
||||
top: 100,
|
||||
right: 800,
|
||||
bottom: 600,
|
||||
},
|
||||
);
|
||||
}
|
||||
wm.process_event(added(id)).unwrap();
|
||||
}
|
||||
}
|
||||
wm
|
||||
});
|
||||
|
||||
(fake, wm)
|
||||
}
|
||||
|
||||
fn try_send(
|
||||
fake: &Arc<FakeBackend>,
|
||||
wm: &mut WindowManager,
|
||||
message: SocketMessage,
|
||||
) -> Result<(), String> {
|
||||
with_backend(fake.clone(), || wm.process_command(message, Vec::new()))
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
fn send(fake: &Arc<FakeBackend>, wm: &mut WindowManager, message: SocketMessage) {
|
||||
try_send(fake, wm, message).unwrap();
|
||||
}
|
||||
|
||||
fn event(fake: &Arc<FakeBackend>, wm: &mut WindowManager, event: WindowManagerEvent) {
|
||||
with_backend(fake.clone(), || wm.process_event(event)).unwrap();
|
||||
}
|
||||
|
||||
/// The windows the layout tiles, in the order of their containers
|
||||
fn tiled(wm: &WindowManager) -> Vec<u32> {
|
||||
wm.focused_workspace()
|
||||
.unwrap()
|
||||
.containers()
|
||||
.iter()
|
||||
.map(|container| container.focused_window().unwrap().id)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The state the daemon shows, as JSON: a window is serialized with what the backend knows of it
|
||||
fn state_of(fake: &Arc<FakeBackend>, wm: &WindowManager) -> serde_json::Value {
|
||||
with_backend(fake.clone(), || {
|
||||
serde_json::to_value(State::from(wm)).unwrap()
|
||||
})
|
||||
}
|
||||
|
||||
/// The window of the monocle container, if there is one
|
||||
fn monocle(wm: &WindowManager) -> Option<u32> {
|
||||
wm.focused_workspace()
|
||||
.unwrap()
|
||||
.monocle_container
|
||||
.as_ref()
|
||||
.map(|container| container.focused_window().unwrap().id)
|
||||
}
|
||||
|
||||
/// Where the one window of a workspace of its own is put: the work area less the paddings
|
||||
fn alone(id: u32) -> komorebi::core::Rect {
|
||||
let (fake, _wm) = desktop_with(&[id]);
|
||||
fake.rect_of(id).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toggle_monocle_gives_the_focused_window_the_work_area_and_toggling_again_puts_it_back() {
|
||||
let (fake, mut wm) = desktop_with(&[35_001, 35_002, 35_003]);
|
||||
event(&fake, &mut wm, activated(35_002));
|
||||
let tile = fake.rect_of(35_002).unwrap();
|
||||
let others = (fake.rect_of(35_001).unwrap(), fake.rect_of(35_003).unwrap());
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
|
||||
assert_eq!(monocle(&wm), Some(35_002));
|
||||
assert_eq!(tiled(&wm), [35_001, 35_003]);
|
||||
assert_eq!(fake.rect_of(35_002), Some(alone(35_009)));
|
||||
assert_ne!(fake.rect_of(35_002), Some(tile));
|
||||
assert!(
|
||||
fake.commands().ends_with(&[Command::Focus(35_002, true)]),
|
||||
"the monocle window is given the focus"
|
||||
);
|
||||
assert_eq!(
|
||||
(fake.rect_of(35_001).unwrap(), fake.rect_of(35_003).unwrap()),
|
||||
others,
|
||||
"the windows behind it are not moved"
|
||||
);
|
||||
assert!(fake.is_hidden(35_001) && fake.is_hidden(35_003) && !fake.is_hidden(35_002));
|
||||
assert!(wm.focused_workspace().unwrap().contains_window(35_002));
|
||||
assert!(
|
||||
wm.focused_workspace()
|
||||
.unwrap()
|
||||
.contains_managed_window(35_002)
|
||||
);
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
|
||||
assert_eq!(monocle(&wm), None);
|
||||
assert_eq!(tiled(&wm), [35_001, 35_002, 35_003]);
|
||||
assert_eq!(fake.rect_of(35_002), Some(tile));
|
||||
assert_eq!(wm.focused_workspace().unwrap().focused_container_idx(), 1);
|
||||
assert!(
|
||||
[35_001, 35_002, 35_003]
|
||||
.iter()
|
||||
.all(|id| !fake.is_hidden(*id))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_monocle_hides_the_other_windows_until_it_is_turned_off() {
|
||||
let (fake, mut wm) = desktop_with(&[35_091, 35_092, 35_093]);
|
||||
event(&fake, &mut wm, activated(35_092));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::MonocleFocusBehaviour(MonocleFocusBehaviour::Cycle),
|
||||
);
|
||||
let hidden = |ids: [u32; 3]| ids.map(|id| fake.is_hidden(id));
|
||||
|
||||
assert_eq!(hidden([35_091, 35_092, 35_093]), [true, false, true]);
|
||||
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::FocusWindow(OperationDirection::Right),
|
||||
);
|
||||
assert_eq!(monocle(&wm), Some(35_093));
|
||||
assert_eq!(
|
||||
hidden([35_091, 35_092, 35_093]),
|
||||
[true, true, false],
|
||||
"the container the monocle gave up is hidden, and the one it took is not"
|
||||
);
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
assert_eq!(hidden([35_091, 35_092, 35_093]), [false, false, false]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_back_of_a_stack_stays_hidden_in_monocle_and_after_it() {
|
||||
let (fake, mut wm) = desktop_with(&[35_101, 35_102, 35_103]);
|
||||
event(&fake, &mut wm, activated(35_102));
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::StackWindow(OperationDirection::Left),
|
||||
);
|
||||
let in_front = wm
|
||||
.focused_workspace()
|
||||
.unwrap()
|
||||
.focused_container()
|
||||
.unwrap()
|
||||
.focused_window()
|
||||
.unwrap()
|
||||
.id;
|
||||
let behind = if in_front == 35_102 { 35_101 } else { 35_102 };
|
||||
assert!(fake.is_hidden(behind));
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
assert_eq!(monocle(&wm), Some(in_front));
|
||||
assert!(
|
||||
fake.is_hidden(behind),
|
||||
"a stack in monocle is still a stack"
|
||||
);
|
||||
assert!(fake.is_hidden(35_103));
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
assert!(fake.is_hidden(behind));
|
||||
assert!(!fake.is_hidden(in_front) && !fake.is_hidden(35_103));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_monocle_goes_back_to_its_index_even_when_a_window_opens_meanwhile() {
|
||||
let (fake, mut wm) = desktop_with(&[35_011, 35_012, 35_013]);
|
||||
event(&fake, &mut wm, activated(35_011));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
|
||||
fake.open_window(35_014, "foot", "foot", "terminal 35014");
|
||||
event(&fake, &mut wm, added(35_014));
|
||||
assert_eq!(monocle(&wm), Some(35_011));
|
||||
assert_eq!(fake.rect_of(35_011), Some(alone(35_019)));
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
|
||||
assert_eq!(tiled(&wm)[0], 35_011);
|
||||
assert_eq!(tiled(&wm).len(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toggle_monocle_on_a_workspace_without_windows_is_an_error() {
|
||||
let (fake, mut wm) = desktop_with(&[]);
|
||||
|
||||
assert_eq!(
|
||||
try_send(&fake, &mut wm, SocketMessage::ToggleMonocle),
|
||||
Err(String::from("there is no container"))
|
||||
);
|
||||
assert_eq!(monocle(&wm), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_window_that_takes_the_focus_from_the_monocle_is_made_to_give_it_back() {
|
||||
let (fake, mut wm) = desktop_with(&[35_021, 35_022]);
|
||||
event(&fake, &mut wm, activated(35_021));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
fake.clear_commands();
|
||||
|
||||
event(&fake, &mut wm, activated(35_022));
|
||||
|
||||
assert_eq!(monocle(&wm), Some(35_021));
|
||||
assert!(
|
||||
fake.commands().contains(&Command::Focus(35_021, false)),
|
||||
"{:?}",
|
||||
fake.commands()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_the_cycle_behaviour_focusing_in_a_direction_moves_the_monocle_to_the_next_container() {
|
||||
let (fake, mut wm) = desktop_with(&[35_031, 35_032, 35_033]);
|
||||
event(&fake, &mut wm, activated(35_031));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::MonocleFocusBehaviour(MonocleFocusBehaviour::Cycle),
|
||||
);
|
||||
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::FocusWindow(OperationDirection::Right),
|
||||
);
|
||||
|
||||
assert_eq!(monocle(&wm), Some(35_032));
|
||||
assert_eq!(tiled(&wm), [35_031, 35_033]);
|
||||
assert_eq!(fake.rect_of(35_032), Some(alone(35_039)));
|
||||
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::FocusWindow(OperationDirection::Left),
|
||||
);
|
||||
|
||||
assert_eq!(monocle(&wm), Some(35_031));
|
||||
assert_eq!(tiled(&wm), [35_032, 35_033]);
|
||||
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::CycleFocusWindow(komorebi::core::CycleDirection::Next),
|
||||
);
|
||||
|
||||
assert_eq!(monocle(&wm), Some(35_032));
|
||||
assert_eq!(tiled(&wm), [35_031, 35_033]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_the_no_op_behaviour_focusing_in_a_direction_leaves_the_monocle_alone() {
|
||||
let (fake, mut wm) = desktop_with(&[35_041, 35_042]);
|
||||
event(&fake, &mut wm, activated(35_041));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
assert_eq!(
|
||||
State::from(&wm).monocle_focus_behaviour,
|
||||
MonocleFocusBehaviour::NoOp
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
try_send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::FocusWindow(OperationDirection::Right)
|
||||
),
|
||||
Err(String::from(
|
||||
"there is no container or monitor in this direction"
|
||||
))
|
||||
);
|
||||
assert_eq!(monocle(&wm), Some(35_041));
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocleFocusBehaviour);
|
||||
assert_eq!(
|
||||
State::from(&wm).monocle_focus_behaviour,
|
||||
MonocleFocusBehaviour::Cycle
|
||||
);
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocleFocusBehaviour);
|
||||
assert_eq!(
|
||||
State::from(&wm).monocle_focus_behaviour,
|
||||
MonocleFocusBehaviour::NoOp
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn what_is_about_the_tiles_is_refused_or_ignored_while_a_monocle_is_on() {
|
||||
let (fake, mut wm) = desktop_with(&[35_051, 35_052]);
|
||||
event(&fake, &mut wm, activated(35_051));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
|
||||
for message in [
|
||||
SocketMessage::MoveWindow(OperationDirection::Right),
|
||||
SocketMessage::CycleMoveWindow(komorebi::core::CycleDirection::Next),
|
||||
] {
|
||||
let refusal = try_send(&fake, &mut wm, message).unwrap_err();
|
||||
assert!(refusal.contains("monocle"), "{refusal}");
|
||||
}
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleFloat);
|
||||
|
||||
assert_eq!(monocle(&wm), Some(35_051));
|
||||
assert_eq!(tiled(&wm), [35_052]);
|
||||
assert!(
|
||||
wm.focused_workspace()
|
||||
.unwrap()
|
||||
.floating_windows()
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_the_window_in_monocle_tiles_the_others_again() {
|
||||
let (fake, mut wm) = desktop_with(&[35_061, 35_062]);
|
||||
event(&fake, &mut wm, activated(35_061));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
|
||||
fake.close_window_now(35_061);
|
||||
event(&fake, &mut wm, removed(35_061));
|
||||
|
||||
assert_eq!(monocle(&wm), None);
|
||||
assert_eq!(tiled(&wm), [35_062]);
|
||||
assert!(!fake.is_hidden(35_062), "the window left is shown again");
|
||||
assert_eq!(fake.rect_of(35_062), Some(alone(35_069)));
|
||||
assert!(!wm.focused_workspace().unwrap().contains_window(35_061));
|
||||
assert!(
|
||||
wm.focused_workspace()
|
||||
.unwrap()
|
||||
.monocle_container_restore_idx
|
||||
.is_none()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_tile_that_was_resized_is_the_size_it_was_after_a_monocle() {
|
||||
let (fake, mut wm) = desktop_with(&[35_081, 35_082]);
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::ResizeWindowEdge(OperationDirection::Left, Sizing::Increase),
|
||||
);
|
||||
let resized = (fake.rect_of(35_081).unwrap(), fake.rect_of(35_082).unwrap());
|
||||
event(&fake, &mut wm, activated(35_081));
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
|
||||
assert_eq!(
|
||||
(fake.rect_of(35_081).unwrap(), fake.rect_of(35_082).unwrap()),
|
||||
resized,
|
||||
"a monocle that is turned off puts the tiles back as they were resized"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_state_shows_the_monocle_container_and_the_index_it_goes_back_to() {
|
||||
let (fake, mut wm) = desktop_with(&[35_071, 35_072]);
|
||||
event(&fake, &mut wm, activated(35_072));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
|
||||
let state = state_of(&fake, &wm);
|
||||
let workspace = &state["monitors"]["elements"][0]["workspaces"]["elements"][0];
|
||||
|
||||
assert_eq!(
|
||||
workspace["monocle_container"]["windows"]["elements"][0]["id"],
|
||||
35_072
|
||||
);
|
||||
assert_eq!(workspace["monocle_container_restore_idx"], 1);
|
||||
assert_eq!(state["monocle_focus_behaviour"], "NoOp");
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
let state = state_of(&fake, &wm);
|
||||
let workspace = &state["monitors"]["elements"][0]["workspaces"]["elements"][0];
|
||||
|
||||
assert!(workspace["monocle_container"].is_null());
|
||||
assert!(workspace.get("monocle_container_restore_idx").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focusing_towards_a_monitor_in_monocle_gives_the_focus_to_its_monocle_window() {
|
||||
let (fake, mut wm) = two_monitors_with(&[35_111, 35_112], &[35_113, 35_114]);
|
||||
event(&fake, &mut wm, activated(35_113));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
event(&fake, &mut wm, activated(35_112));
|
||||
assert_eq!(wm.focused_monitor_idx(), 0);
|
||||
let before = wm.monitors()[1]
|
||||
.focused_workspace()
|
||||
.unwrap()
|
||||
.focused_container_idx();
|
||||
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::FocusWindow(OperationDirection::Right),
|
||||
);
|
||||
|
||||
assert_eq!(wm.focused_monitor_idx(), 1);
|
||||
assert_eq!(fake.foreground_window(), Some(35_113));
|
||||
assert_eq!(
|
||||
wm.monitors()[1]
|
||||
.focused_workspace()
|
||||
.unwrap()
|
||||
.focused_container_idx(),
|
||||
before,
|
||||
"no container of the monitor in monocle is picked by the side the focus came from"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_container_moved_to_a_monitor_in_monocle_turns_the_monocle_off_there() {
|
||||
let (fake, mut wm) = two_monitors_with(&[35_121, 35_122], &[35_123, 35_124]);
|
||||
event(&fake, &mut wm, activated(35_123));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
assert!(fake.is_hidden(35_124));
|
||||
event(&fake, &mut wm, activated(35_122));
|
||||
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::MoveWindow(OperationDirection::Right),
|
||||
);
|
||||
|
||||
assert!(
|
||||
wm.monitors()[1]
|
||||
.focused_workspace()
|
||||
.unwrap()
|
||||
.monocle_container
|
||||
.is_none()
|
||||
);
|
||||
assert!(
|
||||
[35_121, 35_122, 35_123, 35_124]
|
||||
.iter()
|
||||
.all(|id| !fake.is_hidden(*id)),
|
||||
"the windows the monocle hid are shown again"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_container_sent_to_a_workspace_in_monocle_turns_the_monocle_off_there() {
|
||||
let (fake, mut wm) = desktop_with(&[35_131]);
|
||||
send(&fake, &mut wm, SocketMessage::FocusWorkspaceNumber(1));
|
||||
for id in [35_132, 35_133] {
|
||||
fake.open_window(id, "foot", "foot", &format!("terminal {id}"));
|
||||
event(&fake, &mut wm, added(id));
|
||||
}
|
||||
event(&fake, &mut wm, activated(35_132));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
assert!(fake.is_hidden(35_133));
|
||||
send(&fake, &mut wm, SocketMessage::FocusWorkspaceNumber(0));
|
||||
event(&fake, &mut wm, activated(35_131));
|
||||
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::SendContainerToWorkspaceNumber(1),
|
||||
);
|
||||
|
||||
let workspace = &wm.focused_monitor().unwrap().workspaces()[1];
|
||||
assert!(workspace.monocle_container.is_none());
|
||||
assert_eq!(workspace.containers().len(), 3);
|
||||
assert!(
|
||||
!fake.is_hidden(35_133),
|
||||
"the window the monocle hid is shown again"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eager_focus_finds_the_window_of_an_executable_in_the_monocle() {
|
||||
let (fake, mut wm) = desktop_with(&[35_141]);
|
||||
fake.open_window(35_142, "kate", "kate", "terminal 35142");
|
||||
event(&fake, &mut wm, added(35_142));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
event(&fake, &mut wm, activated(35_141));
|
||||
assert_eq!(monocle(&wm), Some(35_142));
|
||||
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::EagerFocus(String::from("kate")),
|
||||
);
|
||||
|
||||
assert_eq!(fake.foreground_window(), Some(35_142));
|
||||
}
|
||||
@@ -27,6 +27,9 @@
|
||||
//! tile, or the focus to it.
|
||||
//! - `toggle-float` takes the focused window out of the layout, or puts it back, and
|
||||
//! `toggle-lock` locks the focused container at its index, or unlocks it.
|
||||
//! - `toggle-monocle` gives the focused container the whole work area, or puts it back, and
|
||||
//! `monocle-focus-behaviour` and `toggle-monocle-focus-behaviour` set what focusing in a
|
||||
//! direction does meanwhile.
|
||||
//! - `focused-workspace-padding`, `focused-workspace-container-padding`, `workspace-padding`,
|
||||
//! `container-padding` and the two `adjust-*-padding` set the padding around the tiles and
|
||||
//! between them, and `global-work-area-offset`, `monitor-work-area-offset`,
|
||||
@@ -190,6 +193,13 @@ gen_target_subcommand_args! {
|
||||
FocusStackWindow,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct MonocleFocusBehaviour {
|
||||
/// Desired monocle focus behavior
|
||||
#[clap(value_enum)]
|
||||
behaviour: komorebi_client::MonocleFocusBehaviour,
|
||||
}
|
||||
|
||||
macro_rules! gen_named_target_subcommand_args {
|
||||
// SubCommand Pattern
|
||||
( $( $name:ident ),+ $(,)? ) => {
|
||||
@@ -880,6 +890,8 @@ enum SubCommand {
|
||||
ToggleTiling,
|
||||
/// Toggle floating mode for the focused window
|
||||
ToggleFloat,
|
||||
/// Toggle monocle mode for the focused container
|
||||
ToggleMonocle,
|
||||
/// Toggle a lock for the focused container, ensuring it will not be displaced by any new windows
|
||||
ToggleLock,
|
||||
/// Force komorebi to manage the focused window
|
||||
@@ -891,6 +903,11 @@ enum SubCommand {
|
||||
CrossMonitorMoveBehaviour(CrossMonitorMoveBehaviour),
|
||||
/// Toggle the behaviour when moving windows across monitor boundaries
|
||||
ToggleCrossMonitorMoveBehaviour,
|
||||
/// Set the behavior when focusing in a direction while a monocle container is active
|
||||
#[clap(arg_required_else_help = true)]
|
||||
MonocleFocusBehaviour(MonocleFocusBehaviour),
|
||||
/// Toggle the behavior when focusing in a direction while a monocle container is active
|
||||
ToggleMonocleFocusBehaviour,
|
||||
/// Set the operation behavior when the focused window is not managed
|
||||
#[clap(arg_required_else_help = true)]
|
||||
UnmanagedWindowOperationBehaviour(UnmanagedWindowOperationBehaviour),
|
||||
@@ -1090,6 +1107,9 @@ fn main() -> eyre::Result<()> {
|
||||
SubCommand::ToggleCrossMonitorMoveBehaviour => {
|
||||
send_message(&SocketMessage::ToggleCrossMonitorMoveBehaviour)?;
|
||||
}
|
||||
SubCommand::ToggleMonocleFocusBehaviour => {
|
||||
send_message(&SocketMessage::ToggleMonocleFocusBehaviour)?;
|
||||
}
|
||||
SubCommand::FocusMonitor(args) => {
|
||||
send_message(&SocketMessage::FocusMonitorNumber(args.target))?;
|
||||
}
|
||||
@@ -1125,6 +1145,9 @@ fn main() -> eyre::Result<()> {
|
||||
args.cycle_direction,
|
||||
))?;
|
||||
}
|
||||
SubCommand::ToggleMonocle => {
|
||||
send_message(&SocketMessage::ToggleMonocle)?;
|
||||
}
|
||||
SubCommand::ToggleFloat => {
|
||||
send_message(&SocketMessage::ToggleFloat)?;
|
||||
}
|
||||
@@ -1434,6 +1457,9 @@ fn main() -> eyre::Result<()> {
|
||||
args.names,
|
||||
))?;
|
||||
}
|
||||
SubCommand::MonocleFocusBehaviour(args) => {
|
||||
send_message(&SocketMessage::MonocleFocusBehaviour(args.behaviour))?;
|
||||
}
|
||||
SubCommand::UnmanagedWindowOperationBehaviour(args) => {
|
||||
send_message(&SocketMessage::UnmanagedWindowOperationBehaviour(
|
||||
args.operation_behaviour,
|
||||
|
||||
@@ -479,6 +479,23 @@ fn the_subcommands_about_the_focused_window_and_pausing_send_their_message() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_monocle_subcommands_send_their_message() {
|
||||
sends(&["toggle-monocle"], r#"{"type":"ToggleMonocle"}"#);
|
||||
sends(
|
||||
&["monocle-focus-behaviour", "cycle"],
|
||||
r#"{"type":"MonocleFocusBehaviour","content":"Cycle"}"#,
|
||||
);
|
||||
sends(
|
||||
&["monocle-focus-behaviour", "no-op"],
|
||||
r#"{"type":"MonocleFocusBehaviour","content":"NoOp"}"#,
|
||||
);
|
||||
sends(
|
||||
&["toggle-monocle-focus-behaviour"],
|
||||
r#"{"type":"ToggleMonocleFocusBehaviour"}"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mouse_follows_focus_is_set_with_enable_and_disable_or_toggled() {
|
||||
sends(
|
||||
@@ -755,6 +772,7 @@ fn docgen_writes_the_help_of_every_subcommand_in_a_text_fence() {
|
||||
"minimize.md",
|
||||
"monitor-information.md",
|
||||
"monitor-work-area-offset.md",
|
||||
"monocle-focus-behaviour.md",
|
||||
"mouse-follows-focus.md",
|
||||
"move-to-last-workspace.md",
|
||||
"move-to-monitor-workspace.md",
|
||||
@@ -800,6 +818,8 @@ fn docgen_writes_the_help_of_every_subcommand_in_a_text_fence() {
|
||||
"toggle-float-override.md",
|
||||
"toggle-float.md",
|
||||
"toggle-lock.md",
|
||||
"toggle-monocle-focus-behaviour.md",
|
||||
"toggle-monocle.md",
|
||||
"toggle-mouse-follows-focus.md",
|
||||
"toggle-pause.md",
|
||||
"toggle-tiling.md",
|
||||
|
||||
@@ -305,6 +305,17 @@ class Kde:
|
||||
for container in elements
|
||||
]
|
||||
|
||||
def monocle(self, workspace: int = 0) -> list[str]:
|
||||
"""The titles of the windows of the monocle container of a workspace of the first monitor.
|
||||
|
||||
The windows are in the order of the stack. A workspace that is not in monocle gives an
|
||||
empty list.
|
||||
"""
|
||||
container = self._workspace(workspace)["monocle_container"]
|
||||
if container is None:
|
||||
return []
|
||||
return [window["details"]["title"] for window in container["windows"]["elements"]]
|
||||
|
||||
def managed(self, workspace: int = 0) -> int:
|
||||
"""The number of windows the daemon has on a workspace of the first monitor."""
|
||||
containers = self._workspace(workspace)["containers"]["elements"]
|
||||
@@ -313,13 +324,15 @@ class Kde:
|
||||
def managed_all(self) -> int:
|
||||
"""The number of windows the daemon has, on every workspace of every monitor.
|
||||
|
||||
That is the windows of the containers, and the floating windows.
|
||||
That is the windows of the containers, the monocle container and the floating windows.
|
||||
"""
|
||||
total = 0
|
||||
for monitor in self.state()["monitors"]["elements"]:
|
||||
for workspace in monitor["workspaces"]["elements"]:
|
||||
for container in workspace["containers"]["elements"]:
|
||||
total += len(container["windows"]["elements"])
|
||||
if workspace["monocle_container"] is not None:
|
||||
total += len(workspace["monocle_container"]["windows"]["elements"])
|
||||
total += len(workspace["floating_windows"]["elements"])
|
||||
return total
|
||||
|
||||
|
||||
@@ -367,10 +367,14 @@ def container(*titles: str, focused: int = 0) -> dict[str, object]:
|
||||
|
||||
|
||||
def workspace(
|
||||
*containers: dict[str, object], focused: int = 0, floating: tuple[str, ...] = ()
|
||||
*containers: dict[str, object],
|
||||
focused: int = 0,
|
||||
floating: tuple[str, ...] = (),
|
||||
monocle: dict[str, object] | None = None,
|
||||
) -> dict[str, object]:
|
||||
return {
|
||||
"containers": {"elements": list(containers), "focused": focused},
|
||||
"monocle_container": monocle,
|
||||
"floating_windows": {"elements": [window(t) for t in floating], "focused": 0},
|
||||
}
|
||||
|
||||
@@ -409,6 +413,21 @@ def test_a_workspace_without_containers_has_no_titles(machine: FakeMachine) -> N
|
||||
assert Kde(machine, "main").containers() == []
|
||||
|
||||
|
||||
def test_monocle_is_the_titles_of_the_monocle_container_and_empty_without_one(
|
||||
machine: FakeMachine,
|
||||
) -> None:
|
||||
machine.reply(
|
||||
"komorebic state",
|
||||
output=a_state(
|
||||
workspace(container("a"), monocle=container("m", "n")), workspace(container("d"))
|
||||
),
|
||||
)
|
||||
kde = Kde(machine, "main")
|
||||
|
||||
assert kde.monocle() == ["m", "n"]
|
||||
assert kde.monocle(1) == []
|
||||
|
||||
|
||||
def test_managed_counts_the_windows_of_every_container_of_the_workspace(
|
||||
machine: FakeMachine,
|
||||
) -> None:
|
||||
@@ -422,7 +441,7 @@ def test_managed_counts_the_windows_of_every_container_of_the_workspace(
|
||||
assert kde.managed(1) == 1
|
||||
|
||||
|
||||
def test_managed_all_counts_the_windows_and_the_floating_windows_of_every_workspace(
|
||||
def test_managed_all_counts_the_windows_the_floating_windows_and_the_monocle_of_every_workspace(
|
||||
machine: FakeMachine,
|
||||
) -> None:
|
||||
first = {
|
||||
@@ -431,14 +450,17 @@ def test_managed_all_counts_the_windows_and_the_floating_windows_of_every_worksp
|
||||
}
|
||||
second = {
|
||||
"id": 2,
|
||||
"workspaces": {"elements": [workspace(container("c")), workspace()], "focused": 0},
|
||||
"workspaces": {
|
||||
"elements": [workspace(container("c")), workspace(monocle=container("m"))],
|
||||
"focused": 0,
|
||||
},
|
||||
}
|
||||
machine.reply(
|
||||
"komorebic state",
|
||||
output=json.dumps({"monitors": {"elements": [first, second], "focused": 0}}),
|
||||
)
|
||||
|
||||
assert Kde(machine, "main").managed_all() == 4
|
||||
assert Kde(machine, "main").managed_all() == 5
|
||||
|
||||
|
||||
def test_managed_is_zero_for_a_workspace_without_containers(machine: FakeMachine) -> None:
|
||||
|
||||
@@ -192,6 +192,8 @@ scrolling-layout-columns 2
|
||||
change-layout bsp
|
||||
preselect-direction left
|
||||
cancel-preselect
|
||||
toggle-monocle
|
||||
toggle-monocle
|
||||
toggle-float
|
||||
toggle-float
|
||||
toggle-lock
|
||||
@@ -302,6 +304,9 @@ cross-monitor-move-behaviour insert
|
||||
cross-monitor-move-behaviour swap
|
||||
toggle-cross-monitor-move-behaviour
|
||||
toggle-cross-monitor-move-behaviour
|
||||
monocle-focus-behaviour cycle
|
||||
toggle-monocle-focus-behaviour
|
||||
toggle-monocle-focus-behaviour
|
||||
unmanaged-window-operation-behaviour op
|
||||
unmanaged-window-operation-behaviour no-op
|
||||
unmanaged-window-operation-behaviour op
|
||||
|
||||
@@ -4,14 +4,18 @@
|
||||
# the fake), that the daemon and KWin agree on which window has the focus, that `komorebic` reaches
|
||||
# the daemon of a session and reads its state, that `komorebic focus` and `cycle-focus` move KWin's
|
||||
# focus (`komorebi/tests/focus.rs` checks which window they pick), that `komorebic move` and
|
||||
# `cycle-move` swap windows between their tiles (`komorebi/tests/moving.rs`), and that
|
||||
# `komorebic stop` gives KWin back what the daemon set up in it. A window manager that agrees with itself proves nothing, so what the daemon
|
||||
# believes is read from its debug log and from `komorebic state`, and what KWin has through kdotool.
|
||||
# `cycle-move` swap windows between their tiles (`komorebi/tests/moving.rs`), that
|
||||
# `komorebic toggle-monocle` gives one window the whole work area and puts it back, and hides the
|
||||
# others on the parking desktop, which a clean stop and the next start after a crash put right
|
||||
# (`komorebi/tests/monocle.rs`), and that `komorebic stop` gives KWin back what the daemon set up in
|
||||
# it. A window manager that agrees with itself proves nothing, so what the daemon believes is read
|
||||
# from its debug log and from `komorebic state`, and what KWin has through kdotool.
|
||||
import json
|
||||
|
||||
from komorebi_vm import Checks, Kde, Rect, daemon
|
||||
|
||||
W, H = 1920, 1080
|
||||
PARK = "komorebi-park"
|
||||
# foot sizes itself to whole cells of its font, so its frame can be short of the one asked for
|
||||
CELL = 24
|
||||
|
||||
@@ -64,6 +68,20 @@ def answering() -> bool:
|
||||
return status == 0 and json.loads(out)[0]["size"]["right"] == W
|
||||
|
||||
|
||||
def parked() -> list[str]:
|
||||
"""The titles of the windows that are on the parking desktop, which is the last desktop."""
|
||||
names = kde.desktop_names()
|
||||
if PARK not in names:
|
||||
return []
|
||||
park = names.index(PARK) + 1
|
||||
return sorted(t for t in ["win1", "win2"] if kde.wid(t) != "" and kde.desk(kde.wid(t)) == park)
|
||||
|
||||
|
||||
def on_a_workspace_desktop() -> bool:
|
||||
"""Every window that is open is on a desktop that is a workspace, not on the parking one."""
|
||||
return all(kde.desk(kde.wid(t)) in (1, 2) for t in ["win1", "win2"] if kde.wid(t) != "")
|
||||
|
||||
|
||||
def state_agrees() -> bool:
|
||||
"""The window komorebi's state has focused is the one KWin has."""
|
||||
active = kde.active()
|
||||
@@ -163,7 +181,65 @@ checks.check(
|
||||
)
|
||||
report(titles)
|
||||
|
||||
print("== 6. minimize and restore")
|
||||
print("== 6. monocle")
|
||||
focused = kde.active()
|
||||
tile = kde.rect(focused)
|
||||
kde.komorebic("toggle-monocle")
|
||||
|
||||
|
||||
def fills_the_work_area(wid: str) -> bool:
|
||||
r = kde.rect(wid)
|
||||
return r.w > W - 120 and r.h > H - 120
|
||||
|
||||
|
||||
checks.check(
|
||||
"in monocle the focused window fills the work area",
|
||||
kde.wait_for(lambda: fills_the_work_area(focused), timeout=20),
|
||||
)
|
||||
checks.check(
|
||||
"komorebi's state has it as the monocle container",
|
||||
kde.wait_for(
|
||||
lambda: kde.state()["monitors"]["elements"][0]["workspaces"]["elements"][0][
|
||||
"monocle_container"
|
||||
]
|
||||
is not None
|
||||
),
|
||||
)
|
||||
checks.check("... and it still has the focus", kde.title(kde.active()) == kde.title(focused))
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"toggling back puts it on its tile",
|
||||
kde.wait_for(lambda: kde.rect(focused) == tile, timeout=20),
|
||||
)
|
||||
checks.check(
|
||||
"... and every window is where the daemon asked for it",
|
||||
kde.wait_for(lambda: all(where_asked(t) for t in titles), timeout=20),
|
||||
)
|
||||
|
||||
kde.komorebic("monocle-focus-behaviour", "cycle")
|
||||
kde.komorebic("toggle-monocle")
|
||||
kde.wait_for(lambda: fills_the_work_area(focused), timeout=20)
|
||||
kde.komorebic("focus", "right")
|
||||
checks.check(
|
||||
"with the cycle behaviour, focusing in a direction gives another window the work area",
|
||||
kde.wait_for(
|
||||
lambda: kde.active() != focused and fills_the_work_area(kde.active()), timeout=20
|
||||
),
|
||||
)
|
||||
kde.komorebic("toggle-monocle")
|
||||
kde.komorebic("monocle-focus-behaviour", "no-op")
|
||||
checks.check(
|
||||
"the three windows are tiled again",
|
||||
kde.wait_for(
|
||||
lambda: (
|
||||
all(where_asked(t) for t in titles)
|
||||
and all(kde.rect(kde.wid(t)).w < W - 20 for t in titles)
|
||||
),
|
||||
timeout=20,
|
||||
),
|
||||
)
|
||||
|
||||
print("== 7. minimize and restore")
|
||||
kde.minimize(kde.wid("win2"))
|
||||
two = ["win1", "win3"]
|
||||
checks.check(
|
||||
@@ -190,7 +266,7 @@ checks.check(
|
||||
)
|
||||
report(titles)
|
||||
|
||||
print("== 7. close")
|
||||
print("== 8. close")
|
||||
kde.close(kde.wid("win3"))
|
||||
checks.check("KWin closed win3", kde.wait_for(lambda: kde.wid("win3") == "", timeout=10))
|
||||
checks.check(
|
||||
@@ -207,7 +283,49 @@ report(["win1", "win2"])
|
||||
checks.check("komorebi manages the two that are left", kde.wait_for(lambda: kde.managed() == 2))
|
||||
checks.check("KWin carried out every command", "the bridge could not do" not in daemon_log())
|
||||
|
||||
print("== 8. KWin restarts under the daemon")
|
||||
print("== 9. a clean stop undoes what a monocle did")
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"the window that is not in monocle is out of sight on a parking desktop",
|
||||
kde.wait_for(lambda: len(parked()) == 1),
|
||||
)
|
||||
kde.komorebic("stop")
|
||||
checks.check("the daemon exited", kde.wait_for(lambda: not kde.komorebi_running()))
|
||||
checks.check("the parking desktop is gone", kde.wait_for(lambda: PARK not in kde.desktop_names()))
|
||||
checks.check(
|
||||
"and every window is on a workspace's desktop", kde.wait_for(on_a_workspace_desktop)
|
||||
)
|
||||
|
||||
print("== 10. a crash with a monocle on leaves nothing stuck behind")
|
||||
kde.start_komorebi()
|
||||
checks.check("the daemon answers", kde.wait_for(answering, timeout=30))
|
||||
checks.check("it manages the two windows again", kde.wait_for(lambda: kde.managed() == 2))
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"a window is parked and a parking desktop exists",
|
||||
kde.wait_for(lambda: len(parked()) == 1),
|
||||
)
|
||||
kde.kill_komorebi()
|
||||
checks.check(
|
||||
"the daemon is dead and the parking desktop is still there, with a window on it",
|
||||
PARK in kde.desktop_names() and len(parked()) == 1,
|
||||
)
|
||||
kde.start_komorebi()
|
||||
checks.check(
|
||||
"the next start removed the stale parking desktop",
|
||||
kde.wait_for(lambda: answering() and PARK not in kde.desktop_names()),
|
||||
)
|
||||
checks.check("and brought the parked window back", kde.wait_for(on_a_workspace_desktop))
|
||||
checks.check("it manages the two windows again", kde.wait_for(lambda: kde.managed() == 2))
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"after a crash and a restart a monocle still hides the other window",
|
||||
kde.wait_for(lambda: len(parked()) == 1),
|
||||
)
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check("and turned off, nothing is out of sight", kde.wait_for(lambda: parked() == []))
|
||||
|
||||
print("== 11. KWin restarts under the daemon")
|
||||
kde.restart_kwin()
|
||||
checks.check(
|
||||
"the daemon loaded its script into the new KWin",
|
||||
@@ -228,7 +346,7 @@ checks.check(
|
||||
)
|
||||
report(["afterwards"])
|
||||
|
||||
print("== 9. komorebic stop")
|
||||
print("== 12. komorebic stop")
|
||||
kde.komorebic("stop")
|
||||
checks.check("the daemon exited", kde.wait_for(lambda: not kde.komorebi_running()))
|
||||
checks.check("its socket is gone", kde.run(f"test -e {kde.runtime}/komorebi/komorebi.sock")[0] != 0)
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
# komorebi stops, and that one a crashed komorebi left behind is swept by the next. The windows a
|
||||
# stack hides are on a desktop of their own, not minimized: their events are not the user's, and
|
||||
# the window that is in view is always the one komorebi and KWin both have focused, also after
|
||||
# the stack is cycled or a window of it is focused by its place in it.
|
||||
# the stack is cycled or a window of it is focused by its place in it. A monocle puts the windows
|
||||
# of the other containers out of sight in the same way, and over a stack leaves the stack as it was.
|
||||
# `komorebi/tests/stacks.rs` checks which windows a stack holds against the fake.
|
||||
from komorebi_vm import Checks, Kde, Rect
|
||||
|
||||
@@ -56,6 +57,12 @@ def inside(r: Rect) -> bool:
|
||||
return r.x >= 0 and r.y >= 0 and r.x + r.w <= W and r.y + r.h <= H
|
||||
|
||||
|
||||
def fills_the_work_area(title: str) -> bool:
|
||||
"""The window is as large as the screen, less the room a panel could take."""
|
||||
r = kde.rect(kde.wid(title))
|
||||
return r.w > W - 120 and r.h > H - 120
|
||||
|
||||
|
||||
def on_a_workspace_desktop() -> bool:
|
||||
"""Every window that is left is on a desktop that is a workspace, not on the parking one."""
|
||||
return all(kde.desk(kde.wid(t)) in (1, 2) for t in TITLES if kde.wid(t) != "")
|
||||
@@ -175,7 +182,51 @@ checks.check(
|
||||
)
|
||||
checks.check("two tiles are left", kde.wait_for(lambda: sizes() == [1, 1]))
|
||||
|
||||
print("== 8. stack all, and unstack all")
|
||||
print("== 8. a monocle hides the other windows, and over a stack it leaves the stack as it was")
|
||||
tiles = {t: kde.rect(kde.wid(t)) for t in TITLES if kde.wid(t) != ""}
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"the window in monocle fills the work area and the other one is out of sight",
|
||||
kde.wait_for(lambda: len(parked()) == 1 and fills_the_work_area(active_title())),
|
||||
)
|
||||
checks.check(
|
||||
"it is the one with the focus, and komorebi's state has it as the monocle container",
|
||||
kde.monocle() == [active_title()] and parked() != [active_title()],
|
||||
)
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"turned off, nothing is out of sight and the windows are on their tiles again",
|
||||
kde.wait_for(
|
||||
lambda: parked() == [] and {t: kde.rect(kde.wid(t)) for t in tiles} == tiles
|
||||
),
|
||||
)
|
||||
kde.komorebic("stack-all")
|
||||
checks.check(
|
||||
"stacked, a window is out of sight", kde.wait_for(lambda: sizes() == [2] and len(parked()) == 1)
|
||||
)
|
||||
stacked = kde.containers()
|
||||
out_of_sight = parked()
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"a monocle over the stack: the whole stack is the monocle, and the same window is out of sight",
|
||||
kde.wait_for(lambda: sorted(kde.monocle()) == sorted(stacked[0]) and parked() == out_of_sight),
|
||||
)
|
||||
checks.check("the layout has no container left", kde.containers() == [])
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"turned off, the stack is the same and the same window is out of sight",
|
||||
kde.wait_for(
|
||||
lambda: kde.containers() == stacked and kde.monocle() == [] and parked() == out_of_sight
|
||||
),
|
||||
)
|
||||
checks.check("and the window in view has the focus", kde.wait_for(agree))
|
||||
kde.komorebic("unstack-all")
|
||||
checks.check(
|
||||
"unstacked, there are two tiles and nothing is out of sight",
|
||||
kde.wait_for(lambda: sizes() == [1, 1] and parked() == []),
|
||||
)
|
||||
|
||||
print("== 9. stack all, and unstack all")
|
||||
kde.komorebic("stack-all")
|
||||
checks.check(
|
||||
"every window is in one stack, with one in view",
|
||||
@@ -188,7 +239,7 @@ checks.check(
|
||||
kde.wait_for(lambda: sizes() == [1, 1] and parked() == []),
|
||||
)
|
||||
|
||||
print("== 9. a crash leaves a parking desktop, which the next start sweeps")
|
||||
print("== 10. a crash leaves a parking desktop, which the next start sweeps")
|
||||
kde.komorebic("stack-all")
|
||||
checks.check("a window is parked", kde.wait_for(lambda: len(parked()) == 1))
|
||||
names_before = kde.desktop_names()
|
||||
@@ -214,7 +265,7 @@ checks.check(
|
||||
kde.wait_for(lambda: park_desktop() != 0 and len(parked()) == 1),
|
||||
)
|
||||
|
||||
print("== 10. a clean stop puts every window back")
|
||||
print("== 11. a clean stop puts every window back")
|
||||
still_open = [t for t in TITLES if kde.wid(t) != ""]
|
||||
kde.komorebic("stop")
|
||||
checks.check("komorebi exited", kde.wait_for(lambda: not kde.komorebi_running()))
|
||||
|
||||
Reference in new issue
Block a user