added 1 changeset to branch 'refs/remotes/orangejua-github/ticket8007' old head: 8182872acb5f9da69105393bbfa4f6feb10acdb6 new head: ad2813ba0905262eb39af485f4fef382164816b5 overview: https://github.com/orangejua/haiku/compare/8182872...ad2813b ---------------------------------------------------------------------------- ad2813b: Move B_MOUSE_IDLE event creation to cursor loop. * Remove cursor idle loop again * EventStream::GetNextCursorPosition gets a timeout parameter. On timeout, the cursor loop sends insert B_MOUSE_IDLE into the event stream. It only does so once, until the next mouse move happened. [ Julian Harnath <github@xxxxxxxxxxxx> ] ---------------------------------------------------------------------------- Commit: ad2813ba0905262eb39af485f4fef382164816b5 Author: Julian Harnath <github@xxxxxxxxxxxx> Date: Mon Oct 7 09:57:18 2013 UTC ---------------------------------------------------------------------------- 4 files changed, 35 insertions(+), 63 deletions(-) src/servers/app/EventDispatcher.cpp | 64 +++++++++------------------------ src/servers/app/EventDispatcher.h | 5 --- src/servers/app/EventStream.cpp | 23 +++++++----- src/servers/app/EventStream.h | 6 ++-- ---------------------------------------------------------------------------- diff --git a/src/servers/app/EventDispatcher.cpp b/src/servers/app/EventDispatcher.cpp index 7885ce5..9492101 100644 --- a/src/servers/app/EventDispatcher.cpp +++ b/src/servers/app/EventDispatcher.cpp @@ -243,8 +243,6 @@ EventDispatcher::EventDispatcher() fNextLatestMouseMoved(NULL), fLastButtons(0), fLastUpdate(system_time()), - fLastMouseMove(system_time()), - fLastNotifyTime(system_time()), fDraggingMessage(false), fDragBitmap(NULL), fCursorLock("cursor loop lock"), @@ -324,13 +322,6 @@ EventDispatcher::_Run() kill_thread(fCursorThread); fCursorThread = -1; } - - fCursorIdleThread = spawn_thread(_cursor_idle_looper, "cursor idle loop", - B_DISPLAY_PRIORITY, this); - if (resume_thread(fCursorIdleThread) != B_OK) { - kill_thread(fCursorIdleThread); - fCursorIdleThread = -1; - } } return resume_thread(fThread); @@ -795,8 +786,6 @@ EventDispatcher::_EventLoop() if (event->FindPoint("where", &where) == B_OK) fLastCursorPosition = where; - fLastMouseMove = system_time(); - if (fDraggingMessage) event->AddMessage("be:drag_message", &fDragMessage); @@ -1015,37 +1004,30 @@ void EventDispatcher::_CursorLoop() { BPoint where; - while (fStream->GetNextCursorPosition(where)) { - BAutolock _(fCursorLock); - - if (fHWInterface != NULL) - fHWInterface->MoveCursorTo(where.x, where.y); - } - - fCursorThread = -1; -} - - -void -EventDispatcher::_CursorIdleLoop() -{ - const bigtime_t toolTipDelay = BToolTipManager::Manager()->ShowDelay(); + const bigtime_t toolTipDelay = BToolTipManager::Manager()->ShowDelay(); + bool mouseIdleSent = true; + status_t status = B_OK; - for (;;) { - const bigtime_t now = system_time(); - - if (fLastNotifyTime < fLastMouseMove - && now - fLastMouseMove >= toolTipDelay) { - fLastNotifyTime = now; + while (status != B_ERROR) { + const bigtime_t timeout = mouseIdleSent ? + B_INFINITE_TIMEOUT : toolTipDelay; + status = fStream->GetNextCursorPosition(where, timeout); + if (status == B_OK) { + mouseIdleSent = false; + BAutolock _(fCursorLock); + + if (fHWInterface != NULL) + fHWInterface->MoveCursorTo(where.x, where.y); + } else if (status == B_TIMED_OUT) { + mouseIdleSent = true; BMessage* mouseIdle = new BMessage(B_MOUSE_IDLE); mouseIdle->AddPoint("be:view_where", fLastCursorPosition); - mouseIdle->AddInt64("idle_time", now - fLastMouseMove); fStream->InsertEvent(mouseIdle); } - - snooze(20000); } + + fCursorThread = -1; } @@ -1071,15 +1053,3 @@ EventDispatcher::_cursor_looper(void* _dispatcher) dispatcher->_CursorLoop(); return B_OK; } - - -/*static*/ -status_t -EventDispatcher::_cursor_idle_looper(void* _dispatcher) -{ - EventDispatcher* dispatcher = (EventDispatcher*)_dispatcher; - - ETRACE(("Start cursor idle loop\n")); - dispatcher->_CursorIdleLoop(); - return B_OK; -} diff --git a/src/servers/app/EventDispatcher.h b/src/servers/app/EventDispatcher.h index 2551075..656234d 100644 --- a/src/servers/app/EventDispatcher.h +++ b/src/servers/app/EventDispatcher.h @@ -123,17 +123,14 @@ class EventDispatcher : public BLocker { void _EventLoop(); void _CursorLoop(); - void _CursorIdleLoop(); static status_t _event_looper(void* dispatcher); static status_t _cursor_looper(void* dispatcher); - static status_t _cursor_idle_looper(void* dispatcher); private: EventStream* fStream; thread_id fThread; thread_id fCursorThread; - thread_id fCursorIdleThread; EventTarget* fPreviousMouseTarget; EventTarget* fFocus; @@ -148,8 +145,6 @@ class EventDispatcher : public BLocker { BPoint fLastCursorPosition; int32 fLastButtons; bigtime_t fLastUpdate; - bigtime_t fLastMouseMove; - bigtime_t fLastNotifyTime; BMessage fDragMessage; bool fDraggingMessage; diff --git a/src/servers/app/EventStream.cpp b/src/servers/app/EventStream.cpp index 803467b..6eb6352 100644 --- a/src/servers/app/EventStream.cpp +++ b/src/servers/app/EventStream.cpp @@ -35,10 +35,10 @@ EventStream::SupportsCursorThread() const } -bool -EventStream::GetNextCursorPosition(BPoint& where) +status_t +EventStream::GetNextCursorPosition(BPoint& where, bigtime_t timeout) { - return false; + return B_ERROR; } @@ -155,18 +155,23 @@ InputServerStream::GetNextEvent(BMessage** _event) } -bool -InputServerStream::GetNextCursorPosition(BPoint &where) +status_t +InputServerStream::GetNextCursorPosition(BPoint &where, bigtime_t timeout) { status_t status; + do { - status = acquire_sem(fCursorSemaphore); + status = acquire_sem_etc(fCursorSemaphore, 1, B_RELATIVE_TIMEOUT, + timeout); } while (status == B_INTERRUPTED); + if (status == B_TIMED_OUT) + return status; + if (status == B_BAD_SEM_ID) { // the semaphore is no longer valid - the input_server must have died fCursorSemaphore = -1; - return false; + return B_ERROR; } #ifdef HAIKU_TARGET_PLATFORM_HAIKU @@ -184,10 +189,10 @@ InputServerStream::GetNextCursorPosition(BPoint &where) if (fQuitting) { fQuitting = false; - return false; + return B_ERROR; } - return true; + return B_OK; } diff --git a/src/servers/app/EventStream.h b/src/servers/app/EventStream.h index 6063b2c..23a33b9 100644 --- a/src/servers/app/EventStream.h +++ b/src/servers/app/EventStream.h @@ -30,7 +30,8 @@ class EventStream { virtual void UpdateScreenBounds(BRect bounds) = 0; virtual bool GetNextEvent(BMessage** _event) = 0; - virtual bool GetNextCursorPosition(BPoint& where); + virtual status_t GetNextCursorPosition(BPoint& where, + bigtime_t timeout = B_INFINITE_TIMEOUT); virtual status_t InsertEvent(BMessage* event) = 0; @@ -55,7 +56,8 @@ class InputServerStream : public EventStream { virtual void UpdateScreenBounds(BRect bounds); virtual bool GetNextEvent(BMessage** _event); - virtual bool GetNextCursorPosition(BPoint& where); + virtual status_t GetNextCursorPosition(BPoint& where, + bigtime_t timeout = B_INFINITE_TIMEOUT); virtual status_t InsertEvent(BMessage* event);