mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-24 02:01:18 +07:00
Move clones up from find_window_and_output
This commit is contained in:
@@ -18,6 +18,7 @@ use smithay::{delegate_compositor, delegate_shm};
|
|||||||
|
|
||||||
use super::xdg_shell;
|
use super::xdg_shell;
|
||||||
use crate::niri::{ClientState, State};
|
use crate::niri::{ClientState, State};
|
||||||
|
use crate::utils::clone2;
|
||||||
|
|
||||||
impl CompositorHandler for State {
|
impl CompositorHandler for State {
|
||||||
fn compositor_state(&mut self) -> &mut CompositorState {
|
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.
|
// 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) {
|
if let Some(win_out) = self.niri.layout.find_window_and_output(surface) {
|
||||||
// This is a commit of a previously-mapped toplevel.
|
let (window, output) = clone2(win_out);
|
||||||
|
|
||||||
window.on_commit();
|
window.on_commit();
|
||||||
|
|
||||||
// This is a commit of a previously-mapped toplevel.
|
// 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.
|
// 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);
|
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();
|
window.on_commit();
|
||||||
self.niri.layout.update_window(&window);
|
self.niri.layout.update_window(&window);
|
||||||
self.niri.queue_redraw(output);
|
self.niri.queue_redraw(output);
|
||||||
@@ -158,7 +160,7 @@ impl CompositorHandler for State {
|
|||||||
self.popups_handle_commit(surface);
|
self.popups_handle_commit(surface);
|
||||||
if let Some(popup) = self.niri.popups.find_popup(surface) {
|
if let Some(popup) = self.niri.popups.find_popup(surface) {
|
||||||
if let Some(output) = self.output_for_popup(&popup) {
|
if let Some(output) = self.output_for_popup(&popup) {
|
||||||
self.niri.queue_redraw(output);
|
self.niri.queue_redraw(output.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ use smithay::wayland::shell::xdg::{
|
|||||||
use smithay::{delegate_kde_decoration, delegate_xdg_decoration, delegate_xdg_shell};
|
use smithay::{delegate_kde_decoration, delegate_xdg_decoration, delegate_xdg_shell};
|
||||||
|
|
||||||
use crate::niri::State;
|
use crate::niri::State;
|
||||||
|
use crate::utils::clone2;
|
||||||
|
|
||||||
impl XdgShellHandler for State {
|
impl XdgShellHandler for State {
|
||||||
fn xdg_shell_state(&mut self) -> &mut XdgShellState {
|
fn xdg_shell_state(&mut self) -> &mut XdgShellState {
|
||||||
@@ -123,8 +124,10 @@ impl XdgShellHandler for State {
|
|||||||
.layout
|
.layout
|
||||||
.find_window_and_output(surface.wl_surface())
|
.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 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
|
self.niri
|
||||||
.layout
|
.layout
|
||||||
.move_window_to_output(window.clone(), &requested_output);
|
.move_window_to_output(window.clone(), &requested_output);
|
||||||
@@ -146,6 +149,7 @@ impl XdgShellHandler for State {
|
|||||||
.layout
|
.layout
|
||||||
.find_window_and_output(surface.wl_surface())
|
.find_window_and_output(surface.wl_surface())
|
||||||
{
|
{
|
||||||
|
let window = window.clone();
|
||||||
self.niri.layout.set_fullscreen(&window, false);
|
self.niri.layout.set_fullscreen(&window, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,7 +170,7 @@ impl XdgShellHandler for State {
|
|||||||
.layout
|
.layout
|
||||||
.find_window_and_output(surface.wl_surface());
|
.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
|
// 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.
|
// involving laptop going to sleep and resuming.
|
||||||
error!("toplevel missing from both unmapped_windows and layout");
|
error!("toplevel missing from both unmapped_windows and layout");
|
||||||
@@ -179,7 +183,7 @@ impl XdgShellHandler for State {
|
|||||||
|
|
||||||
fn popup_destroyed(&mut self, surface: PopupSurface) {
|
fn popup_destroyed(&mut self, surface: PopupSurface) {
|
||||||
if let Some(output) = self.output_for_popup(&PopupKind::Xdg(surface)) {
|
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()?;
|
let root = find_popup_root_surface(popup).ok()?;
|
||||||
self.niri.output_for_root(&root)
|
self.niri.output_for_root(&root)
|
||||||
}
|
}
|
||||||
@@ -304,7 +308,7 @@ impl State {
|
|||||||
|
|
||||||
// Figure out if the root is a window or a layer surface.
|
// 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) {
|
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| {
|
} else if let Some((layer_surface, output)) = self.niri.layout.outputs().find_map(|o| {
|
||||||
let map = layer_map_for_output(o);
|
let map = layer_map_for_output(o);
|
||||||
let layer_surface = map.layer_for_surface(&root, WindowSurfaceType::TOPLEVEL)?;
|
let layer_surface = map.layer_for_surface(&root, WindowSurfaceType::TOPLEVEL)?;
|
||||||
|
|||||||
+2
-2
@@ -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 {
|
if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
|
||||||
for mon in monitors {
|
for mon in monitors {
|
||||||
for ws in &mon.workspaces {
|
for ws in &mon.workspaces {
|
||||||
if let Some(window) = ws.find_wl_surface(wl_surface) {
|
if let Some(window) = ws.find_wl_surface(wl_surface) {
|
||||||
return Some((window.clone(), mon.output.clone()));
|
return Some((window, &mon.output));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1222,7 +1222,7 @@ impl Niri {
|
|||||||
.or_else(|| self.global_space.outputs().next())
|
.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.
|
// Check the main layout.
|
||||||
let win_out = self.layout.find_window_and_output(root);
|
let win_out = self.layout.find_window_and_output(root);
|
||||||
let layout_output = win_out.map(|(_, output)| output);
|
let layout_output = win_out.map(|(_, output)| output);
|
||||||
@@ -1233,7 +1233,7 @@ impl Niri {
|
|||||||
.layer_for_surface(root, WindowSurfaceType::TOPLEVEL)
|
.layer_for_surface(root, WindowSurfaceType::TOPLEVEL)
|
||||||
.is_some()
|
.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)
|
layout_output.or_else(layer_shell_output)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ use smithay::utils::{Logical, Point, Rectangle, Size};
|
|||||||
|
|
||||||
use crate::config::Config;
|
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 {
|
pub fn get_monotonic_time() -> Duration {
|
||||||
let ts = clock_gettime(ClockId::Monotonic);
|
let ts = clock_gettime(ClockId::Monotonic);
|
||||||
Duration::new(ts.tv_sec as u64, ts.tv_nsec as u32)
|
Duration::new(ts.tv_sec as u64, ts.tv_nsec as u32)
|
||||||
|
|||||||
Reference in New Issue
Block a user