forge
Explore
Log in

Don't you dare go Hollow

Extract rules.apply_{min,max}_size()

Browse files at this commit

40fa82275cc092d313a9a60d01a2b4e3e8e3f7d3Ivan MolodetskikhParent: 9824321
src/window/mapped.rsmodified+4 -27
@@ -1,5 +1,4 @@
11 use std::cell::{Cell, RefCell};
2-use std::cmp::{max, min};
32 use std::time::Duration;
43
54 use niri_config::{Color, CornerRadius, GradientInterpolation, WindowRule};
@@ -535,43 +534,21 @@ impl LayoutElement for Mapped {
535534 }
536535
537536 fn min_size(&self) -> Size<i32, Logical> {
538- let mut size = with_states(self.toplevel().wl_surface(), |state| {
537+ let min_size = with_states(self.toplevel().wl_surface(), |state| {
539538 let mut guard = state.cached_state.get::<SurfaceCachedState>();
540539 guard.current().min_size
541540 });
542541
543- if let Some(x) = self.rules.min_width {
544- size.w = max(size.w, i32::from(x));
545- }
546- if let Some(x) = self.rules.min_height {
547- size.h = max(size.h, i32::from(x));
548- }
549-
550- size
542+ self.rules.apply_min_size(min_size)
551543 }
552544
553545 fn max_size(&self) -> Size<i32, Logical> {
554- let mut size = with_states(self.toplevel().wl_surface(), |state| {
546+ let max_size = with_states(self.toplevel().wl_surface(), |state| {
555547 let mut guard = state.cached_state.get::<SurfaceCachedState>();
556548 guard.current().max_size
557549 });
558550
559- if let Some(x) = self.rules.max_width {
560- if size.w == 0 {
561- size.w = i32::from(x);
562- } else if x > 0 {
563- size.w = min(size.w, i32::from(x));
564- }
565- }
566- if let Some(x) = self.rules.max_height {
567- if size.h == 0 {
568- size.h = i32::from(x);
569- } else if x > 0 {
570- size.h = min(size.h, i32::from(x));
571- }
572- }
573-
574- size
551+ self.rules.apply_max_size(max_size)
575552 }
576553
577554 fn is_wl_surface(&self, wl_surface: &WlSurface) -> bool {
src/window/mod.rsmodified+37 -0
@@ -1,5 +1,8 @@
1+use std::cmp::{max, min};
2+
13 use niri_config::{BlockOutFrom, BorderRule, CornerRadius, Match, WindowRule};
24 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
5+use smithay::utils::{Logical, Size};
36 use smithay::wayland::shell::xdg::{ToplevelSurface, XdgToplevelSurfaceRoleAttributes};
47
58 use crate::layout::scrolling::ColumnWidth;
@@ -236,6 +239,40 @@ impl ResolvedWindowRules {
236239
237240 resolved
238241 }
242+
243+ pub fn apply_min_size(&self, min_size: Size<i32, Logical>) -> Size<i32, Logical> {
244+ let mut size = min_size;
245+
246+ if let Some(x) = self.min_width {
247+ size.w = max(size.w, i32::from(x));
248+ }
249+ if let Some(x) = self.min_height {
250+ size.h = max(size.h, i32::from(x));
251+ }
252+
253+ size
254+ }
255+
256+ pub fn apply_max_size(&self, max_size: Size<i32, Logical>) -> Size<i32, Logical> {
257+ let mut size = max_size;
258+
259+ if let Some(x) = self.max_width {
260+ if size.w == 0 {
261+ size.w = i32::from(x);
262+ } else if x > 0 {
263+ size.w = min(size.w, i32::from(x));
264+ }
265+ }
266+ if let Some(x) = self.max_height {
267+ if size.h == 0 {
268+ size.h = i32::from(x);
269+ } else if x > 0 {
270+ size.h = min(size.h, i32::from(x));
271+ }
272+ }
273+
274+ size
275+ }
239276 }
240277
241278 fn window_matches(window: WindowRef, role: &XdgToplevelSurfaceRoleAttributes, m: &Match) -> bool {