Respect Window.AllowAltF4 For SDLGamePlatform #8248
+17
−1
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.
Description
Currently
Window.AllowAltF4
is not respected forSDLGamePlatform
. No matter the property settingALT+F4
will close the window.This PR adds the check for
Alt+F4
during the exit check in the platform loop and handles exiting based on the keyboard key combination and theWindow.AllowAltF4
property. If the keyboard combination was not pressed, then it falls back to the default behavior of allowing the exit to occur.Notes
Press
Alt+F4
will triggerSDL.EventType.Quit
MonoGame/MonoGame.Framework/Platform/SDL/SDLGamePlatform.cs
Lines 109 to 111 in 40452a4
However,
Alt+F4
can also triggerSdl.Window.EventId.Close
MonoGame/MonoGame.Framework/Platform/SDL/SDLGamePlatform.cs
Lines 227 to 229 in 40452a4
It is inconsistent on which of these events is triggered first. Regardless, when both events are triggered, they
_keys
collection does not contain both theKeys.LeftAlt
/Keys.RightAlt
and theKeys.F4
due to the events firing before the keyboard update is performed.Due to these reasons, this is why the check was moved into the platform loop and made during the
_isExiting
check.