Skip to content

Fix taskbar buttons on wrong monitor after slow multi-monitor wakeup#1354

Merged
dremin merged 1 commit into
dremin:masterfrom
SMUsamaShah:claude/fix-taskbar-multimonitor-nBJRx
Mar 10, 2026
Merged

Fix taskbar buttons on wrong monitor after slow multi-monitor wakeup#1354
dremin merged 1 commit into
dremin:masterfrom
SMUsamaShah:claude/fix-taskbar-multimonitor-nBJRx

Conversation

@SMUsamaShah
Copy link
Copy Markdown
Contributor

@SMUsamaShah SMUsamaShah commented Mar 4, 2026

I have two monitors connected to laptop via dock and for some silly reasons the wakeup after sleep is very slow. First laptop screen turns on, then those monitors wakeup a few second later. This has been causing a weird issue.

When I login, the taskbar buttons don't appear on the same screen as the window. Most buttons gather on primary monitor, some remain on other screens. Even if I move windows to other displays, the buttons stay on wrong taskbar.

Work around I have is to open settings, then uncheck "Show on multiple displays" then check it again. That puts buttons on correct task bars.

It was bothering me a lot. I used Claude to find and fix it. And it is working fine for me.

Because I used AI, I cant say that this is the correct solution. Close the PR if it isn't.

Blurb Claude wrote about this fix

When a monitor wakes up slowly, Windows may assign it a new HMonitor handle while keeping bounds and device name unchanged. haveDisplaysChanged() only compared Bounds/DeviceName/Primary (using WinForms Screen objects which have no HMonitor field), so it missed such changes and skipped ReopenTaskbars(). As a result, each taskbar's Host.Screen.HMonitor stayed stale, causing Tasks_Filter to mismatch windows to the wrong taskbar even when live filtering re-evaluated.

Fix: use AppBarScreen.FromAllScreens() (which fetches fresh HMonitors via MonitorFromPoint) instead of Screen.AllScreens, and include HMonitor in the equality check. When an HMonitor change is detected, ReopenTaskbars() is called, creating new taskbars with correct handles.

When a monitor wakes up slowly, Windows may assign it a new HMonitor
handle while keeping bounds and device name unchanged. haveDisplaysChanged()
only compared Bounds/DeviceName/Primary (using WinForms Screen objects
which have no HMonitor field), so it missed such changes and skipped
ReopenTaskbars(). As a result, each taskbar's Host.Screen.HMonitor stayed
stale, causing Tasks_Filter to mismatch windows to the wrong taskbar
even when live filtering re-evaluated.

Fix: use AppBarScreen.FromAllScreens() (which fetches fresh HMonitors via
MonitorFromPoint) instead of Screen.AllScreens, and include HMonitor in
the equality check. When an HMonitor change is detected, ReopenTaskbars()
is called, creating new taskbars with correct handles.

https://claude.ai/code/session_01FpcNUJRXQN59TNdE93aKSk
@dremin dremin self-requested a review March 10, 2026 04:54
@github-actions
Copy link
Copy Markdown

@dremin
Copy link
Copy Markdown
Owner

dremin commented Mar 10, 2026

Interesting! Even though it seems odd that Windows would be assigning a new handle to the monitor, the fix is reasonable and I probably should have done this in the first place. Thanks!

@dremin dremin merged commit f206c35 into dremin:master Mar 10, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants