Implemented SDL_HINT_ALLOW_TOPMOST for the Cocoa video driver
authorSam Lantinga <slouken@libsdl.org>
Mon, 31 Dec 2012 10:14:38 -0800
changeset 6784 8fd20f04d5d9
parent 6783 001f59dc43be
child 6785 c094c438c0a6
Implemented SDL_HINT_ALLOW_TOPMOST for the Cocoa video driver
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/cocoa/SDL_cocoawindow.m
src/video/windows/SDL_windowswindow.c
--- a/src/video/SDL_sysvideo.h	Mon Dec 31 10:13:25 2012 -0800
+++ b/src/video/SDL_sysvideo.h	Mon Dec 31 10:14:38 2012 -0800
@@ -369,6 +369,8 @@
 extern void SDL_UpdateWindowGrab(SDL_Window * window);
 extern SDL_Window * SDL_GetFocusWindow(void);
 
+extern SDL_bool SDL_ShouldAllowTopmost();
+
 #endif /* _SDL_sysvideo_h */
 
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/SDL_video.c	Mon Dec 31 10:13:25 2012 -0800
+++ b/src/video/SDL_video.c	Mon Dec 31 10:14:38 2012 -0800
@@ -2989,4 +2989,18 @@
     return SDL_ShowMessageBox(&data, NULL);
 }
 
+SDL_bool
+SDL_ShouldAllowTopmost()
+{
+	const char *hint = SDL_GetHint(SDL_HINT_ALLOW_TOPMOST);
+	if (hint) {
+		if (*hint == '0') {
+			return SDL_FALSE;
+		} else {
+			return SDL_TRUE;
+		}
+	}
+	return SDL_TRUE;
+}
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/cocoa/SDL_cocoawindow.m	Mon Dec 31 10:13:25 2012 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Dec 31 10:14:38 2012 -0800
@@ -915,7 +915,7 @@
     }
 
 #ifdef FULLSCREEN_TOGGLEABLE
-    if (fullscreen) {
+    if (SDL_ShouldAllowTopmost() && fullscreen) {
         /* OpenGL is rendering to the window, so make it visible! */
         [nswindow setLevel:CGShieldingWindowLevel()];
     } else {
@@ -997,22 +997,16 @@
         CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
     }
 	
-    if ( window->flags & SDL_WINDOW_FULLSCREEN )
-	{
+    if ( window->flags & SDL_WINDOW_FULLSCREEN ) {
 		SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
 
-		if (window->flags & SDL_WINDOW_INPUT_FOCUS)
-		{
+		if (SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
 			/* OpenGL is rendering to the window, so make it visible! */
 			[data->nswindow setLevel:CGShieldingWindowLevel()];
-		} 
-		else 
-		{
+		} else {
 			[data->nswindow setLevel:kCGNormalWindowLevel];
 		}
-		
 	}
-
 }
 
 void
--- a/src/video/windows/SDL_windowswindow.c	Mon Dec 31 10:13:25 2012 -0800
+++ b/src/video/windows/SDL_windowswindow.c	Mon Dec 31 10:14:38 2012 -0800
@@ -28,7 +28,6 @@
 
 #include "SDL_windowsvideo.h"
 #include "SDL_windowswindow.h"
-#include "SDL_hints.h"
 
 /* Dropfile support */
 #include <shellapi.h>
@@ -74,22 +73,6 @@
     return style;
 }
 
-static SDL_bool
-ShouldAllowTopMost()
-{
-    const char *hint;
-
-    /* If the user has specified a software renderer we can't use a
-       texture framebuffer, or renderer creation will go recursive.
-     */
-    hint = SDL_GetHint(SDL_HINT_ALLOW_TOPMOST);
-    if (hint && hint[0] == '0' ) {
-        return SDL_FALSE;
-    }
-
-	return SDL_TRUE;
-}
-
 static int
 SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
 {
@@ -371,7 +354,7 @@
     int w, h;
 
     /* Figure out what the window area will be */
-    if ( ShouldAllowTopMost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
+    if ( SDL_ShouldAllowTopmost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
 		top = HWND_TOPMOST;
     } else {
         top = HWND_NOTOPMOST;
@@ -423,7 +406,7 @@
     HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
     HWND top;
 
-	if ( ShouldAllowTopMost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
+	if ( SDL_ShouldAllowTopmost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
 		top = HWND_TOPMOST;
 	} else {
 		top = HWND_NOTOPMOST;
@@ -484,7 +467,7 @@
     int x, y;
     int w, h;
 
-	if ( ShouldAllowTopMost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
+	if ( SDL_ShouldAllowTopmost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
 		top = HWND_TOPMOST;
 	} else {
 		top = HWND_NOTOPMOST;
@@ -577,7 +560,7 @@
 		HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
 		UINT flags = SWP_NOMOVE | SWP_NOSIZE;
 
-		if ( ShouldAllowTopMost() && (window->flags & SDL_WINDOW_INPUT_FOCUS ) ) {
+		if ( SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_INPUT_FOCUS ) ) {
 			top = HWND_TOPMOST;
 		} else {
 			top = HWND_NOTOPMOST;