forge
Explore
Log in

Don't you dare go Hollow

Move clones up from find_window_and_output

Browse files at this commit

be2e551a89abb98099f094f73889d6d0cc46c87cIvan MolodetskikhParent: ed3080d
src/handlers/compositor.rsmodified+6 -4
@@ -18,6 +18,7 @@ use smithay::{delegate_compositor, delegate_shm};
18 18
19 use super::xdg_shell;19 use super::xdg_shell;
20 use crate::niri::{ClientState, State};20 use crate::niri::{ClientState, State};
21+use crate::utils::clone2;
21 22
22 impl CompositorHandler for State {23 impl CompositorHandler for State {
23 fn compositor_state(&mut self) -> &mut CompositorState {24 fn compositor_state(&mut self) -> &mut CompositorState {
@@ -116,8 +117,9 @@ impl CompositorHandler for State {
116 }117 }
117 118
118 // This is a commit of a previously-mapped root or a non-toplevel root.119 // This is a commit of a previously-mapped root or a non-toplevel root.
119- if let Some((window, output)) = self.niri.layout.find_window_and_output(surface) {120+ if let Some(win_out) = self.niri.layout.find_window_and_output(surface) {
120- // This is a commit of a previously-mapped toplevel.121+ let (window, output) = clone2(win_out);
122+
121 window.on_commit();123 window.on_commit();
122 124
123 // This is a commit of a previously-mapped toplevel.125 // This is a commit of a previously-mapped toplevel.
@@ -147,7 +149,7 @@ impl CompositorHandler for State {
147 149
148 // This is a commit of a non-root or a non-toplevel root.150 // This is a commit of a non-root or a non-toplevel root.
149 let root_window_output = self.niri.layout.find_window_and_output(&root_surface);151 let root_window_output = self.niri.layout.find_window_and_output(&root_surface);
150- if let Some((window, output)) = root_window_output {152+ if let Some((window, output)) = root_window_output.map(clone2) {
151 window.on_commit();153 window.on_commit();
152 self.niri.layout.update_window(&window);154 self.niri.layout.update_window(&window);
153 self.niri.queue_redraw(output);155 self.niri.queue_redraw(output);
@@ -158,7 +160,7 @@ impl CompositorHandler for State {
158 self.popups_handle_commit(surface);160 self.popups_handle_commit(surface);
159 if let Some(popup) = self.niri.popups.find_popup(surface) {161 if let Some(popup) = self.niri.popups.find_popup(surface) {
160 if let Some(output) = self.output_for_popup(&popup) {162 if let Some(output) = self.output_for_popup(&popup) {
161- self.niri.queue_redraw(output);163+ self.niri.queue_redraw(output.clone());
162 }164 }
163 }165 }
164 166
src/handlers/xdg_shell.rsmodified+9 -5
@@ -20,6 +20,7 @@ use smithay::wayland::shell::xdg::{
20 use smithay::{delegate_kde_decoration, delegate_xdg_decoration, delegate_xdg_shell};20 use smithay::{delegate_kde_decoration, delegate_xdg_decoration, delegate_xdg_shell};
21 21
22 use crate::niri::State;22 use crate::niri::State;
23+use crate::utils::clone2;
23 24
24 impl XdgShellHandler for State {25 impl XdgShellHandler for State {
25 fn xdg_shell_state(&mut self) -> &mut XdgShellState {26 fn xdg_shell_state(&mut self) -> &mut XdgShellState {
@@ -123,8 +124,10 @@ impl XdgShellHandler for State {
123 .layout124 .layout
124 .find_window_and_output(surface.wl_surface())125 .find_window_and_output(surface.wl_surface())
125 {126 {
127+ let window = window.clone();
128+
126 if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) {129 if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) {
127- if requested_output != current_output {130+ if &requested_output != current_output {
128 self.niri131 self.niri
129 .layout132 .layout
130 .move_window_to_output(window.clone(), &requested_output);133 .move_window_to_output(window.clone(), &requested_output);
@@ -146,6 +149,7 @@ impl XdgShellHandler for State {
146 .layout149 .layout
147 .find_window_and_output(surface.wl_surface())150 .find_window_and_output(surface.wl_surface())
148 {151 {
152+ let window = window.clone();
149 self.niri.layout.set_fullscreen(&window, false);153 self.niri.layout.set_fullscreen(&window, false);
150 }154 }
151 }155 }
@@ -166,7 +170,7 @@ impl XdgShellHandler for State {
166 .layout170 .layout
167 .find_window_and_output(surface.wl_surface());171 .find_window_and_output(surface.wl_surface());
168 172
169- let Some((window, output)) = win_out else {173+ let Some((window, output)) = win_out.map(clone2) else {
170 // I have no idea how this can happen, but I saw it happen once, in a weird interaction174 // I have no idea how this can happen, but I saw it happen once, in a weird interaction
171 // involving laptop going to sleep and resuming.175 // involving laptop going to sleep and resuming.
172 error!("toplevel missing from both unmapped_windows and layout");176 error!("toplevel missing from both unmapped_windows and layout");
@@ -179,7 +183,7 @@ impl XdgShellHandler for State {
179 183
180 fn popup_destroyed(&mut self, surface: PopupSurface) {184 fn popup_destroyed(&mut self, surface: PopupSurface) {
181 if let Some(output) = self.output_for_popup(&PopupKind::Xdg(surface)) {185 if let Some(output) = self.output_for_popup(&PopupKind::Xdg(surface)) {
182- self.niri.queue_redraw(output);186+ self.niri.queue_redraw(output.clone());
183 }187 }
184 }188 }
185 }189 }
@@ -288,7 +292,7 @@ impl State {
288 }292 }
289 }293 }
290 294
291- pub fn output_for_popup(&self, popup: &PopupKind) -> Option<Output> {295+ pub fn output_for_popup(&self, popup: &PopupKind) -> Option<&Output> {
292 let root = find_popup_root_surface(popup).ok()?;296 let root = find_popup_root_surface(popup).ok()?;
293 self.niri.output_for_root(&root)297 self.niri.output_for_root(&root)
294 }298 }
@@ -304,7 +308,7 @@ impl State {
304 308
305 // Figure out if the root is a window or a layer surface.309 // Figure out if the root is a window or a layer surface.
306 if let Some((window, output)) = self.niri.layout.find_window_and_output(&root) {310 if let Some((window, output)) = self.niri.layout.find_window_and_output(&root) {
307- self.unconstrain_window_popup(popup, &window, &output);311+ self.unconstrain_window_popup(popup, window, output);
308 } else if let Some((layer_surface, output)) = self.niri.layout.outputs().find_map(|o| {312 } else if let Some((layer_surface, output)) = self.niri.layout.outputs().find_map(|o| {
309 let map = layer_map_for_output(o);313 let map = layer_map_for_output(o);
310 let layer_surface = map.layer_for_surface(&root, WindowSurfaceType::TOPLEVEL)?;314 let layer_surface = map.layer_for_surface(&root, WindowSurfaceType::TOPLEVEL)?;
src/layout/mod.rsmodified+2 -2
@@ -477,12 +477,12 @@ impl<W: LayoutElement> Layout<W> {
477 }477 }
478 }478 }
479 479
480- pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(W, Output)> {480+ pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(&W, &Output)> {
481 if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {481 if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
482 for mon in monitors {482 for mon in monitors {
483 for ws in &mon.workspaces {483 for ws in &mon.workspaces {
484 if let Some(window) = ws.find_wl_surface(wl_surface) {484 if let Some(window) = ws.find_wl_surface(wl_surface) {
485- return Some((window.clone(), mon.output.clone()));485+ return Some((window, &mon.output));
486 }486 }
487 }487 }
488 }488 }
src/niri.rsmodified+2 -2
@@ -1222,7 +1222,7 @@ impl Niri {
1222 .or_else(|| self.global_space.outputs().next())1222 .or_else(|| self.global_space.outputs().next())
1223 }1223 }
1224 1224
1225- pub fn output_for_root(&self, root: &WlSurface) -> Option<Output> {1225+ pub fn output_for_root(&self, root: &WlSurface) -> Option<&Output> {
1226 // Check the main layout.1226 // Check the main layout.
1227 let win_out = self.layout.find_window_and_output(root);1227 let win_out = self.layout.find_window_and_output(root);
1228 let layout_output = win_out.map(|(_, output)| output);1228 let layout_output = win_out.map(|(_, output)| output);
@@ -1233,7 +1233,7 @@ impl Niri {
1233 .layer_for_surface(root, WindowSurfaceType::TOPLEVEL)1233 .layer_for_surface(root, WindowSurfaceType::TOPLEVEL)
1234 .is_some()1234 .is_some()
1235 };1235 };
1236- let layer_shell_output = || self.layout.outputs().find(has_layer_surface).cloned();1236+ let layer_shell_output = || self.layout.outputs().find(has_layer_surface);
1237 1237
1238 layout_output.or_else(layer_shell_output)1238 layout_output.or_else(layer_shell_output)
1239 }1239 }
src/utils.rsmodified+4 -0
@@ -17,6 +17,10 @@ use smithay::utils::{Logical, Point, Rectangle, Size};
17 17
18 use crate::config::Config;18 use crate::config::Config;
19 19
20+pub fn clone2<T: Clone, U: Clone>(t: (&T, &U)) -> (T, U) {
21+ (t.0.clone(), t.1.clone())
22+}
23+
20 pub fn get_monotonic_time() -> Duration {24 pub fn get_monotonic_time() -> Duration {
21 let ts = clock_gettime(ClockId::Monotonic);25 let ts = clock_gettime(ClockId::Monotonic);
22 Duration::new(ts.tv_sec as u64, ts.tv_nsec as u32)26 Duration::new(ts.tv_sec as u64, ts.tv_nsec as u32)