Improvements from Alfred:
authorSam Lantinga <slouken@libsdl.org>
Sat, 15 Dec 2012 00:30:17 +0000
changeset 6755af77e1a6faf0
parent 6754 c8cbb53af33e
child 6756 398073b195bb
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)
include/SDL_hints.h
include/SDL_video.h
src/events/SDL_mouse.c
src/video/SDL_video.c
src/video/cocoa/SDL_cocoawindow.m
test/automated/surface/surface.c
     1.1 --- a/include/SDL_hints.h	Fri Dec 14 18:50:07 2012 +0000
     1.2 +++ b/include/SDL_hints.h	Sat Dec 15 00:30:17 2012 +0000
     1.3 @@ -164,6 +164,13 @@
     1.4  #define SDL_HINT_GRAB_KEYBOARD              "SDL_GRAB_KEYBOARD"
     1.5  
     1.6  /**
     1.7 + *  \brief Minimize your SDL_Window if it loses key focus when in Fullscreen mode. Defaults to true.
     1.8 + *
     1.9 + */
    1.10 +#define SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS   "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS"
    1.11 +
    1.12 +	
    1.13 +/**
    1.14   *  \brief  A variable controlling whether the idle timer is disabled on iOS.
    1.15   *
    1.16   *  When an iOS app does not receive touches for some time, the screen is
     2.1 --- a/include/SDL_video.h	Fri Dec 14 18:50:07 2012 +0000
     2.2 +++ b/include/SDL_video.h	Sat Dec 15 00:30:17 2012 +0000
     2.3 @@ -108,6 +108,7 @@
     2.4      SDL_WINDOW_INPUT_GRABBED = 0x00000100,      /**< window has grabbed input focus */
     2.5      SDL_WINDOW_INPUT_FOCUS = 0x00000200,        /**< window has input focus */
     2.6      SDL_WINDOW_MOUSE_FOCUS = 0x00000400,        /**< window has mouse focus */
     2.7 +	SDL_WINDOW_FULLSCREEN_DESKTOP = ( SDL_WINDOW_FULLSCREEN | 0x00001000 ),
     2.8      SDL_WINDOW_FOREIGN = 0x00000800             /**< window not created by SDL */
     2.9  } SDL_WindowFlags;
    2.10  
    2.11 @@ -604,7 +605,7 @@
    2.12   *  \sa SDL_GetWindowDisplayMode()
    2.13   */
    2.14  extern DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_Window * window,
    2.15 -                                                    SDL_bool fullscreen);
    2.16 +                                                    Uint32 flags);
    2.17  
    2.18  /**
    2.19   *  \brief Get the SDL surface associated with the window.
     3.1 --- a/src/events/SDL_mouse.c	Fri Dec 14 18:50:07 2012 +0000
     3.2 +++ b/src/events/SDL_mouse.c	Sat Dec 15 00:30:17 2012 +0000
     3.3 @@ -379,6 +379,12 @@
     3.4  SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
     3.5  {
     3.6      SDL_Mouse *mouse = SDL_GetMouse();
     3.7 +	
     3.8 +	if ( window == NULL )
     3.9 +		window = mouse->focus;
    3.10 +	
    3.11 +	if ( window == NULL )
    3.12 +		return;
    3.13  
    3.14      if (mouse->WarpMouse) {
    3.15          mouse->WarpMouse(window, x, y);
     4.1 --- a/src/video/SDL_video.c	Fri Dec 14 18:50:07 2012 +0000
     4.2 +++ b/src/video/SDL_video.c	Sat Dec 15 00:30:17 2012 +0000
     4.3 @@ -1001,6 +1001,7 @@
     4.4  SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode)
     4.5  {
     4.6      SDL_DisplayMode fullscreen_mode;
     4.7 +	SDL_VideoDisplay *display;
     4.8  
     4.9      CHECK_WINDOW_MAGIC(window, -1);
    4.10  
    4.11 @@ -1011,8 +1012,15 @@
    4.12      if (!fullscreen_mode.h) {
    4.13          fullscreen_mode.h = window->h;
    4.14      }
    4.15 -
    4.16 -    if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window),
    4.17 +	
    4.18 +	display = SDL_GetDisplayForWindow(window);
    4.19 +
    4.20 +	/* if in desktop size mode, just return the size of the desktop */
    4.21 +	if ( ( window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP ) == SDL_WINDOW_FULLSCREEN_DESKTOP ) 
    4.22 +	{
    4.23 +		fullscreen_mode = display->desktop_mode;
    4.24 +	}
    4.25 +	else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window),
    4.26                                               &fullscreen_mode,
    4.27                                               &fullscreen_mode)) {
    4.28          SDL_SetError("Couldn't find display mode match");
    4.29 @@ -1087,7 +1095,13 @@
    4.30                      resized = SDL_FALSE;
    4.31                  }
    4.32  
    4.33 -                SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
    4.34 +				/* only do the mode change if we want exclusive fullscreen */
    4.35 +				if ( ( window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP ) != SDL_WINDOW_FULLSCREEN_DESKTOP ) 
    4.36 +					SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
    4.37 +				else
    4.38 +					SDL_SetDisplayModeForDisplay(display, NULL);
    4.39 +
    4.40 +				
    4.41                  if (_this->SetWindowFullscreen) {
    4.42                      _this->SetWindowFullscreen(_this, other, display, SDL_TRUE);
    4.43                  }
    4.44 @@ -1140,7 +1154,7 @@
    4.45          SDL_MinimizeWindow(window);
    4.46      }
    4.47      if (flags & SDL_WINDOW_FULLSCREEN) {
    4.48 -        SDL_SetWindowFullscreen(window, SDL_TRUE);
    4.49 +        SDL_SetWindowFullscreen(window, flags);
    4.50      }
    4.51      if (flags & SDL_WINDOW_INPUT_GRABBED) {
    4.52          SDL_SetWindowGrab(window, SDL_TRUE);
    4.53 @@ -1696,19 +1710,22 @@
    4.54      }
    4.55  }
    4.56  
    4.57 +#define FULLSCREEN_MASK ( SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN )
    4.58  int
    4.59 -SDL_SetWindowFullscreen(SDL_Window * window, SDL_bool fullscreen)
    4.60 +SDL_SetWindowFullscreen(SDL_Window * window, Uint32 flags)
    4.61  {
    4.62      CHECK_WINDOW_MAGIC(window, -1);
    4.63  
    4.64 -    if (!!fullscreen == !!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    4.65 +	flags &= FULLSCREEN_MASK;
    4.66 +	
    4.67 +    if ( flags == (window->flags & FULLSCREEN_MASK) ) {
    4.68          return 0;
    4.69      }
    4.70 -    if (fullscreen) {
    4.71 -        window->flags |= SDL_WINDOW_FULLSCREEN;
    4.72 -    } else {
    4.73 -        window->flags &= ~SDL_WINDOW_FULLSCREEN;
    4.74 -    }
    4.75 +	
    4.76 +	/* clear the previous flags and OR in the new ones */
    4.77 +	window->flags &= ~FULLSCREEN_MASK;
    4.78 +    window->flags |= flags;
    4.79 +
    4.80      SDL_UpdateFullscreenMode(window, FULLSCREEN_VISIBLE(window));
    4.81  
    4.82      return 0;
    4.83 @@ -1973,6 +1990,19 @@
    4.84      SDL_UpdateWindowGrab(window);
    4.85  }
    4.86  
    4.87 +static SDL_bool ShouldMinimizeOnFocusLoss()
    4.88 +{
    4.89 +	const char *hint = SDL_GetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS);
    4.90 +	if (hint) {
    4.91 +		if (*hint == '0') {
    4.92 +			return SDL_FALSE;
    4.93 +		} else {
    4.94 +			return SDL_TRUE;
    4.95 +		}
    4.96 +	}
    4.97 +	return SDL_TRUE;
    4.98 +}
    4.99 +
   4.100  void
   4.101  SDL_OnWindowFocusLost(SDL_Window * window)
   4.102  {
   4.103 @@ -1983,8 +2013,8 @@
   4.104      SDL_UpdateWindowGrab(window);
   4.105  
   4.106      /* If we're fullscreen on a single-head system and lose focus, minimize */
   4.107 -    if ((window->flags & SDL_WINDOW_FULLSCREEN) && _this->num_displays == 1) {
   4.108 -        SDL_MinimizeWindow(window);
   4.109 +	 if ((window->flags & SDL_WINDOW_FULLSCREEN) && ShouldMinimizeOnFocusLoss() ) {
   4.110 +			SDL_MinimizeWindow(window);
   4.111      }
   4.112  }
   4.113  
     5.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Fri Dec 14 18:50:07 2012 +0000
     5.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sat Dec 15 00:30:17 2012 +0000
     5.3 @@ -996,6 +996,23 @@
     5.4          cgpoint.y = window->y + y;
     5.5          CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
     5.6      }
     5.7 +	
     5.8 +    if ( window->flags & SDL_WINDOW_FULLSCREEN )
     5.9 +	{
    5.10 +		SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    5.11 +
    5.12 +		if (window->flags & SDL_WINDOW_INPUT_FOCUS)
    5.13 +		{
    5.14 +			/* OpenGL is rendering to the window, so make it visible! */
    5.15 +			[data->nswindow setLevel:CGShieldingWindowLevel()];
    5.16 +		} 
    5.17 +		else 
    5.18 +		{
    5.19 +			[data->nswindow setLevel:kCGNormalWindowLevel];
    5.20 +		}
    5.21 +		
    5.22 +	}
    5.23 +
    5.24  }
    5.25  
    5.26  void