From 1fb2789cb1c80f89a700e01a7d0ba8ec165ce677 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Mon, 28 Jul 2025 17:11:35 +0100 Subject: [PATCH] fix: Prevent flicker on desk leave with 30ms delay --- src/lib/platform/MSWindowsDesks.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/platform/MSWindowsDesks.cpp b/src/lib/platform/MSWindowsDesks.cpp index 552ea5c6c..6e7a97ba9 100644 --- a/src/lib/platform/MSWindowsDesks.cpp +++ b/src/lib/platform/MSWindowsDesks.cpp @@ -582,8 +582,16 @@ void MSWindowsDesks::deskLeave(Desk *desk, HKL keyLayout) // we aren't notified when the mouse leaves our window. SetCapture(desk->m_window); - // warp the mouse to the cursor center - LOG((CLOG_DEBUG2 "warping cursor to center: %+d,%+d", m_xCenter, m_yCenter)); + // windows can take a while to hide the cursor, so wait a few milliseconds to ensure the cursor + // is hidden before centering. this doesn't seem to affect the fluidity of the transition. + // without this, the cursor appears to flicker in the center of the screen which is annoying. + // a slightly more elegant but complex solution could be to use a timed event. + // 30 ms seems to work well enough without making the transition feel janky; a lower number + // would be better but 10 ms doesn't seem to be quite long enough, as we get noticeable flicker. + // this is largely a balance and out of our control, since windows can be unpredictable... + // maybe another approach would be to repeatedly check the cursor visibility until it is hidden. + LOG_DEBUG1("centering cursor on leave: %+d,%+d", m_xCenter, m_yCenter); + ARCH->sleep(0.03); deskMouseMove(m_xCenter, m_yCenter); } }