Implemented SDL_HINT_ALLOW_TOPMOST for the Cocoa video driver

This commit is contained in:
Sam Lantinga 2012-12-31 10:14:38 -08:00
parent 13fe19497e
commit f367ee7277
4 changed files with 24 additions and 31 deletions

View file

@ -369,6 +369,8 @@ extern void SDL_OnWindowFocusLost(SDL_Window * window);
extern void SDL_UpdateWindowGrab(SDL_Window * window); extern void SDL_UpdateWindowGrab(SDL_Window * window);
extern SDL_Window * SDL_GetFocusWindow(void); extern SDL_Window * SDL_GetFocusWindow(void);
extern SDL_bool SDL_ShouldAllowTopmost();
#endif /* _SDL_sysvideo_h */ #endif /* _SDL_sysvideo_h */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View file

@ -2989,4 +2989,18 @@ SDL_ShowSimpleMessageBox(Uint32 flags, const char *title, const char *message, S
return SDL_ShowMessageBox(&data, NULL); 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: */ /* vi: set ts=4 sw=4 expandtab: */

View file

@ -915,7 +915,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
} }
#ifdef FULLSCREEN_TOGGLEABLE #ifdef FULLSCREEN_TOGGLEABLE
if (fullscreen) { if (SDL_ShouldAllowTopmost() && fullscreen) {
/* OpenGL is rendering to the window, so make it visible! */ /* OpenGL is rendering to the window, so make it visible! */
[nswindow setLevel:CGShieldingWindowLevel()]; [nswindow setLevel:CGShieldingWindowLevel()];
} else { } else {
@ -997,22 +997,16 @@ Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint); CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
} }
if ( window->flags & SDL_WINDOW_FULLSCREEN ) if ( window->flags & SDL_WINDOW_FULLSCREEN ) {
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata; 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! */ /* OpenGL is rendering to the window, so make it visible! */
[data->nswindow setLevel:CGShieldingWindowLevel()]; [data->nswindow setLevel:CGShieldingWindowLevel()];
} } else {
else
{
[data->nswindow setLevel:kCGNormalWindowLevel]; [data->nswindow setLevel:kCGNormalWindowLevel];
} }
} }
} }
void void

View file

@ -28,7 +28,6 @@
#include "SDL_windowsvideo.h" #include "SDL_windowsvideo.h"
#include "SDL_windowswindow.h" #include "SDL_windowswindow.h"
#include "SDL_hints.h"
/* Dropfile support */ /* Dropfile support */
#include <shellapi.h> #include <shellapi.h>
@ -74,22 +73,6 @@ GetWindowStyle(SDL_Window * window)
return style; 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 static int
SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
{ {
@ -371,7 +354,7 @@ WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
int w, h; int w, h;
/* Figure out what the window area will be */ /* 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; top = HWND_TOPMOST;
} else { } else {
top = HWND_NOTOPMOST; top = HWND_NOTOPMOST;
@ -423,7 +406,7 @@ WIN_RaiseWindow(_THIS, SDL_Window * window)
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
HWND top; 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; top = HWND_TOPMOST;
} else { } else {
top = HWND_NOTOPMOST; top = HWND_NOTOPMOST;
@ -484,7 +467,7 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
int x, y; int x, y;
int w, h; 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; top = HWND_TOPMOST;
} else { } else {
top = HWND_NOTOPMOST; top = HWND_NOTOPMOST;
@ -577,7 +560,7 @@ WIN_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
UINT flags = SWP_NOMOVE | SWP_NOSIZE; 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; top = HWND_TOPMOST;
} else { } else {
top = HWND_NOTOPMOST; top = HWND_NOTOPMOST;