Skip to content

Fix Screen.DisplayName always being null on Windows - #22593

Open
izakusilov wants to merge 1 commit into
AvaloniaUI:mainfrom
izakusilov:22541-screen-displayname-always-null
Open

izakusilov wants to merge 1 commit into
AvaloniaUI:mainfrom
izakusilov:22541-screen-displayname-always-null

Conversation

@izakusilov

Copy link
Copy Markdown
Contributor

What does the pull request do?

Fixes Screen.DisplayName always being null on Windows. WinScreen.GetDisplayName now calls QueryDisplayConfig with valid arguments, so the monitor's friendly name is returned again.

What is the current behavior?

On Windows, Screen.DisplayName is null for every screen, e.g. desktop.MainWindow.Screens.All[0].DisplayName (reported on 12.1.4).

WinScreen.GetDisplayName passes a non-null currentTopologyId pointer to QueryDisplayConfig together with QDC_ONLY_ACTIVE_PATHS. According to the documentation, this pointer must be NULL unless QDC_DATABASE_CURRENT is used; otherwise the call fails with ERROR_INVALID_PARAMETER. GetDisplayName treats that failure as "no name" and returns null, so neither the friendly name nor the \\.\DISPLAYn fallback is ever reached.

What is the updated/expected behavior with this PR?

Screen.DisplayName contains the monitor's friendly name (from DISPLAYCONFIG_TARGET_DEVICE_NAME), or the GDI device name (e.g. \\.\DISPLAY1) when no matching display path is found.

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

  • Removed the currentTopologyId argument from the QueryDisplayConfig call, so the CsWin32-generated overload that passes NULL is used.
  • Added the Screens_Have_DisplayName integration test, which checks that every screen reports a non-null DisplayName.

Checklist

Breaking changes

None.

Obsoletions / Deprecations

None.

Fixed issues

Fixes #22541

@MrJul MrJul added bug os-windows backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Oct 25, 2026
@github-actions

Copy link
Copy Markdown

NuGet packages

The packages for this pull request have been published (workflow run):

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch bug os-windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Screen DisplayName always null

3 participants