Skip to content

Commit

Permalink
Fixed bug 875 - Title bar unresponsive after video mode change
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slouken committed Dec 30, 2011
1 parent f222938 commit 1634e34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -573,6 +573,10 @@ static void SDL_CreateShadowSurface(int depth)
#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.
*/
Expand All @@ -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!
*/
Expand Down
11 changes: 6 additions & 5 deletions src/video/wincommon/SDL_sysevents.c
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 ) {
Expand Down

0 comments on commit 1634e34

Please sign in to comment.