Skip to content

Commit

Permalink
Reset mouse state when changing video modes
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Aug 20, 2002
1 parent f7bae6d commit 484b4cc
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/events/SDL_events_c.h
Expand Up @@ -63,7 +63,7 @@ extern int SDL_PrivateQuit(void);
extern int SDL_PrivateSysWMEvent(SDL_SysWMmsg *message);

/* Used by the activity event handler to remove mouse focus */
extern void SDL_MouseFocus(int focus);
extern void SDL_ResetMouse(void);

/* Used by the activity event handler to remove keyboard focus */
extern void SDL_ResetKeyboard(void);
Expand Down
11 changes: 11 additions & 0 deletions src/events/SDL_mouse.c
Expand Up @@ -59,6 +59,17 @@ int SDL_MouseInit(void)
return(0);
}

/* We lost the mouse, so post button up messages for all pressed buttons */
void SDL_ResetMouse(void)
{
int i;
for ( i = 0; i < sizeof(SDL_ButtonState)*8; ++i ) {
if ( SDL_ButtonState & SDL_BUTTON(i) ) {
SDL_PrivateMouseButton(SDL_RELEASED, i, 0, 0);
}
}
}

Uint8 SDL_GetMouseState (int *x, int *y)
{
if ( x )
Expand Down
1 change: 1 addition & 0 deletions src/video/SDL_video.c
Expand Up @@ -607,6 +607,7 @@ SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)

/* Reset the keyboard here so event callbacks can run */
SDL_ResetKeyboard();
SDL_ResetMouse();

/* Clean up any previous video mode */
if ( SDL_PublicSurface != NULL ) {
Expand Down
69 changes: 36 additions & 33 deletions src/video/windx5/SDL_dx5events.c
Expand Up @@ -221,33 +221,6 @@ static int DX5_DInputInit(_THIS)
return(0);
}

/* Change cooperative level based on whether or not we are fullscreen */
void DX5_DInputReset(_THIS, int fullscreen)
{
DWORD level;
int i;
HRESULT result;

for ( i=0; i<MAX_INPUTS; ++i ) {
if ( SDL_DIdev[i] != NULL ) {
if ( fullscreen ) {
level = inputs[i].raw_level;
} else {
level = inputs[i].win_level;
}
IDirectInputDevice2_Unacquire(SDL_DIdev[i]);
result = IDirectInputDevice2_SetCooperativeLevel(
SDL_DIdev[i], SDL_Window, level);
IDirectInputDevice2_Acquire(SDL_DIdev[i]);
if ( result != DI_OK ) {
SetDIerror(
"DirectInputDevice::SetCooperativeLevel", result);
}
}
}
mouse_lost = 1;
}

/* Clean up DirectInput */
static void DX5_DInputQuit(_THIS)
{
Expand Down Expand Up @@ -396,10 +369,10 @@ static void handle_mouse(const int numevents, DIDEVICEOBJECTDATA *ptrbuf)
yrel = 0;
}
if((int)ptrbuf[i].dwData > 0)
button = 4;
button = SDL_BUTTON_WHEELUP;
else
button = 5;
posted = SDL_PrivateMouseButton(
button = SDL_BUTTON_WHEELDOWN;
posted = SDL_PrivateMouseButton(
SDL_PRESSED, button, 0, 0);
posted |= SDL_PrivateMouseButton(
SDL_RELEASED, button, 0, 0);
Expand Down Expand Up @@ -543,7 +516,7 @@ LONG
1 if there was input, 0 if there was no input, or -1 if the application has
posted a quit message.
*/
static int DX5_CheckInput(_THIS, int timeout)
static int DX5_CheckInput(_THIS, int timeout, BOOL processInput)
{
MSG msg;
int i;
Expand Down Expand Up @@ -602,7 +575,7 @@ static int DX5_CheckInput(_THIS, int timeout)
evtbuf, &numevents, 0);
}
/* Handle the events */
if ( result == DI_OK ) {
if ( result == DI_OK && processInput ) {
/* Note: This can post multiple events to event queue
*/
(*SDL_DIfun[event])((int)numevents, evtbuf);
Expand All @@ -623,10 +596,40 @@ static int DX5_CheckInput(_THIS, int timeout)
return(0);
}

/* Change cooperative level based on whether or not we are fullscreen */
void DX5_DInputReset(_THIS, int fullscreen)
{
DWORD level;
int i;
HRESULT result;

for ( i=0; i<MAX_INPUTS; ++i ) {
if ( SDL_DIdev[i] != NULL ) {
if ( fullscreen ) {
level = inputs[i].raw_level;
} else {
level = inputs[i].win_level;
}
IDirectInputDevice2_Unacquire(SDL_DIdev[i]);
result = IDirectInputDevice2_SetCooperativeLevel(
SDL_DIdev[i], SDL_Window, level);
IDirectInputDevice2_Acquire(SDL_DIdev[i]);
if ( result != DI_OK ) {
SetDIerror(
"DirectInputDevice::SetCooperativeLevel", result);
}
}
}
mouse_lost = 1;

/* Flush pending input */
DX5_CheckInput(this, 0, FALSE);
}

void DX5_PumpEvents(_THIS)
{
/* Wait for messages and DirectInput */
while ( DX5_CheckInput(this, 0) > 0 ) {
while ( DX5_CheckInput(this, 0, TRUE) > 0 ) {
/* Loop and check again */;
}
}
Expand Down

0 comments on commit 484b4cc

Please sign in to comment.