From e173d576f219f8844d310b9c8f2f27afcb6c3d2f Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 26 May 2003 01:47:57 +0000 Subject: [PATCH] Use mySDL_EventState. Set up event types in the ctor. Restore event masks when we change modes. It's vital that we not do this incorrectly. Resetting the video system resets the mask. If we have events that are enabled that we don't actually monitor, it'll just stay in the event queue and eventually fill it. Re-fix alt-enter causing both keys to "stick". --- .../LowLevelWindow/LowLevelWindow_SDL.cpp | 74 +++++++++++++------ 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/stepmania/src/arch/LowLevelWindow/LowLevelWindow_SDL.cpp b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_SDL.cpp index 601383878e..1a75109595 100644 --- a/stepmania/src/arch/LowLevelWindow/LowLevelWindow_SDL.cpp +++ b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_SDL.cpp @@ -8,25 +8,6 @@ LowLevelWindow_SDL::LowLevelWindow_SDL() { - Windowed = false; -} - -LowLevelWindow_SDL::~LowLevelWindow_SDL() -{ - SDL_QuitSubSystem(SDL_INIT_VIDEO); - SDL_EventState(SDL_VIDEORESIZE, SDL_IGNORE); - SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE); -} - -void *LowLevelWindow_SDL::GetProcAddress(CString s) -{ - return SDL_GL_GetProcAddress(s); -} - -bool LowLevelWindow_SDL::SetVideoMode( bool windowed, int width, int height, int bpp, int rate, bool vsync, CString sWindowTitle, CString sIconFile ) -{ - SDL_QuitSubSystem(SDL_INIT_VIDEO); - /* By default, ignore all SDL events. We'll enable them as we need them. * We must not enable any events we don't actually want, since we won't * query for them and they'll fill up the event queue. @@ -38,8 +19,59 @@ bool LowLevelWindow_SDL::SetVideoMode( bool windowed, int width, int height, int SDL_EventState(SDL_VIDEORESIZE, SDL_ENABLE); SDL_EventState(SDL_ACTIVEEVENT, SDL_ENABLE); + Windowed = false; +} + +LowLevelWindow_SDL::~LowLevelWindow_SDL() +{ + SDL_QuitSubSystem(SDL_INIT_VIDEO); + mySDL_EventState(SDL_VIDEORESIZE, SDL_IGNORE); + mySDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE); +} + +void *LowLevelWindow_SDL::GetProcAddress(CString s) +{ + return SDL_GL_GetProcAddress(s); +} + +bool LowLevelWindow_SDL::SetVideoMode( bool windowed, int width, int height, int bpp, int rate, bool vsync, CString sWindowTitle, CString sIconFile ) +{ + /* We need to preserve the event mask and all events, since they're lost by + * SDL_QuitSubSystem(SDL_INIT_VIDEO). */ + vector events; + mySDL_GetAllEvents(events); + Uint8 EventEnabled[SDL_NUMEVENTS]; + + /* Queue up key-up events for all keys that are currently down (eg. alt-enter). + * This is normally done by SDL, but since we're shutting down the video system + * we're also shutting down the event system. */ + { + const Uint8 *KeyState = SDL_GetKeyState(NULL); + for ( SDLKey key=SDLK_FIRST; keyTrace("up %i", key); + } + } + + int i; + for( i = 0; i < SDL_NUMEVENTS; ++i) + EventEnabled[i] = mySDL_EventState( (Uint8) i, SDL_QUERY ); + + SDL_QuitSubSystem(SDL_INIT_VIDEO); SDL_InitSubSystem(SDL_INIT_VIDEO); + /* Put them back. */ + for( int i = 0; i < SDL_NUMEVENTS; ++i) + mySDL_EventState((Uint8) i, EventEnabled[i]); + mySDL_PushEvents(events); + /* Set SDL window title and icon -before- creating the window */ SDL_WM_SetCaption(sWindowTitle, ""); mySDL_WM_SetIcon( sIconFile ); @@ -79,7 +111,7 @@ bool LowLevelWindow_SDL::SetVideoMode( bool windowed, int width, int height, int #endif #if defined(WIN32) -// SDL_EventState(SDL_OPENGLRESET, SDL_ENABLE); +// mySDL_EventState(SDL_OPENGLRESET, SDL_ENABLE); #endif SDL_Surface *screen = SDL_SetVideoMode(width, height, bpp, flags); @@ -102,7 +134,7 @@ bool LowLevelWindow_SDL::SetVideoMode( bool windowed, int width, int height, int SDL_WM_SetCaption("StepMania", "StepMania"); -// SDL_EventState(SDL_OPENGLRESET, SDL_IGNORE); +// mySDL_EventState(SDL_OPENGLRESET, SDL_IGNORE); #endif {