forge
Explore
Log in

Don't you dare go Hollow

Fix layer-shell initial commit logic

Browse files at this commit

ffb3030e36877aa346d476d717829e24bc7bfcc2Ivan MolodetskikhParent: 4808ba2
I didn't properly update it for the Smithay refactor. It was reading
initial_configure_sent too early. This worked before when niri had to reset it
manually, but it no longer works now that it is automatically reset already
before entering this function.
src/handlers/layer_shell.rsmodified+98 -92
@@ -97,104 +97,110 @@ impl State {
97 return false;97 return false;
98 };98 };
99 99
100- if surface == &root_surface {100+ if surface != &root_surface {
101- let initial_configure_sent = with_states(surface, |states| {101+ // This is an unsync layer-shell subsurface.
102- states102+ self.niri.queue_redraw(&output);
103- .data_map103+ return true;
104- .get::<LayerSurfaceData>()104+ }
105- .unwrap()105+
106- .lock()106+ let mut map = layer_map_for_output(&output);
107- .unwrap()107+
108- .initial_configure_sent108+ // Arrange the layers before sending the initial configure to respect any size the
109- });109+ // client may have sent.
110-110+ map.arrange();
111- let mut map = layer_map_for_output(&output);111+
112-112+ let layer = map
113- // Arrange the layers before sending the initial configure to respect any size the113+ .layer_for_surface(surface, WindowSurfaceType::TOPLEVEL)
114- // client may have sent.114+ .unwrap();
115- map.arrange();
116-
117- let layer = map
118- .layer_for_surface(surface, WindowSurfaceType::TOPLEVEL)
119- .unwrap();
120-
121- if initial_configure_sent {
122- if is_mapped(surface) {
123- let was_unmapped = self.niri.unmapped_layer_surfaces.remove(surface);
124-
125- // Resolve rules for newly mapped layer surfaces.
126- if was_unmapped {
127- let config = self.niri.config.borrow();
128-
129- let rules = &config.layer_rules;
130- let rules =
131- ResolvedLayerRules::compute(rules, layer, self.niri.is_at_startup);
132-
133- let output_size = output_size(&output);
134- let scale = output.current_scale().fractional_scale();
135-
136- let mapped = MappedLayer::new(
137- layer.clone(),
138- rules,
139- output_size,
140- scale,
141- self.niri.clock.clone(),
142- &config,
143- );
144-
145- let prev = self
146- .niri
147- .mapped_layer_surfaces
148- .insert(layer.clone(), mapped);
149- if prev.is_some() {
150- error!("MappedLayer was present for an unmapped surface");
151- }
152- }
153-
154- // Give focus to newly mapped on-demand surfaces. Some launchers like
155- // lxqt-runner rely on this behavior. While this behavior doesn't make much
156- // sense for other clients like panels, the consensus seems to be that it's not
157- // a big deal since panels generally only open once at the start of the
158- // session.
159- //
160- // Note that:
161- // 1) Exclusive layer surfaces already get focus automatically in
162- // update_keyboard_focus().
163- // 2) Same-layer exclusive layer surfaces are already preferred to on-demand
164- // surfaces in update_keyboard_focus(), so we don't need to check for that
165- // here.
166- //
167- // https://github.com/YaLTeR/niri/issues/641
168- let on_demand = layer.cached_state().keyboard_interactivity
169- == wlr_layer::KeyboardInteractivity::OnDemand;
170- if was_unmapped && on_demand {
171- // I guess it'd make sense to check that no higher-layer on-demand surface
172- // has focus, but Smithay's Layer doesn't implement Ord so this would be a
173- // little annoying.
174- self.niri.layer_shell_on_demand_focus = Some(layer.clone());
175- }
176- } else {
177- self.niri.mapped_layer_surfaces.remove(layer);
178- self.niri.unmapped_layer_surfaces.insert(surface.clone());
179- }
180- } else {
181- let scale = output.current_scale();
182- let transform = output.current_transform();
183- with_states(surface, |data| {
184- send_scale_transform(surface, data, scale, transform);
185- });
186 115
187- layer.layer_surface().send_configure();116+ if is_mapped(surface) {
117+ let was_unmapped = self.niri.unmapped_layer_surfaces.remove(surface);
118+
119+ // Resolve rules for newly mapped layer surfaces.
120+ if was_unmapped {
121+ let config = self.niri.config.borrow();
122+
123+ let rules = &config.layer_rules;
124+ let rules = ResolvedLayerRules::compute(rules, layer, self.niri.is_at_startup);
125+
126+ let output_size = output_size(&output);
127+ let scale = output.current_scale().fractional_scale();
128+
129+ let mapped = MappedLayer::new(
130+ layer.clone(),
131+ rules,
132+ output_size,
133+ scale,
134+ self.niri.clock.clone(),
135+ &config,
136+ );
137+
138+ let prev = self
139+ .niri
140+ .mapped_layer_surfaces
141+ .insert(layer.clone(), mapped);
142+ if prev.is_some() {
143+ error!("MappedLayer was present for an unmapped surface");
144+ }
188 }145 }
189- drop(map);
190 146
191- // This will call queue_redraw() inside.147+ // Give focus to newly mapped on-demand surfaces. Some launchers like lxqt-runner rely
192- self.niri.output_resized(&output);148+ // on this behavior. While this behavior doesn't make much sense for other clients like
149+ // panels, the consensus seems to be that it's not a big deal since panels generally
150+ // only open once at the start of the session.
151+ //
152+ // Note that:
153+ // 1) Exclusive layer surfaces already get focus automatically in
154+ // update_keyboard_focus().
155+ // 2) Same-layer exclusive layer surfaces are already preferred to on-demand surfaces in
156+ // update_keyboard_focus(), so we don't need to check for that here.
157+ //
158+ // https://github.com/YaLTeR/niri/issues/641
159+ let on_demand = layer.cached_state().keyboard_interactivity
160+ == wlr_layer::KeyboardInteractivity::OnDemand;
161+ if was_unmapped && on_demand {
162+ // I guess it'd make sense to check that no higher-layer on-demand surface
163+ // has focus, but Smithay's Layer doesn't implement Ord so this would be a
164+ // little annoying.
165+ self.niri.layer_shell_on_demand_focus = Some(layer.clone());
166+ }
193 } else {167 } else {
194- // This is an unsync layer-shell subsurface.168+ // The surface is unmapped.
195- self.niri.queue_redraw(&output);169+ if self.niri.mapped_layer_surfaces.remove(layer).is_some() {
170+ // A mapped surface got unmapped via a null commit. Now it needs to do a new
171+ // initial commit again.
172+ self.niri.unmapped_layer_surfaces.insert(surface.clone());
173+ } else {
174+ // An unmapped surface remains unmapped. If we haven't sent an initial configure
175+ // yet, we should do so.
176+ let initial_configure_sent = with_states(surface, |states| {
177+ states
178+ .data_map
179+ .get::<LayerSurfaceData>()
180+ .unwrap()
181+ .lock()
182+ .unwrap()
183+ .initial_configure_sent
184+ });
185+ if !initial_configure_sent {
186+ let scale = output.current_scale();
187+ let transform = output.current_transform();
188+ with_states(surface, |data| {
189+ send_scale_transform(surface, data, scale, transform);
190+ });
191+
192+ layer.layer_surface().send_configure();
193+ }
194+ // If we already sent an initial configure, then map.arange() above had just sent
195+ // it a new configure, if needed.
196+ }
196 }197 }
197 198
199+ drop(map);
200+
201+ // This will call queue_redraw() inside.
202+ self.niri.output_resized(&output);
203+
198 true204 true
199 }205 }
200 }206 }
src/tests/client.rsmodified+4 -0
@@ -438,6 +438,10 @@ impl LayerSurface {
438 self.surface.attach(Some(&buffer), 0, 0);438 self.surface.attach(Some(&buffer), 0, 0);
439 }439 }
440 440
441+ pub fn attach_null(&self) {
442+ self.surface.attach(None, 0, 0);
443+ }
444+
441 pub fn set_size(&self, w: u16, h: u16) {445 pub fn set_size(&self, w: u16, h: u16) {
442 self.viewport.set_destination(i32::from(w), i32::from(h));446 self.viewport.set_destination(i32::from(w), i32::from(h));
443 }447 }
src/tests/layer_shell.rsmodified+169 -1
@@ -1,6 +1,8 @@
1 use insta::assert_snapshot;1 use insta::assert_snapshot;
2 use smithay::reexports::wayland_protocols_wlr::layer_shell::v1::client::zwlr_layer_shell_v1::Layer;2 use smithay::reexports::wayland_protocols_wlr::layer_shell::v1::client::zwlr_layer_shell_v1::Layer;
3-use smithay::reexports::wayland_protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::Anchor;3+use smithay::reexports::wayland_protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::{
4+ Anchor, KeyboardInteractivity,
5+};
4 6
5 use super::*;7 use super::*;
6 use crate::tests::client::{LayerConfigureProps, LayerMargin};8 use crate::tests::client::{LayerConfigureProps, LayerMargin};
@@ -88,3 +90,169 @@ fn margin_overflow() {
88 let layer = f.client(id).layer(&surface);90 let layer = f.client(id).layer(&surface);
89 assert_snapshot!(layer.format_recent_configures(), @"size: 0 × 0");91 assert_snapshot!(layer.format_recent_configures(), @"size: 0 × 0");
90 }92 }
93+
94+#[test]
95+fn unmap_through_null_buffer() {
96+ let mut f = Fixture::new();
97+ f.add_output(1, (1920, 1080));
98+ let id = f.add_client();
99+
100+ let layer = f.client(id).create_layer(None, Layer::Top, "");
101+ let surface = layer.surface.clone();
102+ layer.set_configure_props(LayerConfigureProps {
103+ anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
104+ size: Some((0, 50)),
105+ ..Default::default()
106+ });
107+ layer.commit();
108+ f.double_roundtrip(id);
109+
110+ let layer = f.client(id).layer(&surface);
111+ assert_snapshot!(layer.format_recent_configures(), @"size: 1920 × 50");
112+
113+ layer.attach_new_buffer();
114+ layer.set_size(100, 100);
115+ layer.ack_last_and_commit();
116+ f.double_roundtrip(id);
117+
118+ let layer = f.client(id).layer(&surface);
119+ // No new configure since nothing changed.
120+ assert_snapshot!(layer.format_recent_configures(), @"");
121+
122+ // Unmap by attaching a null buffer. This moves the surface back to pre-initial-commit stage.
123+ layer.attach_null();
124+ layer.commit();
125+ f.double_roundtrip(id);
126+
127+ let layer = f.client(id).layer(&surface);
128+ // Configures must be empty because we haven't done an initial commit yet.
129+ assert_snapshot!(layer.format_recent_configures(), @"");
130+
131+ // Do the initial commit again.
132+ layer.set_configure_props(LayerConfigureProps {
133+ anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
134+ size: Some((0, 100)),
135+ ..Default::default()
136+ });
137+ layer.commit();
138+ f.double_roundtrip(id);
139+
140+ let layer = f.client(id).layer(&surface);
141+ // This is the new initial configure.
142+ assert_snapshot!(layer.format_recent_configures(), @"size: 1920 × 100");
143+
144+ layer.attach_new_buffer();
145+ layer.set_size(100, 100);
146+ layer.ack_last_and_commit();
147+ f.double_roundtrip(id);
148+
149+ let layer = f.client(id).layer(&surface);
150+ assert_snapshot!(layer.format_recent_configures(), @"");
151+}
152+
153+#[test]
154+fn multiple_commits_before_mapping() {
155+ let mut f = Fixture::new();
156+ f.add_output(1, (1920, 1080));
157+ let id = f.add_client();
158+
159+ let layer = f.client(id).create_layer(None, Layer::Top, "");
160+ let surface = layer.surface.clone();
161+ layer.set_configure_props(LayerConfigureProps {
162+ anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
163+ size: Some((0, 50)),
164+ ..Default::default()
165+ });
166+ layer.commit();
167+ f.double_roundtrip(id);
168+
169+ let layer = f.client(id).layer(&surface);
170+ assert_snapshot!(layer.format_recent_configures(), @"size: 1920 × 50");
171+
172+ // Change something that won't cause a configure.
173+ layer.set_configure_props(LayerConfigureProps {
174+ anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
175+ size: Some((0, 50)),
176+ kb_interactivity: Some(KeyboardInteractivity::OnDemand),
177+ ..Default::default()
178+ });
179+ layer.ack_last_and_commit();
180+ f.double_roundtrip(id);
181+
182+ let layer = f.client(id).layer(&surface);
183+ // No new configure since the size hasn't changed.
184+ assert_snapshot!(layer.format_recent_configures(), @"");
185+
186+ // Change something that will cause a configure.
187+ layer.set_configure_props(LayerConfigureProps {
188+ anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
189+ size: Some((0, 100)),
190+ ..Default::default()
191+ });
192+ layer.commit();
193+ f.double_roundtrip(id);
194+
195+ let layer = f.client(id).layer(&surface);
196+ // Configure with new size.
197+ assert_snapshot!(layer.format_recent_configures(), @"size: 1920 × 100");
198+
199+ // Map.
200+ layer.attach_new_buffer();
201+ layer.set_size(100, 100);
202+ layer.ack_last_and_commit();
203+ f.double_roundtrip(id);
204+
205+ let layer = f.client(id).layer(&surface);
206+ // No new configure since nothing changed.
207+ assert_snapshot!(layer.format_recent_configures(), @"");
208+
209+ // Unmap by attaching a null buffer. This moves the surface back to pre-initial-commit stage.
210+ layer.attach_null();
211+ layer.commit();
212+ f.double_roundtrip(id);
213+
214+ let layer = f.client(id).layer(&surface);
215+ // Configures must be empty because we haven't done an initial commit yet.
216+ assert_snapshot!(layer.format_recent_configures(), @"");
217+
218+ // Same configure props as before, but since we unmapped, we should get a new initial
219+ // configure (that will happen to match the previous configure we had got while mapped).
220+ let surface = layer.surface.clone();
221+ layer.set_configure_props(LayerConfigureProps {
222+ anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
223+ size: Some((0, 100)),
224+ ..Default::default()
225+ });
226+ layer.commit();
227+ f.double_roundtrip(id);
228+
229+ let layer = f.client(id).layer(&surface);
230+ assert_snapshot!(layer.format_recent_configures(), @"size: 1920 × 100");
231+
232+ // Change something that won't cause a configure.
233+ layer.set_configure_props(LayerConfigureProps {
234+ anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
235+ size: Some((0, 100)),
236+ kb_interactivity: Some(KeyboardInteractivity::OnDemand),
237+ ..Default::default()
238+ });
239+ layer.ack_last_and_commit();
240+ f.double_roundtrip(id);
241+
242+ let layer = f.client(id).layer(&surface);
243+ // No new configure since the size hasn't changed.
244+ assert_snapshot!(layer.format_recent_configures(), @"");
245+
246+ // Change something that will cause a configure.
247+ layer.set_configure_props(LayerConfigureProps {
248+ anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
249+ size: Some((0, 50)),
250+ ..Default::default()
251+ });
252+ layer.commit();
253+ f.double_roundtrip(id);
254+
255+ let layer = f.client(id).layer(&surface);
256+ // Configure with new size.
257+ assert_snapshot!(layer.format_recent_configures(), @"size: 1920 × 50");
258+}