Re-send the window icon after a theme flip or resume - #4149
Draft
christophwille wants to merge 1 commit into
Draft
christophwille wants to merge 1 commit into
christophwille wants to merge 1 commit into
Conversation
#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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_GETICONquery goes unanswered. Avalonia answersWM_GETICONitself and registers its window class without a class icon, so Explorer has no fallback and nothing prompts it to ask again.Change
MainWindowhooksWM_SETTINGCHANGE("ImmersiveColorSet")andWM_POWERBROADCAST(PBT_APMRESUMEAUTOMATIC)via Avalonia'sWin32Properties.AddWndProcHookCallbackand, two seconds later, assigns a freshWindowIcon. A new instance is required: Avalonia'sSetIconignores the instance it already holds. With a new one it re-sendsWM_SETICONand 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.ColorValuesChangedwas 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
ReapplyWindowIcon_Hands_The_Platform_A_New_Icon_Instance(red before, green after).WM_GETICON(ICON_BIG)handle before/after - re-created in both cases, app stays responsive.Disclosure: this PR (code and description) was written with AI assistance - Claude (claude-fable-5-1), Claude Code.