Fixed bug #611 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Thu, 02 Apr 2009 04:43:36 +0000
branchSDL-1.2
changeset 4167a6f635e5eaa6
parent 4166 72a00fe65ffe
child 4168 69bcba65c388
Fixed bug #611

From Tim Angus 2008-08-12 11:18:06

I'm one of the maintainers of ioquake3.org, an updated version of the
Quake 3 engine. Relatively recently, we moved ioq3 to use SDL as a
replacement for 95% of the platform specific code that was there. On the
whole it's doing a great job but unfortunately since the move we've been
getting complaints about the quality of the mouse input on the Windows
platform to the point where for many the game is unplayable. Put in
other terms, the current stable SDL 1.2 is basically not fit for purpose
if you need high quality mouse input as you do in a first person shooter.

Over the weekend I decided to pull my finger out and actually figure out
what's going on. There are basically two major problems. Firstly, when
using the "windib" driver, mouse input is gathered via the WM_MOUSEMOVE
message. Googling for this indicates that often this is known to result
in "spurious" and/or "missing" mouse movement events; this is the
primary cause of the poor mouse input. The second problem is that the
"directx" driver does not work at all in combination with OpenGL meaning
that you can't use DirectInput if your application also uses OpenGL. In
other words you're locked into using the "windib" driver and its poor
mouse input.

In order to address these problems I've done the following:

* Remove WM_MOUSEMOVE based motion event generation and replace with
calls to GetCursorPos which seems much more reliable. In order to
achieve this I've moved mouse motion out into a separate function that
is called once per DIB_PumpEvents.

* Remove the restriction on the "directx" driver being inoperable in
combination with OpenGL. There is a bug for this issues that I've
hijacked to a certain extent
(http://bugzilla.libsdl.org/show_bug.cgi?id=265). I'm the first to admit
I don't really understand why this restriction is there in the first
place. The commit message for the bug fix that introduced this
restriction (r581) isn't very elaborate and I couldn't see any other bug
tracking the issue. If anyone has more information on the bug that was
avoided by r581 it would be helpful as I/someone could then look into
addressing the problem without disabling the "directx" driver.

* I've also removed the restriction on not being allowed to use
DirectInput in windowed mode. I couldn't see any reason for this, at
least not from our perspective. I have my suspicions that it'll be
something like matching up the cursor with the mouse coordinates...

* I bumped up the DirectInput API used to version 7 in order to get
access to mouse buttons 4-7. I've had to inject a little bit of the DX7
headers into SDL there as the MinGW ones aren't up to date in this respect.
configure.in
src/video/wincommon/SDL_lowvideo.h
src/video/wincommon/SDL_sysevents.c
src/video/wincommon/SDL_sysmouse.c
src/video/windib/SDL_dibevents.c
src/video/windx5/SDL_dx5events.c
src/video/windx5/directx.h
     1.1 --- a/configure.in	Thu Apr 02 04:09:40 2009 +0000
     1.2 +++ b/configure.in	Thu Apr 02 04:43:36 2009 +0000
     1.3 @@ -2470,7 +2470,7 @@
     1.4          # Set up the system libraries we need
     1.5          EXTRA_LDFLAGS="$EXTRA_LDFLAGS -luser32 -lgdi32 -lwinmm"
     1.6          if test x$have_directx = xyes; then
     1.7 -            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -ldxguid"
     1.8 +            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -ldxguid -ldinput8"
     1.9          fi
    1.10          # The Win32 platform requires special setup
    1.11          SOURCES="$SOURCES $srcdir/src/main/win32/*.rc"
     2.1 --- a/src/video/wincommon/SDL_lowvideo.h	Thu Apr 02 04:09:40 2009 +0000
     2.2 +++ b/src/video/wincommon/SDL_lowvideo.h	Thu Apr 02 04:43:36 2009 +0000
     2.3 @@ -51,10 +51,13 @@
     2.4  /* Hidden "this" pointer for the video functions */
     2.5  #define _THIS	SDL_VideoDevice *this
     2.6  
     2.7 +#define FULLSCREEN() \
     2.8 +	((SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
     2.9 +
    2.10  #define WINDIB_FULLSCREEN()						\
    2.11  (									\
    2.12  	SDL_VideoSurface &&						\
    2.13 -	((SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && \
    2.14 +	FULLSCREEN() && \
    2.15  	(((SDL_VideoSurface->flags & SDL_OPENGL   ) == SDL_OPENGL    ) || \
    2.16  	((SDL_strcmp(this->name, "windib") == 0) || \
    2.17  	 (SDL_strcmp(this->name, "gapi") == 0))) \
    2.18 @@ -62,12 +65,18 @@
    2.19  #define DDRAW_FULLSCREEN() 						\
    2.20  (									\
    2.21  	SDL_VideoSurface &&						\
    2.22 -	((SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && \
    2.23 +	FULLSCREEN() && \
    2.24  	((SDL_VideoSurface->flags & SDL_OPENGL    ) != SDL_OPENGL    ) && \
    2.25  	(SDL_strcmp(this->name, "directx") == 0)				\
    2.26  )
    2.27  
    2.28 -#define DINPUT_FULLSCREEN()	DDRAW_FULLSCREEN()
    2.29 +#define DINPUT_FULLSCREEN() 						\
    2.30 +(									\
    2.31 +	FULLSCREEN() && \
    2.32 +	(strcmp(this->name, "directx") == 0)				\
    2.33 +)
    2.34 +
    2.35 +#define DINPUT() (strcmp(this->name, "directx") == 0)
    2.36  
    2.37  /* The main window -- and a function to set it for the audio */
    2.38  #ifdef _WIN32_WCE
     3.1 --- a/src/video/wincommon/SDL_sysevents.c	Thu Apr 02 04:09:40 2009 +0000
     3.2 +++ b/src/video/wincommon/SDL_sysevents.c	Thu Apr 02 04:43:36 2009 +0000
     3.3 @@ -363,7 +363,6 @@
     3.4  {
     3.5  	SDL_VideoDevice *this = current_video;
     3.6  	static int mouse_pressed = 0;
     3.7 -	static int in_window = 0;
     3.8  #ifdef WMMSG_DEBUG
     3.9  	fprintf(stderr, "Received windows message:  ");
    3.10  	if ( msg > MAX_WMMSG ) {
    3.11 @@ -508,7 +507,7 @@
    3.12  		case WM_XBUTTONDOWN:
    3.13  		case WM_XBUTTONUP: {
    3.14  			/* Mouse is handled by DirectInput when fullscreen */
    3.15 -			if ( SDL_VideoSurface && ! DINPUT_FULLSCREEN() ) {
    3.16 +			if ( SDL_VideoSurface && ! DINPUT() ) {
    3.17  				WORD xbuttonval = 0;
    3.18  				Sint16 x, y;
    3.19  				Uint8 button, state;
    3.20 @@ -606,7 +605,7 @@
    3.21  
    3.22  #if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400)
    3.23  		case WM_MOUSEWHEEL: 
    3.24 -			if ( SDL_VideoSurface && ! DINPUT_FULLSCREEN() ) {
    3.25 +			if ( SDL_VideoSurface && ! DINPUT() ) {
    3.26  				int move = (short)HIWORD(wParam);
    3.27  				if ( move ) {
    3.28  					Uint8 button;
     4.1 --- a/src/video/wincommon/SDL_sysmouse.c	Thu Apr 02 04:09:40 2009 +0000
     4.2 +++ b/src/video/wincommon/SDL_sysmouse.c	Thu Apr 02 04:43:36 2009 +0000
     4.3 @@ -188,8 +188,7 @@
     4.4  {
     4.5  	POINT mouse_pos;
     4.6  
     4.7 -	/* The fullscreen cursor must be done in software with DirectInput */
     4.8 -	if ( !this->screen || DDRAW_FULLSCREEN() ) {
     4.9 +	if ( !this->screen ) {
    4.10  		return(0);
    4.11  	}
    4.12  
    4.13 @@ -208,15 +207,20 @@
    4.14  
    4.15  void WIN_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
    4.16  {
    4.17 -	if ( DDRAW_FULLSCREEN() ) {
    4.18 -		SDL_PrivateMouseMotion(0, 0, x, y);
    4.19 -	} else if ( mouse_relative) {
    4.20 +	if ( mouse_relative) {
    4.21  		/*	RJR: March 28, 2000
    4.22  			leave physical cursor at center of screen if
    4.23  			mouse hidden and grabbed */
    4.24  		SDL_PrivateMouseMotion(0, 0, x, y);
    4.25  	} else {
    4.26  		POINT pt;
    4.27 +
    4.28 +		/* With DirectInput the position doesn't follow
    4.29 +		 * the cursor, so it is set manually */
    4.30 +		if ( DINPUT() ) {
    4.31 +			SDL_PrivateMouseMotion(0, 0, x, y);
    4.32 +		}
    4.33 +
    4.34  		pt.x = x;
    4.35  		pt.y = y;
    4.36  		ClientToScreen(SDL_Window, &pt);
    4.37 @@ -227,20 +231,15 @@
    4.38  /* Update the current mouse state and position */
    4.39  void WIN_UpdateMouse(_THIS)
    4.40  {
    4.41 -	RECT rect;
    4.42  	POINT pt;
    4.43  
    4.44 -	if ( ! DDRAW_FULLSCREEN() ) {
    4.45 -		GetClientRect(SDL_Window, &rect);
    4.46 -		GetCursorPos(&pt);
    4.47 -		MapWindowPoints(NULL, SDL_Window, &pt, 1);
    4.48 -		if (PtInRect(&rect, pt) && (WindowFromPoint(pt) == SDL_Window)){
    4.49 -			SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
    4.50 -			SDL_PrivateMouseMotion(0,0, (Sint16)pt.x, (Sint16)pt.y);
    4.51 -		} else {
    4.52 -			SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
    4.53 -		}
    4.54 -	}
    4.55 +	/* Always unset SDL_APPMOUSEFOCUS to give the WM_MOUSEMOVE event
    4.56 +	 * handler a chance to install a TRACKMOUSEEVENT */
    4.57 +	SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
    4.58 +
    4.59 +	GetCursorPos(&pt);
    4.60 +	ScreenToClient(SDL_Window, &pt);
    4.61 +	SDL_PrivateMouseMotion(0,0, (Sint16)pt.x, (Sint16)pt.y);
    4.62  }
    4.63  
    4.64  /* Check to see if we need to enter or leave mouse relative mode */
     5.1 --- a/src/video/windib/SDL_dibevents.c	Thu Apr 02 04:09:40 2009 +0000
     5.2 +++ b/src/video/windib/SDL_dibevents.c	Thu Apr 02 04:43:36 2009 +0000
     5.3 @@ -271,6 +271,36 @@
     5.4  	return(DefWindowProc(hwnd, msg, wParam, lParam));
     5.5  }
     5.6  
     5.7 +static void DIB_GenerateMouseMotionEvent(void)
     5.8 +{
     5.9 +	extern int mouse_relative;
    5.10 +	extern int posted;
    5.11 +
    5.12 +	POINT mouse;
    5.13 +	GetCursorPos( &mouse );
    5.14 +
    5.15 +	if ( mouse_relative ) {
    5.16 +		POINT center;
    5.17 +		center.x = (SDL_VideoSurface->w/2);
    5.18 +		center.y = (SDL_VideoSurface->h/2);
    5.19 +		ClientToScreen(SDL_Window, &center);
    5.20 +
    5.21 +		mouse.x -= (Sint16)center.x;
    5.22 +		mouse.y -= (Sint16)center.y;
    5.23 +		if ( mouse.x || mouse.y ) {
    5.24 +			SetCursorPos(center.x, center.y);
    5.25 +			posted = SDL_PrivateMouseMotion(0, 1, mouse.x, mouse.y);
    5.26 +		}
    5.27 +	} else if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
    5.28 +		ScreenToClient(SDL_Window, &mouse);
    5.29 +#ifdef _WIN32_WCE
    5.30 +		if (SDL_VideoSurface)
    5.31 +			GapiTransform(this->hidden->userOrientation, this->hidden->hiresFix, &mouse.x, &mouse.y);
    5.32 +#endif
    5.33 +		posted = SDL_PrivateMouseMotion(0, 0, mouse.x, mouse.y);
    5.34 +	}
    5.35 +}
    5.36 +
    5.37  void DIB_PumpEvents(_THIS)
    5.38  {
    5.39  	MSG msg;
    5.40 @@ -280,6 +310,10 @@
    5.41  			DispatchMessage(&msg);
    5.42  		}
    5.43  	}
    5.44 +
    5.45 +	if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
    5.46 +		DIB_GenerateMouseMotionEvent( );
    5.47 +	}
    5.48  }
    5.49  
    5.50  static HKL hLayoutUS = NULL;
     6.1 --- a/src/video/windx5/SDL_dx5events.c	Thu Apr 02 04:09:40 2009 +0000
     6.2 +++ b/src/video/windx5/SDL_dx5events.c	Thu Apr 02 04:43:36 2009 +0000
     6.3 @@ -143,9 +143,14 @@
     6.4  		(DISCL_FOREGROUND|DISCL_NONEXCLUSIVE),
     6.5  		(DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), handle_keyboard },
     6.6  	{ "mouse",
     6.7 -		&GUID_SysMouse, &c_dfDIMouse,
     6.8 +		&GUID_SysMouse,
     6.9 +#if DIRECTINPUT_VERSION >= 0x700
    6.10 +		&c_dfDIMouse2,
    6.11 +#else
    6.12 +		&c_dfDIMouse,
    6.13 +#endif
    6.14  		(DISCL_FOREGROUND|DISCL_NONEXCLUSIVE),
    6.15 -		(DISCL_FOREGROUND|DISCL_EXCLUSIVE), handle_mouse },
    6.16 +		(DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), handle_mouse },
    6.17  	{ NULL, NULL, NULL, 0, 0, NULL }
    6.18  };
    6.19  	
    6.20 @@ -285,6 +290,76 @@
    6.21  		}
    6.22  	}
    6.23  }
    6.24 +
    6.25 +static void post_mouse_motion(int relative, Sint16 x, Sint16 y)
    6.26 +{
    6.27 +	extern int mouse_relative;
    6.28 +
    6.29 +	if ( SDL_GetAppState() & (SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS) ==
    6.30 +		(SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS) ) {
    6.31 +		posted = SDL_PrivateMouseMotion(
    6.32 +			0, relative, x, y);
    6.33 +
    6.34 +		if ( !mouse_relative ) {
    6.35 +			/* As DirectInput reads raw device coordinates, it has no notion of
    6.36 +			 * cursors or absolute position. We must assume responsibility for
    6.37 +			 * keeping track of this. */
    6.38 +			int current_x, current_y;
    6.39 +			POINT cursor;
    6.40 +			RECT trap;
    6.41 +			RECT window;
    6.42 +			int at_edge;
    6.43 +
    6.44 +			/* Get the current cursor position */
    6.45 +			SDL_GetMouseState(&current_x, &current_y);
    6.46 +			cursor.x = current_x;
    6.47 +			cursor.y = current_y;
    6.48 +			ClientToScreen(SDL_Window, &cursor);
    6.49 +
    6.50 +			/* Construct a 1 pixel square RECT that is used to confine the cursor
    6.51 +			 * pointer to a specific pixel using ClipCursor. This is used in
    6.52 +			 * preference to SetCursorPos as it avoids the cursor jumping around as
    6.53 +			 * both the OS and SDL attempt to move it simultaneously. */
    6.54 +			trap.left = cursor.x;
    6.55 +			trap.top = cursor.y;
    6.56 +			trap.right = cursor.x + 1;
    6.57 +			trap.bottom = cursor.y + 1;
    6.58 +
    6.59 +			GetClientRect(SDL_Window, &window);
    6.60 +			window.right -= window.left; window.left = 0;
    6.61 +			window.bottom -= window.top; window.top = 0;
    6.62 +
    6.63 +			/* As we're assuming control over the cursor, we need to know when to
    6.64 +			 * relinquish control of it back to the operating system. This is when
    6.65 +			 * the cursor reaches the edge of the window. */
    6.66 +			at_edge = (current_x == window.left) ||
    6.67 +				(current_x == (window.right - 1)) ||
    6.68 +				(current_y == window.top) ||
    6.69 +				(current_y == (window.bottom - 1));
    6.70 +
    6.71 +			if ( at_edge ) {
    6.72 +				ClipCursor(NULL);
    6.73 +			} else {
    6.74 +				ClipCursor(&trap);
    6.75 +			}
    6.76 +		} else {
    6.77 +			/* When in relative mode, warp the OS's idea of where the cursor is to
    6.78 +			 * the center of the screen. This isn't really necessary as DirectInput
    6.79 +			 * reads from the hardware itself, but in case things go wrong, the
    6.80 +			 * cursor will be left in a sensible place. */
    6.81 +			POINT center;
    6.82 +			center.x = (SDL_VideoSurface->w/2);
    6.83 +			center.y = (SDL_VideoSurface->h/2);
    6.84 +			ClientToScreen(SDL_Window, &center);
    6.85 +			SetCursorPos(center.x, center.y);
    6.86 +		}
    6.87 +	} else {
    6.88 +		/* No window or mouse focus, control is lost */
    6.89 +		mouse_lost = 1;
    6.90 +		ClipCursor(NULL);
    6.91 +	}
    6.92 +}
    6.93 +
    6.94  static void handle_mouse(const int numevents, DIDEVICEOBJECTDATA *ptrbuf)
    6.95  {
    6.96  	int i;
    6.97 @@ -298,14 +373,8 @@
    6.98  		return;
    6.99  	}
   6.100  
   6.101 -	/* If we are in windowed mode, Windows is taking care of the mouse */
   6.102 -	if (  (SDL_PublicSurface->flags & SDL_OPENGL) ||
   6.103 -	     !(SDL_PublicSurface->flags & SDL_FULLSCREEN) ) {
   6.104 -		return;
   6.105 -	}
   6.106 -
   6.107  	/* If the mouse was lost, regain some sense of mouse state */
   6.108 -	if ( mouse_lost ) {
   6.109 +	if ( mouse_lost && (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
   6.110  		POINT mouse_pos;
   6.111  		Uint8 old_state;
   6.112  		Uint8 new_state;
   6.113 @@ -313,14 +382,17 @@
   6.114  		/* Set ourselves up with the current cursor position */
   6.115  		GetCursorPos(&mouse_pos);
   6.116  		ScreenToClient(SDL_Window, &mouse_pos);
   6.117 -		posted = SDL_PrivateMouseMotion(0, 0,
   6.118 -				(Sint16)mouse_pos.x, (Sint16)mouse_pos.y);
   6.119 +		post_mouse_motion( 0, (Sint16)mouse_pos.x, (Sint16)mouse_pos.y);
   6.120  
   6.121  		/* Check for mouse button changes */
   6.122  		old_state = SDL_GetMouseState(NULL, NULL);
   6.123  		new_state = 0;
   6.124  		{ /* Get the new DirectInput button state for the mouse */
   6.125 +#if DIRECTINPUT_VERSION >= 0x700
   6.126 +			DIMOUSESTATE2 distate;
   6.127 +#else
   6.128  			DIMOUSESTATE distate;
   6.129 +#endif
   6.130  			HRESULT result;
   6.131  
   6.132  			result=IDirectInputDevice2_GetDeviceState(SDL_DIdev[1],
   6.133 @@ -341,14 +413,13 @@
   6.134  		for ( i=0; i<8; ++i ) {
   6.135  			if ( (old_state&0x01) != (new_state&0x01) ) {
   6.136  				button = (Uint8)(i+1);
   6.137 -				/* Button #2 on two button mice is button 3
   6.138 -				   (the middle button is button 2)
   6.139 -				 */
   6.140 -				if ( button == 2 ) {
   6.141 -					button = 3;
   6.142 -				} else
   6.143 -				if ( button == 3 ) {
   6.144 -					button = 2;
   6.145 +				/* Map DI button numbers to SDL */
   6.146 +				switch ( button ) {
   6.147 +					case 2: button = SDL_BUTTON_RIGHT; break;
   6.148 +					case 3: button = SDL_BUTTON_MIDDLE; break;
   6.149 +					case 4: button = SDL_BUTTON_X1; break;
   6.150 +					case 5: button = SDL_BUTTON_X2; break;
   6.151 +					default: break;
   6.152  				}
   6.153  				if ( new_state & 0x01 ) {
   6.154  					/* Grab mouse so we get mouse-up */
   6.155 @@ -387,8 +458,7 @@
   6.156  			case DIMOFS_X:
   6.157  				if ( timestamp != ptrbuf[i].dwTimeStamp ) {
   6.158  					if ( xrel || yrel ) {
   6.159 -						posted = SDL_PrivateMouseMotion(
   6.160 -								0, 1, xrel, yrel);
   6.161 +						post_mouse_motion(1, xrel, yrel);
   6.162  						xrel = 0;
   6.163  						yrel = 0;
   6.164  					}
   6.165 @@ -399,8 +469,7 @@
   6.166  			case DIMOFS_Y:
   6.167  				if ( timestamp != ptrbuf[i].dwTimeStamp ) {
   6.168  					if ( xrel || yrel ) {
   6.169 -						posted = SDL_PrivateMouseMotion(
   6.170 -								0, 1, xrel, yrel);
   6.171 +						post_mouse_motion(1, xrel, yrel);
   6.172  						xrel = 0;
   6.173  						yrel = 0;
   6.174  					}
   6.175 @@ -410,8 +479,7 @@
   6.176  				break;
   6.177  			case DIMOFS_Z:
   6.178  				if ( xrel || yrel ) {
   6.179 -					posted = SDL_PrivateMouseMotion(
   6.180 -							0, 1, xrel, yrel);
   6.181 +					post_mouse_motion(1, xrel, yrel);
   6.182  					xrel = 0;
   6.183  					yrel = 0;
   6.184  				}
   6.185 @@ -429,22 +497,26 @@
   6.186  			case DIMOFS_BUTTON1:
   6.187  			case DIMOFS_BUTTON2:
   6.188  			case DIMOFS_BUTTON3:
   6.189 +#if DIRECTINPUT_VERSION >= 0x700
   6.190 +			case DIMOFS_BUTTON4:
   6.191 +			case DIMOFS_BUTTON5:
   6.192 +			case DIMOFS_BUTTON6:
   6.193 +			case DIMOFS_BUTTON7:
   6.194 +#endif
   6.195  				if ( xrel || yrel ) {
   6.196 -					posted = SDL_PrivateMouseMotion(
   6.197 -							0, 1, xrel, yrel);
   6.198 +					post_mouse_motion(1, xrel, yrel);
   6.199  					xrel = 0;
   6.200  					yrel = 0;
   6.201  				}
   6.202  				timestamp = 0;
   6.203  				button = (Uint8)(ptrbuf[i].dwOfs-DIMOFS_BUTTON0)+1;
   6.204 -				/* Button #2 on two button mice is button 3
   6.205 -				   (the middle button is button 2)
   6.206 -				 */
   6.207 -				if ( button == 2 ) {
   6.208 -					button = 3;
   6.209 -				} else
   6.210 -				if ( button == 3 ) {
   6.211 -					button = 2;
   6.212 +				/* Map DI button numbers to SDL */
   6.213 +				switch ( button ) {
   6.214 +					case 2: button = SDL_BUTTON_RIGHT; break;
   6.215 +					case 3: button = SDL_BUTTON_MIDDLE; break;
   6.216 +					case 4: button = SDL_BUTTON_X1; break;
   6.217 +					case 5: button = SDL_BUTTON_X2; break;
   6.218 +					default: break;
   6.219  				}
   6.220  				if ( ptrbuf[i].dwData & 0x80 ) {
   6.221  					/* Grab mouse so we get mouse-up */
   6.222 @@ -471,7 +543,7 @@
   6.223  		}
   6.224  	}
   6.225  	if ( xrel || yrel ) {
   6.226 -		posted = SDL_PrivateMouseMotion( 0, 1, xrel, yrel);
   6.227 +		post_mouse_motion(1, xrel, yrel);
   6.228  	}
   6.229  }
   6.230  
     7.1 --- a/src/video/windx5/directx.h	Thu Apr 02 04:09:40 2009 +0000
     7.2 +++ b/src/video/windx5/directx.h	Thu Apr 02 04:43:36 2009 +0000
     7.3 @@ -72,7 +72,7 @@
     7.4  /* We need these defines to mark what version of DirectX API we use */
     7.5  #define DIRECTDRAW_VERSION  0x0700
     7.6  #define DIRECTSOUND_VERSION 0x0500
     7.7 -#define DIRECTINPUT_VERSION 0x0500
     7.8 +#define DIRECTINPUT_VERSION 0x0700
     7.9  
    7.10  #ifdef __GNUC__
    7.11  #define NONAMELESSUNION
    7.12 @@ -81,4 +81,20 @@
    7.13  #include <dsound.h>
    7.14  #include <dinput.h>
    7.15  
    7.16 +#if DIRECTINPUT_VERSION >= 0x0700 && !defined(DIMOFS_BUTTON4)
    7.17 +typedef struct _DIMOUSESTATE2 {
    7.18 +    LONG    lX;
    7.19 +    LONG    lY;
    7.20 +    LONG    lZ;
    7.21 +    BYTE    rgbButtons[8];
    7.22 +} DIMOUSESTATE2, *LPDIMOUSESTATE2;
    7.23 +
    7.24 +#define DIMOFS_BUTTON4 (FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + 4)
    7.25 +#define DIMOFS_BUTTON5 (FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + 5)
    7.26 +#define DIMOFS_BUTTON6 (FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + 6)
    7.27 +#define DIMOFS_BUTTON7 (FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + 7)
    7.28 +
    7.29 +extern const DIDATAFORMAT c_dfDIMouse2;
    7.30 +#endif
    7.31 +
    7.32  #endif /* _directx_h */