feat(wm): add new cmd to set active border offset

This commit introduces a new command, active-window-border-offset, which
allows the user to offset the starting position of the active window
border, thereby allowing for thicker or thinner active window borders,
when used in conjunction with the active-window-border-width command.

resolve #232
This commit is contained in:
LGUG2Z
2022-12-19 19:00:37 -08:00
parent 00477e2696
commit 4ee4d199a0
6 changed files with 47 additions and 0 deletions

View File

@@ -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),

View File

@@ -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)

View File

@@ -160,6 +160,9 @@ lazy_static! {
static ref BORDER_RECT: Arc<Mutex<Rect>> =
Arc::new(Mutex::new(Rect::default()));
static ref BORDER_OFFSET: Arc<Mutex<Option<Rect>>> =
Arc::new(Mutex::new(None));
}
pub static INITIAL_CONFIGURATION_LOADED: AtomicBool = AtomicBool::new(false);

View File

@@ -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(&notification)?;
@@ -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

View File

@@ -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
}

View File

@@ -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()?)?;
}