forge
Explore
Log in

Don't you dare go Hollow

Fix some cases of incomplete search for surface output

Browse files at this commit

c29a049245ffa0eb737114774da4c01c09897dfcIvan MolodetskikhParent: d6b62ad
Most visibly, fixes screen not immediately redrawing upon layer-shell
popup commits.

There's still a number of places with questionable handling left, mostly
to do with subsurfaces (like, find_popup_root_surface() doesn't go up to
subsurfaces), and session-lock. I don't have good clients to test these.
src/handlers/compositor.rsmodified+8 -7
@@ -1,7 +1,6 @@
11 use std::collections::hash_map::Entry;
22
33 use smithay::backend::renderer::utils::{on_commit_buffer_handler, with_renderer_surface_state};
4-use smithay::desktop::find_popup_root_surface;
54 use smithay::input::pointer::CursorImageStatus;
65 use smithay::reexports::calloop::Interest;
76 use smithay::reexports::wayland_server::protocol::wl_buffer;
@@ -30,7 +29,12 @@ impl CompositorHandler for State {
3029 }
3130
3231 fn new_subsurface(&mut self, surface: &WlSurface, parent: &WlSurface) {
33- if let Some((_, output)) = self.niri.layout.find_window_and_output(parent) {
32+ let mut root = parent.clone();
33+ while let Some(parent) = get_parent(&root) {
34+ root = parent;
35+ }
36+
37+ if let Some(output) = self.niri.output_for_root(&root) {
3438 let scale = output.current_scale().integer_scale();
3539 let transform = output.current_transform();
3640 with_states(surface, |data| {
@@ -150,11 +154,8 @@ impl CompositorHandler for State {
150154 // This might be a popup.
151155 self.popups_handle_commit(surface);
152156 if let Some(popup) = self.niri.popups.find_popup(surface) {
153- if let Ok(root) = find_popup_root_surface(&popup) {
154- let root_window_output = self.niri.layout.find_window_and_output(&root);
155- if let Some((_window, output)) = root_window_output {
156- self.niri.queue_redraw(output);
157- }
157+ if let Some(output) = self.output_for_popup(&popup) {
158+ self.niri.queue_redraw(output);
158159 }
159160 }
160161
src/handlers/mod.rsmodified+3 -5
@@ -80,10 +80,8 @@ delegate_text_input_manager!(State);
8080
8181 impl InputMethodHandler for State {
8282 fn new_popup(&mut self, surface: PopupSurface) {
83- if let Some((_, output)) = surface
84- .get_parent()
85- .and_then(|parent| self.niri.layout.find_window_and_output(&parent.surface))
86- {
83+ let popup = PopupKind::from(surface.clone());
84+ if let Some(output) = self.output_for_popup(&popup) {
8785 let scale = output.current_scale().integer_scale();
8886 let transform = output.current_transform();
8987 let wl_surface = surface.wl_surface();
@@ -91,7 +89,7 @@ impl InputMethodHandler for State {
9189 send_surface_state(wl_surface, data, scale, transform);
9290 });
9391 }
94- if let Err(err) = self.niri.popups.track_popup(PopupKind::from(surface)) {
92+ if let Err(err) = self.niri.popups.track_popup(popup) {
9593 warn!("error tracking ime popup {err:?}");
9694 }
9795 }
src/handlers/xdg_shell.rsmodified+9 -11
@@ -175,11 +175,8 @@ impl XdgShellHandler for State {
175175 }
176176
177177 fn popup_destroyed(&mut self, surface: PopupSurface) {
178- if let Ok(root) = find_popup_root_surface(&surface.into()) {
179- let root_window_output = self.niri.layout.find_window_and_output(&root);
180- if let Some((_window, output)) = root_window_output {
181- self.niri.queue_redraw(output);
182- }
178+ if let Some(output) = self.output_for_popup(&PopupKind::Xdg(surface)) {
179+ self.niri.queue_redraw(output);
183180 }
184181 }
185182 }
@@ -271,12 +268,8 @@ impl State {
271268 .initial_configure_sent
272269 });
273270 if !initial_configure_sent {
274- if let Some(output) = popup.get_parent_surface().and_then(|parent| {
275- self.niri
276- .layout
277- .find_window_and_output(&parent)
278- .map(|(_, output)| output)
279- }) {
271+ if let Some(output) = self.output_for_popup(&PopupKind::Xdg(popup.clone()))
272+ {
280273 let scale = output.current_scale().integer_scale();
281274 let transform = output.current_transform();
282275 with_states(surface, |data| {
@@ -291,4 +284,9 @@ impl State {
291284 }
292285 }
293286 }
287+
288+ pub fn output_for_popup(&self, popup: &PopupKind) -> Option<Output> {
289+ let root = find_popup_root_surface(popup).ok()?;
290+ self.niri.output_for_root(&root)
291+ }
294292 }
src/niri.rsmodified+16 -0
@@ -1211,6 +1211,22 @@ impl Niri {
12111211 .or_else(|| self.global_space.outputs().next())
12121212 }
12131213
1214+ pub fn output_for_root(&self, root: &WlSurface) -> Option<Output> {
1215+ // Check the main layout.
1216+ let win_out = self.layout.find_window_and_output(root);
1217+ let layout_output = win_out.map(|(_, output)| output);
1218+
1219+ // Check layer-shell.
1220+ let has_layer_surface = |o: &&Output| {
1221+ layer_map_for_output(o)
1222+ .layer_for_surface(root, WindowSurfaceType::TOPLEVEL)
1223+ .is_some()
1224+ };
1225+ let layer_shell_output = || self.layout.outputs().find(has_layer_surface).cloned();
1226+
1227+ layout_output.or_else(layer_shell_output)
1228+ }
1229+
12141230 fn lock_surface_focus(&self) -> Option<WlSurface> {
12151231 let output_under_cursor = self.output_under_cursor();
12161232 let output = output_under_cursor