forge
Explore
Log in

Don't you dare go Hollow

Add a resize transaction client-server test

Browse files at this commit

e9c6f08906143c3fec1ad1301d538bef4cbc1978Ivan MolodetskikhParent: 17343a6
src/tests/mod.rsmodified+1 -0
@@ -6,4 +6,5 @@ mod server;
6 6
7 mod floating;7 mod floating;
8 mod fullscreen;8 mod fullscreen;
9+mod transactions;
9 mod window_opening;10 mod window_opening;
src/tests/transactions.rsadded+105 -0
@@ -0,0 +1,105 @@
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+ // 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+}
src/utils/transaction.rsmodified+2 -0
@@ -93,6 +93,8 @@ impl Transaction {
93 let _span = trace_span!("deadline timer", transaction = ?Weak::as_ptr(&inner))93 let _span = trace_span!("deadline timer", transaction = ?Weak::as_ptr(&inner))
94 .entered();94 .entered();
95 95
96+ // FIXME: come up with some way to control the deadline timer from tests.
97+ #[cfg(not(test))]
96 if let Some(inner) = inner.upgrade() {98 if let Some(inner) = inner.upgrade() {
97 trace!("deadline reached, completing transaction");99 trace!("deadline reached, completing transaction");
98 inner.complete();100 inner.complete();