bool CWinEventsSDL::MessagePump() { SDL_Event event; bool ret = false; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: if (!g_application.m_bStop) CApplicationMessenger::Get().Quit(); break; #ifdef HAS_SDL_JOYSTICK case SDL_JOYBUTTONUP: case SDL_JOYBUTTONDOWN: case SDL_JOYAXISMOTION: case SDL_JOYBALLMOTION: case SDL_JOYHATMOTION: g_Joystick.Update(event); ret = true; break; #endif case SDL_ACTIVEEVENT: //If the window was inconified or restored if( event.active.state & SDL_APPACTIVE ) { g_application.m_AppActive = event.active.gain != 0; g_Windowing.NotifyAppActiveChange(g_application.m_AppActive); } else if (event.active.state & SDL_APPINPUTFOCUS) { g_application.m_AppFocused = event.active.gain != 0; g_Windowing.NotifyAppFocusChange(g_application.m_AppFocused); } break; case SDL_KEYDOWN: { // process any platform specific shortcuts before handing off to XBMC #ifdef __APPLE__ if (ProcessOSXShortcuts(event)) { ret = true; break; } #endif XBMC_Event newEvent; newEvent.type = XBMC_KEYDOWN; newEvent.key.keysym.scancode = event.key.keysym.scancode; newEvent.key.keysym.sym = (XBMCKey) event.key.keysym.sym; newEvent.key.keysym.unicode = event.key.keysym.unicode; newEvent.key.state = event.key.state; newEvent.key.type = event.key.type; newEvent.key.which = event.key.which; // Check if the Windows keys are down because SDL doesn't flag this. uint16_t mod = event.key.keysym.mod; uint8_t* keystate = SDL_GetKeyState(NULL); if (keystate[SDLK_LSUPER] || keystate[SDLK_RSUPER]) mod |= XBMCKMOD_LSUPER; newEvent.key.keysym.mod = (XBMCMod) mod; #if defined(_LINUX) && !defined(__APPLE__) // If the keysym.sym is zero try to get it from the scan code if (newEvent.key.keysym.sym == 0) newEvent.key.keysym.sym = (XBMCKey) SymFromScancode(newEvent.key.keysym.scancode); #endif // don't handle any more messages in the queue until we've handled keydown, // if a keyup is in the queue it will reset the keypress before it is handled. ret |= g_application.OnEvent(newEvent); break; } case SDL_KEYUP: { XBMC_Event newEvent; newEvent.type = XBMC_KEYUP; newEvent.key.keysym.scancode = event.key.keysym.scancode; newEvent.key.keysym.sym = (XBMCKey) event.key.keysym.sym; newEvent.key.keysym.mod =(XBMCMod) event.key.keysym.mod; newEvent.key.keysym.unicode = event.key.keysym.unicode; newEvent.key.state = event.key.state; newEvent.key.type = event.key.type; newEvent.key.which = event.key.which; ret |= g_application.OnEvent(newEvent); break; } case SDL_MOUSEBUTTONDOWN: { XBMC_Event newEvent; newEvent.type = XBMC_MOUSEBUTTONDOWN; newEvent.button.button = event.button.button; newEvent.button.state = event.button.state; newEvent.button.type = event.button.type; newEvent.button.which = event.button.which; newEvent.button.x = event.button.x; newEvent.button.y = event.button.y; ret |= g_application.OnEvent(newEvent); break; } case SDL_MOUSEBUTTONUP: { XBMC_Event newEvent; newEvent.type = XBMC_MOUSEBUTTONUP; newEvent.button.button = event.button.button; newEvent.button.state = event.button.state; newEvent.button.type = event.button.type; newEvent.button.which = event.button.which; newEvent.button.x = event.button.x; newEvent.button.y = event.button.y; ret |= g_application.OnEvent(newEvent); break; } case SDL_MOUSEMOTION: { if (0 == (SDL_GetAppState() & SDL_APPMOUSEFOCUS)) { g_Mouse.SetActive(false); #if defined(__APPLE__) // See CApplication::ProcessSlow() for a description as to why we call Cocoa_HideMouse. // this is here to restore the pointer when toggling back to window mode from fullscreen. Cocoa_ShowMouse(); #endif break; } XBMC_Event newEvent; newEvent.type = XBMC_MOUSEMOTION; newEvent.motion.xrel = event.motion.xrel; newEvent.motion.yrel = event.motion.yrel; newEvent.motion.state = event.motion.state; newEvent.motion.type = event.motion.type; newEvent.motion.which = event.motion.which; newEvent.motion.x = event.motion.x; newEvent.motion.y = event.motion.y; ret |= g_application.OnEvent(newEvent); break; } case SDL_VIDEORESIZE: { XBMC_Event newEvent; newEvent.type = XBMC_VIDEORESIZE; newEvent.resize.w = event.resize.w; newEvent.resize.h = event.resize.h; ret |= g_application.OnEvent(newEvent); g_windowManager.MarkDirty(); break; } case SDL_USEREVENT: { XBMC_Event newEvent; newEvent.type = XBMC_USEREVENT; newEvent.user.code = event.user.code; ret |= g_application.OnEvent(newEvent); break; } case SDL_VIDEOEXPOSE: g_windowManager.MarkDirty(); break; } memset(&event, 0, sizeof(SDL_Event)); } return ret; }
bool CWinEventsSDL::MessagePump() { SDL_Event event; bool ret = false; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: if (!g_application.m_bStop) CApplicationMessenger::Get().Quit(); break; #ifdef HAS_SDL_JOYSTICK case SDL_JOYBUTTONUP: case SDL_JOYBUTTONDOWN: case SDL_JOYAXISMOTION: case SDL_JOYBALLMOTION: case SDL_JOYHATMOTION: case SDL_JOYDEVICEADDED: case SDL_JOYDEVICEREMOVED: CInputManager::GetInstance().UpdateJoystick(event); ret = true; break; #endif case SDL_ACTIVEEVENT: //If the window was inconified or restored if( event.active.state & SDL_APPACTIVE ) { g_application.SetRenderGUI(event.active.gain != 0); g_Windowing.NotifyAppActiveChange(g_application.GetRenderGUI()); } else if (event.active.state & SDL_APPINPUTFOCUS) { g_application.m_AppFocused = event.active.gain != 0; g_Windowing.NotifyAppFocusChange(g_application.m_AppFocused); } break; case SDL_KEYDOWN: { // process any platform specific shortcuts before handing off to XBMC #ifdef TARGET_DARWIN_OSX if (ProcessOSXShortcuts(event)) { ret = true; break; } #endif XBMC_Event newEvent; newEvent.type = XBMC_KEYDOWN; newEvent.key.keysym.scancode = event.key.keysym.scancode; newEvent.key.keysym.sym = (XBMCKey) event.key.keysym.sym; newEvent.key.keysym.unicode = event.key.keysym.unicode; newEvent.key.state = event.key.state; newEvent.key.type = event.key.type; newEvent.key.which = event.key.which; // Check if the Windows keys are down because SDL doesn't flag this. uint16_t mod = event.key.keysym.mod; uint8_t* keystate = SDL_GetKeyState(NULL); if (keystate[SDLK_LSUPER] || keystate[SDLK_RSUPER]) mod |= XBMCKMOD_LSUPER; newEvent.key.keysym.mod = (XBMCMod) mod; #if defined(TARGET_POSIX) && !defined(TARGET_DARWIN) // If the keysym.sym is zero try to get it from the scan code if (newEvent.key.keysym.sym == 0) newEvent.key.keysym.sym = (XBMCKey) SymFromScancode(newEvent.key.keysym.scancode); #endif // don't handle any more messages in the queue until we've handled keydown, // if a keyup is in the queue it will reset the keypress before it is handled. ret |= g_application.OnEvent(newEvent); break; } case SDL_KEYUP: { XBMC_Event newEvent; newEvent.type = XBMC_KEYUP; newEvent.key.keysym.scancode = event.key.keysym.scancode; newEvent.key.keysym.sym = (XBMCKey) event.key.keysym.sym; newEvent.key.keysym.mod =(XBMCMod) event.key.keysym.mod; newEvent.key.keysym.unicode = event.key.keysym.unicode; newEvent.key.state = event.key.state; newEvent.key.type = event.key.type; newEvent.key.which = event.key.which; ret |= g_application.OnEvent(newEvent); break; } case SDL_MOUSEBUTTONDOWN: { XBMC_Event newEvent; newEvent.type = XBMC_MOUSEBUTTONDOWN; newEvent.button.button = event.button.button; newEvent.button.state = event.button.state; newEvent.button.type = event.button.type; newEvent.button.which = event.button.which; newEvent.button.x = event.button.x; newEvent.button.y = event.button.y; ret |= g_application.OnEvent(newEvent); break; } case SDL_MOUSEBUTTONUP: { XBMC_Event newEvent; newEvent.type = XBMC_MOUSEBUTTONUP; newEvent.button.button = event.button.button; newEvent.button.state = event.button.state; newEvent.button.type = event.button.type; newEvent.button.which = event.button.which; newEvent.button.x = event.button.x; newEvent.button.y = event.button.y; ret |= g_application.OnEvent(newEvent); break; } case SDL_MOUSEMOTION: { if (0 == (SDL_GetAppState() & SDL_APPMOUSEFOCUS)) { g_Mouse.SetActive(false); #if defined(TARGET_DARWIN_OSX) // See CApplication::ProcessSlow() for a description as to why we call Cocoa_HideMouse. // this is here to restore the pointer when toggling back to window mode from fullscreen. Cocoa_ShowMouse(); #endif break; } XBMC_Event newEvent; newEvent.type = XBMC_MOUSEMOTION; newEvent.motion.xrel = event.motion.xrel; newEvent.motion.yrel = event.motion.yrel; newEvent.motion.state = event.motion.state; newEvent.motion.type = event.motion.type; newEvent.motion.which = event.motion.which; newEvent.motion.x = event.motion.x; newEvent.motion.y = event.motion.y; ret |= g_application.OnEvent(newEvent); break; } case SDL_VIDEORESIZE: { // Under linux returning from fullscreen, SDL sends an extra event to resize to the desktop // resolution causing the previous window dimensions to be lost. This is needed to rectify // that problem. if(!g_Windowing.IsFullScreen()) { int RES_SCREEN = g_Windowing.DesktopResolution(g_Windowing.GetCurrentScreen()); if((event.resize.w == CDisplaySettings::Get().GetResolutionInfo(RES_SCREEN).iWidth) && (event.resize.h == CDisplaySettings::Get().GetResolutionInfo(RES_SCREEN).iHeight)) break; } XBMC_Event newEvent; newEvent.type = XBMC_VIDEORESIZE; newEvent.resize.w = event.resize.w; newEvent.resize.h = event.resize.h; ret |= g_application.OnEvent(newEvent); g_windowManager.MarkDirty(); break; } case SDL_USEREVENT: { XBMC_Event newEvent; newEvent.type = XBMC_USEREVENT; newEvent.user.code = event.user.code; ret |= g_application.OnEvent(newEvent); break; } case SDL_VIDEOEXPOSE: g_windowManager.MarkDirty(); break; } memset(&event, 0, sizeof(SDL_Event)); } return ret; }