aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-12-24 17:38:13 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-12-24 17:38:13 +0400
commitbe2e551a89abb98099f094f73889d6d0cc46c87c (patch)
tree28e13fb690fc207fa46361b0670df52181552042 /src
parented3080d908001bf468789b8f47f893e00306135d (diff)
downloadniri-be2e551a89abb98099f094f73889d6d0cc46c87c.tar.gz
niri-be2e551a89abb98099f094f73889d6d0cc46c87c.tar.bz2
niri-be2e551a89abb98099f094f73889d6d0cc46c87c.zip
Move clones up from find_window_and_output
Diffstat (limited to 'src')
-rw-r--r--src/handlers/compositor.rs10
-rw-r--r--src/handlers/xdg_shell.rs14
-rw-r--r--src/layout/mod.rs4
-rw-r--r--src/niri.rs4
-rw-r--r--src/utils.rs4
5 files changed, 23 insertions, 13 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)?;
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 5d747cfe..5ccbebd1 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -477,12 +477,12 @@ impl<W: LayoutElement> Layout<W> {
}
}
- pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(W, Output)> {
+ pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(&W, &Output)> {
if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
for mon in monitors {
for ws in &mon.workspaces {
if let Some(window) = ws.find_wl_surface(wl_surface) {
- return Some((window.clone(), mon.output.clone()));
+ return Some((window, &mon.output));
}
}
}
diff --git a/src/niri.rs b/src/niri.rs
index f09be356..a0a98c90 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -1222,7 +1222,7 @@ impl Niri {
.or_else(|| self.global_space.outputs().next())
}
- pub fn output_for_root(&self, root: &WlSurface) -> Option<Output> {
+ pub fn output_for_root(&self, root: &WlSurface) -> Option<&Output> {
// Check the main layout.
let win_out = self.layout.find_window_and_output(root);
let layout_output = win_out.map(|(_, output)| output);
@@ -1233,7 +1233,7 @@ impl Niri {
.layer_for_surface(root, WindowSurfaceType::TOPLEVEL)
.is_some()
};
- let layer_shell_output = || self.layout.outputs().find(has_layer_surface).cloned();
+ let layer_shell_output = || self.layout.outputs().find(has_layer_surface);
layout_output.or_else(layer_shell_output)
}
diff --git a/src/utils.rs b/src/utils.rs
index 07c737df..08606a53 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -17,6 +17,10 @@ use smithay::utils::{Logical, Point, Rectangle, Size};
use crate::config::Config;
+pub fn clone2<T: Clone, U: Clone>(t: (&T, &U)) -> (T, U) {
+ (t.0.clone(), t.1.clone())
+}
+
pub fn get_monotonic_time() -> Duration {
let ts = clock_gettime(ClockId::Monotonic);
Duration::new(ts.tv_sec as u64, ts.tv_nsec as u32)