diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2023-12-24 17:38:13 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2023-12-24 17:38:13 +0400 |
| commit | be2e551a89abb98099f094f73889d6d0cc46c87c (patch) | |
| tree | 28e13fb690fc207fa46361b0670df52181552042 /src/handlers | |
| parent | ed3080d908001bf468789b8f47f893e00306135d (diff) | |
| download | niri-be2e551a89abb98099f094f73889d6d0cc46c87c.tar.gz niri-be2e551a89abb98099f094f73889d6d0cc46c87c.tar.bz2 niri-be2e551a89abb98099f094f73889d6d0cc46c87c.zip | |
Move clones up from find_window_and_output
Diffstat (limited to 'src/handlers')
| -rw-r--r-- | src/handlers/compositor.rs | 10 | ||||
| -rw-r--r-- | src/handlers/xdg_shell.rs | 14 |
2 files changed, 15 insertions, 9 deletions
diff --git a/src/handlers/compositor.rs b/src/handlers/compositor.rs index 7cceaea0..df95942a 100644 --- a/src/handlers/compositor.rs +++ b/src/handlers/compositor.rs @@ -18,6 +18,7 @@ use smithay::{delegate_compositor, delegate_shm}; use super::xdg_shell; use crate::niri::{ClientState, State}; +use crate::utils::clone2; impl CompositorHandler for State { fn compositor_state(&mut self) -> &mut CompositorState { @@ -116,8 +117,9 @@ impl CompositorHandler for State { } // This is a commit of a previously-mapped root or a non-toplevel root. - if let Some((window, output)) = self.niri.layout.find_window_and_output(surface) { - // This is a commit of a previously-mapped toplevel. + if let Some(win_out) = self.niri.layout.find_window_and_output(surface) { + let (window, output) = clone2(win_out); + window.on_commit(); // This is a commit of a previously-mapped toplevel. @@ -147,7 +149,7 @@ impl CompositorHandler for State { // This is a commit of a non-root or a non-toplevel root. let root_window_output = self.niri.layout.find_window_and_output(&root_surface); - if let Some((window, output)) = root_window_output { + if let Some((window, output)) = root_window_output.map(clone2) { window.on_commit(); self.niri.layout.update_window(&window); self.niri.queue_redraw(output); @@ -158,7 +160,7 @@ impl CompositorHandler for State { self.popups_handle_commit(surface); if let Some(popup) = self.niri.popups.find_popup(surface) { if let Some(output) = self.output_for_popup(&popup) { - self.niri.queue_redraw(output); + self.niri.queue_redraw(output.clone()); } } diff --git a/src/handlers/xdg_shell.rs b/src/handlers/xdg_shell.rs index 3a290796..f99aa82b 100644 --- a/src/handlers/xdg_shell.rs +++ b/src/handlers/xdg_shell.rs @@ -20,6 +20,7 @@ use smithay::wayland::shell::xdg::{ use smithay::{delegate_kde_decoration, delegate_xdg_decoration, delegate_xdg_shell}; use crate::niri::State; +use crate::utils::clone2; impl XdgShellHandler for State { fn xdg_shell_state(&mut self) -> &mut XdgShellState { @@ -123,8 +124,10 @@ impl XdgShellHandler for State { .layout .find_window_and_output(surface.wl_surface()) { + let window = window.clone(); + if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) { - if requested_output != current_output { + if &requested_output != current_output { self.niri .layout .move_window_to_output(window.clone(), &requested_output); @@ -146,6 +149,7 @@ impl XdgShellHandler for State { .layout .find_window_and_output(surface.wl_surface()) { + let window = window.clone(); self.niri.layout.set_fullscreen(&window, false); } } @@ -166,7 +170,7 @@ impl XdgShellHandler for State { .layout .find_window_and_output(surface.wl_surface()); - let Some((window, output)) = win_out else { + let Some((window, output)) = win_out.map(clone2) else { // I have no idea how this can happen, but I saw it happen once, in a weird interaction // involving laptop going to sleep and resuming. error!("toplevel missing from both unmapped_windows and layout"); @@ -179,7 +183,7 @@ impl XdgShellHandler for State { fn popup_destroyed(&mut self, surface: PopupSurface) { if let Some(output) = self.output_for_popup(&PopupKind::Xdg(surface)) { - self.niri.queue_redraw(output); + self.niri.queue_redraw(output.clone()); } } } @@ -288,7 +292,7 @@ impl State { } } - pub fn output_for_popup(&self, popup: &PopupKind) -> Option<Output> { + pub fn output_for_popup(&self, popup: &PopupKind) -> Option<&Output> { let root = find_popup_root_surface(popup).ok()?; self.niri.output_for_root(&root) } @@ -304,7 +308,7 @@ impl State { // Figure out if the root is a window or a layer surface. if let Some((window, output)) = self.niri.layout.find_window_and_output(&root) { - self.unconstrain_window_popup(popup, &window, &output); + self.unconstrain_window_popup(popup, window, output); } else if let Some((layer_surface, output)) = self.niri.layout.outputs().find_map(|o| { let map = layer_map_for_output(o); let layer_surface = map.layer_for_surface(&root, WindowSurfaceType::TOPLEVEL)?; |
