Skip to content

Commit

Permalink
fix(borders): handle snapshot edge cases
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LGUG2Z committed Jun 9, 2024
1 parent 6b9a084 commit a11da21
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions komorebi/src/border_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> 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
Expand All @@ -133,7 +135,33 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> 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;
}
Expand All @@ -154,6 +182,8 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
}

borders.clear();

previous_is_paused = is_paused;
continue 'receiver;
}

Expand Down Expand Up @@ -346,7 +376,9 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
}
}

latest_snapshot = monitors;
previous_snapshot = monitors;
previous_pending_move_op = pending_move_op;
previous_is_paused = is_paused;
}

Ok(())
Expand Down

0 comments on commit a11da21

Please sign in to comment.