From 36ed4b9b2914761beade25d898f30146bf4cc91c Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 22:26:22 -0700 Subject: [PATCH] refactor(kde): use EventChannel for the window events window_manager_event_listener.rs keeps its three functions (event_rx, resize_step_taken, send_notification) and its callers, but the channel, the try_send with the drop warning and the ResizeStep coalescing flag are now a komorebi_transport::EventChannel made with capacity 20 and the predicate matches!(.., ResizeStep(..)). The overflow flag exists in the channel and nothing reads it. The KDE bug where a ResizeStep that arrives while paused leaves the flag set (process_event.rs, paused return before resize_step_taken) is NOT fixed here: that is R5, a behaviour change. 25 lines of channel code removed. Logs use the target komorebi::transport (D29). Verified in komorebi-for-kde: cargo check -p komorebi --all-targets: no errors or warnings. The full workspace test run follows in the next progress entry. --- komorebi-for-kde/Cargo.lock | 1 + .../src/window_manager_event_listener.rs | 44 ++++++------------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/komorebi-for-kde/Cargo.lock b/komorebi-for-kde/Cargo.lock index 73ee4793..244ead6e 100644 --- a/komorebi-for-kde/Cargo.lock +++ b/komorebi-for-kde/Cargo.lock @@ -2607,6 +2607,7 @@ name = "komorebi-transport" version = "0.1.42" dependencies = [ "color-eyre", + "crossbeam-channel", "komorebi-protocol", "tracing", "uds_windows", diff --git a/komorebi-for-kde/komorebi/src/window_manager_event_listener.rs b/komorebi-for-kde/komorebi/src/window_manager_event_listener.rs index 2ab31a75..adc87795 100644 --- a/komorebi-for-kde/komorebi/src/window_manager_event_listener.rs +++ b/komorebi-for-kde/komorebi/src/window_manager_event_listener.rs @@ -10,52 +10,36 @@ use crate::window_manager_event::WindowManagerEvent; use crossbeam_channel::Receiver; -use crossbeam_channel::Sender; +use komorebi_transport::EventChannel; use std::sync::OnceLock; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering; -static CHANNEL: OnceLock<(Sender, Receiver)> = - OnceLock::new(); +static CHANNEL: OnceLock> = OnceLock::new(); -fn channel() -> &'static (Sender, Receiver) { - CHANNEL.get_or_init(|| crossbeam_channel::bounded(20)) -} - -fn event_tx() -> Sender { - channel().0.clone() +fn channel() -> &'static EventChannel { + // a drag makes `ResizeStep`s as fast as the pointer moves, and each says where the pointer is + // now, so one waiting is enough: the window manager asks the window where its edges are when + // it gets to it, and that is the newest + CHANNEL.get_or_init(|| { + EventChannel::coalescing(20, |event| { + matches!(event, WindowManagerEvent::ResizeStep(..)) + }) + }) } /// Returns the receiving end of the channel, for the window manager. pub fn event_rx() -> Receiver { - channel().1.clone() + channel().receiver() } -/// Whether a `ResizeStep` is already waiting in the channel. A drag makes them as fast as the pointer -/// moves, and each says where the pointer is now, so one waiting is enough: the window manager asks -/// the window where its edges are when it gets to it, and that is the newest. -static RESIZE_STEP_WAITING: AtomicBool = AtomicBool::new(false); - /// Says that the window manager has taken the `ResizeStep` that was waiting, so that the next one /// may be queued. pub fn resize_step_taken() { - RESIZE_STEP_WAITING.store(false, Ordering::SeqCst); + channel().coalesced_taken(); } /// Queues an event for the window manager, or drops it with a warning if 20 are already waiting. /// /// A [`WindowManagerEvent::ResizeStep`] is dropped without a word while another one is waiting. pub fn send_notification(notification: WindowManagerEvent) { - let is_step = matches!(notification, WindowManagerEvent::ResizeStep(..)); - - if is_step && RESIZE_STEP_WAITING.swap(true, Ordering::SeqCst) { - return; - } - - if event_tx().try_send(notification).is_err() { - if is_step { - RESIZE_STEP_WAITING.store(false, Ordering::SeqCst); - } - tracing::warn!("channel is full; dropping notification") - } + channel().send(notification); }