From e60a4c43affb40c43319bd4e85dab7f317b25cc3 Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Sun, 3 May 2026 09:42:08 +0200 Subject: [PATCH] remove redraw flag --- rio-window/src/platform_impl/linux/x11/mod.rs | 16 ---------------- rio-window/src/platform_impl/linux/x11/window.rs | 13 +++++++++---- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/rio-window/src/platform_impl/linux/x11/mod.rs b/rio-window/src/platform_impl/linux/x11/mod.rs index e8a4aebf..d16651b8 100644 --- a/rio-window/src/platform_impl/linux/x11/mod.rs +++ b/rio-window/src/platform_impl/linux/x11/mod.rs @@ -156,10 +156,6 @@ pub struct ActiveEventLoop { /// presentation window — single keystrokes don't. See /// `platform_impl::input_rate`. input_rate_tracker: RefCell, - /// Shared with `EventLoopState` and every window. Set by - /// `request_redraw`, checked by `has_pending`, cleared by - /// the vsync tick after fanning out. - pub(super) redraw_flag: Arc, /// Waker ping so `request_redraw` can unblock calloop dispatch. pub(super) waker: Ping, /// Calloop loop handle so per-window vsync timers can be @@ -193,10 +189,6 @@ type ActivationToken = (WindowId, crate::event_loop::AsyncRequestSerial); pub(crate) struct EventLoopState { /// The latest readiness state for the x11 file descriptor x11_readiness: Readiness, - /// Set by `request_redraw` (via the shared `Arc`). - /// Checked by `has_pending` so the event loop wakes even when - /// the timer hasn't fired yet. - redraw_flag: Arc, } /// Per-window vsync timer state. Mirrors zed's @@ -380,7 +372,6 @@ impl EventLoop { input_rate_tracker: RefCell::new( crate::platform_impl::input_rate::InputRateTracker::new(), ), - redraw_flag: Arc::new(std::sync::atomic::AtomicBool::new(false)), waker: waker.clone(), loop_handle: handle.clone(), }; @@ -388,8 +379,6 @@ impl EventLoop { // Set initial device event filter. window_target.update_listen_device_events(true); - let redraw_flag = window_target.redraw_flag.clone(); - let root_window_target = RootAEL { p: PlatformActiveEventLoop::X(window_target), _marker: PhantomData, @@ -452,7 +441,6 @@ impl EventLoop { user_sender, state: EventLoopState { x11_readiness: Readiness::EMPTY, - redraw_flag, }, } } @@ -535,10 +523,6 @@ impl EventLoop { fn has_pending(&mut self) -> bool { self.vsync_receiver.has_incoming() - || self - .state - .redraw_flag - .load(std::sync::atomic::Ordering::Acquire) || self.event_processor.poll() || self.user_receiver.has_incoming() || self.redraw_receiver.has_incoming() diff --git a/rio-window/src/platform_impl/linux/x11/window.rs b/rio-window/src/platform_impl/linux/x11/window.rs index c5257897..9f5643e4 100644 --- a/rio-window/src/platform_impl/linux/x11/window.rs +++ b/rio-window/src/platform_impl/linux/x11/window.rs @@ -132,7 +132,6 @@ pub struct UnownedWindow { pub shared_state: Mutex, activation_sender: WakeSender, pub(crate) redraw_pending: std::sync::atomic::AtomicBool, - redraw_flag: Arc, waker: calloop::ping::Ping, /// Per-window vsync timer state. Mirrors zed's `RefreshState` /// in `gpui_linux::linux::x11::client`. Managed by @@ -391,7 +390,6 @@ impl UnownedWindow { shared_state: SharedState::new(guessed_monitor, &window_attrs), activation_sender: event_loop.activation_sender.clone(), redraw_pending: std::sync::atomic::AtomicBool::new(false), - redraw_flag: event_loop.redraw_flag.clone(), waker: event_loop.waker.clone(), refresh_state: std::sync::Mutex::new(None), // The window starts unmapped; `MapNotify` will flip these. @@ -2008,10 +2006,17 @@ impl UnownedWindow { #[inline] pub fn request_redraw(&self) { + // Mark the per-window dirty flag; the per-window vsync timer + // (registered in `update_refresh_loop`) picks it up on the + // next tick. Ping wakes the calloop dispatcher in case it + // is blocked in `Wait` so the next tick isn't deferred. No + // global "has work" flag — that pattern caused a 100% CPU + // spin between key/mouse events and the next vsync edge, + // because nothing ever cleared it. Mirrors zed's + // `gpui_linux::linux::x11` flow (no global flag) and the + // Wayland backend (per-window AtomicBool + ping). self.redraw_pending .store(true, std::sync::atomic::Ordering::Release); - self.redraw_flag - .store(true, std::sync::atomic::Ordering::Release); self.waker.ping(); } -- 2.51.2