mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-18 06:38:38 +01:00
feat(wm): maximize
A window could be given the work area only as a tile of the layout, which has padding around it. `komorebic toggle-maximize` has KWin maximize the focused window instead: it gets the work area of its monitor with the panels left alone, and it leaves the layout, so that it is in no container. Toggled again, the window is restored, put in a container of its own at the index it was taken from, and the workspace is tiled again. The window is kept in the workspace as its maximized window, with the index it goes back to, and the state shows both. While it is maximized the workspace asks KWin to maximize it again on every tiling, and does not move the containers behind it. The messages that are about the tiles (move, stack, resize, promote, preselect, lock, float, monocle, and the ones that send a container to another monitor or workspace) are dropped before they are handled, since there is no tile to act on. Focusing in a direction finds no container on any side of it, so the focus goes to the monitor on that side, where a maximized window or a monocle is given the focus whole. Showing the workspace again restores the maximized window and focuses it ahead of the containers' windows. A window in monocle that is maximized leaves the monocle, and one that closes takes the maximize with it. Backend gets a maximize command, which does nothing unless a backend implements it; the fake desktop and the KWin backend do, and the bridge carries it out with KWin's own `setMaximize`. A maximize also makes the bridge forget the position it was last asked to put the window at, which it would otherwise set again on the work area's size when the window's frame changed within a second of a tiling. komorebi/tests/maximize.rs and maximize_commands.rs drive it against the fake desktop, with one monitor and with two. The bridge's tests and the backend's tests read the maximize command from the same fixture, so that what one sends is what the other carries out. vm-features is a new session suite that reads screenshots: the first thing it checks is that the maximized window fills the work area, is the one on top, and goes back to its tile; the vm-commands sweep runs the new command.
This commit is contained in:
1 parent
0d21dd332c
commit
05de20749b
31 files changed
+1501
-68
No files matched your search
@@ -38,8 +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, give one window the whole work area, 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 or have KWin maximize it, 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:
|
||||
@@ -162,9 +162,10 @@ another layout, `layout-ratios` and `scrolling-layout-columns` tune it,
|
||||
`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, `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
|
||||
others, and puts it back, `toggle-maximize` has KWin maximize the focused window
|
||||
and restore it, 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`
|
||||
takes it back, and `toggle-pause` stops the daemon acting on events and orders
|
||||
until it is resumed. The padding commands set the gaps around the tiles, and
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
```text
|
||||
Toggle the compositor's maximization for the focused window
|
||||
|
||||
Usage: toggle-maximize
|
||||
|
||||
Options:
|
||||
-h, --help
|
||||
Print help
|
||||
|
||||
```
|
||||
+52
-13
@@ -39,6 +39,9 @@ daemon. It grows with the code: each part of the daemon that is added has its pl
|
||||
- **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`]).
|
||||
- **Maximized window**: a workspace's one window that the compositor has maximized. It is in no
|
||||
container, so it has left the layout, until it is put back in a container of its own where it
|
||||
was ([`Workspace::maximized_window`]).
|
||||
- **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
|
||||
@@ -98,9 +101,10 @@ The desktop, as the window manager sees it, is two lists and a pointer:
|
||||
of the window that has it.
|
||||
|
||||
A command is one of: move and resize a window, focus it, raise it, hide it or restore it,
|
||||
minimize it or bring it back, close it, put the pointer in the middle of a rectangle, make
|
||||
desktops for the workspaces, show a workspace on a monitor, and put a window on a workspace. The workspace a
|
||||
window is on, and the one each monitor shows, are queries.
|
||||
minimize it or bring it back, maximize it or unmaximize it, close it, put the pointer in the
|
||||
middle of a rectangle, make desktops for the workspaces, show a workspace on a monitor, and put
|
||||
a window on a workspace. The workspace a window is on, and the one each monitor shows, are
|
||||
queries.
|
||||
|
||||
The window manager tiles a tree of four levels, each level a [`Ring`]: a list with one
|
||||
element focused, so that "the focused workspace" or "the focused container" means
|
||||
@@ -111,8 +115,8 @@ the same thing at every level.
|
||||
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, its
|
||||
monocle container, if it has one, and its floating windows, which are in no container and
|
||||
which the layout does not tile.
|
||||
monocle container and its maximized window, if it has them, 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
|
||||
@@ -413,7 +417,8 @@ columns out of view are off the screen; a window whose tile is out of view while
|
||||
in view is centered in the work area first. A `FocusChange` tiles a scrolling workspace after the
|
||||
focused container has changed, which scrolls the strip to it. KWin keeps part of a window it
|
||||
resizes on an output, so the bridge asks again for the position of a window KWin pulled back
|
||||
within a second of the command, three times at most ([`bridge.js`]'s `settle`).
|
||||
within a second of the command, three times at most ([`bridge.js`]'s `settle`), unless the window
|
||||
is maximized meanwhile.
|
||||
|
||||
`Promote` moves the focused container to index 0, the largest tile of every layout but the grid,
|
||||
through `LockableSequence`, so the containers before it move one index on
|
||||
@@ -479,6 +484,27 @@ is none. `CycleFocusWindow` always carries the monocle to the next or the previo
|
||||
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.
|
||||
|
||||
`ToggleMaximize` takes the focused window out of its container, and the container with it when
|
||||
it was the last window in it, remembers the index, and asks the backend to maximize it: KWin's
|
||||
own maximize, to the work area with the panels left alone ([`WindowManager::toggle_maximize`],
|
||||
[`Workspace::new_maximized_window`]). From then on the workspace has a maximized window, in no
|
||||
container, and [`Workspace::update`] asks the backend to maximize it again and moves nothing
|
||||
else, so the containers stay where they were behind it. Toggled again, the window is restored
|
||||
(the backend gives it back the frame it had), put in a container of its own at the index it came
|
||||
from, and the workspace is tiled again ([`Workspace::reintegrate_maximized_window`]). A window in
|
||||
monocle that is maximized leaves the monocle. While a window is maximized, the messages that are
|
||||
about the tiles are dropped before they are handled: `MoveWindow`, `CycleMoveWindow`, the stack
|
||||
messages, the resize, promote and preselect messages, `ToggleLock`, `ToggleFloat`,
|
||||
`ToggleMonocle`, and the messages that send a container to another monitor or workspace
|
||||
(`is_layout_command` in [`process_command`](../../komorebi/src/process_command.rs)). A window that
|
||||
closes while it is maximized leaves the workspace like any other. `FocusWindow` finds no
|
||||
container on any side of the maximized window, so the focus goes to the monitor on that side and
|
||||
fails where there is none, and a maximized window, or a monocle, on the workspace it reaches is
|
||||
given the focus whole. `CycleFocusWindow` is not dropped: it gives the focus to the next
|
||||
container's window (the code has a TODO for what it should do). A maximized window is hidden
|
||||
with the rest of its workspace, and restored and focused ahead of the containers' windows when
|
||||
the workspace is shown again ([`Workspace::hide`], [`Workspace::restore`]).
|
||||
|
||||
`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
|
||||
@@ -637,12 +663,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, 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).
|
||||
promote the focused container, float a window, put a container in monocle, maximize 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).
|
||||
- [`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
|
||||
@@ -714,7 +740,7 @@ the fake. The window manager is its only caller, through [`backend`]. The contra
|
||||
|
||||
| Rule | Enforced by | Proof | Escape hatch |
|
||||
|---|---|---|---|
|
||||
| A backend implements every query and command | type system: the methods have no defaults | `compile_fail,E0046` on [`Backend`] | none |
|
||||
| A backend implements every query and command but `maximize` | type system: the methods have no defaults, except `maximize`, which does nothing until a backend implements it | `compile_fail,E0046` on [`Backend`] | none |
|
||||
| A backend can be shared between threads | type system: `Backend: Send + Sync + 'static` | `compile_fail,E0277` on [`Backend`] | none |
|
||||
| The window manager asks for a backend that was never installed | runtime error: [`backend`] panics, naming [`set_backend`] and [`with_backend`] | `# Panics` on [`backend`] | none |
|
||||
| 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 |
|
||||
@@ -727,6 +753,11 @@ the fake. The window manager is its only caller, through [`backend`]. The contra
|
||||
| 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 maximized window goes back in a container of its own at the index it came from, and the tiles are where they were | framework path: [`Workspace::new_maximized_window`] keeps the index and [`Workspace::reintegrate_maximized_window`] inserts at it, after asking the backend to restore the window, and nothing else moves in between | `toggle_maximize_takes_the_window_out_of_the_layout_and_back`, `maximizing_works_in_every_layout`, `a_window_goes_back_in_a_container_of_its_own_at_the_index_it_came_from` | none |
|
||||
| What is about the tiles does nothing while a window is maximized | framework path: `is_layout_command` in [`WindowManager::process_command`] drops the message before it is handled | `while_a_window_is_maximized_what_is_about_the_tiles_does_nothing` | none |
|
||||
| A window stays maximized through a retile | framework path: [`Workspace::update`] asks the backend to maximize it again, and moves no container | `a_retile_while_a_window_is_maximized_asks_the_compositor_to_maximize_it_again` | none |
|
||||
| A maximized window that closes takes the maximize with it | framework path: [`Workspace::remove_window`] looks at the maximized window first, which the index of managed windows lists | `a_maximized_window_that_closes_leaves_the_layout_whole` | none |
|
||||
| In a real KWin, the maximized window fills the work area, is on top, and goes back to its tile | VM test | `vm-features` ("the focused window fills the work area", "and is the one on top", "toggled back, it is in its tile again") | 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 |
|
||||
@@ -895,6 +926,8 @@ A window is shown, and ends up on a tile:
|
||||
[`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/maximize.rs`](../../komorebi/tests/maximize.rs) and
|
||||
[`komorebi/tests/maximize_commands.rs`](../../komorebi/tests/maximize_commands.rs), maximizing;
|
||||
[`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
|
||||
@@ -903,6 +936,8 @@ A window is shown, and ends up on a tile:
|
||||
messages that add and show them.
|
||||
- [`nix/tests/vm/suites/scrolling`](../../nix/tests/vm/suites/scrolling/test.py): the scrolling
|
||||
strip in a real KWin, with its columns out of view off the screen.
|
||||
- [`nix/tests/vm/suites/features`](../../nix/tests/vm/suites/features/test.py): what is on the
|
||||
screen of a real compositing session, read from screenshots.
|
||||
- [`nix/tests/vm/suites/commands`](../../nix/tests/vm/suites/commands/test.py): every layout,
|
||||
and every `komorebic` command, against a real KWin with two outputs.
|
||||
- [`komorebi/tests/workspaces.rs`](../../komorebi/tests/workspaces.rs): workspaces as the
|
||||
@@ -994,6 +1029,7 @@ A window is shown, and ends up on a tile:
|
||||
[`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::toggle_maximize`]: ../../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
|
||||
@@ -1001,6 +1037,9 @@ A window is shown, and ends up on a tile:
|
||||
[`Workspace::monocle_container`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::new_monocle_container`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::reintegrate_monocle_container`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::maximized_window`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::new_maximized_window`]: ../../komorebi/src/workspace.rs
|
||||
[`Workspace::reintegrate_maximized_window`]: ../../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
|
||||
|
||||
@@ -315,3 +315,16 @@ the same reason `update` does not shorten the list of adjustments while there is
|
||||
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`).
|
||||
|
||||
## Why does a maximized window leave the layout, instead of being given the work area?
|
||||
|
||||
Because KWin has a maximize of its own, and komorebi asks for it. The window gets the work area of
|
||||
its output with the panels left alone, and a restore goes back to where the window was
|
||||
(`docs/kde.md`, and the comment in the bridge where it carries the command out). It is the work
|
||||
area and not the padded one that [`Workspace::update`](../../komorebi/src/workspace.rs) maximizes
|
||||
a window to ("the compositor's own maximize, which is the work area and not the padded one"), so
|
||||
the window cannot be a container: a layout would give it a tile, less the padding. It is held in
|
||||
`maximized_window` instead, with the index it came from, and when it is restored it goes back to
|
||||
that index in a container of its own. It is restored before it is tiled again, because "it is its
|
||||
tile's size that it has to get back, not the compositor's idea of its old size" (the comment in
|
||||
`reintegrate_maximized_window`).
|
||||
+10
-7
@@ -140,11 +140,13 @@ it is on the workspace it will come back to. It checks that KWin still lists the
|
||||
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
|
||||
queued for the
|
||||
bridge, which gets the queue as the answer to its held call and carries the commands out in
|
||||
KWin, in order. The script API cannot move the pointer, so
|
||||
when the pointer follows the focus komorebi invokes KWin's own "Move Mouse to Focus" shortcut,
|
||||
bring back, maximize, unmaximize or close a window, show a workspace on an output, put a window
|
||||
on a workspace) is queued for the bridge, which gets the queue as the answer to its held call and
|
||||
carries the commands out in KWin, in order. A maximize is KWin's own, `setMaximize(true, true)`:
|
||||
the window gets the work area of its output with the panels left alone, komorebi sets no frame
|
||||
for it meanwhile, and unmaximizing it gives it back the frame it had. The VM test `vm-features`
|
||||
checks that the window fills the work area and is on top. The script API cannot move the pointer,
|
||||
so when the pointer follows the focus komorebi invokes KWin's own "Move Mouse to Focus" shortcut,
|
||||
which puts the pointer in the middle of the window KWin has focused.
|
||||
|
||||
#### When KWin restarts
|
||||
@@ -343,8 +345,9 @@ with the columns out of view, is pulled back onto the screen a moment later; so
|
||||
client rounds the size, as `foot` does. The bridge therefore remembers the position it was asked
|
||||
for, for a second, and when the window's frame changes to another position in that time, asks
|
||||
for the position again, which is a plain move. It tries three times at most, so a window that
|
||||
cannot go where it was asked is left alone. The VM test `vm-scrolling` checks that the columns
|
||||
out of view stay where komorebi put them.
|
||||
cannot go where it was asked is left alone. A maximize makes the bridge forget the position: the
|
||||
window's frame then changes to the work area, which is not where it was last asked to be. The VM
|
||||
test `vm-scrolling` checks that the columns out of view stay where komorebi put them.
|
||||
|
||||
## How long a retile takes
|
||||
|
||||
|
||||
@@ -79,7 +79,8 @@ user in by itself, as in nixpkgs' own `plasma6` test, and Plasma draws on the
|
||||
machine's display device. The login starts the module's unit, so komorebi runs
|
||||
in the session from the start, as on a user's machine; `render-smoke`, which
|
||||
checks that the session draws, turns it off. It is the node for anything that
|
||||
needs pixels. The choice of login manager is made in
|
||||
needs pixels: `features` reads what komorebi does from screenshots of it. The
|
||||
choice of login manager is made in
|
||||
[`nodes/session.nix`](../../nix/tests/vm/nodes/session.nix) and nowhere else;
|
||||
the file says how to switch to sddm, the other one that has been seen to work.
|
||||
Its display is 1280x800, because screenshots are taken of the machine's one
|
||||
@@ -127,10 +128,11 @@ 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 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.
|
||||
has on every workspace of every monitor (floating windows, monocle containers
|
||||
and maximized windows 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
|
||||
|
||||
@@ -40,6 +40,7 @@ out of sight and bring one of them to the front,
|
||||
[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,
|
||||
[Maximizing windows](usage/maximizing-windows.md) how to have KWin maximize one,
|
||||
[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,39 @@
|
||||
# Maximizing windows
|
||||
|
||||
[`komorebic toggle-maximize`](../cli/toggle-maximize.md) has KWin maximize the window that has the
|
||||
focus: it takes the work area of its monitor, the panels left alone, and has no padding around it.
|
||||
The window leaves the layout while it is maximized, and the same command restores it and puts it
|
||||
back in a container of its own, at the place in the order of the workspace it was taken from.
|
||||
|
||||
```sh
|
||||
komorebic toggle-maximize
|
||||
```
|
||||
|
||||
A window that is the only one of its container takes the container with it, and the container is
|
||||
made again when the window comes back. The tiles that were left are not moved while the window is
|
||||
maximized: it covers them. A window that opens meanwhile is added to the layout, after the focused
|
||||
container, and has its tile when the maximized window is restored. A window that closes while it
|
||||
is maximized takes the maximize with it, and the other windows are tiled again.
|
||||
|
||||
A window in [monocle](monocle.md) that is maximized leaves the monocle.
|
||||
|
||||
## What is left alone
|
||||
|
||||
While a window is maximized, the commands that are about the tiles of the layout do nothing, and
|
||||
the daemon logs that it ignores them: [`move`](../cli/move.md), [`cycle-move`](../cli/cycle-move.md),
|
||||
the [stack](stacking-windows.md) commands, [`promote`](../cli/promote.md) and the other promote
|
||||
commands, [`resize-edge`](../cli/resize-edge.md) and [`resize-axis`](../cli/resize-axis.md),
|
||||
[`preselect-direction`](../cli/preselect-direction.md), [`toggle-lock`](../cli/toggle-lock.md),
|
||||
[`toggle-float`](../cli/toggle-float.md), [`toggle-monocle`](../cli/toggle-monocle.md), and the
|
||||
commands that move or send a container to another monitor or workspace, such as
|
||||
[`move-to-monitor`](../cli/move-to-monitor.md) and
|
||||
[`send-to-workspace`](../cli/send-to-workspace.md). Restore the window first.
|
||||
|
||||
[`komorebic focus`](../cli/focus.md) finds no container on any side of the maximized window, so
|
||||
the focus goes to the monitor on that side, and the command fails where there is none. A
|
||||
maximized window, or a window in monocle, on the workspace it reaches is given the focus whole.
|
||||
|
||||
## In the daemon's state
|
||||
|
||||
A workspace with a maximized window has it as `maximized_window`, which is not in its
|
||||
`containers`, and the index it goes back to as `maximized_window_restore_idx`.
|
||||
@@ -58,6 +58,8 @@ pub enum Command {
|
||||
CenterCursor(Rect),
|
||||
/// [`Backend::ensure_workspaces`]: how many workspaces were asked for.
|
||||
EnsureWorkspaces(usize),
|
||||
/// [`Backend::maximize`]: the window, and whether it was to be maximized or restored.
|
||||
Maximize(u32, bool),
|
||||
/// [`Backend::switch_workspace`]: the monitor, and the workspace it was asked to show.
|
||||
SwitchWorkspace(u32, usize),
|
||||
/// [`Backend::set_window_workspace`]: the window, and the workspace it was put on.
|
||||
@@ -77,6 +79,8 @@ struct State {
|
||||
foreground: Option<u32>,
|
||||
cursor: Option<(i32, i32)>,
|
||||
commands: Vec<Command>,
|
||||
/// windows the compositor has maximized, with the frame to give back
|
||||
maximized: HashMap<u32, Rect>,
|
||||
/// how many virtual desktops there are
|
||||
desktops: usize,
|
||||
/// the desktop every window is on
|
||||
@@ -86,6 +90,46 @@ struct State {
|
||||
}
|
||||
|
||||
impl State {
|
||||
/// Maximizes a window to the work area of its monitor, or gives it back the frame it had
|
||||
fn set_maximized(&mut self, id: u32, maximize: bool) {
|
||||
let Some(window) = self.windows.get(&id) else {
|
||||
return;
|
||||
};
|
||||
let current = window.rect;
|
||||
|
||||
if maximize {
|
||||
// the work area of the monitor the window is on (the first one if none is)
|
||||
let center = (
|
||||
current.left + current.right / 2,
|
||||
current.top + current.bottom / 2,
|
||||
);
|
||||
let area = self
|
||||
.monitors
|
||||
.iter()
|
||||
.find(|m| {
|
||||
center.0 >= m.size.left
|
||||
&& center.0 < m.size.left + m.size.right
|
||||
&& center.1 >= m.size.top
|
||||
&& center.1 < m.size.top + m.size.bottom
|
||||
})
|
||||
.or_else(|| self.monitors.first())
|
||||
.map(|m| m.work_area);
|
||||
|
||||
if let Some(area) = area
|
||||
&& !self.maximized.contains_key(&id)
|
||||
{
|
||||
self.maximized.insert(id, current);
|
||||
if let Some(window) = self.windows.get_mut(&id) {
|
||||
window.rect = area;
|
||||
}
|
||||
}
|
||||
} else if let Some(before) = self.maximized.remove(&id)
|
||||
&& let Some(window) = self.windows.get_mut(&id)
|
||||
{
|
||||
window.rect = before;
|
||||
}
|
||||
}
|
||||
|
||||
/// The monitor a window is on: the one that holds the middle of it, else the first
|
||||
fn monitor_of(&self, id: u32) -> Option<u32> {
|
||||
let w = self.windows.get(&id)?;
|
||||
@@ -253,6 +297,12 @@ impl FakeBackend {
|
||||
self.state.lock().cursor = Some((x, y));
|
||||
}
|
||||
|
||||
/// Returns true if and only if the window has been maximized by a command and not restored
|
||||
/// since.
|
||||
pub fn is_maximized(&self, id: u32) -> bool {
|
||||
self.state.lock().maximized.contains_key(&id)
|
||||
}
|
||||
|
||||
/// Returns where a window is, if it was ever opened.
|
||||
pub fn rect_of(&self, id: u32) -> Option<Rect> {
|
||||
self.state.lock().windows.get(&id).map(|w| w.rect)
|
||||
@@ -490,6 +540,12 @@ impl Backend for FakeBackend {
|
||||
state.window_ws.get(&id).copied()
|
||||
}
|
||||
|
||||
fn maximize(&self, id: u32, maximize: bool) -> eyre::Result<()> {
|
||||
self.record(id, Command::Maximize(id, maximize), |state| {
|
||||
state.set_maximized(id, maximize);
|
||||
})
|
||||
}
|
||||
|
||||
fn current_workspaces(&self) -> Vec<(u32, usize)> {
|
||||
let state = self.state.lock();
|
||||
state
|
||||
@@ -568,6 +624,34 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_maximized_window_has_the_work_area_and_gets_its_frame_back() -> eyre::Result<()> {
|
||||
let fake = fake_with(&[1]);
|
||||
fake.set_rect(1, &tile(100, 200))?;
|
||||
|
||||
fake.maximize(1, true)?;
|
||||
// a second maximize does not make the maximized frame the one to give back
|
||||
fake.maximize(1, true)?;
|
||||
|
||||
assert!(fake.is_maximized(1));
|
||||
assert_eq!(fake.rect_of(1), Some(tile(0, 1920)));
|
||||
|
||||
fake.maximize(1, false)?;
|
||||
|
||||
assert!(!fake.is_maximized(1));
|
||||
assert_eq!(fake.rect_of(1), Some(tile(100, 200)));
|
||||
assert_eq!(
|
||||
fake.commands(),
|
||||
[
|
||||
Command::SetRect(1, tile(100, 200)),
|
||||
Command::Maximize(1, true),
|
||||
Command::Maximize(1, true),
|
||||
Command::Maximize(1, false),
|
||||
]
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_command_about_a_window_nobody_opened_is_an_error() {
|
||||
let fake = fake_with(&[1]);
|
||||
|
||||
@@ -307,6 +307,18 @@ pub trait Backend: Send + Sync + 'static {
|
||||
/// something in the compositor.
|
||||
fn shutdown(&self) {}
|
||||
|
||||
/// Has the compositor maximize the window to the work area of its monitor, panels left alone,
|
||||
/// or, with `maximize` false, give it back the frame it had before.
|
||||
///
|
||||
/// The default does nothing, for a compositor that has no maximize of its own.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// When the window does not exist or is no longer alive.
|
||||
fn maximize(&self, _id: u32, _maximize: bool) -> eyre::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns true if and only if the compositor has a live window with this id.
|
||||
fn is_window(&self, id: u32) -> bool {
|
||||
self.window(id).is_some_and(|w| w.alive)
|
||||
|
||||
@@ -386,6 +386,8 @@ pub enum SocketMessage {
|
||||
ToggleLock,
|
||||
ToggleFloat,
|
||||
ToggleMonocle,
|
||||
ToggleMaximize,
|
||||
// ToggleMaximize,
|
||||
ToggleWindowContainerBehaviour,
|
||||
ToggleFloatOverride,
|
||||
ToggleCrossMonitorMoveBehaviour,
|
||||
|
||||
@@ -79,19 +79,21 @@
|
||||
/**
|
||||
* What the daemon sends: the answer to `Poll` is a list of batches, each a list of commands. A
|
||||
* window command names the window by its `id`: `geo` sets its frame, `min` minimizes it (`v`) or
|
||||
* brings it back, `desktop` puts it on the desktop `v` (and on no other), and `activate`, `raise`
|
||||
* and `close` do what they say. `output_desktop` shows the desktop `v` on one output, leaving the
|
||||
* others as they are. A cursor query is numbered by `token` so that its answer can be matched.
|
||||
* brings it back, `maximize` maximizes it (`v`) or restores it, `desktop` puts it on the desktop
|
||||
* `v` (and on no other), and `activate`, `raise` and `close` do what they say. `output_desktop`
|
||||
* shows the desktop `v` on one output, leaving the others as they are. A cursor query is
|
||||
* numbered by `token` so that its answer can be matched.
|
||||
*
|
||||
* @typedef {{ op: "cursor", token: number }} CursorQuery
|
||||
* @typedef {{ op: "output_desktop", output: string, v: string }} OutputDesktop
|
||||
* @typedef {{ op: "geo", id: string, x: number, y: number, w: number, h: number }} SetFrame
|
||||
* @typedef {{ op: "min", id: string, v: boolean }} SetMinimized
|
||||
* @typedef {{ op: "maximize", id: string, v: boolean }} SetMaximized
|
||||
* @typedef {{ op: "activate", id: string }} Activate
|
||||
* @typedef {{ op: "raise", id: string }} Raise
|
||||
* @typedef {{ op: "close", id: string }} Close
|
||||
* @typedef {{ op: "desktop", id: string, v: string }} SetDesktop
|
||||
* @typedef {SetFrame | SetMinimized | Activate | Raise | Close | SetDesktop} WindowCommand
|
||||
* @typedef {SetFrame | SetMinimized | SetMaximized | Activate | Raise | Close | SetDesktop} WindowCommand
|
||||
* @typedef {CursorQuery | OutputDesktop | WindowCommand} Command
|
||||
* @typedef {{ batch: number, cmds: Command[] }} Batch
|
||||
*/
|
||||
@@ -444,6 +446,13 @@ function applyOne(c) {
|
||||
case "min":
|
||||
w.minimized = !!c.v;
|
||||
break;
|
||||
case "maximize":
|
||||
// KWin's own: the whole work area, panels left alone, and a restore that goes back to
|
||||
// where the window was. The position asked for last is not wanted any more: `settle`
|
||||
// would put the window back there, on the work area's size
|
||||
delete want[c.id];
|
||||
w.setMaximize(!!c.v, !!c.v);
|
||||
break;
|
||||
case "activate":
|
||||
workspace.activeWindow = w;
|
||||
break;
|
||||
|
||||
@@ -58,8 +58,9 @@ function geometry(x, y, width, height) {
|
||||
|
||||
// A window. `id` becomes its `internalId`, which is a QUuid in KWin: an object, not a string.
|
||||
// Setting `minimized`, `frameGeometry` or `desktops` raises the signal KWin raises, and
|
||||
// `closeWindow` closes it once it is in a KWin. `place` is where KWin puts the window when it is
|
||||
// asked for a frame: where it was asked, unless a test says otherwise.
|
||||
// `closeWindow` closes it once it is in a KWin. `setMaximize` sets `maximizeMode` the way KWin's
|
||||
// does and records what it was asked in `maximizations`. `place` is where KWin puts the window
|
||||
// when it is asked for a frame: where it was asked, unless a test says otherwise.
|
||||
function window({
|
||||
id,
|
||||
minimized = false,
|
||||
@@ -82,6 +83,11 @@ function window({
|
||||
fullScreen: false,
|
||||
maximizeMode: 0,
|
||||
minSize: { width: 0, height: 0 },
|
||||
maximizations: [],
|
||||
setMaximize: (vertically, horizontally) => {
|
||||
w.maximizations.push([vertically, horizontally]);
|
||||
w.maximizeMode = (vertically ? 1 : 0) | (horizontally ? 2 : 0);
|
||||
},
|
||||
move: false,
|
||||
resize: false,
|
||||
frameGeometryChanged: new Signal(),
|
||||
@@ -311,8 +317,8 @@ test("what the bridge sends for a session is what the daemon's tests read", () =
|
||||
|
||||
k.close(terminal);
|
||||
|
||||
// the editor is tiled, focused, raised, minimized and brought back, the dialog closed, and the
|
||||
// terminal, which has closed, is asked for a frame
|
||||
// the editor is tiled, focused, raised, minimized and brought back, maximized and restored,
|
||||
// the dialog closed, and the terminal, which has closed, is asked for a frame
|
||||
assert.equal(k.events().at(-1).seq, windowCommands.after_seq);
|
||||
k.answer([windowCommands.batch]);
|
||||
|
||||
@@ -334,6 +340,11 @@ test("what the bridge sends for a session is what the daemon's tests read", () =
|
||||
assert.equal(k.workspace.activeWindow, editor);
|
||||
assert.deepStrictEqual(k.raised, [editor]);
|
||||
assert.equal(editor.minimized, false);
|
||||
assert.deepStrictEqual(editor.maximizations, [
|
||||
[true, true],
|
||||
[false, false],
|
||||
]);
|
||||
assert.equal(editor.maximizeMode, 0);
|
||||
assert.deepStrictEqual(k.workspace.windowList(), [editor]);
|
||||
});
|
||||
|
||||
@@ -637,3 +648,19 @@ test("a window the user is moving or resizing is not asked for its position agai
|
||||
|
||||
assert.deepStrictEqual(w.frameGeometry, geometry(-700, 0, 800, 600));
|
||||
});
|
||||
|
||||
test("a window maximized right after it was given a frame is not put back at that frame", () => {
|
||||
const w = window({ id: "{w}" });
|
||||
const maximize = w.setMaximize;
|
||||
// KWin gives a maximized window the work area, which moves its frame
|
||||
w.setMaximize = (vertically, horizontally) => {
|
||||
maximize(vertically, horizontally);
|
||||
w.frameGeometry = geometry(0, 0, 1920, 1050);
|
||||
};
|
||||
const k = kwin({ windows: [w] });
|
||||
k.answer([{ batch: 1, cmds: [{ op: "geo", id: "{w}", x: 480, y: 270, w: 960, h: 540 }] }]);
|
||||
|
||||
k.answer([{ batch: 2, cmds: [{ op: "maximize", id: "{w}", v: true }] }]);
|
||||
|
||||
assert.deepStrictEqual(w.frameGeometry, geometry(0, 0, 1920, 1050));
|
||||
});
|
||||
@@ -13,6 +13,8 @@
|
||||
{"op": "raise", "id": "{0e5a1c3b-0000-4000-8000-00000000000a}"},
|
||||
{"op": "min", "id": "{0e5a1c3b-0000-4000-8000-00000000000a}", "v": true},
|
||||
{"op": "min", "id": "{0e5a1c3b-0000-4000-8000-00000000000a}", "v": false},
|
||||
{"op": "maximize", "id": "{0e5a1c3b-0000-4000-8000-00000000000a}", "v": true},
|
||||
{"op": "maximize", "id": "{0e5a1c3b-0000-4000-8000-00000000000a}", "v": false},
|
||||
{"op": "close", "id": "{c4b8a2f0-0000-4000-8000-00000000000c}"},
|
||||
{
|
||||
"op": "geo", "id": "{7f3d9e21-0000-4000-8000-00000000000b}",
|
||||
|
||||
Vendored
+5
@@ -92,6 +92,11 @@ interface KWinWindow {
|
||||
readonly captionChanged: Signal;
|
||||
readonly desktopsChanged: Signal;
|
||||
closeWindow(): void;
|
||||
/**
|
||||
* Maximizes the window vertically and horizontally, or restores it from either. Maximizing
|
||||
* is to the work area, panels left alone, and restoring gives back the frame it had.
|
||||
*/
|
||||
setMaximize(vertically: boolean, horizontally: boolean): void;
|
||||
}
|
||||
|
||||
/** The global `workspace` (`KWin::ScriptingWorkspace`). */
|
||||
|
||||
@@ -858,6 +858,13 @@ impl Backend for KWinBackend {
|
||||
self.command(id, |uuid| json!({ "op": "close", "id": uuid }))
|
||||
}
|
||||
|
||||
fn maximize(&self, id: u32, maximize: bool) -> eyre::Result<()> {
|
||||
self.command(
|
||||
id,
|
||||
|uuid| json!({ "op": "maximize", "id": uuid, "v": maximize }),
|
||||
)
|
||||
}
|
||||
|
||||
fn center_cursor_in(&self, _rect: &Rect) -> eyre::Result<()> {
|
||||
// KWin can center the pointer on the active window and nothing else; the WM calls this
|
||||
// right after focusing the window in question
|
||||
@@ -997,6 +1004,8 @@ mod tests {
|
||||
backend.raise(1).unwrap();
|
||||
backend.minimize(1).unwrap();
|
||||
backend.unminimize(1).unwrap();
|
||||
backend.maximize(1, true).unwrap();
|
||||
backend.maximize(1, false).unwrap();
|
||||
backend.close(3).unwrap();
|
||||
// the terminal has closed, and the table still knows it: the bridge gives it back
|
||||
backend.set_rect(2, &left(960)).unwrap();
|
||||
|
||||
@@ -249,7 +249,8 @@ impl Monitor {
|
||||
.monocle_container
|
||||
.iter()
|
||||
.flat_map(|c| c.windows().iter()),
|
||||
);
|
||||
)
|
||||
.chain(workspace.maximized_window.iter());
|
||||
|
||||
for window in windows {
|
||||
if backend().window_workspace(window.id) != Some(idx)
|
||||
|
||||
@@ -73,6 +73,12 @@
|
||||
//! 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.
|
||||
//! - **ToggleMaximize** has the compositor maximize the focused window, which leaves the layout,
|
||||
//! or restores it and puts it back in its tile ([`WindowManager::toggle_maximize`]). While a
|
||||
//! window is maximized, the messages about the tiles (**MoveWindow**, **CycleMoveWindow**, the
|
||||
//! stack messages, the resize, promote and preselect messages, **ToggleLock**, **ToggleFloat**,
|
||||
//! **ToggleMonocle** and the ones that send a container to another monitor or workspace) are
|
||||
//! ignored.
|
||||
//! - **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
|
||||
@@ -240,6 +246,48 @@ pub fn listen_for_commands(wm: Arc<Mutex<WindowManager>>) {
|
||||
});
|
||||
}
|
||||
|
||||
/// Commands that are about the tiles of the layout (moving, stacking, resizing, promoting,
|
||||
/// locking, floating, the monocle, and sending containers to other monitors and workspaces), which
|
||||
/// a maximized window has left
|
||||
fn is_layout_command(message: &SocketMessage) -> bool {
|
||||
matches!(
|
||||
message,
|
||||
SocketMessage::MoveWindow(_)
|
||||
| SocketMessage::CycleMoveWindow(_)
|
||||
| SocketMessage::StackWindow(_)
|
||||
| SocketMessage::UnstackWindow
|
||||
| SocketMessage::CycleStack(_)
|
||||
| SocketMessage::CycleStackIndex(_)
|
||||
| SocketMessage::FocusStackWindow(_)
|
||||
| SocketMessage::StackAll
|
||||
| SocketMessage::UnstackAll
|
||||
| SocketMessage::ResizeWindowEdge(..)
|
||||
| SocketMessage::ResizeWindowAxis(..)
|
||||
| SocketMessage::PreselectDirection(_)
|
||||
| SocketMessage::Promote
|
||||
| SocketMessage::PromoteSwap
|
||||
| SocketMessage::PromoteFocus
|
||||
| SocketMessage::PromoteWindow(_)
|
||||
| SocketMessage::ToggleLock
|
||||
| SocketMessage::ToggleFloat
|
||||
| SocketMessage::ToggleMonocle
|
||||
| SocketMessage::MoveContainerToLastWorkspace
|
||||
| SocketMessage::SendContainerToLastWorkspace
|
||||
| SocketMessage::MoveContainerToMonitorNumber(_)
|
||||
| SocketMessage::CycleMoveContainerToMonitor(_)
|
||||
| SocketMessage::MoveContainerToWorkspaceNumber(_)
|
||||
| SocketMessage::MoveContainerToNamedWorkspace(_)
|
||||
| SocketMessage::CycleMoveContainerToWorkspace(_)
|
||||
| SocketMessage::SendContainerToMonitorNumber(_)
|
||||
| SocketMessage::CycleSendContainerToMonitor(_)
|
||||
| SocketMessage::SendContainerToWorkspaceNumber(_)
|
||||
| SocketMessage::CycleSendContainerToWorkspace(_)
|
||||
| SocketMessage::SendContainerToMonitorWorkspaceNumber(..)
|
||||
| SocketMessage::MoveContainerToMonitorWorkspaceNumber(..)
|
||||
| SocketMessage::SendContainerToNamedWorkspace(_)
|
||||
)
|
||||
}
|
||||
|
||||
impl WindowManager {
|
||||
/// Handles one message, writes the answer to a question to `reply`, and sends the subscribers
|
||||
/// a notification of the message
|
||||
@@ -265,6 +313,8 @@ impl WindowManager {
|
||||
/// [`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 maximized or restored, for one of the reasons
|
||||
/// [`WindowManager::toggle_maximize`] 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`],
|
||||
@@ -304,6 +354,18 @@ impl WindowManager {
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("processing command: {message}");
|
||||
|
||||
// a window that is maximized (by `toggle-maximize`) is not in the layout, and what is
|
||||
// asked of the layout is not asked of it: nothing happens until it is restored, by
|
||||
// `toggle-maximize`
|
||||
if is_layout_command(&message)
|
||||
&& self
|
||||
.focused_workspace()
|
||||
.is_ok_and(|workspace| workspace.maximized_window.is_some())
|
||||
{
|
||||
tracing::info!("ignoring {message}: the window in front is maximized");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
#[allow(clippy::useless_asref)]
|
||||
// We don't have From implemented for &mut WindowManager
|
||||
let initial_state = State::from(self.as_ref());
|
||||
@@ -359,6 +421,13 @@ impl WindowManager {
|
||||
WorkspaceWindowLocation::Monocle(window_idx) => {
|
||||
self.focus_container_window(window_idx)?;
|
||||
}
|
||||
WorkspaceWindowLocation::Maximized => {
|
||||
if let Some(window) =
|
||||
&mut self.focused_workspace_mut()?.maximized_window
|
||||
{
|
||||
window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
}
|
||||
WorkspaceWindowLocation::Container(container_idx, window_idx) => {
|
||||
let focused_container_idx = self.focused_container_idx()?;
|
||||
if container_idx != focused_container_idx {
|
||||
@@ -589,6 +658,7 @@ impl WindowManager {
|
||||
&& workspace.containers().is_empty()
|
||||
&& workspace.floating_windows().is_empty()
|
||||
&& workspace.monocle_container.is_none()
|
||||
&& workspace.maximized_window.is_none()
|
||||
&& workspace.name.is_none()
|
||||
{
|
||||
can_close = true;
|
||||
@@ -833,6 +903,7 @@ impl WindowManager {
|
||||
self.ensure_named_workspaces_for_monitor(monitor_idx, names)?;
|
||||
}
|
||||
SocketMessage::ToggleMonocle => self.toggle_monocle()?,
|
||||
SocketMessage::ToggleMaximize => self.toggle_maximize()?,
|
||||
SocketMessage::ToggleFloat => self.toggle_float(false)?,
|
||||
SocketMessage::ResizeWindowEdge(direction, sizing) => {
|
||||
self.resize_window(direction, sizing, self.resize_delta, true)?;
|
||||
|
||||
@@ -162,6 +162,8 @@ impl From<&WindowManager> for State {
|
||||
containers: workspace.containers.clone(),
|
||||
monocle_container: workspace.monocle_container.clone(),
|
||||
monocle_container_restore_idx: workspace.monocle_container_restore_idx,
|
||||
maximized_window: workspace.maximized_window,
|
||||
maximized_window_restore_idx: workspace.maximized_window_restore_idx,
|
||||
floating_windows: workspace.floating_windows.clone(),
|
||||
layout: workspace.layout.clone(),
|
||||
layout_options: workspace.layout_options,
|
||||
|
||||
@@ -199,6 +199,24 @@ impl Window {
|
||||
backend().focus(self.id, mouse_follows_focus)
|
||||
}
|
||||
|
||||
/// Have the compositor maximize the window (the work area, panels respected)
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The backend does not know the window, or refuses to maximize it.
|
||||
pub fn maximize(self) -> eyre::Result<()> {
|
||||
backend().maximize(self.id, true)
|
||||
}
|
||||
|
||||
/// Have the compositor give the window back the frame it had before it was maximized
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The backend does not know the window, or refuses to restore it.
|
||||
pub fn unmaximize(self) -> eyre::Result<()> {
|
||||
backend().maximize(self.id, false)
|
||||
}
|
||||
|
||||
pub fn raise(self) -> eyre::Result<()> {
|
||||
backend().raise(self.id)
|
||||
}
|
||||
@@ -911,6 +929,8 @@ mod tests {
|
||||
window.unminimize()?;
|
||||
window.hide();
|
||||
window.restore();
|
||||
window.maximize()?;
|
||||
window.unmaximize()?;
|
||||
window.close()
|
||||
})?;
|
||||
|
||||
@@ -924,6 +944,8 @@ mod tests {
|
||||
Command::Unminimize(203),
|
||||
Command::Hide(203),
|
||||
Command::Restore(203),
|
||||
Command::Maximize(203, true),
|
||||
Command::Maximize(203, false),
|
||||
Command::Close(203),
|
||||
]
|
||||
);
|
||||
|
||||
+270
-11
@@ -223,11 +223,12 @@ impl WindowManager {
|
||||
|
||||
tracing::info!("preselecting container");
|
||||
|
||||
let new_idx = if workspace.monocle_container.is_some() {
|
||||
None
|
||||
} else {
|
||||
workspace.new_idx_for_direction(direction)
|
||||
};
|
||||
let new_idx =
|
||||
if workspace.maximized_window.is_some() || workspace.monocle_container.is_some() {
|
||||
None
|
||||
} else {
|
||||
workspace.new_idx_for_direction(direction)
|
||||
};
|
||||
|
||||
match new_idx {
|
||||
Some(new_idx) => {
|
||||
@@ -298,11 +299,12 @@ impl WindowManager {
|
||||
return self.cycle_monocle(cycle_direction);
|
||||
}
|
||||
|
||||
let new_idx = if workspace.monocle_container.is_some() {
|
||||
None
|
||||
} else {
|
||||
workspace.new_idx_for_direction(direction)
|
||||
};
|
||||
let new_idx =
|
||||
if workspace.maximized_window.is_some() || workspace.monocle_container.is_some() {
|
||||
None
|
||||
} else {
|
||||
workspace.new_idx_for_direction(direction)
|
||||
};
|
||||
|
||||
let mut cross_monitor_monocle_or_max = false;
|
||||
|
||||
@@ -372,7 +374,10 @@ impl WindowManager {
|
||||
self.focus_monitor(monitor_idx)?;
|
||||
|
||||
if let Ok(focused_workspace) = self.focused_workspace_mut() {
|
||||
if let Some(monocle) = &focused_workspace.monocle_container {
|
||||
if let Some(window) = &focused_workspace.maximized_window {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
cross_monitor_monocle_or_max = true;
|
||||
} else 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;
|
||||
@@ -1071,6 +1076,55 @@ impl WindowManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Toggles the compositor's own maximize for the focused window: it leaves the layout, fills
|
||||
/// the work area, and goes back to its tile, where it was, when toggled again
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - There is no focused workspace, or nothing to maximize on it.
|
||||
/// - The compositor refuses to maximize or to restore the window.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn toggle_maximize(&mut self) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
match workspace.maximized_window {
|
||||
None => self.maximize_window()?,
|
||||
Some(_) => self.unmaximize_window()?,
|
||||
}
|
||||
|
||||
self.update_focused_workspace(true, false)
|
||||
}
|
||||
|
||||
/// Takes the focused window out of the layout of the focused workspace and has the compositor
|
||||
/// maximize it ([`Workspace::new_maximized_window`])
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// See [`Workspace::new_maximized_window`].
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn maximize_window(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("maximizing window");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.new_maximized_window()
|
||||
}
|
||||
|
||||
/// Puts the maximized window of the focused workspace back in the layout, where it was
|
||||
/// ([`Workspace::reintegrate_maximized_window`])
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// See [`Workspace::reintegrate_maximized_window`].
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn unmaximize_window(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("unmaximizing window");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.reintegrate_maximized_window()
|
||||
}
|
||||
|
||||
/// 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
|
||||
@@ -1791,6 +1845,10 @@ impl WindowManager {
|
||||
.focused_workspace_mut()
|
||||
.ok_or_eyre("there is no workspace")?;
|
||||
|
||||
if workspace.maximized_window.is_some() {
|
||||
eyre::bail!("cannot move native maximized window to another monitor or workspace");
|
||||
}
|
||||
|
||||
let foreground_window_id = backend()
|
||||
.foreground_window()
|
||||
.ok_or_eyre("no foreground window")?;
|
||||
@@ -1999,10 +2057,17 @@ impl WindowManager {
|
||||
direction: CycleDirection,
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("focusing container");
|
||||
// let mut maximize_next = false;
|
||||
let mut monocle_next = false;
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
|
||||
if self.focused_workspace_mut()?.maximized_window.is_some() {
|
||||
// TODO: maximized window stuff
|
||||
// maximize_next = true;
|
||||
// self.unmaximize_window()?;
|
||||
}
|
||||
|
||||
if self.focused_workspace_mut()?.monocle_container.is_some() {
|
||||
monocle_next = true;
|
||||
self.monocle_off()?;
|
||||
@@ -2016,6 +2081,9 @@ impl WindowManager {
|
||||
|
||||
workspace.focus_container(new_idx);
|
||||
|
||||
// if maximize_next {
|
||||
// self.toggle_maximize()?;
|
||||
// } else
|
||||
if monocle_next {
|
||||
self.toggle_monocle()?;
|
||||
} else {
|
||||
@@ -2329,6 +2397,10 @@ impl WindowManager {
|
||||
known_window_ids.insert(window.id, (m_idx, w_idx));
|
||||
}
|
||||
|
||||
if let Some(window) = &workspace.maximized_window {
|
||||
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));
|
||||
@@ -2780,6 +2852,14 @@ impl WindowManager {
|
||||
),
|
||||
)?;
|
||||
}
|
||||
} else if origin_workspace
|
||||
.maximized_window
|
||||
.as_ref()
|
||||
.map(|max| max.id == window_id)
|
||||
.unwrap_or_default()
|
||||
{
|
||||
// A maximized window is in no container, so there is none to transfer: it stays where
|
||||
// it is
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -4484,6 +4564,185 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn test_maximize_and_unmaximize_window() {
|
||||
// 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 three windows to the container
|
||||
// for i in 0..3 {
|
||||
// container.windows_mut().push_back(Window::from(i));
|
||||
// }
|
||||
//
|
||||
// // Should have 3 windows in the container
|
||||
// assert_eq!(container.windows().len(), 3);
|
||||
//
|
||||
// // 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);
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// // No windows should be maximized
|
||||
// let workspace = wm.focused_workspace().unwrap();
|
||||
// let maximized_window = workspace.maximized_window;
|
||||
// assert_eq!(maximized_window, None);
|
||||
// }
|
||||
//
|
||||
// // Maximize the focused window
|
||||
// wm.maximize_window().ok();
|
||||
//
|
||||
// {
|
||||
// // Window 0 should be maximized
|
||||
// let workspace = wm.focused_workspace().unwrap();
|
||||
// let maximized_window = workspace.maximized_window;
|
||||
// assert_eq!(maximized_window, Some(Window::from(0)));
|
||||
// }
|
||||
//
|
||||
// wm.unmaximize_window().ok();
|
||||
//
|
||||
// {
|
||||
// // No windows should be maximized
|
||||
// let workspace = wm.focused_workspace().unwrap();
|
||||
// let maximized_window = workspace.maximized_window;
|
||||
// assert_eq!(maximized_window, None);
|
||||
// }
|
||||
//
|
||||
// // Focus container at index 1
|
||||
// wm.focused_workspace_mut().unwrap().focus_container(1);
|
||||
//
|
||||
// {
|
||||
// // Focus the window at index 1
|
||||
// let container = wm.focused_container_mut().unwrap();
|
||||
// container.focus_window(1);
|
||||
// }
|
||||
//
|
||||
// // Maximize the focused window
|
||||
// wm.maximize_window().ok();
|
||||
//
|
||||
// {
|
||||
// // Window 2 should be maximized
|
||||
// let workspace = wm.focused_workspace().unwrap();
|
||||
// let maximized_window = workspace.maximized_window;
|
||||
// assert_eq!(maximized_window, Some(Window::from(2)));
|
||||
// }
|
||||
//
|
||||
// wm.unmaximize_window().ok();
|
||||
//
|
||||
// {
|
||||
// // No windows should be maximized
|
||||
// let workspace = wm.focused_workspace().unwrap();
|
||||
// let maximized_window = workspace.maximized_window;
|
||||
// assert_eq!(maximized_window, None);
|
||||
// }
|
||||
// }
|
||||
|
||||
// #[test]
|
||||
// fn test_toggle_maximize() {
|
||||
// let (mut wm, _context) = setup_window_manager();
|
||||
//
|
||||
// {
|
||||
// // Create a monitor
|
||||
// let mut m = monitor::new(
|
||||
// 0,
|
||||
// Rect::default(),
|
||||
// Rect::default(),
|
||||
// "TestMonitor".to_string(),
|
||||
// "TestDevice".to_string(),
|
||||
// "TestDeviceID".to_string(),
|
||||
// Some("TestMonitorID".to_string()),
|
||||
// );
|
||||
//
|
||||
// // Create a container
|
||||
// let mut container = Container::default();
|
||||
//
|
||||
// // Add three windows to the container
|
||||
// for i in 0..3 {
|
||||
// container.windows_mut().push_back(Window::from(i));
|
||||
// }
|
||||
//
|
||||
// // Should have 3 windows in the container
|
||||
// assert_eq!(container.windows().len(), 3);
|
||||
//
|
||||
// // 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 maximize on
|
||||
// wm.toggle_maximize().ok();
|
||||
//
|
||||
// {
|
||||
// // Window 0 should be maximized
|
||||
// let workspace = wm.focused_workspace().unwrap();
|
||||
// let maximized_window = workspace.maximized_window;
|
||||
// assert_eq!(maximized_window, Some(Window::from(0)));
|
||||
// }
|
||||
//
|
||||
// // Toggle maximize off
|
||||
// wm.toggle_maximize().ok();
|
||||
//
|
||||
// {
|
||||
// // No windows should be maximized
|
||||
// let workspace = wm.focused_workspace().unwrap();
|
||||
// let maximized_window = workspace.maximized_window;
|
||||
// assert_eq!(maximized_window, None);
|
||||
// }
|
||||
// }
|
||||
|
||||
// #[test]
|
||||
// fn test_toggle_maximize_nonexistent_window() {
|
||||
// let (mut wm, _context) = setup_window_manager();
|
||||
//
|
||||
// {
|
||||
// // Create a monitor
|
||||
// let mut m = monitor::new(
|
||||
// 0,
|
||||
// Rect::default(),
|
||||
// Rect::default(),
|
||||
// "TestMonitor".to_string(),
|
||||
// "TestDevice".to_string(),
|
||||
// "TestDeviceID".to_string(),
|
||||
// Some("TestMonitorID".to_string()),
|
||||
// );
|
||||
//
|
||||
// // Create a container
|
||||
// let container = Container::default();
|
||||
//
|
||||
// // 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);
|
||||
// }
|
||||
//
|
||||
// // Should return an error when trying to toggle maximize on a non-existent window
|
||||
// let result = wm.toggle_maximize();
|
||||
// assert!(
|
||||
// result.is_err(),
|
||||
// "Expected an error when trying to toggle maximize on a non-existent window"
|
||||
// );
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn test_monocle_on_and_monocle_off() {
|
||||
let (mut wm, _context) = setup_window_manager();
|
||||
|
||||
+185
-13
@@ -37,6 +37,13 @@ pub struct Workspace {
|
||||
/// The index in `containers` the monocle container goes back to
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub monocle_container_restore_idx: Option<usize>,
|
||||
/// The window the compositor has maximized, which is in no container: the containers are left
|
||||
/// where they are, behind it ([`Workspace::new_maximized_window`],
|
||||
/// [`Workspace::reintegrate_maximized_window`])
|
||||
pub maximized_window: Option<Window>,
|
||||
/// The index in `containers` the maximized window goes back to, in a container of its own
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub maximized_window_restore_idx: Option<usize>,
|
||||
pub floating_windows: Ring<Window>,
|
||||
pub layout: Layout,
|
||||
pub layout_options: Option<LayoutOptions>,
|
||||
@@ -74,6 +81,8 @@ impl Default for Workspace {
|
||||
containers: Default::default(),
|
||||
monocle_container: None,
|
||||
monocle_container_restore_idx: None,
|
||||
maximized_window: None,
|
||||
maximized_window_restore_idx: None,
|
||||
workspace_padding: None,
|
||||
container_padding: None,
|
||||
resize_dimensions: vec![],
|
||||
@@ -97,7 +106,8 @@ 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
|
||||
Monocle(usize), // window_idx
|
||||
Maximized,
|
||||
Container(usize, usize), // container_idx, window_idx
|
||||
Floating(usize), // idx in floating_windows
|
||||
}
|
||||
@@ -379,6 +389,15 @@ 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(window) = self.maximized_window
|
||||
&& window.id == window_id
|
||||
{
|
||||
let _ = window.unmaximize();
|
||||
self.maximized_window = None;
|
||||
self.maximized_window_restore_idx = None;
|
||||
return Ok(window);
|
||||
}
|
||||
|
||||
if let Some(container) = self.monocle_container.as_mut()
|
||||
&& let Some(window_idx) = container
|
||||
.windows()
|
||||
@@ -450,8 +469,8 @@ 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
|
||||
/// Returns true if the window that has the focus in the compositor is the maximized window or
|
||||
/// in the monocle container, and so out of the layout
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
@@ -460,6 +479,11 @@ impl Workspace {
|
||||
let window_id = backend()
|
||||
.foreground_window()
|
||||
.ok_or_eyre("no foreground window")?;
|
||||
if let Some(window) = &self.maximized_window
|
||||
&& window_id == window.id
|
||||
{
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
if let Some(container) = &self.monocle_container
|
||||
&& container.contains_window(window_id)
|
||||
@@ -472,6 +496,7 @@ impl Workspace {
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.containers().is_empty()
|
||||
&& self.maximized_window.is_none()
|
||||
&& self.monocle_container.is_none()
|
||||
&& self.floating_windows().is_empty()
|
||||
}
|
||||
@@ -483,6 +508,12 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(window) = &self.maximized_window
|
||||
&& window_id == window.id
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if let Some(container) = &self.monocle_container
|
||||
&& container.contains_window(window_id)
|
||||
{
|
||||
@@ -498,8 +529,8 @@ impl Workspace {
|
||||
false
|
||||
}
|
||||
|
||||
/// Where this workspace has a window of the executable `exe`: in a container first, then in
|
||||
/// the monocle container, then floating
|
||||
/// Where this workspace has a window of the executable `exe`: in a container first, then the
|
||||
/// maximized window, then the monocle container, then the floating windows
|
||||
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) {
|
||||
@@ -510,6 +541,13 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(window) = &self.maximized_window
|
||||
&& let Some(window_exe) = window.exe()
|
||||
&& exe == window_exe
|
||||
{
|
||||
return Some(WorkspaceWindowLocation::Maximized);
|
||||
}
|
||||
|
||||
if let Some(container) = &self.monocle_container
|
||||
&& let Some(window_idx) = container.idx_from_exe(exe)
|
||||
{
|
||||
@@ -527,8 +565,9 @@ impl Workspace {
|
||||
None
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// Returns true if and only if the window is in one of the containers, is the maximized
|
||||
/// window or is 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) {
|
||||
@@ -536,6 +575,12 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(window) = &self.maximized_window
|
||||
&& window_id == window.id
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if let Some(container) = &self.monocle_container
|
||||
&& container.contains_window(window_id)
|
||||
{
|
||||
@@ -626,9 +671,9 @@ impl Workspace {
|
||||
}
|
||||
|
||||
/// Hides every window of the workspace, or every one but `omit`: the floating windows and the
|
||||
/// 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.
|
||||
/// windows of every container, the maximized window and 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.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
@@ -668,6 +713,10 @@ impl Workspace {
|
||||
self.resize_dimensions = resize_dimensions;
|
||||
}
|
||||
|
||||
if let Some(window) = self.maximized_window {
|
||||
window.hide();
|
||||
}
|
||||
|
||||
if let Some(container) = &mut self.monocle_container {
|
||||
container.hide(omit)?;
|
||||
}
|
||||
@@ -683,7 +732,7 @@ impl Workspace {
|
||||
/// 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). While there is a monocle container
|
||||
/// only its window is restored and focused, for the other containers are out of sight behind
|
||||
/// it.
|
||||
/// it. A maximized window is restored and given the focus ahead of the containers' windows.
|
||||
pub fn restore(&mut self, mouse_follows_focus: bool) -> eyre::Result<()> {
|
||||
if let Some(container) = &mut self.monocle_container {
|
||||
container.restore()?;
|
||||
@@ -718,8 +767,21 @@ impl Workspace {
|
||||
window.restore();
|
||||
}
|
||||
|
||||
// Do this here to make sure that an error doesn't stop the restoration of other windows
|
||||
// Maximized windows and floating windows should always be drawn at the top of the Z order
|
||||
// when switching to a workspace
|
||||
if let Some(window) = to_focus {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
if self.maximized_window.is_none() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
} else if let Some(maximized_window) = self.maximized_window {
|
||||
maximized_window.restore();
|
||||
maximized_window.focus(mouse_follows_focus)?;
|
||||
} else if let Some(floating_window) = self.focused_floating_window() {
|
||||
floating_window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
} else if let Some(maximized_window) = self.maximized_window {
|
||||
maximized_window.restore();
|
||||
maximized_window.focus(mouse_follows_focus)?;
|
||||
} else if let Some(floating_window) = self.focused_floating_window() {
|
||||
floating_window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
@@ -885,6 +947,104 @@ impl Workspace {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Takes the focused window out of its container, and so out of the layout, and has the
|
||||
/// compositor maximize it: the work area, panels respected, and a restore that goes back to
|
||||
/// where the window was. The window of the monocle container is the focused one while there
|
||||
/// is a monocle container.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The workspace has no containers, the focused one has no window, or the compositor refuses
|
||||
/// to maximize the window.
|
||||
pub fn new_maximized_window(&mut self) -> eyre::Result<()> {
|
||||
let focused_idx = self.focused_container_idx();
|
||||
|
||||
let monocle_restore_idx = self.monocle_container_restore_idx;
|
||||
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()?;
|
||||
}
|
||||
|
||||
self.maximized_window = Option::from(window);
|
||||
self.maximized_window_restore_idx = monocle_restore_idx;
|
||||
window.maximize()?;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let container = self
|
||||
.focused_container_mut()
|
||||
.ok_or_eyre("there is no container")?;
|
||||
|
||||
let window = container
|
||||
.remove_focused_window()
|
||||
.ok_or_eyre("there is no window")?;
|
||||
|
||||
if container.windows().is_empty() {
|
||||
// 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
|
||||
self.containers_mut().remove(focused_idx);
|
||||
if self.resize_dimensions.get(focused_idx).is_some() {
|
||||
self.resize_dimensions.remove(focused_idx);
|
||||
}
|
||||
} else {
|
||||
container.load_focused_window()?;
|
||||
}
|
||||
|
||||
self.maximized_window = Option::from(window);
|
||||
self.maximized_window_restore_idx = Option::from(focused_idx);
|
||||
window.maximize()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The maximized window is a tile again, in a container of its own at the index it was taken
|
||||
/// from, and the compositor gives it back the frame it had
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The workspace has no maximized window, or the compositor refuses to restore it.
|
||||
pub fn reintegrate_maximized_window(&mut self) -> eyre::Result<()> {
|
||||
let restore_idx = self
|
||||
.maximized_window_restore_idx
|
||||
.ok_or_eyre("there is no maximized restore index")?;
|
||||
|
||||
let window = self
|
||||
.maximized_window
|
||||
.ok_or_eyre("there is no maximized window")?;
|
||||
|
||||
// it is its tile's size that it has to get back, not the compositor's idea of its old size
|
||||
window.unmaximize()?;
|
||||
|
||||
if !self.containers().is_empty() && restore_idx > self.containers().len().saturating_sub(1)
|
||||
{
|
||||
self.containers_mut()
|
||||
.resize(restore_idx, Container::default());
|
||||
}
|
||||
|
||||
let mut container = Container::default();
|
||||
container.add_window(&window)?;
|
||||
|
||||
// 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.maximized_window = None;
|
||||
self.maximized_window_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
|
||||
@@ -893,7 +1053,12 @@ 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 = if let Some(monocle_container) = &mut self.monocle_container {
|
||||
let window = if let Some(maximized_window) = self.maximized_window {
|
||||
maximized_window.unmaximize()?;
|
||||
self.maximized_window = None;
|
||||
self.maximized_window_restore_idx = None;
|
||||
maximized_window
|
||||
} else if let Some(monocle_container) = &mut self.monocle_container {
|
||||
let window = monocle_container
|
||||
.remove_focused_window()
|
||||
.ok_or_eyre("there is no window")?;
|
||||
@@ -1012,6 +1177,10 @@ impl Workspace {
|
||||
/// are left where they are. The window-based offset is then applied whatever the number of
|
||||
/// containers, if the monitor has one.
|
||||
///
|
||||
/// While it has a maximized window ([`Workspace::maximized_window`]), the compositor is asked
|
||||
/// to maximize it again, which it does in its own work area, with no padding, and the
|
||||
/// containers are left where they are.
|
||||
///
|
||||
/// 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.
|
||||
@@ -1083,6 +1252,9 @@ impl Workspace {
|
||||
adjusted_work_area.add_padding(container_padding);
|
||||
window.set_position(&adjusted_work_area)?;
|
||||
};
|
||||
} else if let Some(window) = self.maximized_window {
|
||||
// the compositor's own maximize, which is the work area and not the padded one
|
||||
window.maximize()?;
|
||||
} else if !self.containers().is_empty() {
|
||||
let mut layouts = self.layout.as_boxed_arrangement().calculate(
|
||||
&adjusted_work_area,
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
//! `komorebic toggle-maximize`, against an in-memory desktop.
|
||||
//!
|
||||
//! The compositor maximizes the window over the whole work area; komorebi takes it out of the
|
||||
//! layout, and puts it back in its tile when it is restored.
|
||||
//!
|
||||
//! Window ids are in the 30_000s.
|
||||
|
||||
use komorebi::backend::fake::FakeBackend;
|
||||
use komorebi::backend::with_backend;
|
||||
use komorebi::core::DefaultLayout;
|
||||
use komorebi::core::Rect;
|
||||
use komorebi::core::SocketMessage;
|
||||
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 desktop() -> (Arc<FakeBackend>, WindowManager) {
|
||||
let fake = Arc::new(FakeBackend::with_one_monitor());
|
||||
let (_sender, receiver) = crossbeam_channel::bounded(1);
|
||||
static NEXT: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
||||
let socket = std::path::PathBuf::from(format!(
|
||||
"/tmp/kmf-{}-{}.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();
|
||||
wm
|
||||
});
|
||||
|
||||
(fake, wm)
|
||||
}
|
||||
|
||||
fn tiled(first: u32, count: u32) -> (Arc<FakeBackend>, WindowManager) {
|
||||
let (fake, mut wm) = desktop();
|
||||
with_backend(fake.clone(), || {
|
||||
for id in first..first + count {
|
||||
fake.open_window(id, "foot", "foot", &format!("terminal {id}"));
|
||||
wm.process_event(added(id)).unwrap();
|
||||
}
|
||||
});
|
||||
(fake, wm)
|
||||
}
|
||||
|
||||
fn command(fake: &Arc<FakeBackend>, wm: &mut WindowManager, message: SocketMessage) {
|
||||
with_backend(fake.clone(), || wm.process_command(message, Vec::new())).unwrap();
|
||||
}
|
||||
|
||||
fn work_area() -> Rect {
|
||||
Rect {
|
||||
left: 0,
|
||||
top: 0,
|
||||
right: 1920,
|
||||
bottom: 1050,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toggle_maximize_takes_the_window_out_of_the_layout_and_back() {
|
||||
let (fake, mut wm) = tiled(30_041, 3);
|
||||
let before: Vec<Rect> = (30_041..30_044)
|
||||
.map(|id| fake.rect_of(id).unwrap())
|
||||
.collect();
|
||||
|
||||
command(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
|
||||
// the focused window (30_043) is maximized: the compositor's, the whole work area
|
||||
assert!(fake.is_maximized(30_043));
|
||||
assert_eq!(fake.rect_of(30_043).unwrap(), work_area());
|
||||
let workspace = wm.focused_workspace().unwrap();
|
||||
assert_eq!(workspace.maximized_window.map(|w| w.id), Some(30_043));
|
||||
assert_eq!(workspace.containers().len(), 2);
|
||||
|
||||
command(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
|
||||
assert!(!fake.is_maximized(30_043));
|
||||
let workspace = wm.focused_workspace().unwrap();
|
||||
assert!(workspace.maximized_window.is_none());
|
||||
assert_eq!(workspace.containers().len(), 3);
|
||||
let after: Vec<Rect> = (30_041..30_044)
|
||||
.map(|id| fake.rect_of(id).unwrap())
|
||||
.collect();
|
||||
assert_eq!(before, after, "every tile is where it was");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_maximized_window_that_closes_leaves_the_layout_whole() {
|
||||
let (fake, mut wm) = tiled(30_051, 3);
|
||||
command(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
|
||||
with_backend(fake.clone(), || {
|
||||
fake.close_window_now(30_053);
|
||||
wm.process_event(WindowManagerEvent::Destroy(
|
||||
SystemNotification::KWin(KWinNotification::WindowRemoved),
|
||||
Window::from(30_053),
|
||||
))
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let workspace = wm.focused_workspace().unwrap();
|
||||
assert!(workspace.maximized_window.is_none());
|
||||
assert_eq!(workspace.containers().len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn maximizing_works_in_every_layout() {
|
||||
for layout in [
|
||||
DefaultLayout::BSP,
|
||||
DefaultLayout::Columns,
|
||||
DefaultLayout::UltrawideVerticalStack,
|
||||
] {
|
||||
let (fake, mut wm) = desktop();
|
||||
let first = 30_100 + 10 * layout as u32;
|
||||
with_backend(fake.clone(), || {
|
||||
wm.process_command(SocketMessage::ChangeLayout(layout), Vec::new())
|
||||
.unwrap();
|
||||
for id in first..first + 3 {
|
||||
fake.open_window(id, "foot", "foot", &format!("terminal {id}"));
|
||||
wm.process_event(added(id)).unwrap();
|
||||
}
|
||||
});
|
||||
let before: Vec<Rect> = (first..first + 3)
|
||||
.map(|id| fake.rect_of(id).unwrap())
|
||||
.collect();
|
||||
|
||||
command(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
command(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
|
||||
let after: Vec<Rect> = (first..first + 3)
|
||||
.map(|id| fake.rect_of(id).unwrap())
|
||||
.collect();
|
||||
assert_eq!(before, after, "{layout}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
//! What `toggle-maximize` does to the rest of the window manager, against an in-memory desktop: a
|
||||
//! window that is maximized is in no container, the messages about the tiles do nothing until it
|
||||
//! is restored, and the state has it. The focus crosses to a monitor where one is maximized, and a
|
||||
//! window that is maximized is hidden and shown with its workspace.
|
||||
//!
|
||||
//! Window ids are in the 36_000s.
|
||||
|
||||
use komorebi::backend::Backend;
|
||||
use komorebi::backend::fake::Command;
|
||||
use komorebi::backend::fake::FakeBackend;
|
||||
use komorebi::backend::with_backend;
|
||||
use komorebi::core::CycleDirection;
|
||||
use komorebi::core::OperationDirection;
|
||||
use komorebi::core::Rect;
|
||||
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),
|
||||
)
|
||||
}
|
||||
|
||||
/// 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/kmx-{}-{}.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)
|
||||
}
|
||||
|
||||
/// 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();
|
||||
let right_half = Rect {
|
||||
left: 1920,
|
||||
top: 0,
|
||||
right: 1920,
|
||||
bottom: 1080,
|
||||
};
|
||||
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/kmx-{}-{}.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()
|
||||
}
|
||||
|
||||
fn maximized(wm: &WindowManager) -> Option<u32> {
|
||||
wm.focused_workspace()
|
||||
.unwrap()
|
||||
.maximized_window
|
||||
.map(|window| window.id)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_window_goes_back_in_a_container_of_its_own_at_the_index_it_came_from() {
|
||||
let (fake, mut wm) = desktop_with(&[36_001, 36_002, 36_003]);
|
||||
event(&fake, &mut wm, activated(36_002));
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
|
||||
assert_eq!(maximized(&wm), Some(36_002));
|
||||
assert_eq!(tiled(&wm), [36_001, 36_003]);
|
||||
assert!(wm.focused_workspace().unwrap().contains_window(36_002));
|
||||
assert!(
|
||||
wm.focused_workspace()
|
||||
.unwrap()
|
||||
.contains_managed_window(36_002)
|
||||
);
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
|
||||
assert_eq!(maximized(&wm), None);
|
||||
assert_eq!(tiled(&wm), [36_001, 36_002, 36_003]);
|
||||
assert_eq!(wm.focused_workspace().unwrap().focused_container_idx(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn while_a_window_is_maximized_what_is_about_the_tiles_does_nothing() {
|
||||
let (fake, mut wm) = desktop_with(&[36_011, 36_012]);
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
let asked = fake.commands();
|
||||
|
||||
for message in [
|
||||
SocketMessage::MoveWindow(OperationDirection::Left),
|
||||
SocketMessage::CycleMoveWindow(CycleDirection::Next),
|
||||
SocketMessage::StackWindow(OperationDirection::Left),
|
||||
SocketMessage::UnstackWindow,
|
||||
SocketMessage::StackAll,
|
||||
SocketMessage::UnstackAll,
|
||||
SocketMessage::CycleStack(CycleDirection::Next),
|
||||
SocketMessage::CycleStackIndex(CycleDirection::Next),
|
||||
SocketMessage::FocusStackWindow(0),
|
||||
SocketMessage::MoveContainerToWorkspaceNumber(1),
|
||||
SocketMessage::SendContainerToWorkspaceNumber(1),
|
||||
SocketMessage::MoveContainerToMonitorNumber(1),
|
||||
SocketMessage::SendContainerToMonitorNumber(1),
|
||||
SocketMessage::Promote,
|
||||
SocketMessage::ToggleLock,
|
||||
SocketMessage::ToggleFloat,
|
||||
SocketMessage::ToggleMonocle,
|
||||
SocketMessage::PreselectDirection(OperationDirection::Left),
|
||||
] {
|
||||
send(&fake, &mut wm, message);
|
||||
}
|
||||
|
||||
assert_eq!(maximized(&wm), Some(36_012));
|
||||
assert_eq!(tiled(&wm), [36_011]);
|
||||
assert!(wm.focused_workspace().unwrap().monocle_container.is_none());
|
||||
assert!(
|
||||
wm.focused_workspace()
|
||||
.unwrap()
|
||||
.floating_windows()
|
||||
.is_empty()
|
||||
);
|
||||
assert_eq!(fake.commands(), asked, "nothing was asked of the backend");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_retile_while_a_window_is_maximized_asks_the_compositor_to_maximize_it_again() {
|
||||
let (fake, mut wm) = desktop_with(&[36_021, 36_022]);
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
fake.clear_commands();
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::Retile);
|
||||
|
||||
assert_eq!(fake.commands(), [Command::Maximize(36_022, true)]);
|
||||
assert!(fake.is_maximized(36_022));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_window_in_monocle_that_is_maximized_leaves_the_monocle() {
|
||||
let (fake, mut wm) = desktop_with(&[36_031, 36_032]);
|
||||
event(&fake, &mut wm, activated(36_031));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMonocle);
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
|
||||
let workspace = wm.focused_workspace().unwrap();
|
||||
assert!(workspace.monocle_container.is_none());
|
||||
assert_eq!(maximized(&wm), Some(36_031));
|
||||
assert_eq!(workspace.maximized_window_restore_idx, Some(0));
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
|
||||
assert_eq!(tiled(&wm), [36_031, 36_032]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_window_that_opens_meanwhile_is_tiled_when_the_maximized_one_is_restored() {
|
||||
let (fake, mut wm) = desktop_with(&[36_041, 36_042]);
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
|
||||
fake.open_window(36_043, "foot", "foot", "terminal 36043");
|
||||
event(&fake, &mut wm, added(36_043));
|
||||
|
||||
assert_eq!(maximized(&wm), Some(36_042));
|
||||
assert_eq!(tiled(&wm), [36_041, 36_043]);
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
|
||||
let rects: Vec<_> = tiled(&wm)
|
||||
.iter()
|
||||
.map(|&id| fake.rect_of(id).unwrap())
|
||||
.collect();
|
||||
assert_eq!(rects.len(), 3);
|
||||
for (i, a) in rects.iter().enumerate() {
|
||||
for b in &rects[i + 1..] {
|
||||
let overlap = a.left < b.left + b.right
|
||||
&& b.left < a.left + a.right
|
||||
&& a.top < b.top + b.bottom
|
||||
&& b.top < a.top + a.bottom;
|
||||
assert!(!overlap, "{a:?} and {b:?} overlap");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toggle_maximize_without_a_window_is_an_error() {
|
||||
let (fake, mut wm) = desktop_with(&[]);
|
||||
|
||||
assert_eq!(
|
||||
try_send(&fake, &mut wm, SocketMessage::ToggleMaximize),
|
||||
Err(String::from("there is no container"))
|
||||
);
|
||||
assert_eq!(maximized(&wm), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_state_shows_the_maximized_window_and_the_index_it_goes_back_to() {
|
||||
let (fake, mut wm) = desktop_with(&[36_051, 36_052]);
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
|
||||
let state = with_backend(fake.clone(), || {
|
||||
serde_json::to_value(State::from(&wm)).unwrap()
|
||||
});
|
||||
let workspace = &state["monitors"]["elements"][0]["workspaces"]["elements"][0];
|
||||
|
||||
assert_eq!(workspace["maximized_window"]["id"], 36_052);
|
||||
assert_eq!(workspace["maximized_window_restore_idx"], 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focusing_towards_a_monitor_with_a_maximized_window_gives_it_the_focus() {
|
||||
let (fake, mut wm) = two_monitors_with(&[36_061, 36_062], &[36_063, 36_064]);
|
||||
event(&fake, &mut wm, activated(36_064));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
event(&fake, &mut wm, activated(36_062));
|
||||
assert_eq!(wm.focused_monitor_idx(), 0);
|
||||
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::FocusWindow(OperationDirection::Right),
|
||||
);
|
||||
|
||||
assert_eq!(wm.focused_monitor_idx(), 1);
|
||||
assert_eq!(fake.foreground_window(), Some(36_064));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_maximized_window_is_hidden_with_its_workspace_and_shown_and_focused_with_it() {
|
||||
let (fake, mut wm) = desktop_with(&[36_071, 36_072]);
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
let workspace = wm.focused_workspace_mut().unwrap();
|
||||
|
||||
with_backend(fake.clone(), || workspace.hide(None)).unwrap();
|
||||
assert!(fake.is_hidden(36_071) && fake.is_hidden(36_072));
|
||||
|
||||
fake.clear_commands();
|
||||
with_backend(fake.clone(), || workspace.restore(true)).unwrap();
|
||||
assert!(!fake.is_hidden(36_072), "the maximized window is shown");
|
||||
assert!(
|
||||
fake.commands().ends_with(&[Command::Focus(36_072, true)]),
|
||||
"and has the focus, ahead of the window of the container: {:?}",
|
||||
fake.commands()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_workspace_with_a_maximized_window_is_not_closed() {
|
||||
let (fake, mut wm) = desktop_with(&[]);
|
||||
send(&fake, &mut wm, SocketMessage::EnsureWorkspaces(0, 2));
|
||||
send(&fake, &mut wm, SocketMessage::FocusWorkspaceNumber(1));
|
||||
fake.open_window(36_081, "foot", "foot", "terminal 36081");
|
||||
event(&fake, &mut wm, added(36_081));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
assert!(wm.focused_workspace().unwrap().containers().is_empty());
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::CloseWorkspace);
|
||||
|
||||
assert_eq!(wm.focused_monitor().unwrap().workspaces().len(), 2);
|
||||
assert_eq!(maximized(&wm), Some(36_081));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eager_focus_finds_the_maximized_window_of_an_executable() {
|
||||
let (fake, mut wm) = desktop_with(&[36_091]);
|
||||
fake.open_window(36_092, "kate", "kate", "terminal 36092");
|
||||
event(&fake, &mut wm, added(36_092));
|
||||
send(&fake, &mut wm, SocketMessage::ToggleMaximize);
|
||||
event(&fake, &mut wm, activated(36_091));
|
||||
assert_eq!(fake.foreground_window(), Some(36_091));
|
||||
|
||||
send(
|
||||
&fake,
|
||||
&mut wm,
|
||||
SocketMessage::EagerFocus(String::from("kate")),
|
||||
);
|
||||
|
||||
assert_eq!(fake.foreground_window(), Some(36_092));
|
||||
}
|
||||
@@ -29,7 +29,8 @@
|
||||
//! `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.
|
||||
//! direction does meanwhile. `toggle-maximize` has KWin maximize the focused window, which
|
||||
//! leaves the layout, and restores it.
|
||||
//! - `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`,
|
||||
@@ -892,6 +893,8 @@ enum SubCommand {
|
||||
ToggleFloat,
|
||||
/// Toggle monocle mode for the focused container
|
||||
ToggleMonocle,
|
||||
/// Toggle the compositor's maximization for the focused window
|
||||
ToggleMaximize,
|
||||
/// 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
|
||||
@@ -1148,6 +1151,9 @@ fn main() -> eyre::Result<()> {
|
||||
SubCommand::ToggleMonocle => {
|
||||
send_message(&SocketMessage::ToggleMonocle)?;
|
||||
}
|
||||
SubCommand::ToggleMaximize => {
|
||||
send_message(&SocketMessage::ToggleMaximize)?;
|
||||
}
|
||||
SubCommand::ToggleFloat => {
|
||||
send_message(&SocketMessage::ToggleFloat)?;
|
||||
}
|
||||
|
||||
@@ -496,6 +496,11 @@ fn the_monocle_subcommands_send_their_message() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toggle_maximize_sends_its_message() {
|
||||
sends(&["toggle-maximize"], r#"{"type":"ToggleMaximize"}"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mouse_follows_focus_is_set_with_enable_and_disable_or_toggled() {
|
||||
sends(
|
||||
@@ -818,6 +823,7 @@ fn docgen_writes_the_help_of_every_subcommand_in_a_text_fence() {
|
||||
"toggle-float-override.md",
|
||||
"toggle-float.md",
|
||||
"toggle-lock.md",
|
||||
"toggle-maximize.md",
|
||||
"toggle-monocle-focus-behaviour.md",
|
||||
"toggle-monocle.md",
|
||||
"toggle-mouse-follows-focus.md",
|
||||
|
||||
@@ -324,7 +324,8 @@ 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, the monocle container and the floating windows.
|
||||
That is the windows of the containers, the monocle container, the maximized window and
|
||||
the floating windows.
|
||||
"""
|
||||
total = 0
|
||||
for monitor in self.state()["monitors"]["elements"]:
|
||||
@@ -333,6 +334,8 @@ class Kde:
|
||||
total += len(container["windows"]["elements"])
|
||||
if workspace["monocle_container"] is not None:
|
||||
total += len(workspace["monocle_container"]["windows"]["elements"])
|
||||
if workspace["maximized_window"] is not None:
|
||||
total += 1
|
||||
total += len(workspace["floating_windows"]["elements"])
|
||||
return total
|
||||
|
||||
|
||||
@@ -371,10 +371,12 @@ def workspace(
|
||||
focused: int = 0,
|
||||
floating: tuple[str, ...] = (),
|
||||
monocle: dict[str, object] | None = None,
|
||||
maximized: str | None = None,
|
||||
) -> dict[str, object]:
|
||||
return {
|
||||
"containers": {"elements": list(containers), "focused": focused},
|
||||
"monocle_container": monocle,
|
||||
"maximized_window": None if maximized is None else window(maximized),
|
||||
"floating_windows": {"elements": [window(t) for t in floating], "focused": 0},
|
||||
}
|
||||
|
||||
@@ -441,7 +443,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_the_floating_windows_and_the_monocle_of_every_workspace(
|
||||
def test_managed_all_counts_the_windows_the_floating_ones_the_monocle_and_the_maximized_one(
|
||||
machine: FakeMachine,
|
||||
) -> None:
|
||||
first = {
|
||||
@@ -451,7 +453,10 @@ def test_managed_all_counts_the_windows_the_floating_windows_and_the_monocle_of_
|
||||
second = {
|
||||
"id": 2,
|
||||
"workspaces": {
|
||||
"elements": [workspace(container("c")), workspace(monocle=container("m"))],
|
||||
"elements": [
|
||||
workspace(container("c"), maximized="x"),
|
||||
workspace(monocle=container("m")),
|
||||
],
|
||||
"focused": 0,
|
||||
},
|
||||
}
|
||||
@@ -460,7 +465,7 @@ def test_managed_all_counts_the_windows_the_floating_windows_and_the_monocle_of_
|
||||
output=json.dumps({"monitors": {"elements": [first, second], "focused": 0}}),
|
||||
)
|
||||
|
||||
assert Kde(machine, "main").managed_all() == 5
|
||||
assert Kde(machine, "main").managed_all() == 6
|
||||
|
||||
|
||||
def test_managed_is_zero_for_a_workspace_without_containers(machine: FakeMachine) -> None:
|
||||
|
||||
@@ -194,6 +194,8 @@ preselect-direction left
|
||||
cancel-preselect
|
||||
toggle-monocle
|
||||
toggle-monocle
|
||||
toggle-maximize
|
||||
toggle-maximize
|
||||
toggle-float
|
||||
toggle-float
|
||||
toggle-lock
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
tier = "slow";
|
||||
kind = "session";
|
||||
timeoutMinutes = 15;
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
# What komorebi does that is on the screen of a real compositing session, read from screenshots: the
|
||||
# session guest draws, and the daemon is the module's unit, as on a user's machine. A headless KWin
|
||||
# cannot draw, so what the compositor puts on top can only be told here.
|
||||
#
|
||||
# A. toggle-maximize the window fills the work area, is the one on top, and goes back to its
|
||||
# tile
|
||||
#
|
||||
# `komorebi/tests/maximize.rs` and `maximize_commands.rs` check what the window manager does against
|
||||
# the fake; this checks that KWin's own maximize does it.
|
||||
import time
|
||||
|
||||
from komorebi_vm import Checks, Kde
|
||||
|
||||
start_all()
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
checks = Checks()
|
||||
kde = Kde.session(machine, scale=SCALE)
|
||||
|
||||
BLUE = (0, 0, 255)
|
||||
|
||||
|
||||
def near(pixel: object, want: tuple[int, int, int], tolerance: int = 14) -> bool:
|
||||
"""True if every channel of the pixel is within `tolerance` of `want`."""
|
||||
assert isinstance(pixel, tuple)
|
||||
return all(abs(got - wanted) <= tolerance for got, wanted in zip(pixel, want, strict=True))
|
||||
|
||||
|
||||
def answering() -> bool:
|
||||
return kde.run("komorebic monitor-information")[0] == 0
|
||||
|
||||
|
||||
def open_window(title: str, background: str) -> None:
|
||||
"""Opens a terminal with a plain background, so that a screenshot says which window is on top."""
|
||||
kde.spawn(
|
||||
f"foot -T {title} -o colors-dark.background={background} -o colors-dark.alpha=1.0"
|
||||
" sleep 3000"
|
||||
)
|
||||
kde.wait_for(lambda: kde.wid(title) != "", timeout=60)
|
||||
|
||||
|
||||
print("== A. toggle-maximize")
|
||||
checks.check("the session started komorebi", kde.wait_for(answering, timeout=120))
|
||||
for count, (title, background) in enumerate(
|
||||
[("red", "ff0000"), ("green", "00ff00"), ("blue", "0000ff")], start=1
|
||||
):
|
||||
open_window(title, background)
|
||||
checks.check(
|
||||
f"komorebi manages {title}", kde.wait_for(lambda count=count: kde.managed() == count)
|
||||
)
|
||||
# komorebi tiles the windows, and the last one to open has the focus. The bridge asks again for the
|
||||
# position of a window that is not where komorebi put it for a second after it did (PLATFORM.md,
|
||||
# "How clients answer a frame"), which would put a window that is maximized in that second back
|
||||
# where its tile was: the test waits that second out, as a person would.
|
||||
kde.wait_for(lambda: kde.focused_title() == "blue", timeout=20)
|
||||
time.sleep(3 * SCALE)
|
||||
|
||||
area = kde.state()["monitors"]["elements"][0]["work_area_size"]
|
||||
blue = kde.wid("blue")
|
||||
tile = kde.rect(blue)
|
||||
print(f" the work area is {area['right']}x{area['bottom']}, blue's tile is {tile}")
|
||||
checks.check(
|
||||
"blue is a tile, not the whole work area",
|
||||
tile.w < area["right"] - 20 or tile.h < area["bottom"] - 20,
|
||||
)
|
||||
|
||||
kde.komorebic("toggle-maximize")
|
||||
|
||||
|
||||
def fills_the_work_area() -> bool:
|
||||
"""KWin's maximize leaves the panel alone, which is at most 100 pixels of the screen."""
|
||||
r = kde.rect(blue)
|
||||
return (
|
||||
r.x <= area["left"] + 2
|
||||
and r.y <= area["top"] + 2
|
||||
and r.w >= area["right"] - 30
|
||||
and r.h >= area["bottom"] - 100
|
||||
)
|
||||
|
||||
|
||||
filled = kde.wait_for(fills_the_work_area, timeout=20)
|
||||
maximized = kde.rect(blue)
|
||||
checks.check(
|
||||
f"the focused window fills the work area (blue is {maximized}, the area is {area})", filled
|
||||
)
|
||||
image = kde.shot("maximized")
|
||||
print(f" the screenshot is {image.size[0]}x{image.size[1]}")
|
||||
middle = image.getpixel(
|
||||
(
|
||||
min(maximized.x + maximized.w // 2, image.width - 1),
|
||||
min(maximized.y + maximized.h // 2, image.height - 1),
|
||||
)
|
||||
)
|
||||
checks.check(f"and is the one on top ({middle})", near(middle, BLUE))
|
||||
workspace = kde.state()["monitors"]["elements"][0]["workspaces"]["elements"][0]
|
||||
checks.check(
|
||||
"komorebi's state has it as the maximized window, out of its containers",
|
||||
workspace["maximized_window"] is not None and len(workspace["containers"]["elements"]) == 2,
|
||||
)
|
||||
checks.check("komorebi still has all three", kde.managed_all() == 3)
|
||||
|
||||
kde.komorebic("toggle-maximize")
|
||||
checks.check(
|
||||
"toggled back, it is in its tile again",
|
||||
kde.wait_for(lambda: kde.rect(blue) == tile, timeout=20),
|
||||
)
|
||||
workspace = kde.state()["monitors"]["elements"][0]["workspaces"]["elements"][0]
|
||||
checks.check(
|
||||
"... and in a container of its own",
|
||||
workspace["maximized_window"] is None and len(workspace["containers"]["elements"]) == 3,
|
||||
)
|
||||
|
||||
checks.finish()
|
||||
Reference in new issue
Block a user