From 4e98d7d36d392592febd90b7555caf47ceb49552 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Thu, 29 Feb 2024 17:22:17 -0800 Subject: [PATCH] fix(wm): restore drag-to-swap window functionality This commit fixes a regression that was most likely introduced in #678 which changed a bunch of stuff related to window and border dimension calculation. While we could previously assume that the points resize.right and resize.bottom would always be 0 if we were dealing with a move rather than a resize, these two points now depend on the values of BORDER_WIDTH and BORDER_OFFSET. The code has been updated to reflect this and calculate this constant just-in-time. --- docs/komorebi.example.json | 10 ++++++---- komorebi.example.json | 10 ++++++---- komorebi/src/lib.rs | 5 +++-- komorebi/src/process_event.rs | 11 ++++++++++- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/docs/komorebi.example.json b/docs/komorebi.example.json index ff66e10f..f3bc73f7 100644 --- a/docs/komorebi.example.json +++ b/docs/komorebi.example.json @@ -1,15 +1,17 @@ { - "$schema": "https://raw.githubusercontent.com/LGUG2Z/komorebi/v0.1.20/schema.json", + "$schema": "https://raw.githubusercontent.com/LGUG2Z/komorebi/v0.1.22/schema.json", "app_specific_configuration_path": "$Env:USERPROFILE/applications.yaml", "window_hiding_behaviour": "Cloak", "cross_monitor_move_behaviour": "Insert", "default_workspace_padding": 20, "default_container_padding": 20, + "border_padding": 8, + "border_offset": -1, "active_window_border": false, "active_window_border_colours": { - "single": { "r": 66, "g": 165, "b": 245 }, - "stack": { "r": 256, "g": 165, "b": 66 }, - "monocle": { "r": 255, "g": 51, "b": 153 } + "single": "#42a5f5", + "stack": "#00a542", + "monocle": "#ff3399" }, "monitors": [ { diff --git a/komorebi.example.json b/komorebi.example.json index ff66e10f..f3bc73f7 100644 --- a/komorebi.example.json +++ b/komorebi.example.json @@ -1,15 +1,17 @@ { - "$schema": "https://raw.githubusercontent.com/LGUG2Z/komorebi/v0.1.20/schema.json", + "$schema": "https://raw.githubusercontent.com/LGUG2Z/komorebi/v0.1.22/schema.json", "app_specific_configuration_path": "$Env:USERPROFILE/applications.yaml", "window_hiding_behaviour": "Cloak", "cross_monitor_move_behaviour": "Insert", "default_workspace_padding": 20, "default_container_padding": 20, + "border_padding": 8, + "border_offset": -1, "active_window_border": false, "active_window_border_colours": { - "single": { "r": 66, "g": 165, "b": 245 }, - "stack": { "r": 256, "g": 165, "b": 66 }, - "monocle": { "r": 255, "g": 51, "b": 153 } + "single": "#42a5f5", + "stack": "#00a542", + "monocle": "#ff3399" }, "monitors": [ { diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index 413c93ba..1514fc80 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -192,7 +192,6 @@ lazy_static! { static ref BORDER_RECT: Arc> = Arc::new(Mutex::new(Rect::default())); - static ref BORDER_OFFSET: AtomicI32 = Default::default(); // Use app-specific titlebar removal options where possible // eg. Windows Terminal, IntelliJ IDEA, Firefox @@ -212,7 +211,9 @@ pub static BORDER_COLOUR_SINGLE: AtomicU32 = AtomicU32::new(0); pub static BORDER_COLOUR_STACK: AtomicU32 = AtomicU32::new(0); pub static BORDER_COLOUR_MONOCLE: AtomicU32 = AtomicU32::new(0); pub static BORDER_COLOUR_CURRENT: AtomicU32 = AtomicU32::new(0); -pub static BORDER_WIDTH: AtomicI32 = AtomicI32::new(20); +pub static BORDER_WIDTH: AtomicI32 = AtomicI32::new(8); +pub static BORDER_OFFSET: AtomicI32 = AtomicI32::new(-1); + // 0 0 0 aka pure black, I doubt anyone will want this as a border colour pub const TRANSPARENCY_COLOUR: u32 = 0; pub static REMOVE_TITLEBARS: AtomicBool = AtomicBool::new(false); diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index a5cb6f96..8be0d173 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -28,6 +28,8 @@ use crate::BORDER_COLOUR_STACK; use crate::BORDER_ENABLED; use crate::BORDER_HIDDEN; use crate::BORDER_HWND; +use crate::BORDER_OFFSET; +use crate::BORDER_WIDTH; use crate::DATA_DIR; use crate::HIDDEN_HWNDS; use crate::REGEX_IDENTIFIERS; @@ -378,7 +380,14 @@ impl WindowManager { // If we have moved across the monitors, use that override, otherwise determine // if a move has taken place by ruling out a resize - let is_move = moved_across_monitors || resize.right == 0 && resize.bottom == 0; + let right_bottom_constant = ((BORDER_WIDTH.load(Ordering::SeqCst) + + BORDER_OFFSET.load(Ordering::SeqCst)) + * 2) + .abs(); + + let is_move = moved_across_monitors + || resize.right.abs() == right_bottom_constant + && resize.bottom.abs() == right_bottom_constant; if is_move { tracing::info!("moving with mouse");