fix(wm): add ws reconciliator cooldown period

I was running komorebi on a MacBook Pro today and ended up quite quickly
being able to reproduce the ws switching loops that I thought I had
fixed (well, I still can't reproduce them on my Mac Mini).

This commit adds an additional cooldown period of 1s to
workspace_reconciliator::send_notification, which seems to do the trick
for me on the MacBook Pro.
This commit is contained in:
LGUG2Z committed 2025-10-31 13:47:23 -07:00
1 parent 270e0847c2
commit 29d9f9ecaa
1 file changed
+21
+21
View File
@@ -8,7 +8,10 @@ use parking_lot::Mutex;
use std::sync::Arc;
use std::sync::OnceLock;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering;
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
#[derive(Copy, Clone, Debug)]
pub struct Notification {
@@ -18,6 +21,8 @@ pub struct Notification {
}
static RECONCILIATION_IN_PROGRESS: AtomicBool = AtomicBool::new(false);
static LAST_RECONCILIATION: AtomicU64 = AtomicU64::new(0);
const COOLDOWN_MS: u64 = 1000; // 1 second cooldown
static CHANNEL: OnceLock<(Sender<Notification>, Receiver<Notification>)> = OnceLock::new();
@@ -38,6 +43,16 @@ pub fn send_notification(
workspace_idx: usize,
triggered_by: WindowManagerEvent,
) {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_millis() as u64;
if now - LAST_RECONCILIATION.load(Ordering::SeqCst) < COOLDOWN_MS {
tracing::debug!("within cooldown period, dropping notification");
return;
}
if !RECONCILIATION_IN_PROGRESS.load(Ordering::Relaxed) {
tracing::debug!("sending reconciliation request");
if event_tx()
@@ -101,6 +116,12 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
}
}
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_millis() as u64;
LAST_RECONCILIATION.store(now, Ordering::SeqCst);
RECONCILIATION_IN_PROGRESS.store(false, Ordering::Relaxed);
}