aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorulion <ulion2002@gmail.com>2013-02-11 14:58:11 +0800
committerS. Davilla <davilla@4pi.com>2013-02-19 11:49:17 -0500
commite112dd63acac2262ab62d9ae66ac6d890c8dce3d (patch)
treea087a7e130483045221f68b4e2053e182be6eab0
parentac329400fc4f9759e2c4e5796009e2a0715584d7 (diff)
Fix event pump order on ios when we drop in deeper message loop.
-rw-r--r--xbmc/windowing/osx/WinEventsIOS.mm36
1 files 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 <list>
#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<XBMC_Event> events;
+static std::list<XBMC_Event> events;
void CWinEventsIOS::DeInit()
{
@@ -51,18 +52,23 @@ void CWinEventsIOS::MessagePush(XBMC_Event *newEvent)
bool CWinEventsIOS::MessagePump()
{
bool ret = false;
- std::vector<XBMC_Event> copy_events;
-
- { // double-buffered events to avoid constant locking for OnEvent().
- CSingleLock lock(g_inputCond);
- copy_events = events;
- events.clear();
- }
- for (vector<XBMC_Event>::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);
}