Extract rules.apply_{min,max}_size()
Browse files at this commit40fa82275cc092d313a9a60d01a2b4e3e8e3f7d3Parent: 98243212 changed files +41 -27
- src/window/mapped.rs +4 -27
- src/window/mod.rs +37 -0
src/window/mapped.rsmodified+4 -27
| @@ -1,5 +1,4 @@ | |||
| 1 | use std::cell::{Cell, RefCell}; | 1 | use std::cell::{Cell, RefCell}; |
| 2 | -use std::cmp::{max, min}; | ||
| 3 | use std::time::Duration; | 2 | use std::time::Duration; |
| 4 | 3 | ||
| 5 | use niri_config::{Color, CornerRadius, GradientInterpolation, WindowRule}; | 4 | use niri_config::{Color, CornerRadius, GradientInterpolation, WindowRule}; |
| @@ -535,43 +534,21 @@ impl LayoutElement for Mapped { | |||
| 535 | } | 534 | } |
| 536 | 535 | ||
| 537 | fn min_size(&self) -> Size<i32, Logical> { | 536 | 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| { |
| 539 | let mut guard = state.cached_state.get::<SurfaceCachedState>(); | 538 | let mut guard = state.cached_state.get::<SurfaceCachedState>(); |
| 540 | guard.current().min_size | 539 | guard.current().min_size |
| 541 | }); | 540 | }); |
| 542 | 541 | ||
| 543 | - if let Some(x) = self.rules.min_width { | 542 | + self.rules.apply_min_size(min_size) |
| 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 | ||
| 551 | } | 543 | } |
| 552 | 544 | ||
| 553 | fn max_size(&self) -> Size<i32, Logical> { | 545 | 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| { |
| 555 | let mut guard = state.cached_state.get::<SurfaceCachedState>(); | 547 | let mut guard = state.cached_state.get::<SurfaceCachedState>(); |
| 556 | guard.current().max_size | 548 | guard.current().max_size |
| 557 | }); | 549 | }); |
| 558 | 550 | ||
| 559 | - if let Some(x) = self.rules.max_width { | 551 | + self.rules.apply_max_size(max_size) |
| 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 | ||
| 575 | } | 552 | } |
| 576 | 553 | ||
| 577 | fn is_wl_surface(&self, wl_surface: &WlSurface) -> bool { | 554 | 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 | + | ||
| 1 | use niri_config::{BlockOutFrom, BorderRule, CornerRadius, Match, WindowRule}; | 3 | use niri_config::{BlockOutFrom, BorderRule, CornerRadius, Match, WindowRule}; |
| 2 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; | 4 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; |
| 5 | +use smithay::utils::{Logical, Size}; | ||
| 3 | use smithay::wayland::shell::xdg::{ToplevelSurface, XdgToplevelSurfaceRoleAttributes}; | 6 | use smithay::wayland::shell::xdg::{ToplevelSurface, XdgToplevelSurfaceRoleAttributes}; |
| 4 | 7 | ||
| 5 | use crate::layout::scrolling::ColumnWidth; | 8 | use crate::layout::scrolling::ColumnWidth; |
| @@ -236,6 +239,40 @@ impl ResolvedWindowRules { | |||
| 236 | 239 | ||
| 237 | resolved | 240 | resolved |
| 238 | } | 241 | } |
| 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 | + } | ||
| 239 | } | 276 | } |
| 240 | 277 | ||
| 241 | fn window_matches(window: WindowRef, role: &XdgToplevelSurfaceRoleAttributes, m: &Match) -> bool { | 278 | fn window_matches(window: WindowRef, role: &XdgToplevelSurfaceRoleAttributes, m: &Match) -> bool { |