Add SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 to SDL so that Reborn can keep running through Alt+F4.
authorandrewb@andrewb-linux.valvesoftware.com
Mon, 03 Aug 2015 11:37:03 -0700
changeset 9829 6961c662493c
parent 9828 4e0e4f544027
child 9830 0ada01db0923
Add SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 to SDL so that Reborn can keep running through Alt+F4.
include/SDL_hints.h
src/video/windows/SDL_windowsevents.c
--- a/include/SDL_hints.h	Sat Aug 01 22:03:50 2015 -0700
+++ b/include/SDL_hints.h	Mon Aug 03 11:37:03 2015 -0700
@@ -594,6 +594,15 @@
 #define SDL_HINT_NO_SIGNAL_HANDLERS   "SDL_NO_SIGNAL_HANDLERS"
 
 /**
+ *  \brief Tell SDL not to generate window-close events for Alt+F4 on Windows.
+ *
+ * The variable can be set to the following values:
+ *   "0"       - SDL will generate a window-close event when it sees Alt+F4.
+ *   "1"       - SDL will only do normal key handling for Alt+F4.
+ */
+#define SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4	"SDL_WINDOWS_NO_CLOSE_ON_ALT_F4"
+
+/**
  *  \brief  An enumeration of hint priorities
  */
 typedef enum
--- a/src/video/windows/SDL_windowsevents.c	Sat Aug 01 22:03:50 2015 -0700
+++ b/src/video/windows/SDL_windowsevents.c	Mon Aug 03 11:37:03 2015 -0700
@@ -32,6 +32,7 @@
 #include "../../events/SDL_touch_c.h"
 #include "../../events/scancodes_windows.h"
 #include "SDL_assert.h"
+#include "SDL_hints.h"
 
 /* Dropfile support */
 #include <shellapi.h>
@@ -322,6 +323,22 @@
     return SDL_TRUE;
 }
 
+static SDL_bool
+ShouldGenerateWindowCloseOnAltF4(void)
+{
+    const char *hint;
+    
+    hint = SDL_GetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4);
+    if (hint) {
+        if (*hint == '0') {
+            return SDL_TRUE;
+        } else {
+            return SDL_FALSE;
+        }
+    }
+    return SDL_TRUE;
+}
+
 LRESULT CALLBACK
 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
@@ -559,7 +576,7 @@
             /* Detect relevant keyboard shortcuts */
             if (keyboardState[SDL_SCANCODE_LALT] == SDL_PRESSED || keyboardState[SDL_SCANCODE_RALT] == SDL_PRESSED) {
                 /* ALT+F4: Close window */
-                if (code == SDL_SCANCODE_F4) {
+                if (code == SDL_SCANCODE_F4 && ShouldGenerateWindowCloseOnAltF4()) {
                     SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
                 }
             }