forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

transactions.rs105 lines, 2.9 KiBHistoryRawDownload
1use std::fmt::Write as _;
2
3use insta::assert_snapshot;
4use niri_ipc::SizeChange;
5use wayland_client::protocol::wl_surface::WlSurface;
6
7use super::client::ClientId;
8use super::*;
9use crate::layout::LayoutElement;
10use crate::niri::Niri;
11
12fn 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
21fn 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]
37fn 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 // Consume into one column.
50 f.niri().layout.consume_or_expel_window_left(None);
51 f.double_roundtrip(id);
52
53 // Commit for the column consume.
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 // This should say 100 × 100 and 200 × 200.
71 assert_snapshot!(format_window_sizes(f.niri()), @r"
72 100 × 100
73 200 × 200
74 ");
75
76 // Issue a resize.
77 f.niri()
78 .layout
79 .set_column_width(SizeChange::AdjustFixed(10));
80 f.double_roundtrip(id);
81
82 // Commit window 1 in response to resize.
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 // This should still say 100 × 100 as we're waiting in a transaction for the second window.
89 assert_snapshot!(format_window_sizes(f.niri()), @r"
90 100 × 100
91 200 × 200
92 ");
93
94 // Commit window 2 in response to resize.
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 // This should say 300 × 300 and 400 × 400 as the transaction completed.
101 assert_snapshot!(format_window_sizes(f.niri()), @r"
102 300 × 300
103 400 × 400
104 ");
105}