Files
komorebi/komorebi/tests/maximize.rs
T
LGUG2Z 05de20749b 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.
2026-10-28 07:20:37 -07:00

147 lines
4.8 KiB
Rust

//! `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}");
}
}