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 @@
1 use std::collections::hash_map::Entry;1 use std::collections::hash_map::Entry;
2 2
3 use smithay::backend::renderer::utils::{on_commit_buffer_handler, with_renderer_surface_state};3 use smithay::backend::renderer::utils::{on_commit_buffer_handler, with_renderer_surface_state};
4-use smithay::desktop::find_popup_root_surface;
5 use smithay::input::pointer::CursorImageStatus;4 use smithay::input::pointer::CursorImageStatus;
6 use smithay::reexports::calloop::Interest;5 use smithay::reexports::calloop::Interest;
7 use smithay::reexports::wayland_server::protocol::wl_buffer;6 use smithay::reexports::wayland_server::protocol::wl_buffer;
@@ -30,7 +29,12 @@ impl CompositorHandler for State {
30 }29 }
31 30
32 fn new_subsurface(&mut self, surface: &WlSurface, parent: &WlSurface) {31 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) {
34 let scale = output.current_scale().integer_scale();38 let scale = output.current_scale().integer_scale();
35 let transform = output.current_transform();39 let transform = output.current_transform();
36 with_states(surface, |data| {40 with_states(surface, |data| {
@@ -150,11 +154,8 @@ impl CompositorHandler for State {
150 // This might be a popup.154 // This might be a popup.
151 self.popups_handle_commit(surface);155 self.popups_handle_commit(surface);
152 if let Some(popup) = self.niri.popups.find_popup(surface) {156 if let Some(popup) = self.niri.popups.find_popup(surface) {
153- if let Ok(root) = find_popup_root_surface(&popup) {157+ if let Some(output) = self.output_for_popup(&popup) {
154- let root_window_output = self.niri.layout.find_window_and_output(&root);158+ self.niri.queue_redraw(output);
155- if let Some((_window, output)) = root_window_output {
156- self.niri.queue_redraw(output);
157- }
158 }159 }
159 }160 }
160 161
src/handlers/mod.rsmodified+3 -5
@@ -80,10 +80,8 @@ delegate_text_input_manager!(State);
80 80
81 impl InputMethodHandler for State {81 impl InputMethodHandler for State {
82 fn new_popup(&mut self, surface: PopupSurface) {82 fn new_popup(&mut self, surface: PopupSurface) {
83- if let Some((_, output)) = surface83+ let popup = PopupKind::from(surface.clone());
84- .get_parent()84+ if let Some(output) = self.output_for_popup(&popup) {
85- .and_then(|parent| self.niri.layout.find_window_and_output(&parent.surface))
86- {
87 let scale = output.current_scale().integer_scale();85 let scale = output.current_scale().integer_scale();
88 let transform = output.current_transform();86 let transform = output.current_transform();
89 let wl_surface = surface.wl_surface();87 let wl_surface = surface.wl_surface();
@@ -91,7 +89,7 @@ impl InputMethodHandler for State {
91 send_surface_state(wl_surface, data, scale, transform);89 send_surface_state(wl_surface, data, scale, transform);
92 });90 });
93 }91 }
94- if let Err(err) = self.niri.popups.track_popup(PopupKind::from(surface)) {92+ if let Err(err) = self.niri.popups.track_popup(popup) {
95 warn!("error tracking ime popup {err:?}");93 warn!("error tracking ime popup {err:?}");
96 }94 }
97 }95 }
src/handlers/xdg_shell.rsmodified+9 -11
@@ -175,11 +175,8 @@ impl XdgShellHandler for State {
175 }175 }
176 176
177 fn popup_destroyed(&mut self, surface: PopupSurface) {177 fn popup_destroyed(&mut self, surface: PopupSurface) {
178- if let Ok(root) = find_popup_root_surface(&surface.into()) {178+ if let Some(output) = self.output_for_popup(&PopupKind::Xdg(surface)) {
179- let root_window_output = self.niri.layout.find_window_and_output(&root);179+ self.niri.queue_redraw(output);
180- if let Some((_window, output)) = root_window_output {
181- self.niri.queue_redraw(output);
182- }
183 }180 }
184 }181 }
185 }182 }
@@ -271,12 +268,8 @@ impl State {
271 .initial_configure_sent268 .initial_configure_sent
272 });269 });
273 if !initial_configure_sent {270 if !initial_configure_sent {
274- if let Some(output) = popup.get_parent_surface().and_then(|parent| {271+ if let Some(output) = self.output_for_popup(&PopupKind::Xdg(popup.clone()))
275- self.niri272+ {
276- .layout
277- .find_window_and_output(&parent)
278- .map(|(_, output)| output)
279- }) {
280 let scale = output.current_scale().integer_scale();273 let scale = output.current_scale().integer_scale();
281 let transform = output.current_transform();274 let transform = output.current_transform();
282 with_states(surface, |data| {275 with_states(surface, |data| {
@@ -291,4 +284,9 @@ impl State {
291 }284 }
292 }285 }
293 }286 }
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+ }
294 }292 }
src/niri.rsmodified+16 -0
@@ -1211,6 +1211,22 @@ impl Niri {
1211 .or_else(|| self.global_space.outputs().next())1211 .or_else(|| self.global_space.outputs().next())
1212 }1212 }
1213 1213
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+
1214 fn lock_surface_focus(&self) -> Option<WlSurface> {1230 fn lock_surface_focus(&self) -> Option<WlSurface> {
1215 let output_under_cursor = self.output_under_cursor();1231 let output_under_cursor = self.output_under_cursor();
1216 let output = output_under_cursor1232 let output = output_under_cursor