use client::ClientId;
use insta::assert_snapshot;
use niri_config::Config;
use niri_ipc::SizeChange;
use smithay::utils::Point;
use wayland_client::protocol::wl_surface::WlSurface;
use super::*;
// Sets up a fixture with two outputs and 100×100 window.
fn set_up() -> (Fixture, ClientId, WlSurface) {
set_up_with_config(Config::default())
}
fn set_up_with_config(config: Config) -> (Fixture, ClientId, WlSurface) {
let mut f = Fixture::with_config(config);
f.add_output(1, (1920, 1080));
f.add_output(2, (1280, 720));
let id = f.add_client();
let window = f.client(id).create_window();
let surface = window.surface.clone();
window.commit();
f.roundtrip(id);
let window = f.client(id).window(&surface);
window.attach_new_buffer();
window.set_size(100, 100);
window.ack_last_and_commit();
f.double_roundtrip(id);
(f, id, surface)
}
#[test]
fn unfocus_preserves_current_size() {
let (mut f, id, surface) = set_up();
f.niri().layout.toggle_window_floating(None);
f.roundtrip(id);
// Change window size while it's floating.
let window = f.client(id).window(&surface);
window.set_size(200, 200);
window.ack_last_and_commit();
f.double_roundtrip(id);
let _ = f.client(id).window(&surface).recent_configures();
// Focus a different output which should drop the Activated state.
f.niri_focus_output(2);
f.double_roundtrip(id);
// This should request 200 × 200 because that's the current window size.
let window = f.client(id).window(&surface);
assert_snapshot!(
window.format_recent_configures(),
@"size: 200 × 200, bounds: 1920 × 1080, states: []"
);
// Change window size again.
let window = f.client(id).window(&surface);
window.set_size(300, 300);
window.ack_last_and_commit();
f.roundtrip(id);
// Focus the first output which should add back the Activated state.
f.niri_focus_output(1);
f.double_roundtrip(id);
// This should request 300 × 300 because that's the current window size.
let window = f.client(id).window(&surface);
assert_snapshot!(
window.format_recent_configures(),
@"size: 300 × 300, bounds: 1920 × 1080, states: [Activated]"
);
}
#[test]
fn resize_to_different_size() {
let (mut f, id, surface) = set_up();
let _ = f.client(id).window(&surface).recent_configures();
// Commit in response to the Activated state change configure.
f.client(id).window(&surface).ack_last_and_commit();
f.double_roundtrip(id);
f.niri().layout.toggle_window_floating(None);
f.niri().layout.set_column_width(SizeChange::SetFixed(500));
f.double_roundtrip(id);
// This should request the new size, 500 × 100.
assert_snapshot!(
f.client(id).window(&surface).format_recent_configures(),
@"size: 500 × 100, bounds: 1920 × 1080, states: [Activated]"
);
// Focus a different output which should drop the Activated state.
f.niri_focus_output(2);
f.double_roundtrip(id);
// This should request the new size since the window hasn't committed yet.
assert_snapshot!(
f.client(id).window(&surface).format_recent_configures(),
@"size: 500 × 100, bounds: 1920 × 1080, states: []"
);
// Ack but don't commit yet.
let window = f.client(id).window(&surface);
window.ack_last();
f.roundtrip(id);
// Add the activated state.
f.niri_focus_output(1);
f.double_roundtrip(id);
// This should request the new si