From e9e25055f95c9be8110a5c6cda8002e20b7a9c47 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 30 Dec 2011 06:22:59 -0500 Subject: [PATCH] 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. --HG-- branch : SDL-1.2 --- src/video/SDL_video.c | 8 ++++++++ src/video/wincommon/SDL_sysevents.c | 11 ++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index ff63e99e3..24a499b5f 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -573,6 +573,10 @@ static void SDL_CreateShadowSurface(int depth) #include #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 @@ SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags) 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! */ diff --git a/src/video/wincommon/SDL_sysevents.c b/src/video/wincommon/SDL_sysevents.c index cd45f189e..5ce562bed 100644 --- a/src/video/wincommon/SDL_sysevents.c +++ b/src/video/wincommon/SDL_sysevents.c @@ -243,13 +243,14 @@ static BOOL WINAPI WIN_TrackMouseEvent(TRACKMOUSEEVENT *ptme) } #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 @@ LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } 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 ) {