From e112dd63acac2262ab62d9ae66ac6d890c8dce3d Mon Sep 17 00:00:00 2001 From: ulion Date: Mon, 11 Feb 2013 14:58:11 +0800 Subject: Fix event pump order on ios when we drop in deeper message loop. --- xbmc/windowing/osx/WinEventsIOS.mm | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/xbmc/windowing/osx/WinEventsIOS.mm b/xbmc/windowing/osx/WinEventsIOS.mm index df5e131c3b..2fb5fea2b0 100644 --- a/xbmc/windowing/osx/WinEventsIOS.mm +++ b/xbmc/windowing/osx/WinEventsIOS.mm @@ -19,6 +19,7 @@ */ #include "system.h" +#include #include "WinEventsIOS.h" #include "input/XBMC_vkeys.h" #include "Application.h" @@ -31,7 +32,7 @@ static CCriticalSection g_inputCond; PHANDLE_EVENT_FUNC CWinEventsBase::m_pEventFunc = NULL; -static std::vector events; +static std::list events; void CWinEventsIOS::DeInit() { @@ -51,18 +52,23 @@ void CWinEventsIOS::MessagePush(XBMC_Event *newEvent) bool CWinEventsIOS::MessagePump() { bool ret = false; - std::vector copy_events; - - { // double-buffered events to avoid constant locking for OnEvent(). - CSingleLock lock(g_inputCond); - copy_events = events; - events.clear(); - } - for (vector::iterator it = copy_events.begin(); it!=copy_events.end(); ++it) + // Do not always loop, only pump the initial queued count events. else if ui keep pushing + // events the loop won't finish then it will block xbmc main message loop. + for (int pumpEventCount = GetQueueSize(); pumpEventCount > 0; --pumpEventCount) { - XBMC_Event *pumpEvent = (XBMC_Event *)&*it; - if (pumpEvent->type == XBMC_USEREVENT) + // Pop up only one event per time since in App::OnEvent it may init modal dialog which init + // deeper message loop and call the deeper MessagePump from there. + XBMC_Event pumpEvent; + { + CSingleLock lock(g_inputCond); + if (events.size() == 0) + return ret; + pumpEvent = events.front(); + events.pop_front(); + } + + if (pumpEvent.type == XBMC_USEREVENT) { // On ATV2, we push in events as a XBMC_USEREVENT, // the jbutton.which will be the keyID to translate using joystick.AppleRemote.xml @@ -70,18 +76,18 @@ bool CWinEventsIOS::MessagePump() std::string joystickName = "AppleRemote"; bool isAxis = false; float fAmount = 1.0; - unsigned char wKeyID = pumpEvent->jbutton.which; - unsigned int holdTime = pumpEvent->jbutton.holdTime; + unsigned char wKeyID = pumpEvent.jbutton.which; + unsigned int holdTime = pumpEvent.jbutton.holdTime; CLog::Log(LOGDEBUG,"CWinEventsIOS: Button press keyID = %i", wKeyID); ret |= g_application.ProcessJoystickEvent(joystickName, wKeyID, isAxis, fAmount, holdTime); } else - ret |= g_application.OnEvent(*it); + ret |= g_application.OnEvent(pumpEvent); //on ios touch devices - unfocus controls on finger lift #if !defined(TARGET_DARWIN_IOS_ATV2) - if (pumpEvent->type == XBMC_MOUSEBUTTONUP) + if (pumpEvent.type == XBMC_MOUSEBUTTONUP) { g_windowManager.SendMessage(GUI_MSG_UNFOCUS_ALL, 0, 0, 0, 0); } -- cgit v1.2.3