Skip to content

Re-send the window icon after a theme flip or resume - #4149

Draft
christophwille wants to merge 1 commit into
masterfrom
fix/4143-taskbar-icon
Draft

christophwille wants to merge 1 commit into
masterfrom
fix/4143-taskbar-icon

Conversation

@christophwille

Copy link
Copy Markdown
Member

Mitigation for #4143 (taskbar button goes blank on Windows 11). Draft because the root cause is a theory that could not be reproduced on demand; the reporter should confirm with a CI build before this is merged.

Theory

The reporter sees the blank button only for ILSpy, usually after the laptop resumes from hibernate, when PowerToys Light Switch flips the system theme. In the screenshot the button is blank while the hover flyout still shows the icon, so the window's icons are intact and only the taskbar's fetch of the large icon failed at some point.

The Windows 11 taskbar re-queries window icons on a light/dark flip. Right after resume ILSpy's UI thread is not pumping messages yet, so the WM_GETICON query goes unanswered. Avalonia answers WM_GETICON itself and registers its window class without a class icon, so Explorer has no fallback and nothing prompts it to ask again.

Change

MainWindow hooks WM_SETTINGCHANGE("ImmersiveColorSet") and WM_POWERBROADCAST(PBT_APMRESUMEAUTOMATIC) via Avalonia's Win32Properties.AddWndProcHookCallback and, two seconds later, assigns a fresh WindowIcon. A new instance is required: Avalonia's SetIcon ignores the instance it already holds. With a new one it re-sends WM_SETICON and pokes the taskbar to redraw. These messages are only dispatched once the thread pumps again, so the re-send always lands after the missed query; the delay coalesces the burst of broadcasts a single flip produces.

PlatformSettings.ColorValuesChanged was not used because it only fires when the app-mode background or the accent color changes, so it misses a flip of the taskbar (system) theme alone.

Verification

  • New headless test ReapplyWindowIcon_Hands_The_Platform_A_New_Icon_Instance (red before, green after).
  • Real app: sent both messages to the ILSpy window only (no system setting touched) and compared the WM_GETICON(ICON_BIG) handle before/after - re-created in both cases, app stays responsive.
  • Not verified: that this actually restores a blank button on a stock Windows 11 taskbar. No such taskbar on the dev machine.

Disclosure: this PR (code and description) was written with AI assistance - Claude (claude-fable-5-1), Claude Code.

#4143: the Windows 11 taskbar button goes blank, typically after the
laptop resumes from hibernate and a scheduled light/dark switch fires.
The taskbar re-queries window icons on the theme flip; ILSpy's UI
thread is not pumping yet, the query goes unanswered, and Avalonia's
window class carries no fallback icon. Not reproducible on demand, so
this is a mitigation based on that theory. It hooks the raw window
messages because Avalonia's ColorValuesChanged stays silent when only
the taskbar (system) theme changes and the app theme does not.

Assisted-by: Claude:claude-fable-5-1:Claude Code
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.

1 participant