forge
Explore
Log in

Don't you dare go Hollow

Honor min/max size in more places like initial configure

Browse files at this commit

10460191b93194ed4d9dc16e1fd7a2eb6f297ae3Ivan MolodetskikhParent: c5fffd6
niri-visual-tests/src/cases/layout.rsmodified+6 -2
@@ -159,8 +159,10 @@ impl Layout {
159 159
160 fn add_window(&mut self, mut window: TestWindow, width: Option<ColumnWidth>) {160 fn add_window(&mut self, mut window: TestWindow, width: Option<ColumnWidth>) {
161 let ws = self.layout.active_workspace().unwrap();161 let ws = self.layout.active_workspace().unwrap();
162+ let min_size = window.min_size();
163+ let max_size = window.max_size();
162 window.request_size(164 window.request_size(
163- ws.new_window_size(width, false, window.rules()),165+ ws.new_window_size(width, false, window.rules(), (min_size, max_size)),
164 false,166 false,
165 None,167 None,
166 );168 );
@@ -183,8 +185,10 @@ impl Layout {
183 width: Option<ColumnWidth>,185 width: Option<ColumnWidth>,
184 ) {186 ) {
185 let ws = self.layout.active_workspace().unwrap();187 let ws = self.layout.active_workspace().unwrap();
188+ let min_size = window.min_size();
189+ let max_size = window.max_size();
186 window.request_size(190 window.request_size(
187- ws.new_window_size(width, false, window.rules()),191+ ws.new_window_size(width, false, window.rules(), (min_size, max_size)),
188 false,192 false,
189 None,193 None,
190 );194 );
src/layout/floating.rsmodified+28 -22
@@ -1,4 +1,4 @@
1-use std::cmp::{max, min};1+use std::cmp::max;
2 use std::iter::zip;2 use std::iter::zip;
3 use std::rc::Rc;3 use std::rc::Rc;
4 4
@@ -16,7 +16,7 @@ use crate::niri_render_elements;
16 use crate::render_helpers::renderer::NiriRenderer;16 use crate::render_helpers::renderer::NiriRenderer;
17 use crate::render_helpers::RenderTarget;17 use crate::render_helpers::RenderTarget;
18 use crate::utils::transaction::TransactionBlocker;18 use crate::utils::transaction::TransactionBlocker;
19-use crate::utils::ResizeEdge;19+use crate::utils::{ensure_min_max_size, ResizeEdge};
20 use crate::window::ResolvedWindowRules;20 use crate::window::ResolvedWindowRules;
21 21
22 /// Space for floating windows.22 /// Space for floating windows.
@@ -332,13 +332,25 @@ impl<W: LayoutElement> FloatingSpace<W> {
332 ) {332 ) {
333 tile.update_config(self.scale, self.options.clone());333 tile.update_config(self.scale, self.options.clone());
334 334
335- if tile.window().is_pending_fullscreen() {335+ let win = tile.window_mut();
336- tile.window_mut()336+ if win.is_pending_fullscreen() {
337- .request_size(Size::from((0, 0)), true, None);337+ let mut size = Size::from((0, 0));
338+
339+ // Make sure fixed-size through window rules keeps working.
340+ let min_size = win.min_size();
341+ let max_size = win.max_size();
342+ if min_size.w == max_size.w {
343+ size.w = min_size.w;
344+ }
345+ if min_size.h == max_size.h {
346+ size.h = min_size.h;
347+ }
348+
349+ win.request_size(size, true, None);
338 }350 }
339 351
340 if activate || self.tiles.is_empty() {352 if activate || self.tiles.is_empty() {
341- self.active_window_id = Some(tile.window().id().clone());353+ self.active_window_id = Some(win.id().clone());
342 }354 }
343 355
344 let mut pos = pos.unwrap_or_else(|| {356 let mut pos = pos.unwrap_or_else(|| {
@@ -500,15 +512,10 @@ impl<W: LayoutElement> FloatingSpace<W> {
500 512
501 let tile = &mut self.tiles[idx];513 let tile = &mut self.tiles[idx];
502 let win = tile.window_mut();514 let win = tile.window_mut();
503- let min_w = win.min_size().w;515+ let min_size = win.min_size();
504- let max_w = win.max_size().w;516+ let max_size = win.max_size();
505 517
506- if max_w > 0 {518+ win_width = ensure_min_max_size(win_width, min_size.w, max_size.w);
507- win_width = min(win_width, max_w);
508- }
509- if min_w > 0 {
510- win_width = max(win_width, min_w);
511- }
512 win_width = max(1, win_width);519 win_width = max(1, win_width);
513 520
514 let win_height = win521 let win_height = win
@@ -517,6 +524,8 @@ impl<W: LayoutElement> FloatingSpace<W> {
517 // If we requested height = 0, then switch to the current height.524 // If we requested height = 0, then switch to the current height.
518 .filter(|h| *h != 0)525 .filter(|h| *h != 0)
519 .unwrap_or_else(|| win.size().h);526 .unwrap_or_else(|| win.size().h);
527+ let win_height = ensure_min_max_size(win_height, min_size.h, max_size.h);
528+
520 let win_size = Size::from((win_width, win_height));529 let win_size = Size::from((win_width, win_height));
521 win.request_size(win_size, animate, None);530 win.request_size(win_size, animate, None);
522 }531 }
@@ -534,15 +543,10 @@ impl<W: LayoutElement> FloatingSpace<W> {
534 543
535 let tile = &mut self.tiles[idx];544 let tile = &mut self.tiles[idx];
536 let win = tile.window_mut();545 let win = tile.window_mut();
537- let min_h = win.min_size().h;546+ let min_size = win.min_size();
538- let max_h = win.max_size().h;547+ let max_size = win.max_size();
539 548
540- if max_h > 0 {549+ win_height = ensure_min_max_size(win_height, min_size.h, max_size.h);
541- win_height = min(win_height, max_h);
542- }
543- if min_h > 0 {
544- win_height = max(win_height, min_h);
545- }
546 win_height = max(1, win_height);550 win_height = max(1, win_height);
547 551
548 let win_width = win552 let win_width = win
@@ -551,6 +555,8 @@ impl<W: LayoutElement> FloatingSpace<W> {
551 // If we requested width = 0, then switch to the current width.555 // If we requested width = 0, then switch to the current width.
552 .filter(|w| *w != 0)556 .filter(|w| *w != 0)
553 .unwrap_or_else(|| win.size().w);557 .unwrap_or_else(|| win.size().w);
558+ let win_width = ensure_min_max_size(win_width, min_size.w, max_size.w);
559+
554 let win_size = Size::from((win_width, win_height));560 let win_size = Size::from((win_width, win_height));
555 win.request_size(win_size, animate, None);561 win.request_size(win_size, animate, None);
556 }562 }
src/layout/mod.rsmodified+15 -3
@@ -3219,9 +3219,21 @@ impl<W: LayoutElement> Layout<W> {
3219 // prefer-no-csd, and occasionally that last size can become the full-width size3219 // prefer-no-csd, and occasionally that last size can become the full-width size
3220 // rather than a smaller size, which is annoying. Need to see if niri can use some3220 // rather than a smaller size, which is annoying. Need to see if niri can use some
3221 // heuristics to make this case behave better.3221 // heuristics to make this case behave better.
3222- if tile.window().is_pending_fullscreen() {3222+ let win = tile.window_mut();
3223- tile.window_mut()3223+ if win.is_pending_fullscreen() {
3224- .request_size(Size::from((0, 0)), true, None);3224+ let mut size = Size::from((0, 0));
3225+
3226+ // Make sure fixed-size through window rules keeps working.
3227+ let min_size = win.min_size();
3228+ let max_size = win.max_size();
3229+ if min_size.w == max_size.w {
3230+ size.w = min_size.w;
3231+ }
3232+ if min_size.h == max_size.h {
3233+ size.h = min_size.h;
3234+ }
3235+
3236+ win.request_size(size, true, None);
3225 }3237 }
3226 3238
3227 let mut data = InteractiveMoveData {3239 let mut data = InteractiveMoveData {
src/layout/workspace.rsmodified+39 -17
@@ -9,6 +9,8 @@ use smithay::output::Output;
9 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;9 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
10 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;10 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
11 use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform};11 use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform};
12+use smithay::wayland::compositor::with_states;
13+use smithay::wayland::shell::xdg::SurfaceCachedState;
12 14
13 use super::floating::{FloatingSpace, FloatingSpaceRenderElement};15 use super::floating::{FloatingSpace, FloatingSpaceRenderElement};
14 use super::scrolling::{16 use super::scrolling::{
@@ -22,7 +24,7 @@ use crate::render_helpers::renderer::NiriRenderer;
22 use crate::render_helpers::RenderTarget;24 use crate::render_helpers::RenderTarget;
23 use crate::utils::id::IdCounter;25 use crate::utils::id::IdCounter;
24 use crate::utils::transaction::{Transaction, TransactionBlocker};26 use crate::utils::transaction::{Transaction, TransactionBlocker};
25-use crate::utils::{output_size, send_scale_transform, ResizeEdge};27+use crate::utils::{ensure_min_max_size, output_size, send_scale_transform, ResizeEdge};
26 use crate::window::ResolvedWindowRules;28 use crate::window::ResolvedWindowRules;
27 29
28 #[derive(Debug)]30 #[derive(Debug)]
@@ -680,12 +682,28 @@ impl<W: LayoutElement> Workspace<W> {
680 width: Option<ColumnWidth>,682 width: Option<ColumnWidth>,
681 is_floating: bool,683 is_floating: bool,
682 rules: &ResolvedWindowRules,684 rules: &ResolvedWindowRules,
685+ (min_size, max_size): (Size<i32, Logical>, Size<i32, Logical>),
683 ) -> Size<i32, Logical> {686 ) -> Size<i32, Logical> {
684- if is_floating {687+ let mut size = if is_floating {
685 Size::from((0, 0))688 Size::from((0, 0))
686 } else {689 } else {
687 self.scrolling.new_window_size(width, rules)690 self.scrolling.new_window_size(width, rules)
691+ };
692+
693+ // If the window has a fixed size, or we're picking some fixed size, apply min and max
694+ // size. This is to ensure that a fixed-size window rule works on open, while still
695+ // allowing the window freedom to pick its default size otherwise.
696+ let (min_size, max_size) = rules.apply_min_max_size(min_size, max_size);
697+ if size.w > 0 || min_size.w == max_size.w {
698+ size.w = ensure_min_max_size(size.w, min_size.w, max_size.w);
699+ }
700+ // For scrolling (where height is > 0) only ensure fixed height, since at runtime scrolling
701+ // will only honor fixed height currently.
702+ if min_size.h == max_size.h {
703+ size.h = ensure_min_max_size(size.h, min_size.h, max_size.h);
688 }704 }
705+
706+ size
689 }707 }
690 708
691 pub fn configure_new_window(709 pub fn configure_new_window(
@@ -699,22 +717,26 @@ impl<W: LayoutElement> Workspace<W> {
699 send_scale_transform(surface, data, self.scale, self.transform);717 send_scale_transform(surface, data, self.scale, self.transform);
700 });718 });
701 719
702- window720+ let toplevel = window.toplevel().expect("no x11 support");
703- .toplevel()721+ let (min_size, max_size) = with_states(toplevel.wl_surface(), |state| {
704- .expect("no x11 support")722+ let mut guard = state.cached_state.get::<SurfaceCachedState>();
705- .with_pending_state(|state| {723+ let current = guard.current();
706- if state.states.contains(xdg_toplevel::State::Fullscreen) {724+ (current.min_size, current.max_size)
707- state.size = Some(self.view_size.to_i32_round());725+ });
708- } else {726+ toplevel.with_pending_state(|state| {
709- state.size = Some(self.new_window_size(width, is_floating, rules));727+ if state.states.contains(xdg_toplevel::State::Fullscreen) {
710- }728+ state.size = Some(self.view_size.to_i32_round());
729+ } else {
730+ let size = self.new_window_size(width, is_floating, rules, (min_size, max_size));
731+ state.size = Some(size);
732+ }
711 733
712- if is_floating {734+ if is_floating {
713- state.bounds = Some(self.floating.toplevel_bounds(rules));735+ state.bounds = Some(self.floating.toplevel_bounds(rules));
714- } else {736+ } else {
715- state.bounds = Some(self.scrolling.toplevel_bounds(rules));737+ state.bounds = Some(self.scrolling.toplevel_bounds(rules));
716- }738+ }
717- });739+ });
718 }740 }
719 741
720 pub fn focus_left(&mut self) -> bool {742 pub fn focus_left(&mut self) -> bool {
src/utils/mod.rsmodified+11 -0
@@ -1,3 +1,4 @@
1+use std::cmp::{max, min};
1 use std::ffi::{CString, OsStr};2 use std::ffi::{CString, OsStr};
2 use std::io::Write;3 use std::io::Write;
3 use std::os::unix::prelude::OsStrExt;4 use std::os::unix::prelude::OsStrExt;
@@ -261,6 +262,16 @@ pub fn get_credentials_for_surface(surface: &WlSurface) -> Option<Credentials> {
261 client.get_credentials(&dh).ok()262 client.get_credentials(&dh).ok()
262 }263 }
263 264
265+pub fn ensure_min_max_size(mut x: i32, min_size: i32, max_size: i32) -> i32 {
266+ if max_size > 0 {
267+ x = min(x, max_size);
268+ }
269+ if min_size > 0 {
270+ x = max(x, min_size);
271+ }
272+ x
273+}
274+
264 #[cfg(feature = "dbus")]275 #[cfg(feature = "dbus")]
265 pub fn show_screenshot_notification(image_path: Option<PathBuf>) {276 pub fn show_screenshot_notification(image_path: Option<PathBuf>) {
266 let mut notification = notify_rust::Notification::new();277 let mut notification = notify_rust::Notification::new();
src/window/mod.rsmodified+12 -3
@@ -285,6 +285,16 @@ impl ResolvedWindowRules {
285 size285 size
286 }286 }
287 287
288+ pub fn apply_min_max_size(
289+ &self,
290+ min_size: Size<i32, Logical>,
291+ max_size: Size<i32, Logical>,
292+ ) -> (Size<i32, Logical>, Size<i32, Logical>) {
293+ let min_size = self.apply_min_size(min_size);
294+ let max_size = self.apply_max_size(max_size);
295+ (min_size, max_size)
296+ }
297+
288 pub fn compute_open_floating(&self, toplevel: &ToplevelSurface) -> bool {298 pub fn compute_open_floating(&self, toplevel: &ToplevelSurface) -> bool {
289 if let Some(res) = self.open_floating {299 if let Some(res) = self.open_floating {
290 return res;300 return res;
@@ -295,13 +305,12 @@ impl ResolvedWindowRules {
295 return true;305 return true;
296 }306 }
297 307
298- let (mut min_size, mut max_size) = with_states(toplevel.wl_surface(), |state| {308+ let (min_size, max_size) = with_states(toplevel.wl_surface(), |state| {
299 let mut guard = state.cached_state.get::<SurfaceCachedState>();309 let mut guard = state.cached_state.get::<SurfaceCachedState>();
300 let current = guard.current();310 let current = guard.current();
301 (current.min_size, current.max_size)311 (current.min_size, current.max_size)
302 });312 });
303- min_size = self.apply_min_size(min_size);313+ let (min_size, max_size) = self.apply_min_max_size(min_size, max_size);
304- max_size = self.apply_max_size(max_size);
305 314
306 // We open fixed-height windows as floating.315 // We open fixed-height windows as floating.
307 min_size.h > 0 && min_size.h == max_size.h316 min_size.h > 0 && min_size.h == max_size.h