Improvements from Alfred:
authorSam Lantinga <slouken@libsdl.org>
Mon, 31 Dec 2012 09:30:15 -0800
changeset 6782582d35419e8a
parent 6781 17a9b53a5ac3
child 6783 001f59dc43be
Improvements from Alfred:
- Added new SDL_HINT_ALLOW_TOPMOST hint, when set to "0" then never set the topmost bit on a window. Useful when debugging fullscreen issues.
- fixed crash in windows joystick scanning if we failed to load the xinput dll
- added support for SDL_WINDOW_FULLSCREEN_DESKTOP under windows
- synthesize relative mouse movements if directinput fails to send relative moves, happens under virtual box.
include/SDL_hints.h
src/joystick/windows/SDL_dxjoystick.c
src/render/direct3d/SDL_render_d3d.c
src/video/windows/SDL_windowsevents.c
src/video/windows/SDL_windowswindow.c
     1.1 --- a/include/SDL_hints.h	Sun Dec 30 19:05:50 2012 -0800
     1.2 +++ b/include/SDL_hints.h	Mon Dec 31 09:30:15 2012 -0800
     1.3 @@ -205,6 +205,18 @@
     1.4  
     1.5  
     1.6  /**
     1.7 + *  \brief If set to 0 then never set the top most bit on a SDL Window, even if the video mode expects it.
     1.8 + *		This is a debugging aid for developers and not expected to be used by end users. The default is "1"
     1.9 + *
    1.10 + *  This variable can be set to the following values:
    1.11 + *    "0"       - don't allow topmost
    1.12 + *    "1"       - allow topmost
    1.13 + */
    1.14 +#define SDL_HINT_ALLOW_TOPMOST "SDL_ALLOW_TOPMOST"
    1.15 +
    1.16 +
    1.17 +
    1.18 +/**
    1.19   *  \brief  An enumeration of hint priorities
    1.20   */
    1.21  typedef enum
     2.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Sun Dec 30 19:05:50 2012 -0800
     2.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Mon Dec 31 09:30:15 2012 -0800
     2.3 @@ -569,28 +569,30 @@
     2.4  			}
     2.5  		}
     2.6  
     2.7 -		// scan for any change in XInput devices
     2.8 -		for ( userId = 0; userId < 4; userId++ )
     2.9 +		if ( XINPUTGETCAPABILITIES )
    2.10  		{
    2.11 -			XINPUT_CAPABILITIES	capabilities;
    2.12 -			DWORD result;
    2.13 +			// scan for any change in XInput devices
    2.14 +			for ( userId = 0; userId < 4; userId++ )
    2.15 +			{
    2.16 +				XINPUT_CAPABILITIES	capabilities;
    2.17 +				DWORD result;
    2.18  
    2.19 -			if ( bOpenedXInputDevices[userId] == SDL_TRUE )
    2.20 -				nCurrentOpenedXInputDevices++;
    2.21 +				if ( bOpenedXInputDevices[userId] == SDL_TRUE )
    2.22 +					nCurrentOpenedXInputDevices++;
    2.23  
    2.24 -			result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities );
    2.25 -			if ( result == ERROR_SUCCESS )
    2.26 -			{
    2.27 -				bOpenedXInputDevices[userId] = SDL_TRUE;
    2.28 -				nNewOpenedXInputDevices++;
    2.29 -			}
    2.30 -			else
    2.31 -			{
    2.32 -				bOpenedXInputDevices[userId] = SDL_FALSE;
    2.33 +				result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities );
    2.34 +				if ( result == ERROR_SUCCESS )
    2.35 +				{
    2.36 +					bOpenedXInputDevices[userId] = SDL_TRUE;
    2.37 +					nNewOpenedXInputDevices++;
    2.38 +				}
    2.39 +				else
    2.40 +				{
    2.41 +					bOpenedXInputDevices[userId] = SDL_FALSE;
    2.42 +				}
    2.43  			}
    2.44  		}
    2.45  
    2.46 -
    2.47  		if ( s_pKnownJoystickGUIDs && ( s_bWindowsDeviceChanged || nNewOpenedXInputDevices != nCurrentOpenedXInputDevices ) )
    2.48  		{
    2.49  			SDL_Delay( 300 ); // wait for direct input to find out about this device
     3.1 --- a/src/render/direct3d/SDL_render_d3d.c	Sun Dec 30 19:05:50 2012 -0800
     3.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Mon Dec 31 09:30:15 2012 -0800
     3.3 @@ -538,9 +538,14 @@
     3.4      pparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
     3.5  
     3.6      if (window_flags & SDL_WINDOW_FULLSCREEN) {
     3.7 +		if ( ( window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP ) == SDL_WINDOW_FULLSCREEN_DESKTOP )  {
     3.8 +			pparams.Windowed = TRUE;
     3.9 +			pparams.FullScreen_RefreshRateInHz = 0;
    3.10 +		} else {
    3.11          pparams.Windowed = FALSE;
    3.12          pparams.FullScreen_RefreshRateInHz =
    3.13              fullscreen_mode.refresh_rate;
    3.14 +		}
    3.15      } else {
    3.16          pparams.Windowed = TRUE;
    3.17          pparams.FullScreen_RefreshRateInHz = 0;
     4.1 --- a/src/video/windows/SDL_windowsevents.c	Sun Dec 30 19:05:50 2012 -0800
     4.2 +++ b/src/video/windows/SDL_windowsevents.c	Mon Dec 31 09:30:15 2012 -0800
     4.3 @@ -221,6 +221,10 @@
     4.4  		HRAWINPUT hRawInput = (HRAWINPUT)lParam;
     4.5  		RAWINPUT inp;
     4.6  		UINT size = sizeof(inp);
     4.7 +
     4.8 +		if(!SDL_GetMouse()->relative_mode)
     4.9 +			break;
    4.10 +
    4.11  		GetRawInputData(hRawInput, RID_INPUT, &inp, &size, sizeof(RAWINPUTHEADER));
    4.12  
    4.13  		/* Mouse data */
    4.14 @@ -229,8 +233,24 @@
    4.15  			RAWMOUSE* mouse = &inp.data.mouse;
    4.16  
    4.17  			if((mouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE)
    4.18 +			{
    4.19  				SDL_SendMouseMotion(data->window, 1, (int)mouse->lLastX, (int)mouse->lLastY);
    4.20 +			}
    4.21 +			else
    4.22 +			{
    4.23 +				// synthesize relative moves from the abs position
    4.24 +				static SDL_Point initialMousePoint;
    4.25 +				if ( initialMousePoint.x == 0 && initialMousePoint.y == 0 )
    4.26 +				{
    4.27 +					initialMousePoint.x = mouse->lLastX;
    4.28 +					initialMousePoint.y = mouse->lLastY;
    4.29 +				}
    4.30  
    4.31 +				SDL_SendMouseMotion(data->window, 1, (int)(mouse->lLastX-initialMousePoint.x), (int)(mouse->lLastY-initialMousePoint.y) );
    4.32 +
    4.33 +				initialMousePoint.x = mouse->lLastX;
    4.34 +				initialMousePoint.y = mouse->lLastY;
    4.35 +			}
    4.36  		}
    4.37  		break;
    4.38  	}
     5.1 --- a/src/video/windows/SDL_windowswindow.c	Sun Dec 30 19:05:50 2012 -0800
     5.2 +++ b/src/video/windows/SDL_windowswindow.c	Mon Dec 31 09:30:15 2012 -0800
     5.3 @@ -28,6 +28,7 @@
     5.4  
     5.5  #include "SDL_windowsvideo.h"
     5.6  #include "SDL_windowswindow.h"
     5.7 +#include "SDL_hints.h"
     5.8  
     5.9  /* Dropfile support */
    5.10  #include <shellapi.h>
    5.11 @@ -73,6 +74,22 @@
    5.12      return style;
    5.13  }
    5.14  
    5.15 +static SDL_bool
    5.16 +ShouldAllowTopMost()
    5.17 +{
    5.18 +    const char *hint;
    5.19 +
    5.20 +    /* If the user has specified a software renderer we can't use a
    5.21 +       texture framebuffer, or renderer creation will go recursive.
    5.22 +     */
    5.23 +    hint = SDL_GetHint(SDL_HINT_ALLOW_TOPMOST);
    5.24 +    if (hint && hint[0] == '0' ) {
    5.25 +        return SDL_FALSE;
    5.26 +    }
    5.27 +
    5.28 +	return SDL_TRUE;
    5.29 +}
    5.30 +
    5.31  static int
    5.32  SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
    5.33  {
    5.34 @@ -354,8 +371,8 @@
    5.35      int w, h;
    5.36  
    5.37      /* Figure out what the window area will be */
    5.38 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
    5.39 -        top = HWND_TOPMOST;
    5.40 +    if ( ShouldAllowTopMost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
    5.41 +		top = HWND_TOPMOST;
    5.42      } else {
    5.43          top = HWND_NOTOPMOST;
    5.44      }
    5.45 @@ -406,11 +423,11 @@
    5.46      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
    5.47      HWND top;
    5.48  
    5.49 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
    5.50 -        top = HWND_TOPMOST;
    5.51 -    } else {
    5.52 -        top = HWND_NOTOPMOST;
    5.53 -    }
    5.54 +	if ( ShouldAllowTopMost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
    5.55 +		top = HWND_TOPMOST;
    5.56 +	} else {
    5.57 +		top = HWND_NOTOPMOST;
    5.58 +	}
    5.59      SetWindowPos(hwnd, top, 0, 0, 0, 0, (SWP_NOMOVE | SWP_NOSIZE));
    5.60  }
    5.61  
    5.62 @@ -467,11 +484,12 @@
    5.63      int x, y;
    5.64      int w, h;
    5.65  
    5.66 -    if (fullscreen) {
    5.67 -        top = HWND_TOPMOST;
    5.68 -    } else {
    5.69 -        top = HWND_NOTOPMOST;
    5.70 -    }
    5.71 +	if ( ShouldAllowTopMost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS )) {
    5.72 +		top = HWND_TOPMOST;
    5.73 +	} else {
    5.74 +		top = HWND_NOTOPMOST;
    5.75 +	}
    5.76 +
    5.77      style = GetWindowLong(hwnd, GWL_STYLE);
    5.78      style &= ~STYLE_MASK;
    5.79      style |= GetWindowStyle(window);
    5.80 @@ -551,6 +569,23 @@
    5.81      } else {
    5.82          ClipCursor(NULL);
    5.83      }
    5.84 +
    5.85 +	if ( window->flags & SDL_WINDOW_FULLSCREEN )
    5.86 +	{
    5.87 +		HWND top;
    5.88 +		SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    5.89 +		HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
    5.90 +		UINT flags = SWP_NOMOVE | SWP_NOSIZE;
    5.91 +
    5.92 +		if ( ShouldAllowTopMost() && (window->flags & SDL_WINDOW_INPUT_FOCUS ) ) {
    5.93 +			top = HWND_TOPMOST;
    5.94 +		} else {
    5.95 +			top = HWND_NOTOPMOST;
    5.96 +			flags |= SWP_NOZORDER;
    5.97 +		}
    5.98 +		
    5.99 +		SetWindowPos(hwnd, top, 0, 0, 0, 0, flags);
   5.100 +	}
   5.101  }
   5.102  
   5.103  void