Skip to content

Fix working area changed on windows platform won't update screen - #21707

Merged
MrJul merged 5 commits into
AvaloniaUI:masterfrom
Misaka-L:fix/working-area-changed-wont-trigger-screens-changed-on-windows
Jul 6, 2026
Merged

MrJul merged 5 commits into
AvaloniaUI:masterfrom
Misaka-L:fix/working-area-changed-wont-trigger-screens-changed-on-windows

Conversation

@Misaka-L

@Misaka-L Misaka-L commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

What does the pull request do?

This pull request will call Screen?.OnChanged() when received window message WM_SETTINGCHANGE with wParam SPI_SETWORKAREA.

What is the current behavior?

Screens.Changed won't trigger and screen WorkingArea property won't updated if only working area changed.
(Change taskbar position or size will change the working area)

What is the updated/expected behavior with this PR?

Screens.Changed will trigger and screen WorkingArea property will also update if working area changed.

How was the solution implemented (if it's not obvious)?

This pull request add a case for WM_SETTINGCHANGE in AppWndProc, which will call Screen?.OnChanged(), update the screen working area property and trigger Screens.Changed.

Test Video

See WorkingArea and Screens.Changed Trigger Counter

2026-07-05.23-31-44.mp4

Checklist

  • Added unit tests (if possible)?
    • Currently no way to trigger working area changed without modify OS settings.
    • Update the IntergrationTestApp to test this patch. See above.
  • Added XML documentation to any related classes?
  • Consider submitting a PR to https://github.com/AvaloniaUI/avalonia-docs with user documentation

Fixed issues

Fixes #19006

@Misaka-L
Misaka-L marked this pull request as ready for review July 5, 2026 16:00
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0067169-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added bug os-windows backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Jul 6, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0067191-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

// SPI_SETWORKAREA
if (wParam == 0x002F)
{
Screen?.OnChanged();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this in the window-specific wndproc. Use Win32Platform.WndProc instead, which is meant for "global" messages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic move to existing WindowsMessage.WM_SETTINGCHANGE if statement in Win32Platform.WndProc.

if (msg == (uint)WindowsMessage.WM_SETTINGCHANGE
&& PlatformSettings is Win32PlatformSettings win32PlatformSettings)
{
var changedSetting = Marshal.PtrToStringAuto(lParam);
if (changedSetting == "ImmersiveColorSet" // dark/light mode
|| changedSetting == "WindowsThemeElement") // high contrast mode
{
win32PlatformSettings.OnColorValuesChanged();
}
// Notify WorkingArea changed to Screens
if ((SystemParametersInfo)wParam == SystemParametersInfo.SPI_SETWORKAREA)
{
Screen?.OnChanged();
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just notice that this statement will only run if PlatformSettings is Win32PlatformSettings win32PlatformSettings...
Should I make a new if statement for this patch?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep a single if (msg == (uint)WindowsMessage.WM_SETTINGCHANGE) for both but wrap the existing color change with an inner if (PlatformSettings is Win32PlatformSettings win32PlatformSettings)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patched

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0067207-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as advertised.
LGTM!

@MrJul
MrJul added this pull request to the merge queue Jul 6, 2026
Merged via the queue into AvaloniaUI:master with commit 50ad082 Jul 6, 2026
11 checks passed
@MrJul MrJul removed the backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch label Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

On Windows OS, Screens.Primary.WorkingArea does not change in response to user actions.

4 participants