diff --git a/komorebi-core/src/lib.rs b/komorebi-core/src/lib.rs index d3fbbe5e..f7e13a8c 100644 --- a/komorebi-core/src/lib.rs +++ b/komorebi-core/src/lib.rs @@ -107,6 +107,7 @@ pub enum SocketMessage { ActiveWindowBorder(bool), ActiveWindowBorderColour(WindowKind, u32, u32, u32), ActiveWindowBorderWidth(i32), + ActiveWindowBorderOffset(i32), InvisibleBorders(Rect), WorkAreaOffset(Rect), MonitorWorkAreaOffset(usize, Rect), diff --git a/komorebi/src/border.rs b/komorebi/src/border.rs index a83d32b0..d1b60229 100644 --- a/komorebi/src/border.rs +++ b/komorebi/src/border.rs @@ -18,6 +18,7 @@ use crate::window::Window; use crate::windows_callbacks; use crate::WindowsApi; use crate::BORDER_HWND; +use crate::BORDER_OFFSET; use crate::BORDER_OVERFLOW_IDENTIFIERS; use crate::BORDER_RECT; use crate::TRANSPARENCY_COLOUR; @@ -128,6 +129,14 @@ impl Border { rect.bottom += invisible_borders.bottom; } + let border_offset = BORDER_OFFSET.lock(); + if let Some(border_offset) = *border_offset { + rect.left -= border_offset.left; + rect.top -= border_offset.top; + rect.right += border_offset.right; + rect.bottom += border_offset.bottom; + } + *BORDER_RECT.lock() = rect; WindowsApi::position_border_window(self.hwnd(), &rect, activate) diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index 18f7d453..e3a4a915 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -160,6 +160,9 @@ lazy_static! { static ref BORDER_RECT: Arc> = Arc::new(Mutex::new(Rect::default())); + + static ref BORDER_OFFSET: Arc>> = + Arc::new(Mutex::new(None)); } pub static INITIAL_CONFIGURATION_LOADED: AtomicBool = AtomicBool::new(false); diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 9c831a83..cfcd5c7e 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -47,6 +47,7 @@ use crate::BORDER_COLOUR_SINGLE; use crate::BORDER_COLOUR_STACK; use crate::BORDER_ENABLED; use crate::BORDER_HWND; +use crate::BORDER_OFFSET; use crate::BORDER_OVERFLOW_IDENTIFIERS; use crate::BORDER_WIDTH; use crate::CUSTOM_FFM; @@ -889,6 +890,20 @@ impl WindowManager { BORDER_WIDTH.store(width, Ordering::SeqCst); WindowsApi::invalidate_border_rect()?; } + SocketMessage::ActiveWindowBorderOffset(offset) => { + let mut current_border_offset = BORDER_OFFSET.lock(); + + let new_border_offset = Rect { + left: offset, + top: offset, + right: offset * 2, + bottom: offset * 2, + }; + + *current_border_offset = Option::from(new_border_offset); + + WindowsApi::invalidate_border_rect()?; + } SocketMessage::NotificationSchema => { let notification = schema_for!(Notification); let schema = serde_json::to_string_pretty(¬ification)?; @@ -927,6 +942,9 @@ impl WindowManager { | SocketMessage::Promote | SocketMessage::PromoteFocus | SocketMessage::Retile + // Adding this one so that changes can be seen instantly after + // modifying the active window border offset + | SocketMessage::ActiveWindowBorderOffset(_) // Adding this one because sometimes EVENT_SYSTEM_FOREGROUND isn't // getting sent on FocusWindow, meaning the border won't be set // when processing events diff --git a/komorebic.lib.ahk b/komorebic.lib.ahk index fceed6b0..68db878a 100644 --- a/komorebic.lib.ahk +++ b/komorebic.lib.ahk @@ -344,6 +344,10 @@ ActiveWindowBorderWidth(width) { RunWait, komorebic.exe active-window-border-width %width%, , Hide } +ActiveWindowBorderOffset(offset) { + RunWait, komorebic.exe active-window-border-offset %offset%, , Hide +} + FocusFollowsMouse(boolean_state, implementation) { RunWait, komorebic.exe focus-follows-mouse %boolean_state% --implementation %implementation%, , Hide } diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 102810ae..e5bcce2e 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -450,6 +450,12 @@ struct ActiveWindowBorderWidth { width: i32, } +#[derive(Parser, AhkFunction)] +struct ActiveWindowBorderOffset { + /// Desired offset of the active window border + offset: i32, +} + #[derive(Parser, AhkFunction)] struct Start { /// Allow the use of komorebi's custom focus-follows-mouse implementation @@ -755,6 +761,9 @@ enum SubCommand { /// Set the width for the active window border #[clap(arg_required_else_help = true)] ActiveWindowBorderWidth(ActiveWindowBorderWidth), + /// Set the offset for the active window border + #[clap(arg_required_else_help = true)] + ActiveWindowBorderOffset(ActiveWindowBorderOffset), /// Enable or disable focus follows mouse for the operating system #[clap(arg_required_else_help = true)] FocusFollowsMouse(FocusFollowsMouse), @@ -1375,6 +1384,9 @@ fn main() -> Result<()> { SubCommand::ActiveWindowBorderWidth(arg) => { send_message(&SocketMessage::ActiveWindowBorderWidth(arg.width).as_bytes()?)?; } + SubCommand::ActiveWindowBorderOffset(arg) => { + send_message(&SocketMessage::ActiveWindowBorderOffset(arg.offset).as_bytes()?)?; + } SubCommand::ResizeDelta(arg) => { send_message(&SocketMessage::ResizeDelta(arg.pixels).as_bytes()?)?; }