From c61361de3ca4484387f39b067eadc612908560eb Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Tue, 19 Mar 2024 15:20:03 +0400 Subject: Implement window rule reloading and min/max size rules --- src/layout/mod.rs | 58 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 17 deletions(-) (limited to 'src/layout') diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 86ce5c85..c2c4bf4e 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -643,13 +643,30 @@ impl Layout { } } - pub fn find_window_mut(&mut self, wl_surface: &WlSurface) -> Option<&mut W> { + 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, &mon.output)); + } + } + } + } + + None + } + + pub fn find_window_and_output_mut( + &mut self, + wl_surface: &WlSurface, + ) -> Option<(&mut W, Option<&Output>)> { match &mut self.monitor_set { MonitorSet::Normal { monitors, .. } => { for mon in monitors { for ws in &mut mon.workspaces { if let Some(window) = ws.find_wl_surface_mut(wl_surface) { - return Some(window); + return Some((window, Some(&mon.output))); } } } @@ -657,21 +674,7 @@ impl Layout { MonitorSet::NoOutputs { workspaces } => { for ws in workspaces { if let Some(window) = ws.find_wl_surface_mut(wl_surface) { - return Some(window); - } - } - } - } - - None - } - - 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, &mon.output)); + return Some((window, None)); } } } @@ -851,6 +854,27 @@ impl Layout { } } + pub fn with_windows_mut(&mut self, mut f: impl FnMut(&mut W, Option<&Output>)) { + match &mut self.monitor_set { + MonitorSet::Normal { monitors, .. } => { + for mon in monitors { + for ws in &mut mon.workspaces { + for win in ws.windows_mut() { + f(win, Some(&mon.output)); + } + } + } + } + MonitorSet::NoOutputs { workspaces } => { + for ws in workspaces { + for win in ws.windows_mut() { + f(win, None); + } + } + } + } + } + fn active_monitor(&mut self) -> Option<&mut Monitor> { let MonitorSet::Normal { monitors, -- cgit