Fixed bug 875 - Title bar unresponsive after video mode change SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Fri, 30 Dec 2011 06:22:59 -0500
branchSDL-1.2
changeset 6125 760a3162e180
parent 6124 f56b95794ac8
child 6126 36f33f295c97
Fixed bug 875 - Title bar unresponsive after video mode change Gabriel Gambetta 2009-11-04 04:51:46 PST If you change the video mode while holding the mouse button down, and then click on the window, you can't move the mouse pointer over the title bar or the close window button. It turns out WinMessage in SDL_Sysevents.c is using a static int mouse_pressed to keep track of whether it should call SetCapture() and ReleaseCapture(). Since it's static and initialized only once, it isn't cleared when the video mode changed, so there's a kind of one-off error and SetCapture() and ReleaseCapture() aren't being called when they should. Here's a patch - I just made that int accessible from the outside and reset it to 0 in SDL_SetVideoMode, wrapped in #ifdef WIN32. Suggestions on how to make this more elegant are welcome.
src/video/SDL_video.c
src/video/wincommon/SDL_sysevents.c
--- a/src/video/SDL_video.c	Fri Dec 30 06:01:09 2011 -0500
+++ b/src/video/SDL_video.c	Fri Dec 30 06:22:59 2011 -0500
@@ -573,6 +573,10 @@
     #include <sys/neutrino.h>
 #endif /* __QNXNTO__ */
 
+#ifdef WIN32
+	extern int sysevents_mouse_pressed;
+#endif
+
 /*
  * Set the requested video mode, allocating a shadow buffer if necessary.
  */
@@ -586,6 +590,10 @@
 	int is_opengl;
 	SDL_GrabMode saved_grab;
 
+	#ifdef WIN32
+		sysevents_mouse_pressed = 0;
+	#endif
+
 	/* Start up the video driver, if necessary..
 	   WARNING: This is the only function protected this way!
 	 */
--- a/src/video/wincommon/SDL_sysevents.c	Fri Dec 30 06:01:09 2011 -0500
+++ b/src/video/wincommon/SDL_sysevents.c	Fri Dec 30 06:22:59 2011 -0500
@@ -243,13 +243,14 @@
 }
 #endif /* WM_MOUSELEAVE */
 
+int sysevents_mouse_pressed = 0;
+
 /* The main Win32 event handler
 DJM: This is no longer static as (DX5/DIB)_CreateWindow needs it
 */
 LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
-	SDL_VideoDevice *this = current_video;
-	static int mouse_pressed = 0;
+	SDL_VideoDevice *this = current_video;	
 #ifdef WMMSG_DEBUG
 	fprintf(stderr, "Received windows message:  ");
 	if ( msg > MAX_WMMSG ) {
@@ -426,14 +427,14 @@
 				}
 				if ( state == SDL_PRESSED ) {
 					/* Grab mouse so we get up events */
-					if ( ++mouse_pressed > 0 ) {
+					if ( ++sysevents_mouse_pressed > 0 ) {
 						SetCapture(hwnd);
 					}
 				} else {
 					/* Release mouse after all up events */
-					if ( --mouse_pressed <= 0 ) {
+					if ( --sysevents_mouse_pressed <= 0 ) {
 						ReleaseCapture();
-						mouse_pressed = 0;
+						sysevents_mouse_pressed = 0;
 					}
 				}
 				if ( mouse_relative ) {