mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-15 21:32:26 +01:00
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<WindowManagerEvent> 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.
This commit is contained in:
1 parent
d55b6daeb7
commit
36ed4b9b29
2 files changed
+15
-30
No files matched your search
Generated
+1
@@ -2607,6 +2607,7 @@ name = "komorebi-transport"
|
||||
version = "0.1.42"
|
||||
dependencies = [
|
||||
"color-eyre",
|
||||
"crossbeam-channel",
|
||||
"komorebi-protocol",
|
||||
"tracing",
|
||||
"uds_windows",
|
||||
|
||||
@@ -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<WindowManagerEvent>, Receiver<WindowManagerEvent>)> =
|
||||
OnceLock::new();
|
||||
static CHANNEL: OnceLock<EventChannel<WindowManagerEvent>> = OnceLock::new();
|
||||
|
||||
fn channel() -> &'static (Sender<WindowManagerEvent>, Receiver<WindowManagerEvent>) {
|
||||
CHANNEL.get_or_init(|| crossbeam_channel::bounded(20))
|
||||
}
|
||||
|
||||
fn event_tx() -> Sender<WindowManagerEvent> {
|
||||
channel().0.clone()
|
||||
fn channel() -> &'static EventChannel<WindowManagerEvent> {
|
||||
// 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<WindowManagerEvent> {
|
||||
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);
|
||||
}
|
||||
Reference in new issue
Block a user