| 1 | use std::fmt::Write as _; |
| 2 | |
| 3 | use insta::assert_snapshot; |
| 4 | use niri_ipc::SizeChange; |
| 5 | use wayland_client::protocol::wl_surface::WlSurface; |
| 6 | |
| 7 | use super::client::ClientId; |
| 8 | use super::*; |
| 9 | use crate::layout::LayoutElement; |
| 10 | use crate::niri::Niri; |
| 11 | |
| 12 | fn format_window_sizes(niri: &Niri) -> String { |
| 13 | let mut buf = String::new(); |
| 14 | for (_out, mapped) in niri.layout.windows() { |
| 15 | let size = mapped.size(); |
| 16 | writeln!(&mut buf, "{} × {}", size.w, size.h).unwrap(); |
| 17 | } |
| 18 | buf |
| 19 | } |
| 20 | |
| 21 | fn create_window(f: &mut Fixture, id: ClientId, w: u16, h: u16) -> WlSurface { |
| 22 | let window = f.client(id).create_window(); |
| 23 | let surface = window.surface.clone(); |
| 24 | window.commit(); |
| 25 | f.roundtrip(id); |
| 26 | |
| 27 | let window = f.client(id).window(&surface); |
| 28 | window.attach_new_buffer(); |
| 29 | window.set_size(w, h); |
| 30 | window.ack_last_and_commit(); |
| 31 | f.roundtrip(id); |
| 32 | |
| 33 | surface |
| 34 | } |
| 35 | |
| 36 | #[test] |
| 37 | fn column_resize_waits_for_both_windows() { |
| 38 | let mut f = Fixture::new(); |
| 39 | f.add_output(1, (1920, 1080)); |
| 40 | let id = f.add_client(); |
| 41 | |
| 42 | let surface1 = create_window(&mut f, id, 100, 100); |
| 43 | let surface2 = create_window(&mut f, id, 200, 200); |
| 44 | f.double_roundtrip(id); |
| 45 | |
| 46 | let _ = f.client(id).window(&surface1).recent_configures(); |
| 47 | let _ = f.client(id).window(&surface2).recent_configures(); |
| 48 | |
| 49 | |
| 50 | f.niri().layout.consume_or_expel_window_left(None); |
| 51 | f.double_roundtrip(id); |
| 52 | |
| 53 | |
| 54 | let window = f.client(id).window(&surface1); |
| 55 | assert_snapshot!( |
| 56 | window.format_recent_configures(), |
| 57 | @"size: 936 × 516, bounds: 1888 × 1048, states: []" |
| 58 | ); |
| 59 | window.ack_last_and_commit(); |
| 60 | |
| 61 | let window = f.client(id).window(&surface2); |
| 62 | assert_snapshot!( |
| 63 | window.format_recent_configures(), |
| 64 | @"size: 936 × 516, bounds: 1888 × 1048, states: [Activated]" |
| 65 | ); |
| 66 | window.ack_last_and_commit(); |
| 67 | |
| 68 | f.double_roundtrip(id); |
| 69 | |
| 70 | |
| 71 | assert_snapshot!(format_window_sizes(f.niri()), @r" |
| 72 | 100 × 100 |
| 73 | 200 × 200 |
| 74 | "); |
| 75 | |
| 76 | |
| 77 | f.niri() |
| 78 | .layout |
| 79 | .set_column_width(SizeChange::AdjustFixed(10)); |
| 80 | f.double_roundtrip(id); |
| 81 | |
| 82 | |
| 83 | let window = f.client(id).window(&surface1); |
| 84 | window.set_size(300, 300); |
| 85 | window.ack_last_and_commit(); |
| 86 | f.double_roundtrip(id); |
| 87 | |
| 88 | |
| 89 | assert_snapshot!(format_window_sizes(f.niri()), @r" |
| 90 | 100 × 100 |
| 91 | 200 × 200 |
| 92 | "); |
| 93 | |
| 94 | |
| 95 | let window = f.client(id).window(&surface2); |
| 96 | window.set_size(400, 400); |
| 97 | window.ack_last_and_commit(); |
| 98 | f.double_roundtrip(id); |
| 99 | |
| 100 | |
| 101 | assert_snapshot!(format_window_sizes(f.niri()), @r" |
| 102 | 300 × 300 |
| 103 | 400 × 400 |
| 104 | "); |
| 105 | } |