shithub: choc

Download patch

ref: d7a68c165d5139497523a67559c0e1f4df9efd50
parent: 05b7e25ca466172d071d17e9f3f665f992342431
author: Jonathan Dowland <jon+github@alcopop.org>
date: Thu Apr 7 04:11:32 EDT 2016

[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.

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -318,6 +318,12 @@
     }
 }
 
+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 @@
         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;