From 6fba4c371e7868f8d581cf3d49d611cdbb590ad4 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 27 Dec 2024 09:58:22 +0300 Subject: Implement default-window-height window rule Only works for floats that aren't initially fullscreen atm. --- src/layout/floating.rs | 23 ++++++++++++++++++++++- src/layout/workspace.rs | 23 ++++++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) (limited to 'src/layout') diff --git a/src/layout/floating.rs b/src/layout/floating.rs index 08a74b37..a04c9b94 100644 --- a/src/layout/floating.rs +++ b/src/layout/floating.rs @@ -1102,9 +1102,14 @@ impl FloatingSpace { width.resolve_no_gaps(&self.options, self.working_area.size.w) } + pub fn resolve_height(&self, height: PresetSize) -> ResolvedSize { + resolve_preset_size(height, self.working_area.size.h) + } + pub fn new_window_size( &self, width: Option, + height: Option, rules: &ResolvedWindowRules, ) -> Size { let border = rules.border.resolve_against(self.options.border); @@ -1125,7 +1130,23 @@ impl FloatingSpace { 0 }; - Size::from((width, 0)) + let height = if let Some(height) = height { + let height = match self.resolve_height(height) { + ResolvedSize::Tile(mut size) => { + if !border.off { + size -= border.width.0 * 2.; + } + size + } + ResolvedSize::Window(size) => size, + }; + + max(1, height.floor() as i32) + } else { + 0 + }; + + Size::from((width, height)) } #[cfg(test)] diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 516e02fd..92900ff3 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -2,7 +2,7 @@ use std::cmp::max; use std::rc::Rc; use std::time::Duration; -use niri_config::{OutputName, Workspace as WorkspaceConfig}; +use niri_config::{OutputName, PresetSize, Workspace as WorkspaceConfig}; use niri_ipc::SizeChange; use smithay::backend::renderer::gles::GlesRenderer; use smithay::desktop::{layer_map_for_output, Window}; @@ -715,15 +715,30 @@ impl Workspace { } } + pub fn resolve_default_height( + &self, + default_height: Option>, + is_floating: bool, + ) -> Option { + match default_height { + Some(Some(height)) => Some(height), + Some(None) => None, + None if is_floating => None, + // We don't have a global default at the moment. + None => None, + } + } + pub fn new_window_size( &self, width: Option, + height: Option, is_floating: bool, rules: &ResolvedWindowRules, (min_size, max_size): (Size, Size), ) -> Size { let mut size = if is_floating { - self.floating.new_window_size(width, rules) + self.floating.new_window_size(width, height, rules) } else { self.scrolling.new_window_size(width, rules) }; @@ -749,6 +764,7 @@ impl Workspace { &self, window: &Window, width: Option, + height: Option, is_floating: bool, rules: &ResolvedWindowRules, ) { @@ -766,7 +782,8 @@ impl Workspace { if state.states.contains(xdg_toplevel::State::Fullscreen) { state.size = Some(self.view_size.to_i32_round()); } else { - let size = self.new_window_size(width, is_floating, rules, (min_size, max_size)); + let size = + self.new_window_size(width, height, is_floating, rules, (min_size, max_size)); state.size = Some(size); } -- cgit