Conversation
…tching With feature.restorePreviousWindowFocus enabled, switching virtual desktops natively (Ctrl+Win+Left/Right) could immediately snap back to the previous desktop. _storeLastWinFocused() reads the foreground window and the current desktop number non-atomically (200 ms poll), so during a switch animation it can file a window under the wrong desktop number. _restorePrevWinFocus() then calls SetForegroundWindow() on that window when landing on the desktop, and because the window actually lives on another desktop, Windows jumps back to it -- the "fighting" from the issue. Rapid switches poison the map heavily, producing the erratic multi-hop behavior also reported. Guard both sides with the public IVirtualDesktopManager COM interface's IsWindowOnCurrentVirtualDesktop(): only record a window under the desktop it actually lives on, and only restore focus to a window that is still on the desktop just landed on. The public interface is stable across all Win10 1607+ and Win11 builds, so it works even when the app falls back to the VirtualDesktopWin11_23H2_2921 implementation (which has no per-version manager). Added once in Util.OS -- no changes to the version-specific implementations or to default settings (the feature stays off by default). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
hi @koppor , many thanks. Am testing this now as well... Anyone on windows 10 tested this? |
Yes. The PR was created on Windows 10 (although development took place on Windows 11). |
|
@koppor What do you mean exactly the PR was created on Windows 10? Does that mean it was also thoroughly tested on Windows 10? I am not just talking about it building, but the actual app tested properly for any regressions (including cases like sleep/resume etc) |
My desktop machine is Windows 10, but has serious issues with suspend/resume, so I could not test there. I see two options to move forward:
|
I am using it continuously on my Windows 10 desktop and Windows 11 laptop. Please consider it for the next release. |
Fixes the focus "fighting" from #166, specifically the mechanism identified in this comment: switching desktops natively snaps back to the previous desktop and refocuses the wrong window.
Root cause
With
feature.restorePreviousWindowFocusenabled, every detected switch runsApp._restorePrevWinFocus(), whichSetForegroundWindow()s the window recorded for the desktop just landed on. That record comes from_storeLastWinFocused(), polled every 200 ms:(A)and(B)are read non-atomically, so during a native switch animation a window that lives on desktop 1 gets filed under desktop 2. Restoring it later force-focuses a window on another desktop, and Windows jumps to that desktop to show it — the snap-back. Rapid switches poison the map heavily, producing the erratic multi-hop behavior also reported.Fix
Guard both sides with the public
IVirtualDesktopManager::IsWindowOnCurrentVirtualDesktop:SetForegroundWindowif the recorded window is still on the desktop just landed on (no snap-back even if a stale record slips through).The public
IVirtualDesktopManager(CLSIDAA509086-…, IIDA5CD92FF-…) is stable across all Win10 1607+/Win11 builds — important because affected users fall back toVirtualDesktopWin11_23H2_2921, which has no per-version manager. It's added once inUtil.OS(fail-closed on any COM error), so the 9 version-specific implementations, the app'sIVirtualDesktopManagerinterface, and the default settings are all untouched.Scope
This addresses the focus-restoration fighting. The feature is off by default, so the separate "fighting on stock config" reports (feature disabled ⇒ no
SetForegroundWindowon the switch path at all) are a different, Windows-level cause (wallpaper/accent-color repaint, stale post-sleep COM) and are out of scope here.Testing
restorePreviousWindowFocuson — no snap-back observed.No automated test: the path is COM- and live-desktop-bound and the repo has no test project.
🤖 Generated with Claude Code