Improvements from Alfred:

- Add new SDL_WINDOW_FULLSCREEN_DESKTOP video mode, makes a fullscreen window the size of the desktop (i.e no window manager mode change)
- Fix crash in warp mouse if you specified null as the window
- Added new SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS Hint, if set to 0 then don't minimize a fullscreen window on focus lost (if not set or set to non-zero then minimize on focus loss)
This commit is contained in:
Sam Lantinga 2012-12-15 00:30:17 +00:00
parent 29bfd0ab48
commit dfe7f2bc59
6 changed files with 74 additions and 13 deletions

View file

@ -163,6 +163,13 @@ extern "C" {
*/ */
#define SDL_HINT_GRAB_KEYBOARD "SDL_GRAB_KEYBOARD" #define SDL_HINT_GRAB_KEYBOARD "SDL_GRAB_KEYBOARD"
/**
* \brief Minimize your SDL_Window if it loses key focus when in Fullscreen mode. Defaults to true.
*
*/
#define SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS"
/** /**
* \brief A variable controlling whether the idle timer is disabled on iOS. * \brief A variable controlling whether the idle timer is disabled on iOS.
* *

View file

@ -108,6 +108,7 @@ typedef enum
SDL_WINDOW_INPUT_GRABBED = 0x00000100, /**< window has grabbed input focus */ SDL_WINDOW_INPUT_GRABBED = 0x00000100, /**< window has grabbed input focus */
SDL_WINDOW_INPUT_FOCUS = 0x00000200, /**< window has input focus */ SDL_WINDOW_INPUT_FOCUS = 0x00000200, /**< window has input focus */
SDL_WINDOW_MOUSE_FOCUS = 0x00000400, /**< window has mouse focus */ SDL_WINDOW_MOUSE_FOCUS = 0x00000400, /**< window has mouse focus */
SDL_WINDOW_FULLSCREEN_DESKTOP = ( SDL_WINDOW_FULLSCREEN | 0x00001000 ),
SDL_WINDOW_FOREIGN = 0x00000800 /**< window not created by SDL */ SDL_WINDOW_FOREIGN = 0x00000800 /**< window not created by SDL */
} SDL_WindowFlags; } SDL_WindowFlags;
@ -604,7 +605,7 @@ extern DECLSPEC void SDLCALL SDL_RestoreWindow(SDL_Window * window);
* \sa SDL_GetWindowDisplayMode() * \sa SDL_GetWindowDisplayMode()
*/ */
extern DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_Window * window, extern DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_Window * window,
SDL_bool fullscreen); Uint32 flags);
/** /**
* \brief Get the SDL surface associated with the window. * \brief Get the SDL surface associated with the window.

View file

@ -380,6 +380,12 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
{ {
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
if ( window == NULL )
window = mouse->focus;
if ( window == NULL )
return;
if (mouse->WarpMouse) { if (mouse->WarpMouse) {
mouse->WarpMouse(window, x, y); mouse->WarpMouse(window, x, y);
} else { } else {

View file

@ -1001,6 +1001,7 @@ int
SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode) SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode)
{ {
SDL_DisplayMode fullscreen_mode; SDL_DisplayMode fullscreen_mode;
SDL_VideoDisplay *display;
CHECK_WINDOW_MAGIC(window, -1); CHECK_WINDOW_MAGIC(window, -1);
@ -1012,7 +1013,14 @@ SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode)
fullscreen_mode.h = window->h; fullscreen_mode.h = window->h;
} }
if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window), display = SDL_GetDisplayForWindow(window);
/* if in desktop size mode, just return the size of the desktop */
if ( ( window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP ) == SDL_WINDOW_FULLSCREEN_DESKTOP )
{
fullscreen_mode = display->desktop_mode;
}
else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window),
&fullscreen_mode, &fullscreen_mode,
&fullscreen_mode)) { &fullscreen_mode)) {
SDL_SetError("Couldn't find display mode match"); SDL_SetError("Couldn't find display mode match");
@ -1087,7 +1095,13 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
resized = SDL_FALSE; resized = SDL_FALSE;
} }
/* only do the mode change if we want exclusive fullscreen */
if ( ( window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP ) != SDL_WINDOW_FULLSCREEN_DESKTOP )
SDL_SetDisplayModeForDisplay(display, &fullscreen_mode); SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
else
SDL_SetDisplayModeForDisplay(display, NULL);
if (_this->SetWindowFullscreen) { if (_this->SetWindowFullscreen) {
_this->SetWindowFullscreen(_this, other, display, SDL_TRUE); _this->SetWindowFullscreen(_this, other, display, SDL_TRUE);
} }
@ -1140,7 +1154,7 @@ SDL_FinishWindowCreation(SDL_Window *window, Uint32 flags)
SDL_MinimizeWindow(window); SDL_MinimizeWindow(window);
} }
if (flags & SDL_WINDOW_FULLSCREEN) { if (flags & SDL_WINDOW_FULLSCREEN) {
SDL_SetWindowFullscreen(window, SDL_TRUE); SDL_SetWindowFullscreen(window, flags);
} }
if (flags & SDL_WINDOW_INPUT_GRABBED) { if (flags & SDL_WINDOW_INPUT_GRABBED) {
SDL_SetWindowGrab(window, SDL_TRUE); SDL_SetWindowGrab(window, SDL_TRUE);
@ -1696,19 +1710,22 @@ SDL_RestoreWindow(SDL_Window * window)
} }
} }
#define FULLSCREEN_MASK ( SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN )
int int
SDL_SetWindowFullscreen(SDL_Window * window, SDL_bool fullscreen) SDL_SetWindowFullscreen(SDL_Window * window, Uint32 flags)
{ {
CHECK_WINDOW_MAGIC(window, -1); CHECK_WINDOW_MAGIC(window, -1);
if (!!fullscreen == !!(window->flags & SDL_WINDOW_FULLSCREEN)) { flags &= FULLSCREEN_MASK;
if ( flags == (window->flags & FULLSCREEN_MASK) ) {
return 0; return 0;
} }
if (fullscreen) {
window->flags |= SDL_WINDOW_FULLSCREEN; /* clear the previous flags and OR in the new ones */
} else { window->flags &= ~FULLSCREEN_MASK;
window->flags &= ~SDL_WINDOW_FULLSCREEN; window->flags |= flags;
}
SDL_UpdateFullscreenMode(window, FULLSCREEN_VISIBLE(window)); SDL_UpdateFullscreenMode(window, FULLSCREEN_VISIBLE(window));
return 0; return 0;
@ -1973,6 +1990,19 @@ SDL_OnWindowFocusGained(SDL_Window * window)
SDL_UpdateWindowGrab(window); SDL_UpdateWindowGrab(window);
} }
static SDL_bool ShouldMinimizeOnFocusLoss()
{
const char *hint = SDL_GetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS);
if (hint) {
if (*hint == '0') {
return SDL_FALSE;
} else {
return SDL_TRUE;
}
}
return SDL_TRUE;
}
void void
SDL_OnWindowFocusLost(SDL_Window * window) SDL_OnWindowFocusLost(SDL_Window * window)
{ {
@ -1983,7 +2013,7 @@ SDL_OnWindowFocusLost(SDL_Window * window)
SDL_UpdateWindowGrab(window); SDL_UpdateWindowGrab(window);
/* If we're fullscreen on a single-head system and lose focus, minimize */ /* If we're fullscreen on a single-head system and lose focus, minimize */
if ((window->flags & SDL_WINDOW_FULLSCREEN) && _this->num_displays == 1) { if ((window->flags & SDL_WINDOW_FULLSCREEN) && ShouldMinimizeOnFocusLoss() ) {
SDL_MinimizeWindow(window); SDL_MinimizeWindow(window);
} }
} }

View file

@ -996,6 +996,23 @@ Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
cgpoint.y = window->y + y; cgpoint.y = window->y + y;
CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint); CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
} }
if ( window->flags & SDL_WINDOW_FULLSCREEN )
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if (window->flags & SDL_WINDOW_INPUT_FOCUS)
{
/* OpenGL is rendering to the window, so make it visible! */
[data->nswindow setLevel:CGShieldingWindowLevel()];
}
else
{
[data->nswindow setLevel:kCGNormalWindowLevel];
}
}
} }
void void

0
test/automated/surface/surface.c Executable file → Normal file
View file