Skip to content

fix: Prevent DXGI from intercepting Alt+Enter and PrintScreen #18970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

M0n7y5
Copy link

@M0n7y5 M0n7y5 commented Jun 2, 2025

What does the pull request do?

This fixes an issue with forced key shortcuts caused by DXGI composition. By default, DXGI hooks into the window message queue, intercepts the PrintScreen key or Alt+Enter key sequence, and forces any Avalonia app into fullscreen mode. There is currently no way to disable this feature.
This behavior only occurs for apps using Win32CompositionMode.LowLatencyDxgiSwapChain. Other composition modes are not affected.
https://groups.google.com/g/angleproject/c/Ks8QXP6UVBk

What is the current behavior?

Any Avalonia app using Win32CompositionMode.LowLatencyDxgiSwapChain switches to fullscreen mode when the Alt+Enter key sequence is pressed.

What is the updated/expected behavior with this PR?

The updated behavior entirely disables forced fullscreen via Alt+Enter, as well as the PrintScreen key interception.

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

The solution involves setting the appropriate flags using MakeWindowAssociation.
https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgifactory-makewindowassociation

Breaking changes

None

@avaloniaui-bot
Copy link

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

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented Jun 2, 2025

  • All contributors have signed the CLA.

@M0n7y5
Copy link
Author

M0n7y5 commented Jun 2, 2025

@cla-avalonia agree

@@ -24,6 +24,14 @@ internal unsafe class DxgiRenderTarget : EglPlatformSurfaceRenderTargetBase
private IUnknown? _renderTexture;
private RECT _clientRect;

[Flags]
enum AssociationFlags : ushort
Copy link
Member

Choose a reason for hiding this comment

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

I was confused by the ushort here before realizing that the current parameters had the wrong types.
Please wait for #18991 to get merged, then remove the ushort.

@@ -24,6 +24,14 @@ internal unsafe class DxgiRenderTarget : EglPlatformSurfaceRenderTargetBase
private IUnknown? _renderTexture;
private RECT _clientRect;

[Flags]
enum AssociationFlags : ushort
Copy link
Member

Choose a reason for hiding this comment

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

Please define this in DirectXEnums.cs for consistency (the name could be DXGI_MWA).
Also, the second parameter for MakeWindowAssociation() in DirectX.idl could probably now be typed.

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.

4 participants