From 37aa99a537368cba6f184ee70e0112ae04e64fc9 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 26 Mar 2024 16:28:54 -0700 Subject: [PATCH] feat(config): add active window border style opt This commit adds a new active window border style configuration option to komorebi.json, allowing users to explicitly opt in to square or rounded active window borders to match whatever patches they may have made at the system / dwm.exe level. --- komorebi/src/lib.rs | 3 +++ komorebi/src/static_config.rs | 19 +++++++++++++++++++ komorebi/src/windows_callbacks.rs | 20 ++++++++++++++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index 690d44fd..3f6e9387 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -194,6 +194,9 @@ lazy_static! { ) }; + static ref ACTIVE_WINDOW_BORDER_STYLE: Arc> = + Arc::new(Mutex::new(ActiveWindowBorderStyle::System)); + static ref BORDER_RECT: Arc> = Arc::new(Mutex::new(Rect::default())); diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index b7149372..f7199a58 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -7,6 +7,7 @@ use crate::window_manager::WindowManager; use crate::window_manager_event::WindowManagerEvent; use crate::windows_api::WindowsApi; use crate::workspace::Workspace; +use crate::ACTIVE_WINDOW_BORDER_STYLE; use crate::BORDER_COLOUR_CURRENT; use crate::BORDER_COLOUR_MONOCLE; use crate::BORDER_COLOUR_SINGLE; @@ -82,6 +83,17 @@ pub struct ActiveWindowBorderColours { pub monocle: Colour, } +#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +pub enum ActiveWindowBorderStyle { + #[default] + /// Use the system border style + System, + /// Use the Windows 11-style rounded borders + Rounded, + /// Use the Windows 10-style square borders + Square, +} + #[derive(Debug, Serialize, Deserialize, JsonSchema)] pub struct WorkspaceConfig { /// Name @@ -260,6 +272,9 @@ pub struct StaticConfig { /// Active window border colours for different container types #[serde(skip_serializing_if = "Option::is_none")] pub active_window_border_colours: Option, + /// Active window border style (default: System) + #[serde(skip_serializing_if = "Option::is_none")] + pub active_window_border_style: Option, /// Global default workspace padding (default: 10) #[serde(skip_serializing_if = "Option::is_none")] pub default_workspace_padding: Option, @@ -411,6 +426,7 @@ impl From<&WindowManager> for StaticConfig { border_offset: Option::from(BORDER_OFFSET.load(Ordering::SeqCst)), active_window_border: Option::from(BORDER_ENABLED.load(Ordering::SeqCst)), active_window_border_colours: border_colours, + active_window_border_style: Option::from(*ACTIVE_WINDOW_BORDER_STYLE.lock()), default_workspace_padding: Option::from( DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst), ), @@ -477,6 +493,9 @@ impl StaticConfig { BORDER_COLOUR_MONOCLE.store(u32::from(colours.monocle), Ordering::SeqCst); } + let active_window_border_style = self.active_window_border_style.unwrap_or_default(); + *ACTIVE_WINDOW_BORDER_STYLE.lock() = active_window_border_style; + let mut float_identifiers = FLOAT_IDENTIFIERS.lock(); let mut regex_identifiers = REGEX_IDENTIFIERS.lock(); let mut manage_identifiers = MANAGE_IDENTIFIERS.lock(); diff --git a/komorebi/src/windows_callbacks.rs b/komorebi/src/windows_callbacks.rs index b56030d0..8bacee9f 100644 --- a/komorebi/src/windows_callbacks.rs +++ b/komorebi/src/windows_callbacks.rs @@ -41,6 +41,8 @@ use crate::window_manager_event::WindowManagerEvent; use crate::windows_api::WindowsApi; use crate::winevent::WinEvent; use crate::winevent_listener; +use crate::ActiveWindowBorderStyle; +use crate::ACTIVE_WINDOW_BORDER_STYLE; use crate::BORDER_COLOUR_CURRENT; use crate::BORDER_RECT; use crate::BORDER_WIDTH; @@ -232,10 +234,20 @@ pub extern "system" fn border_window( // the window was made with DWMWCP_ROUNDSMALL then this is the // wrong size. In the future we should read the DWM properties // of windows and attempt to match appropriately. - if *WINDOWS_11 { - RoundRect(hdc, 0, 0, border_rect.right, border_rect.bottom, 20, 20); - } else { - Rectangle(hdc, 0, 0, border_rect.right, border_rect.bottom); + match *ACTIVE_WINDOW_BORDER_STYLE.lock() { + ActiveWindowBorderStyle::System => { + if *WINDOWS_11 { + RoundRect(hdc, 0, 0, border_rect.right, border_rect.bottom, 20, 20); + } else { + Rectangle(hdc, 0, 0, border_rect.right, border_rect.bottom); + } + } + ActiveWindowBorderStyle::Rounded => { + RoundRect(hdc, 0, 0, border_rect.right, border_rect.bottom, 20, 20); + } + ActiveWindowBorderStyle::Square => { + Rectangle(hdc, 0, 0, border_rect.right, border_rect.bottom); + } } EndPaint(window, &ps); ValidateRect(window, None);