Skip to content

Commit

Permalink
feat(wm): add min height/width options
Browse files Browse the repository at this point in the history
This commit adds two new fields, minimum_window_height and
minimum_window_width, to the static configuration file.

These options should be considered quite broad and heavy-handed for now
and avoided if at all possible.

These options are an escape hatch for buggy applications such as Windows
Teams which do not give application windows and child windows unique
names or classes.

Ultimately users should push for buggy applications to be fixed upstream
and respect the usual Microsoft Windows application development
guidelines.

Further support will most likely not be provided for these two
configuration options because it's not my job or my responsibility to
compensate for multi million, billion and trillion dollar companies who
can't follow basic application development guidelines.

resolve #896
  • Loading branch information
LGUG2Z committed Jul 4, 2024
1 parent 6fa3f8d commit 38ac454
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions komorebi/src/static_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Rect>,
/// DISCOURAGED: Minimum width for a window to be eligible for tiling
#[serde(skip_serializing_if = "Option::is_none")]
pub minimum_window_width: Option<i32>,
/// DISCOURAGED: Minimum height for a window to be eligible for tiling
#[serde(skip_serializing_if = "Option::is_none")]
pub minimum_window_height: Option<i32>,
/// Delta to resize windows by (default 50)
#[serde(skip_serializing_if = "Option::is_none")]
pub resize_delta: Option<i32>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down
21 changes: 21 additions & 0 deletions komorebi/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 38ac454

Please sign in to comment.