From bb859a85d56dca724e3173c2d2e1cbdb43697977 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 1 Dec 2025 12:30:14 +0100 Subject: [PATCH] gpui(windows): Only poll PAINT messages twice in foreground task timeout (#43883) Release Notes: - N/A *or* Added/Fixed/Improved ... --- crates/gpui/src/platform/windows/platform.rs | 23 +++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs index 14b9511581a55a7654c8a48fc8f383c560c1a0ee..e1efaeb8a3425a28a6534a55c40585b6af8e3f97 100644 --- a/crates/gpui/src/platform/windows/platform.rs +++ b/crates/gpui/src/platform/windows/platform.rs @@ -822,12 +822,25 @@ impl WindowsPlatformInner { // we spent our budget on gpui tasks, we likely have a lot of work queued so drain system events first // before returning to main thread task work let mut msg = MSG::default(); - let peek_msg_type = PM_REMOVE | PM_QS_INPUT | PM_QS_PAINT; - while unsafe { PeekMessageW(&mut msg, None, 0, 0, peek_msg_type) }.as_bool() { - if translate_accelerator(&msg).is_none() { - _ = unsafe { TranslateMessage(&msg) }; - unsafe { DispatchMessageW(&msg) }; + let process_message = |msg: &_| { + if translate_accelerator(msg).is_none() { + _ = unsafe { TranslateMessage(msg) }; + unsafe { DispatchMessageW(msg) }; } + }; + let peek_msg = |msg: &mut _, msg_kind| unsafe { + PeekMessageW(msg, None, 0, 0, PM_REMOVE | msg_kind).as_bool() + }; + // We process a paint at the start and end only to prevent getting stuck in a paint loop + // due to on going gpui animations + if peek_msg(&mut msg, PM_QS_PAINT) { + process_message(&msg); + } + while peek_msg(&mut msg, PM_QS_INPUT) { + process_message(&msg); + } + if peek_msg(&mut msg, PM_QS_PAINT) { + process_message(&msg); } } match self.main_receiver.try_recv() {