diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index a74e7306..d95a04d7 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -16,6 +16,7 @@ use crate::stackbar_manager::STACKBAR_TAB_HEIGHT; use crate::stackbar_manager::STACKBAR_TAB_WIDTH; use crate::stackbar_manager::STACKBAR_UNFOCUSED_TEXT_COLOUR; use crate::transparency_manager; +use crate::window; use crate::window_manager::WindowManager; use crate::window_manager_event::WindowManagerEvent; use crate::windows_api::WindowsApi; @@ -241,6 +242,12 @@ pub struct StaticConfig { /// DEPRECATED from v0.1.22: no longer required #[serde(skip_serializing_if = "Option::is_none")] pub invisible_borders: Option, + /// DISCOURAGED: Minimum width for a window to be eligible for tiling + #[serde(skip_serializing_if = "Option::is_none")] + pub minimum_window_width: Option, + /// DISCOURAGED: Minimum height for a window to be eligible for tiling + #[serde(skip_serializing_if = "Option::is_none")] + pub minimum_window_height: Option, /// Delta to resize windows by (default 50) #[serde(skip_serializing_if = "Option::is_none")] pub resize_delta: Option, @@ -489,6 +496,8 @@ impl From<&WindowManager> for StaticConfig { unmanaged_window_operation_behaviour: Option::from( value.unmanaged_window_operation_behaviour, ), + minimum_window_height: Some(window::MINIMUM_HEIGHT.load(Ordering::SeqCst)), + minimum_window_width: Some(window::MINIMUM_WIDTH.load(Ordering::SeqCst)), focus_follows_mouse: value.focus_follows_mouse, mouse_follows_focus: Option::from(value.mouse_follows_focus), app_specific_configuration_path: None, @@ -545,6 +554,14 @@ impl StaticConfig { *window_hiding_behaviour = behaviour; } + if let Some(height) = self.minimum_window_height { + window::MINIMUM_HEIGHT.store(height, Ordering::SeqCst); + } + + if let Some(width) = self.minimum_window_width { + window::MINIMUM_WIDTH.store(width, Ordering::SeqCst); + } + if let Some(container) = self.default_container_padding { DEFAULT_CONTAINER_PADDING.store(container, Ordering::SeqCst); } diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index e0d87f77..e835613f 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -4,6 +4,8 @@ use std::convert::TryFrom; use std::fmt::Display; use std::fmt::Formatter; use std::fmt::Write as _; +use std::sync::atomic::AtomicI32; +use std::sync::atomic::Ordering; use std::time::Duration; use color_eyre::eyre; @@ -39,6 +41,9 @@ use crate::PERMAIGNORE_CLASSES; use crate::REGEX_IDENTIFIERS; use crate::WSL2_UI_PROCESSES; +pub static MINIMUM_WIDTH: AtomicI32 = AtomicI32::new(0); +pub static MINIMUM_HEIGHT: AtomicI32 = AtomicI32::new(0); + #[derive(Debug, Default, Clone, Copy, Deserialize, JsonSchema, PartialEq)] pub struct Window { pub hwnd: isize, @@ -360,6 +365,20 @@ impl Window { debug.is_window = true; + let rect = WindowsApi::window_rect(self.hwnd()).unwrap_or_default(); + + if rect.right < MINIMUM_WIDTH.load(Ordering::SeqCst) { + return Ok(false); + } + + debug.has_minimum_width = true; + + if rect.bottom < MINIMUM_HEIGHT.load(Ordering::SeqCst) { + return Ok(false); + } + + debug.has_minimum_height = true; + if self.title().is_err() { return Ok(false); } @@ -416,6 +435,8 @@ impl Window { pub struct RuleDebug { pub should_manage: bool, pub is_window: bool, + pub has_minimum_width: bool, + pub has_minimum_height: bool, pub has_title: bool, pub is_cloaked: bool, pub allow_cloaked: bool,