From a11da2167cd07b81a5ef71b4410403a4c2bea609 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sun, 9 Jun 2024 10:38:23 -0700 Subject: [PATCH] fix(borders): handle snapshot edge cases This commit handles three subtle edge cases which surfaced after adding state snapshot comparisons to the border manager module. 1) Update borders when windows are dragged 2) Update borders on pause and unpause 3) Redraw borders on retile These two edge cases do not change the snapshot state but still require updates to be made to the borders. --- komorebi/src/border_manager/mod.rs | 38 +++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/komorebi/src/border_manager/mod.rs b/komorebi/src/border_manager/mod.rs index c8932646..13db75be 100644 --- a/komorebi/src/border_manager/mod.rs +++ b/komorebi/src/border_manager/mod.rs @@ -122,7 +122,9 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result let receiver = event_rx(); event_tx().send(Notification)?; - let mut latest_snapshot = Ring::default(); + let mut previous_snapshot = Ring::default(); + let mut previous_pending_move_op = None; + let mut previous_is_paused = false; 'receiver: for _ in receiver { // Check the wm state every time we receive a notification @@ -133,7 +135,33 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result let pending_move_op = state.pending_move_op; drop(state); - if monitors == latest_snapshot { + let mut should_process_notification = true; + + if monitors == previous_snapshot + // handle the window dragging edge case + && pending_move_op == previous_pending_move_op + { + should_process_notification = false; + } + + // handle the pause edge case + if is_paused && !previous_is_paused { + should_process_notification = true; + } + + // handle the unpause edge case + if previous_is_paused && !is_paused { + should_process_notification = true; + } + + // handle the retile edge case + if !should_process_notification { + if BORDER_STATE.lock().is_empty() { + should_process_notification = true; + } + } + + if !should_process_notification { tracing::trace!("monitor state matches latest snapshot, skipping notification"); continue 'receiver; } @@ -154,6 +182,8 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result } borders.clear(); + + previous_is_paused = is_paused; continue 'receiver; } @@ -346,7 +376,9 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result } } - latest_snapshot = monitors; + previous_snapshot = monitors; + previous_pending_move_op = pending_move_op; + previous_is_paused = is_paused; } Ok(())