Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Implemented SDL_HINT_ALLOW_TOPMOST for the Cocoa video driver
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 31, 2012
1 parent a4d86b9 commit 9a337c7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 31 deletions.
2 changes: 2 additions & 0 deletions src/video/SDL_sysvideo.h
Expand Up @@ -369,6 +369,8 @@ extern void SDL_OnWindowFocusLost(SDL_Window * window);
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: */
14 changes: 14 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -2989,4 +2989,18 @@ SDL_ShowSimpleMessageBox(Uint32 flags, const char *title, const char *message, S
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: */
14 changes: 4 additions & 10 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -915,7 +915,7 @@ - (void)rightMouseDown:(NSEvent *)theEvent
}

#ifdef FULLSCREEN_TOGGLEABLE
if (fullscreen) {
if (SDL_ShouldAllowTopmost() && fullscreen) {
/* OpenGL is rendering to the window, so make it visible! */
[nswindow setLevel:CGShieldingWindowLevel()];
} else {
Expand Down Expand Up @@ -997,22 +997,16 @@ - (void)rightMouseDown:(NSEvent *)theEvent
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
Expand Down
25 changes: 4 additions & 21 deletions src/video/windows/SDL_windowswindow.c
Expand Up @@ -28,7 +28,6 @@

#include "SDL_windowsvideo.h"
#include "SDL_windowswindow.h"
#include "SDL_hints.h"

/* Dropfile support */
#include <shellapi.h>
Expand Down Expand Up @@ -74,22 +73,6 @@ GetWindowStyle(SDL_Window * window)
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)
{
Expand Down Expand Up @@ -371,7 +354,7 @@ WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
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;
Expand Down Expand Up @@ -423,7 +406,7 @@ WIN_RaiseWindow(_THIS, SDL_Window * window)
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;
Expand Down Expand Up @@ -484,7 +467,7 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
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;
Expand Down Expand Up @@ -577,7 +560,7 @@ WIN_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
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;
Expand Down

0 comments on commit 9a337c7

Please sign in to comment.