commit d7a68c165d5139497523a67559c0e1f4df9efd50
Author: Jonathan Dowland <jon+github@alcopop.org>
AuthorDate: Thu Apr 7 08:11:32 2016 +0100
Commit: Jonathan Dowland <jon+github@alcopop.org>
CommitDate: Fri Apr 8 14:06:31 2016 +0100
[sdl2-branch] toggle fullscreen with cmd+enter
This morning's breakfast coding...
Special-case listen for LGUI/RGUI + enter (which is Command on Mac;
Windows key on Windows; Meta or whatever on Linux) and toggle
fullscreen.
On Mac, when you are fullscreen-via-maximize-button, if you push the mouse
pointer to the top edge, the titlebar scrolls down and you could click to
de-maximize. This does not happen if you are fullscreen-via-shortcut. I
think this might be an SDL2 bug or quirk.
---
src/i_video.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/src/i_video.c b/src/i_video.c
index c0fd78db..cc7c8331 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -318,6 +318,12 @@ static void HandleWindowEvent(SDL_WindowEvent *event)
}
}
+static void I_ToggleFullScreen(void)
+{
+ Uint32 flags = SDL_GetWindowFlags(screen) & SDL_WINDOW_FULLSCREEN_DESKTOP;
+ SDL_SetWindowFullscreen(screen, flags ^ SDL_WINDOW_FULLSCREEN_DESKTOP);
+}
+
void I_GetEvent(void)
{
extern void I_HandleKeyboardEvent(SDL_Event *sdlevent);
@@ -331,6 +337,14 @@ void I_GetEvent(void)
switch (sdlevent.type)
{
case SDL_KEYDOWN:
+ if (sdlevent.key.keysym.scancode == SDL_SCANCODE_RETURN &&
+ sdlevent.key.keysym.mod & (KMOD_LGUI | KMOD_RGUI))
+ {
+ I_ToggleFullScreen();
+ break;
+ }
+ // deliberate fall-though
+
case SDL_KEYUP:
I_HandleKeyboardEvent(&sdlevent);
break;