diff options
Diffstat (limited to 'src/window/mod.rs')
| -rw-r--r-- | src/window/mod.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/window/mod.rs b/src/window/mod.rs index 45c1d125..98c26e7f 100644 --- a/src/window/mod.rs +++ b/src/window/mod.rs @@ -1,5 +1,8 @@ +use std::cmp::{max, min}; + use niri_config::{BlockOutFrom, BorderRule, CornerRadius, Match, WindowRule}; use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; +use smithay::utils::{Logical, Size}; use smithay::wayland::shell::xdg::{ToplevelSurface, XdgToplevelSurfaceRoleAttributes}; use crate::layout::scrolling::ColumnWidth; @@ -236,6 +239,40 @@ impl ResolvedWindowRules { resolved } + + pub fn apply_min_size(&self, min_size: Size<i32, Logical>) -> Size<i32, Logical> { + let mut size = min_size; + + if let Some(x) = self.min_width { + size.w = max(size.w, i32::from(x)); + } + if let Some(x) = self.min_height { + size.h = max(size.h, i32::from(x)); + } + + size + } + + pub fn apply_max_size(&self, max_size: Size<i32, Logical>) -> Size<i32, Logical> { + let mut size = max_size; + + if let Some(x) = self.max_width { + if size.w == 0 { + size.w = i32::from(x); + } else if x > 0 { + size.w = min(size.w, i32::from(x)); + } + } + if let Some(x) = self.max_height { + if size.h == 0 { + size.h = i32::from(x); + } else if x > 0 { + size.h = min(size.h, i32::from(x)); + } + } + + size + } } fn window_matches(window: WindowRef, role: &XdgToplevelSurfaceRoleAttributes, m: &Match) -> bool { |
