Implemented SDL_HINT_ALLOW_TOPMOST for the Cocoa video driver
authorSam Lantinga <slouken@libsdl.org>
Mon, 31 Dec 2012 10:14:38 -0800
changeset 67848fd20f04d5d9
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
     1.1 --- a/src/video/SDL_sysvideo.h	Mon Dec 31 10:13:25 2012 -0800
     1.2 +++ b/src/video/SDL_sysvideo.h	Mon Dec 31 10:14:38 2012 -0800
     1.3 @@ -369,6 +369,8 @@
     1.4  extern void SDL_UpdateWindowGrab(SDL_Window * window);
     1.5  extern SDL_Window * SDL_GetFocusWindow(void);
     1.6  
     1.7 +extern SDL_bool SDL_ShouldAllowTopmost();
     1.8 +
     1.9  #endif /* _SDL_sysvideo_h */
    1.10  
    1.11  /* vi: set ts=4 sw=4 expandtab: */
     2.1 --- a/src/video/SDL_video.c	Mon Dec 31 10:13:25 2012 -0800
     2.2 +++ b/src/video/SDL_video.c	Mon Dec 31 10:14:38 2012 -0800
     2.3 @@ -2989,4 +2989,18 @@
     2.4      return SDL_ShowMessageBox(&data, NULL);
     2.5  }
     2.6  
     2.7 +SDL_bool
     2.8 +SDL_ShouldAllowTopmost()
     2.9 +{
    2.10 +	const char *hint = SDL_GetHint(SDL_HINT_ALLOW_TOPMOST);
    2.11 +	if (hint) {
    2.12 +		if (*hint == '0') {
    2.13 +			return SDL_FALSE;
    2.14 +		} else {
    2.15 +			return SDL_TRUE;
    2.16 +		}
    2.17 +	}
    2.18 +	return SDL_TRUE;
    2.19 +}
    2.20 +
    2.21  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Dec 31 10:13:25 2012 -0800
     3.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Dec 31 10:14:38 2012 -0800
     3.3 @@ -915,7 +915,7 @@
     3.4      }
     3.5  
     3.6  #ifdef FULLSCREEN_TOGGLEABLE
     3.7 -    if (fullscreen) {
     3.8 +    if (SDL_ShouldAllowTopmost() && fullscreen) {
     3.9          /* OpenGL is rendering to the window, so make it visible! */
    3.10          [nswindow setLevel:CGShieldingWindowLevel()];
    3.11      } else {
    3.12 @@ -997,22 +997,16 @@
    3.13          CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
    3.14      }
    3.15  	
    3.16 -    if ( window->flags & SDL_WINDOW_FULLSCREEN )
    3.17 -	{
    3.18 +    if ( window->flags & SDL_WINDOW_FULLSCREEN ) {
    3.19  		SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    3.20  
    3.21 -		if (window->flags & SDL_WINDOW_INPUT_FOCUS)
    3.22 -		{
    3.23 +		if (SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
    3.24  			/* OpenGL is rendering to the window, so make it visible! */
    3.25  			[data->nswindow setLevel:CGShieldingWindowLevel()];
    3.26 -		} 
    3.27 -		else 
    3.28 -		{
    3.29 +		} else {
    3.30  			[data->nswindow setLevel:kCGNormalWindowLevel];
    3.31  		}
    3.32 -		
    3.33  	}
    3.34 -
    3.35  }
    3.36  
    3.37  void
     4.1 --- a/src/video/windows/SDL_windowswindow.c	Mon Dec 31 10:13:25 2012 -0800
     4.2 +++ b/src/video/windows/SDL_windowswindow.c	Mon Dec 31 10:14:38 2012 -0800
     4.3 @@ -28,7 +28,6 @@
     4.4  
     4.5  #include "SDL_windowsvideo.h"
     4.6  #include "SDL_windowswindow.h"
     4.7 -#include "SDL_hints.h"
     4.8  
     4.9  /* Dropfile support */
    4.10  #include <shellapi.h>
    4.11 @@ -74,22 +73,6 @@
    4.12      return style;
    4.13  }
    4.14  
    4.15 -static SDL_bool
    4.16 -ShouldAllowTopMost()
    4.17 -{
    4.18 -    const char *hint;
    4.19 -
    4.20 -    /* If the user has specified a software renderer we can't use a
    4.21 -       texture framebuffer, or renderer creation will go recursive.
    4.22 -     */
    4.23 -    hint = SDL_GetHint(SDL_HINT_ALLOW_TOPMOST);
    4.24 -    if (hint && hint[0] == '0' ) {
    4.25 -        return SDL_FALSE;
    4.26 -    }
    4.27 -
    4.28 -	return SDL_TRUE;
    4.29 -}
    4.30 -
    4.31  static int
    4.32  SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
    4.33  {
    4.34 @@ -371,7 +354,7 @@
    4.35      int w, h;
    4.36  
    4.37      /* Figure out what the window area will be */
    4.38 -    if ( ShouldAllowTopMost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
    4.39 +    if ( SDL_ShouldAllowTopmost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
    4.40  		top = HWND_TOPMOST;
    4.41      } else {
    4.42          top = HWND_NOTOPMOST;
    4.43 @@ -423,7 +406,7 @@
    4.44      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
    4.45      HWND top;
    4.46  
    4.47 -	if ( ShouldAllowTopMost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
    4.48 +	if ( SDL_ShouldAllowTopmost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
    4.49  		top = HWND_TOPMOST;
    4.50  	} else {
    4.51  		top = HWND_NOTOPMOST;
    4.52 @@ -484,7 +467,7 @@
    4.53      int x, y;
    4.54      int w, h;
    4.55  
    4.56 -	if ( ShouldAllowTopMost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
    4.57 +	if ( SDL_ShouldAllowTopmost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
    4.58  		top = HWND_TOPMOST;
    4.59  	} else {
    4.60  		top = HWND_NOTOPMOST;
    4.61 @@ -577,7 +560,7 @@
    4.62  		HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
    4.63  		UINT flags = SWP_NOMOVE | SWP_NOSIZE;
    4.64  
    4.65 -		if ( ShouldAllowTopMost() && (window->flags & SDL_WINDOW_INPUT_FOCUS ) ) {
    4.66 +		if ( SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_INPUT_FOCUS ) ) {
    4.67  			top = HWND_TOPMOST;
    4.68  		} else {
    4.69  			top = HWND_NOTOPMOST;