Ticket #8007: 0002-Move-B_MOUSE_IDLE-generation-to-app_server.patch

File 0002-Move-B_MOUSE_IDLE-generation-to-app_server.patch, 6.4 KB (added by jua, 11 years ago)

Move B_MOUSE_IDLE generation to app_server

  • headers/os/interface/Window.h

    From 70b8b182bde2b5650d0dfe50f5f3df60009e5f9a Mon Sep 17 00:00:00 2001
    From: Julian Harnath <github@orangejua.de>
    Date: Mon, 7 Oct 2013 12:01:55 +0200
    Subject: [PATCH] Move B_MOUSE_IDLE generation to app_server.
    
    * BWindow used to generate the B_MOUSE_IDLE events by sending a
      delayed message with a one-shot BMessageRunner to itself.
      Every creation and deletion of BMessageRunners causes synchronous
      messaging between the application under the mouse cursor and the
      registrar. This creates large amounts of calls to set_port_owner()
      in the kernel whenever moving the mouse.
    * Now, B_MOUSE_IDLE is sent by the cursor loop inside the app_server
      instead. When the mouse wasn't moved for the tooltip delay time,
      it inserts a B_MOUSE_IDLE message into the event stream.
    * The tooltip delay thus becomes a system-wide constant and is not
      configurable per-application anymore (no code currently in the
      Haiku repo makes use of that anyhow).
    ---
     headers/os/interface/Window.h       |  2 +-
     src/kits/interface/Window.cpp       | 13 +------------
     src/servers/app/EventDispatcher.cpp | 28 +++++++++++++++++++++++-----
     src/servers/app/EventStream.cpp     | 23 ++++++++++++++---------
     src/servers/app/EventStream.h       |  6 ++++--
     5 files changed, 43 insertions(+), 29 deletions(-)
    
    diff --git a/headers/os/interface/Window.h b/headers/os/interface/Window.h
    index 9853bb5..bc8eb16 100644
    a b private:  
    369369            BView*              fTopView;
    370370            BView*              fFocus;
    371371            BView*              fLastMouseMovedView;
    372             BMessageRunner*     fIdleMouseRunner;
     372            uint32              _unused1;
    373373            BMenuBar*           fKeyMenuBar;
    374374            BButton*            fDefaultButton;
    375375            BList               fShortcuts;
  • src/kits/interface/Window.cpp

    diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp
    index b609353..cfbd4de 100644
    a b FrameMoved(origin);  
    13151315                message->FindPoint("be:view_where", &where);
    13161316                message->FindInt32("buttons", (int32*)&buttons);
    13171317
    1318                 delete fIdleMouseRunner;
    1319 
    1320                 if (transit != B_EXITED_VIEW && transit != B_OUTSIDE_VIEW) {
    1321                     // Start new idle runner
    1322                     BMessage idle(B_MOUSE_IDLE);
    1323                     idle.AddPoint("be:view_where", where);
    1324                     fIdleMouseRunner = new BMessageRunner(
    1325                         BMessenger(NULL, this), &idle,
    1326                         BToolTipManager::Manager()->ShowDelay(), 1);
    1327                 } else {
    1328                     fIdleMouseRunner = NULL;
     1318                if (transit == B_EXITED_VIEW || transit == B_OUTSIDE_VIEW) {
    13291319                    if (dynamic_cast<BPrivate::ToolTipWindow*>(this) == NULL)
    13301320                        BToolTipManager::Manager()->HideTip();
    13311321                }
    BWindow::_InitData(BRect frame, const char* title, window_look look,  
    27942784    fTopView = NULL;
    27952785    fFocus = NULL;
    27962786    fLastMouseMovedView = NULL;
    2797     fIdleMouseRunner = NULL;
    27982787    fKeyMenuBar = NULL;
    27992788    fDefaultButton = NULL;
    28002789
  • src/servers/app/EventDispatcher.cpp

    diff --git a/src/servers/app/EventDispatcher.cpp b/src/servers/app/EventDispatcher.cpp
    index 1cddaf6..9492101 100644
    a b  
    2222#include <TokenSpace.h>
    2323
    2424#include <Autolock.h>
     25#include <ToolTipManager.h>
    2526#include <View.h>
    2627
    2728#include <new>
    EventDispatcher::_EventLoop()  
    817818            }
    818819            case B_MOUSE_DOWN:
    819820            case B_MOUSE_UP:
     821            case B_MOUSE_IDLE:
    820822            {
    821823#ifdef TRACE_EVENTS
    822824                if (event->what != B_MOUSE_MOVED)
    void  
    10021004EventDispatcher::_CursorLoop()
    10031005{
    10041006    BPoint where;
    1005     while (fStream->GetNextCursorPosition(where)) {
    1006         BAutolock _(fCursorLock);
    1007 
    1008         if (fHWInterface != NULL)
    1009             fHWInterface->MoveCursorTo(where.x, where.y);
     1007    const bigtime_t toolTipDelay = BToolTipManager::Manager()->ShowDelay();
     1008    bool mouseIdleSent = true;
     1009    status_t status = B_OK;
     1010   
     1011    while (status != B_ERROR) {
     1012        const bigtime_t timeout = mouseIdleSent ?
     1013            B_INFINITE_TIMEOUT : toolTipDelay;
     1014        status = fStream->GetNextCursorPosition(where, timeout);
     1015       
     1016        if (status == B_OK) {
     1017            mouseIdleSent = false;
     1018            BAutolock _(fCursorLock);
     1019
     1020            if (fHWInterface != NULL)
     1021                fHWInterface->MoveCursorTo(where.x, where.y);
     1022        } else if (status == B_TIMED_OUT) {
     1023            mouseIdleSent = true;
     1024            BMessage* mouseIdle = new BMessage(B_MOUSE_IDLE);
     1025            mouseIdle->AddPoint("be:view_where", fLastCursorPosition);
     1026            fStream->InsertEvent(mouseIdle);
     1027        }
    10101028    }
    10111029
    10121030    fCursorThread = -1;
  • src/servers/app/EventStream.cpp

    diff --git a/src/servers/app/EventStream.cpp b/src/servers/app/EventStream.cpp
    index 803467b..6eb6352 100644
    a b EventStream::SupportsCursorThread() const  
    3535}
    3636
    3737
    38 bool
    39 EventStream::GetNextCursorPosition(BPoint& where)
     38status_t
     39EventStream::GetNextCursorPosition(BPoint& where, bigtime_t timeout)
    4040{
    41     return false;
     41    return B_ERROR;
    4242}
    4343
    4444
    InputServerStream::GetNextEvent(BMessage** _event)  
    155155}
    156156
    157157
    158 bool
    159 InputServerStream::GetNextCursorPosition(BPoint &where)
     158status_t
     159InputServerStream::GetNextCursorPosition(BPoint &where, bigtime_t timeout)
    160160{
    161161    status_t status;
     162
    162163    do {
    163         status = acquire_sem(fCursorSemaphore);
     164        status = acquire_sem_etc(fCursorSemaphore, 1, B_RELATIVE_TIMEOUT,
     165            timeout);
    164166    } while (status == B_INTERRUPTED);
    165167
     168    if (status == B_TIMED_OUT)
     169        return status;
     170
    166171    if (status == B_BAD_SEM_ID) {
    167172        // the semaphore is no longer valid - the input_server must have died
    168173        fCursorSemaphore = -1;
    169         return false;
     174        return B_ERROR;
    170175    }
    171176
    172177#ifdef HAIKU_TARGET_PLATFORM_HAIKU
    InputServerStream::GetNextCursorPosition(BPoint &where)  
    184189
    185190    if (fQuitting) {
    186191        fQuitting = false;
    187         return false;
     192        return B_ERROR;
    188193    }
    189194
    190     return true;
     195    return B_OK;
    191196}
    192197
    193198
  • src/servers/app/EventStream.h

    diff --git a/src/servers/app/EventStream.h b/src/servers/app/EventStream.h
    index 6063b2c..23a33b9 100644
    a b class EventStream {  
    3030        virtual void UpdateScreenBounds(BRect bounds) = 0;
    3131
    3232        virtual bool GetNextEvent(BMessage** _event) = 0;
    33         virtual bool GetNextCursorPosition(BPoint& where);
     33        virtual status_t GetNextCursorPosition(BPoint& where,
     34                bigtime_t timeout = B_INFINITE_TIMEOUT);
    3435
    3536        virtual status_t InsertEvent(BMessage* event) = 0;
    3637
    class InputServerStream : public EventStream {  
    5556        virtual void UpdateScreenBounds(BRect bounds);
    5657
    5758        virtual bool GetNextEvent(BMessage** _event);
    58         virtual bool GetNextCursorPosition(BPoint& where);
     59        virtual status_t GetNextCursorPosition(BPoint& where,
     60                bigtime_t timeout = B_INFINITE_TIMEOUT);
    5961
    6062        virtual status_t InsertEvent(BMessage* event);
    6163