Index: trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk	(revision 30407)
+++ trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk	(revision 30408)
@@ -327,4 +327,5 @@
 	src/runtime/UIActionsPool.h \
 	src/runtime/UIIndicatorsPool.h \
+	src/runtime/UIMouseHandler.h \
 	src/runtime/UIMachineLogic.h \
 	src/runtime/UIMachineView.h \
@@ -460,4 +461,5 @@
 	src/runtime/UIActionsPool.cpp \
 	src/runtime/UIIndicatorsPool.cpp \
+	src/runtime/UIMouseHandler.cpp \
 	src/runtime/UIFrameBuffer.cpp \
 	src/runtime/UIFrameBufferQGL.cpp \
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 30407)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 30408)
@@ -24,4 +24,5 @@
 #include "UIDownloaderAdditions.h"
 #include "UIIconPool.h"
+#include "UIMouseHandler.h"
 #include "UIMachineLogic.h"
 #include "UIMachineLogicFullscreen.h"
@@ -337,4 +338,5 @@
     , m_pActionsPool(pActionsPool)
     , m_visualStateType(visualStateType)
+    , m_pMouseHandler(0)
     , m_pRunningActions(0)
     , m_pRunningOrPausedActions(0)
@@ -370,4 +372,9 @@
 {
     m_machineWindowsList << pMachineWindow;
+}
+
+void UIMachineLogic::setMouseHandler(UIMouseHandler *pMouseHandler)
+{
+    m_pMouseHandler = pMouseHandler;
 }
 
@@ -904,6 +911,5 @@
 
     /* Disable/Enable mouse-integration for all view(s): */
-    foreach(UIMachineWindow *pMachineWindow, machineWindows())
-        pMachineWindow->machineView()->setMouseIntegrationEnabled(!fOff);
+    m_pMouseHandler->setMouseIntegrationEnabled(!fOff);
 }
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h	(revision 30407)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h	(revision 30408)
@@ -39,4 +39,5 @@
 class UISession;
 class UIActionsPool;
+class UIMouseHandler;
 class UIMachineWindow;
 class UIMachineView;
@@ -68,4 +69,5 @@
     UIVisualStateType visualStateType() const { return m_visualStateType; }
     const QList<UIMachineWindow*>& machineWindows() const { return m_machineWindowsList; }
+    UIMouseHandler* mouseHandler() const { return m_pMouseHandler; }
     UIMachineWindow* mainMachineWindow() const;
     UIMachineWindow* defaultMachineWindow() const;
@@ -100,4 +102,5 @@
 
     /* Protected members: */
+    void setMouseHandler(UIMouseHandler *pMouseHandler);
     void addMachineWindow(UIMachineWindow *pMachineWindow);
     void retranslateUi();
@@ -192,4 +195,5 @@
     UIActionsPool *m_pActionsPool;
     UIVisualStateType m_visualStateType;
+    UIMouseHandler *m_pMouseHandler;
     QList<UIMachineWindow*> m_machineWindowsList;
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 30407)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 30408)
@@ -36,4 +36,5 @@
 #include "UISession.h"
 #include "UIActionsPool.h"
+#include "UIMouseHandler.h"
 #include "UIMachineLogic.h"
 #include "UIMachineWindow.h"
@@ -157,38 +158,4 @@
 }
 
-int UIMachineView::mouseState() const
-{
-    return (uisession()->isMouseCaptured() ? UIMouseStateType_MouseCaptured : 0) |
-           (uisession()->isMouseSupportsAbsolute() ? UIMouseStateType_MouseAbsolute : 0) |
-           (uisession()->isMouseIntegrated() ? 0 : UIMouseStateType_MouseAbsoluteDisabled);
-}
-
-void UIMachineView::setMouseIntegrationEnabled(bool fEnabled)
-{
-    /* Do not change anything if its already so: */
-    if (uisession()->isMouseIntegrated() == fEnabled)
-        return;
-
-    /* Store new mouse 'integrated' state value: */
-    uisession()->setMouseIntegrated(fEnabled);
-
-    /* We should capture/release mouse depending on mouse 'integrated' state value: */
-    captureMouse(!uisession()->isMouseIntegrated(), false /* emit signal? */);
-
-    /* Update mouse cursor shape: */
-    updateMouseCursorShape();
-
-    /* If mouse is integrated and supports absolute pointing
-     * we should switch guest mouse to the absolute mode: */
-    if (uisession()->isMouseIntegrated() && uisession()->isMouseSupportsAbsolute())
-    {
-        CMouse mouse = session().GetConsole().GetMouse();
-        mouse.PutMouseEventAbsolute(-1, -1, 0, 0, 0);
-    }
-
-    /* Notify all listeners: */
-    emitMouseStateChanged();
-}
-
 UIMachineView::UIMachineView(  UIMachineWindow *pMachineWindow
 #ifdef VBOX_WITH_VIDEOHWACCEL
@@ -205,5 +172,4 @@
     , m_previousState(KMachineState_Null)
     , m_desktopGeometryType(DesktopGeo_Invalid)
-    , m_iLastMouseWheelDelta(0)
     , m_bIsKeyboardCaptured(false)
     , m_bIsHostkeyPressed(false)
@@ -215,7 +181,4 @@
     , m_fAccelerate2DVideo(bAccelerate2DVideo)
 #endif /* VBOX_WITH_VIDEOHWACCEL */
-#ifdef Q_WS_WIN
-    , m_fItsMeWhoCapturedMouse(false)
-#endif
 #ifdef Q_WS_MAC
     , m_darwinKeyModifiers(0)
@@ -385,54 +348,4 @@
     machine.SetExtraData(strKey, strValue);
 }
-
-void UIMachineView::updateMouseCursorShape()
-{
-    /* First of all, we should check if the host pointer should be visible.
-     * We should hide host pointer in case of:
-     * 1. mouse is 'captured' or
-     * 2. mouse is 'not captured', 'integrated', 'absolute', host pointer is hidden by the guest. */
-    if (uisession()->isMouseCaptured() ||
-        (uisession()->isMouseIntegrated() &&
-         uisession()->isMouseSupportsAbsolute() &&
-         uisession()->isHidingHostPointer()))
-    {
-        viewport()->setCursor(Qt::BlankCursor);
-    }
-
-    else
-
-    /* Otherwise we should show host pointer with guest shape assigned to it if:
-     * mouse is 'integrated', 'absolute', valid pointer shape is present. */
-    if (uisession()->isMouseIntegrated() &&
-        uisession()->isMouseSupportsAbsolute() &&
-        uisession()->isValidPointerShapePresent())
-    {
-        viewport()->setCursor(uisession()->cursor());
-    }
-
-    else
-
-    /* There could be other states covering such situations as:
-     * 1. mouse is 'not captured', 'integrated', 'not absolute' or
-     * 2. mouse is 'not captured', 'not integrated', 'absolute'.
-     * We have nothing to do with that except just unset the cursor. */
-    viewport()->unsetCursor();
-}
-
-#ifdef Q_WS_WIN
-/* This method is actually required only because under win-host
- * we do not really grab the mouse in case of capturing it.
- * I have to check if its really need, may be just grabMouse() will be enought: */
-void UIMachineView::updateMouseCursorClipping()
-{
-    if (m_fItsMeWhoCapturedMouse)
-    {
-        QRect r = viewport()->rect();
-        r.moveTopLeft(viewport()->mapToGlobal(QPoint(0, 0)));
-        RECT rect = { r.left(), r.top(), r.right() + 1, r.bottom() + 1 };
-        ::ClipCursor(&rect);
-    }
-}
-#endif
 
 void UIMachineView::updateSliders()
@@ -643,4 +556,7 @@
     NOREF(ok);
 #endif
+
+    /* Register mouse-handler: */
+    machineLogic()->mouseHandler()->addMachineView(screenId(), this);
 }
 
@@ -662,13 +578,4 @@
     /* Machine state-change updater: */
     connect(uisession(), SIGNAL(sigMachineStateChange()), this, SLOT(sltMachineStateChanged()));
-
-    /* Mouse pointer shape state-change updater: */
-    connect(uisession(), SIGNAL(sigMousePointerShapeChange()), this, SLOT(sltMousePointerShapeChanged()));
-
-    /* Mouse capability state-change updater: */
-    connect(uisession(), SIGNAL(sigMouseCapabilityChange()), this, SLOT(sltMouseCapabilityChanged()));
-
-    /* Mouse captivity status-change updater: */
-    connect(uisession(), SIGNAL(sigMouseCapturedStatusChanged()), this, SLOT(sltMouseCapturedStatusChanged()));
 }
 
@@ -708,4 +615,7 @@
 void UIMachineView::cleanupCommon()
 {
+    /* Unregister mouse-handler: */
+    machineLogic()->mouseHandler()->delMachineView(screenId());
+
 #ifdef Q_WS_PM
     bool ok = VBoxHlpUninstallKbdHook(0, winId(), UM_PREACCEL_CHAR);
@@ -953,130 +863,13 @@
 bool UIMachineView::eventFilter(QObject *pWatched, QEvent *pEvent)
 {
+#ifdef VBOX_WITH_VIDEOHWACCEL
     if (pWatched == viewport())
     {
         switch (pEvent->type())
         {
-            case QEvent::MouseMove:
-            case QEvent::MouseButtonRelease:
-            {
-                /* Check if we should propagate this event to another window: */
-                QWidget *pWidgetAt = QApplication::widgetAt(QCursor::pos());
-                if (pWidgetAt && pWidgetAt->window() && pWidgetAt->window()->inherits("UIMachineWindow") &&
-                    pWidgetAt->window() != machineWindowWrapper()->machineWindow())
-                {
-                    /* Get current mouse-move event: */
-                    QMouseEvent *pOldMouseEvent = static_cast<QMouseEvent*>(pEvent);
-
-                    /* Get real destination window of that event: */
-                    UIMachineWindow *pMachineWindow =
-                        pWidgetAt->window()->inherits("UIMachineWindowNormal") ?
-                        static_cast<UIMachineWindow*>(qobject_cast<UIMachineWindowNormal*>(pWidgetAt->window())) :
-                        pWidgetAt->window()->inherits("UIMachineWindowFullscreen") ?
-                        static_cast<UIMachineWindow*>(qobject_cast<UIMachineWindowFullscreen*>(pWidgetAt->window())) :
-                        pWidgetAt->window()->inherits("UIMachineWindowSeamless") ?
-                        static_cast<UIMachineWindow*>(qobject_cast<UIMachineWindowSeamless*>(pWidgetAt->window())) : 0;
-                    if (pMachineWindow)
-                    {
-                        /* Get viewport: */
-                        QWidget *pOtherViewport = pMachineWindow->machineView()->viewport();
-
-                        /* Prepare redirected mouse-move event: */
-                        QMouseEvent *pNewMouseEvent = new QMouseEvent(pOldMouseEvent->type(),
-                                                                      pOtherViewport->mapFromGlobal(pOldMouseEvent->globalPos()),
-                                                                      pOldMouseEvent->globalPos(),
-                                                                      pOldMouseEvent->button(),
-                                                                      pOldMouseEvent->buttons(),
-                                                                      pOldMouseEvent->modifiers());
-
-                        /* Send that event to real destination: */
-                        QApplication::postEvent(pOtherViewport, pNewMouseEvent);
-
-                        /* Filter out that event: */
-                        return true;
-                    }
-                }
-
-                /* Check if we should activate window under cursor: */
-                if (QApplication::activeWindow() &&
-                    QApplication::activeWindow()->inherits("UIMachineWindow") &&
-                    QApplication::activeWindow() != machineWindowWrapper()->machineWindow())
-                {
-                    /* Activating hovered machine window: */
-                    machineWindowWrapper()->machineWindow()->activateWindow();
-#ifdef Q_WS_X11
-                    /* On X11 its not enough to just activate window if you
-                     * want to raise it also, so we will make it separately: */
-                    machineWindowWrapper()->machineWindow()->raise();
-#endif /* Q_WS_X11 */
-                }
-
-                /* This event should be also processed using next 'case': */
-            }
-            case QEvent::MouseButtonPress:
-            case QEvent::MouseButtonDblClick:
-            {
-                QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(pEvent);
-                m_iLastMouseWheelDelta = 0;
-                if (mouseEvent(pMouseEvent->type(), pMouseEvent->pos(), pMouseEvent->globalPos(),
-                               pMouseEvent->buttons(), pMouseEvent->modifiers(), 0, Qt::Horizontal))
-                    return true;
-                break;
-            }
-            case QEvent::Wheel:
-            {
-                QWheelEvent *pWheelEvent = static_cast<QWheelEvent*>(pEvent);
-                /* There are pointing devices which send smaller values for the delta than 120.
-                 * Here we sum them up until we are greater than 120. This allows to have finer control
-                 * over the speed acceleration & enables such devices to send a valid wheel event to our
-                 * guest mouse device at all: */
-                int iDelta = 0;
-                m_iLastMouseWheelDelta += pWheelEvent->delta();
-                if (qAbs(m_iLastMouseWheelDelta) >= 120)
-                {
-                    iDelta = m_iLastMouseWheelDelta;
-                    m_iLastMouseWheelDelta = m_iLastMouseWheelDelta % 120;
-                }
-                if (mouseEvent(pWheelEvent->type(), pWheelEvent->pos(), pWheelEvent->globalPos(),
-#ifdef QT_MAC_USE_COCOA
-                               /* Qt Cocoa is buggy. It always reports a left button pressed when the
-                                * mouse wheel event occurs. A workaround is to ask the application which
-                                * buttons are pressed currently: */
-                               QApplication::mouseButtons(),
-#else /* QT_MAC_USE_COCOA */
-                               pWheelEvent->buttons(),
-#endif /* !QT_MAC_USE_COCOA */
-                               pWheelEvent->modifiers(),
-                               iDelta, pWheelEvent->orientation()))
-                    return true;
-                break;
-            }
-#ifdef Q_WS_MAC
-            case QEvent::Leave:
-            {
-                /* Enable mouse event compression if we leave the VM view. This is necessary for
-                 * having smooth resizing of the VM/other windows: */
-                setMouseCoalescingEnabled(true);
-                break;
-            }
-            case QEvent::Enter:
-            {
-                /* Disable mouse event compression if we enter the VM view. So all mouse events are
-                 * registered in the VM. Only do this if the keyboard/mouse is grabbed (this is when
-                 * we have a valid event handler): */
-                setMouseCoalescingEnabled(false);
-                break;
-            }
-#endif /* Q_WS_MAC */
             case QEvent::Resize:
             {
-#ifdef Q_WS_WIN32
-                updateMouseCursorClipping();
-#endif
-#ifdef VBOX_WITH_VIDEOHWACCEL
                 if (m_pFrameBuffer)
-                {
                     m_pFrameBuffer->viewportResized(static_cast<QResizeEvent*>(pEvent));
-                }
-#endif
                 break;
             }
@@ -1085,5 +878,6 @@
         }
     }
-    else if (pWatched == machineWindowWrapper()->machineWindow())
+#endif /* VBOX_WITH_VIDEOHWACCEL */
+    if (pWatched == machineWindowWrapper()->machineWindow())
     {
         switch (pEvent->type())
@@ -1173,5 +967,5 @@
                 viewport()->repaint();
             }
-            /* Reuse the focus event handler to uncapture everything: */
+            /* Reuse the focus event handler to uncapture keyboard: */
             if (hasFocus())
                 focusEvent(false /* aHasFocus*/, false /* aReleaseHostKey */);
@@ -1180,5 +974,5 @@
         case KMachineState_Stuck:
         {
-            /* Reuse the focus event handler to uncapture everything: */
+            /* Reuse the focus event handler to uncapture keyboard: */
             if (hasFocus())
                 focusEvent(false /* aHasFocus*/, false /* aReleaseHostKey */);
@@ -1213,49 +1007,4 @@
 }
 
-void UIMachineView::sltMousePointerShapeChanged()
-{
-    /* Update mouse cursor: */
-    updateMouseCursorShape();
-}
-
-void UIMachineView::sltMouseCapabilityChanged()
-{
-    /* We should release mouse if guest notified us about it supports 'absolute' mouse
-     * and mouse is in 'integrated' mode, which could be chosen from main machine menu: */
-    if (uisession()->isMouseIntegrated() && uisession()->isMouseSupportsAbsolute())
-    {
-        CMouse mouse = session().GetConsole().GetMouse();
-        mouse.PutMouseEventAbsolute(-1, -1, 0, 0, 0);
-        captureMouse(false, false);
-    }
-
-    /* Update mouse cursor shape: */
-    updateMouseCursorShape();
-
-    /* Notify user about mouse 'absolute' state if method was called by signal: */
-    if (sender()) vboxProblem().remindAboutMouseIntegration(uisession()->isMouseSupportsAbsolute());
-
-    /* Notify all listeners: */
-    emitMouseStateChanged();
-}
-
-void UIMachineView::sltMouseCapturedStatusChanged()
-{
-    /* If mouse 'captured' state value changed to 'false': */
-    if (!uisession()->isMouseCaptured())
-    {
-        /* Releasing grabbed mouse from that window: */
-#ifdef Q_WS_WIN
-        m_fItsMeWhoCapturedMouse = false;
-        ::ClipCursor(NULL);
-#else
-        viewport()->releaseMouse();
-#endif /* Q_WS_WIN */
-    }
-
-    /* Update mouse cursor shape: */
-    updateMouseCursorShape();
-}
-
 void UIMachineView::focusEvent(bool fHasFocus, bool fReleaseHostKey /* = true */)
 {
@@ -1277,5 +1026,4 @@
     else
     {
-        captureMouse(false);
         captureKbd(false, false);
         releaseAllPressedKeys(fReleaseHostKey);
@@ -1352,5 +1100,5 @@
                     captureKbd(false);
                     if (!(uisession()->isMouseSupportsAbsolute() && uisession()->isMouseIntegrated()))
-                        captureMouse(false);
+                        machineLogic()->mouseHandler()->captureMouse(screenId());
                 }
 
@@ -1467,5 +1215,8 @@
                                 qApp->processEvents();
 #endif
-                                captureMouse(m_bIsKeyboardCaptured);
+                                if (m_bIsKeyboardCaptured)
+                                    machineLogic()->mouseHandler()->captureMouse(screenId());
+                                else
+                                    machineLogic()->mouseHandler()->releaseMouse();
                             }
                         }
@@ -1562,239 +1313,4 @@
     /* Grab the key from Qt: */
     return true;
-}
-
-bool UIMachineView::mouseEvent(int aType, const QPoint &aPos, const QPoint &aGlobalPos,
-                               Qt::MouseButtons aButtons, Qt::KeyboardModifiers /* aModifiers */,
-                               int aWheelDelta, Qt::Orientation aWheelDir)
-{
-    int state = 0;
-    if (aButtons & Qt::LeftButton)
-        state |= KMouseButtonState_LeftButton;
-    if (aButtons & Qt::RightButton)
-        state |= KMouseButtonState_RightButton;
-    if (aButtons & Qt::MidButton)
-        state |= KMouseButtonState_MiddleButton;
-    if (aButtons & Qt::XButton1)
-        state |= KMouseButtonState_XButton1;
-    if (aButtons & Qt::XButton2)
-        state |= KMouseButtonState_XButton2;
-
-#ifdef Q_WS_MAC
-    /* Simulate the right click on Host+Left Mouse: */
-    if (m_bIsHostkeyPressed &&
-        m_bIsHostkeyAlone &&
-        state == KMouseButtonState_LeftButton)
-        state = KMouseButtonState_RightButton;
-#endif /* Q_WS_MAC */
-
-    int wheelVertical = 0;
-    int wheelHorizontal = 0;
-    if (aWheelDir == Qt::Vertical)
-    {
-        /* The absolute value of wheel delta is 120 units per every wheel move;
-         * positive deltas correspond to counterclockwize rotations (usually up),
-         * negative deltas correspond to clockwize (usually down). */
-        wheelVertical = - (aWheelDelta / 120);
-    }
-    else if (aWheelDir == Qt::Horizontal)
-        wheelHorizontal = aWheelDelta / 120;
-
-    if (uisession()->isMouseCaptured())
-    {
-#ifdef Q_WS_WIN32
-        /* Send pending WM_PAINT events: */
-        ::UpdateWindow(viewport()->winId());
-#endif
-
-        CMouse mouse = session().GetConsole().GetMouse();
-        mouse.PutMouseEvent(aGlobalPos.x() - m_lastMousePos.x(),
-                            aGlobalPos.y() - m_lastMousePos.y(),
-                            wheelVertical, wheelHorizontal, state);
-
-#if defined (Q_WS_MAC)
-        /*
-         * Keep the mouse from leaving the widget.
-         *
-         * This is a bit tricky to get right because if it escapes we won't necessarily
-         * get mouse events any longer and can warp it back. So, we keep safety zone
-         * of up to 300 pixels around the borders of the widget to prevent this from
-         * happening. Also, the mouse is warped back to the center of the widget.
-         *
-         * (Note, aPos seems to be unreliable, it caused endless recursion here at one points...)
-         * (Note, synergy and other remote clients might not like this cursor warping.)
-         */
-        QRect rect = viewport()->visibleRegion().boundingRect();
-        QPoint pw = viewport()->mapToGlobal(viewport()->pos());
-        rect.translate(pw.x(), pw.y());
-
-        QRect dpRect = QApplication::desktop()->screenGeometry(viewport());
-        if (rect.intersects (dpRect))
-            rect = rect.intersect(dpRect);
-
-        int wsafe = rect.width() / 6;
-        rect.setWidth(rect.width() - wsafe * 2);
-        rect.setLeft(rect.left() + wsafe);
-
-        int hsafe = rect.height() / 6;
-        rect.setWidth(rect.height() - hsafe * 2);
-        rect.setTop(rect.top() + hsafe);
-
-        if (rect.contains(aGlobalPos, true))
-            m_lastMousePos = aGlobalPos;
-        else
-        {
-            m_lastMousePos = rect.center();
-            QCursor::setPos(m_lastMousePos);
-        }
-#else /* !Q_WS_MAC */
-
-        /* "jerk" the mouse by bringing it to the opposite side
-         * to simulate the endless moving */
-
-# ifdef Q_WS_WIN32
-        int we = viewport()->width() - 1;
-        int he = viewport()->height() - 1;
-        QPoint p = aPos;
-        if (aPos.x() == 0)
-            p.setX(we - 1);
-        else if (aPos.x() == we)
-            p.setX(1);
-        if (aPos.y() == 0 )
-            p.setY(he - 1);
-        else if (aPos.y() == he)
-            p.setY(1);
-
-        if (p != aPos)
-        {
-            m_lastMousePos = viewport()->mapToGlobal (p);
-            QCursor::setPos(m_lastMousePos);
-        }
-        else
-        {
-            m_lastMousePos = aGlobalPos;
-        }
-# else
-        int we = QApplication::desktop()->width() - 1;
-        int he = QApplication::desktop()->height() - 1;
-        QPoint p = aGlobalPos;
-        if (aGlobalPos.x() == 0)
-            p.setX (we - 1);
-        else if (aGlobalPos.x() == we)
-            p.setX( 1 );
-        if (aGlobalPos.y() == 0)
-            p.setY (he - 1);
-        else if (aGlobalPos.y() == he)
-            p.setY (1);
-
-        if (p != aGlobalPos)
-        {
-            m_lastMousePos =  p;
-            QCursor::setPos(m_lastMousePos);
-        }
-        else
-        {
-            m_lastMousePos = aGlobalPos;
-        }
-# endif
-#endif /* !Q_WS_MAC */
-        return true; /* stop further event handling */
-    }
-    else /* !uisession()->isMouseCaptured() */
-    {
-#if 0 // TODO: Move that to fullscreen event-hjadler:
-        if (vboxGlobal().vmRenderMode() != VBoxDefs::SDLMode)
-        {
-            /* try to automatically scroll the guest canvas if the
-             * mouse is on the screen border */
-            /// @todo (r=dmik) better use a timer for autoscroll
-            QRect scrGeo = QApplication::desktop()->screenGeometry (this);
-            int dx = 0, dy = 0;
-            if (scrGeo.width() < contentsWidth())
-            {
-                if (scrGeo.left() == aGlobalPos.x()) dx = -1;
-                if (scrGeo.right() == aGlobalPos.x()) dx = +1;
-            }
-            if (scrGeo.height() < contentsHeight())
-            {
-                if (scrGeo.top() == aGlobalPos.y()) dy = -1;
-                if (scrGeo.bottom() == aGlobalPos.y()) dy = +1;
-            }
-            if (dx || dy)
-                scrollBy(dx, dy);
-        }
-#endif
-
-        if (uisession()->isMouseSupportsAbsolute() && uisession()->isMouseIntegrated())
-        {
-            int cw = contentsWidth(), ch = contentsHeight();
-            int vw = visibleWidth(), vh = visibleHeight();
-
-            if (vboxGlobal().vmRenderMode() != VBoxDefs::SDLMode)
-            {
-                /* Try to automatically scroll the guest canvas if the
-                 * mouse goes outside its visible part: */
-                int dx = 0;
-                if (aPos.x() > vw) dx = aPos.x() - vw;
-                else if (aPos.x() < 0) dx = aPos.x();
-                int dy = 0;
-                if (aPos.y() > vh) dy = aPos.y() - vh;
-                else if (aPos.y() < 0) dy = aPos.y();
-                if (dx != 0 || dy != 0) scrollBy (dx, dy);
-            }
-
-            QPoint cpnt = viewportToContents(aPos);
-            if (cpnt.x() < 0) cpnt.setX(0);
-            else if (cpnt.x() > cw - 1) cpnt.setX(cw - 1);
-            if (cpnt.y() < 0) cpnt.setY(0);
-            else if (cpnt.y() > ch - 1) cpnt.setY(ch - 1);
-
-            // TODO: Where to put that actually?
-            /* Get & Setup absolute-event shift: */
-            CFramebuffer framebuffer;
-            LONG xShift = 0, yShift = 0;
-            session().GetConsole().GetDisplay().GetFramebuffer(screenId(), framebuffer, xShift, yShift);
-            cpnt.setX(cpnt.x() + xShift);
-            cpnt.setY(cpnt.y() + yShift);
-
-            CMouse mouse = session().GetConsole().GetMouse();
-            // AssertMsgFailed(("x=%d, y=%d", cpnt.x(), cpnt.y())); // this shows what absolute coordinates are correct!
-            mouse.PutMouseEventAbsolute(cpnt.x() + 1, cpnt.y() + 1, wheelVertical, wheelHorizontal, state);
-            return true;
-        }
-        else
-        {
-            if (hasFocus() && (aType == QEvent::MouseButtonRelease && aButtons == Qt::NoButton))
-            {
-                if (uisession()->isPaused())
-                {
-                    vboxProblem().remindAboutPausedVMInput();
-                }
-                else if (uisession()->isRunning())
-                {
-                    /* Temporarily disable auto capture that will take place after this dialog is dismissed because
-                     * the capture state is to be defined by the dialog result itself: */
-                    uisession()->setAutoCaptureDisabled(true);
-                    bool autoConfirmed = false;
-                    bool ok = vboxProblem().confirmInputCapture(&autoConfirmed);
-                    if (autoConfirmed)
-                        uisession()->setAutoCaptureDisabled(false);
-                    /* Otherwise, the disable flag will be reset in the next console view's foucs in event (since
-                     * may happen asynchronously on some platforms, after we return from this code): */
-                    if (ok)
-                    {
-#ifdef Q_WS_X11
-                        /* Make sure that pending FocusOut events from the previous message box are handled,
-                         * otherwise the mouse is immediately ungrabbed again: */
-                        qApp->processEvents();
-#endif
-                        captureKbd(true);
-                        captureMouse(true);
-                    }
-                }
-            }
-        }
-    }
-
-    return false;
 }
 
@@ -2114,5 +1630,9 @@
             {
                 if (VBoxGlobal::qtRTVersion() < ((4 << 16) | (5 << 8) | 0))
-                    focusEvent (pEvent->type == XFocusIn);
+                {
+                    focusEvent(pEvent->type == XFocusIn);
+                    if (pEvent->type == XFocusOut)
+                        machineLogic()->mouseHandler()->releaseMouse();
+                }
             }
             return false;
@@ -2423,9 +1943,4 @@
 }
 
-void UIMachineView::emitMouseStateChanged()
-{
-    emit mouseStateChanged(mouseState());
-}
-
 void UIMachineView::captureKbd(bool fCapture, bool fEmitSignal /* = true */)
 {
@@ -2496,52 +2011,4 @@
     if (fEmitSignal)
         emitKeyboardStateChanged();
-}
-
-void UIMachineView::captureMouse(bool fCapture, bool fEmitSignal /* = true */)
-{
-    /* Do not change anything if its already so: */
-    if (uisession()->isMouseCaptured() == fCapture)
-        return;
-
-    /* Store new mouse 'captured' state value: */
-    uisession()->setMouseCaptured(fCapture);
-
-    if (fCapture)
-    {
-        /* Memorize the host position where the cursor was captured: */
-        m_capturedMousePos = QCursor::pos();
-#ifdef Q_WS_WIN32
-        /* Remember what this window captured mouse: */
-        m_fItsMeWhoCapturedMouse = true;
-        /* Move the mouse to the center of the visible area: */
-        m_lastMousePos = mapToGlobal(visibleRegion().boundingRect().center());
-        QCursor::setPos(m_lastMousePos);
-        /* Update mouse clipping: */
-        updateMouseCursorClipping();
-#elif defined (Q_WS_MAC)
-        /* Move the mouse to the center of the visible area: */
-        m_lastMousePos = mapToGlobal(visibleRegion().boundingRect().center());
-        QCursor::setPos(m_lastMousePos);
-        /* Grab all mouse events: */
-        viewport()->grabMouse();
-#else
-        /* Grab all mouse events: */
-        viewport()->grabMouse();
-        m_lastMousePos = QCursor::pos();
-#endif
-    }
-    else
-    {
-        /* Return the cursor to where it was when we captured it: */
-        QCursor::setPos(m_capturedMousePos);
-    }
-
-    /* Updating guest mouse: */
-    CMouse mouse = session().GetConsole().GetMouse();
-    mouse.PutMouseEvent(0, 0, 0, 0, 0);
-
-    /* Emit signal if required: */
-    if (fEmitSignal)
-        emitMouseStateChanged();
 }
 
@@ -2710,17 +2177,4 @@
     machineLogic()->updateDockIcon();
 }
-
-void UIMachineView::setMouseCoalescingEnabled(bool fOn)
-{
-    /* Enable mouse event compression if we leave the VM view. This
-       is necessary for having smooth resizing of the VM/other
-       windows.
-       Disable mouse event compression if we enter the VM view. So
-       all mouse events are registered in the VM. Only do this if
-       the keyboard/mouse is grabbed (this is when we have a valid
-       event handler). */
-    if (fOn || m_fKeyboardGrabbed)
-        ::darwinSetMouseCoalescingEnabled(fOn);
-}
 #endif /* Q_WS_MAC */
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h	(revision 30407)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h	(revision 30408)
@@ -59,10 +59,8 @@
     /* Public getters: */
     int keyboardState() const;
-    int mouseState() const;
     virtual QRegion lastVisibleRegion() const { return QRegion(); }
 
     /* Public setters: */
     virtual void setGuestAutoresizeEnabled(bool /* fEnabled */) {}
-    virtual void setMouseIntegrationEnabled(bool fEnabled);
 
     /* Public members: */
@@ -71,7 +69,6 @@
 signals:
 
-    /* Mouse/Keyboard state-change signals: */
+    /* Keyboard state-change signals: */
     void keyboardStateChanged(int iState);
-    void mouseStateChanged(int iState);
 
     /* Utility signals: */
@@ -109,4 +106,9 @@
     QSize desktopGeometry() const;
     QSize guestSizeHint();
+#ifdef Q_WS_MAC
+    /* These getters are temporary here while UIKeyboardHandler is not implemented: */
+    bool isHostKeyAlone() const { return m_bIsHostkeyAlone; }
+    bool isKeyboardGrabbed() const { return m_fKeyboardGrabbed; }
+#endif /* Q_WS_MAC */
 
     /* Protected setters: */
@@ -117,8 +119,4 @@
 
     /* Protected helpers: */
-    void updateMouseCursorShape();
-#ifdef Q_WS_WIN32
-    void updateMouseCursorClipping();
-#endif
     virtual QRect workingArea() = 0;
     virtual void calculateDesktopGeometry() = 0;
@@ -128,5 +126,4 @@
 #ifdef Q_WS_MAC
     void updateDockIcon();
-    void setMouseCoalescingEnabled(bool fOn);
     CGImageRef vmContentImage();
     CGImageRef frameBuffertoCGImageRef(UIFrameBuffer *pFrameBuffer);
@@ -158,10 +155,5 @@
     /* Console callback handlers: */
     virtual void sltMachineStateChanged();
-    virtual void sltMousePointerShapeChanged();
-    virtual void sltMouseCapabilityChanged();
     virtual void sltPerformGuestResize(const QSize & /* toSize */) {};
-
-    /* Session callback handlers: */
-    virtual void sltMouseCapturedStatusChanged();
 
     /* Various helper slots: */
@@ -173,7 +165,4 @@
     void focusEvent(bool aHasFocus, bool aReleaseHostKey = true);
     bool keyEvent(int aKey, uint8_t aScan, int aFlags, wchar_t *aUniKey = NULL);
-    bool mouseEvent(int aType, const QPoint &aPos, const QPoint &aGlobalPos,
-                    Qt::MouseButtons aButtons, Qt::KeyboardModifiers aModifiers,
-                    int aWheelDelta, Qt::Orientation aWheelDir);
     void resizeEvent(QResizeEvent *pEvent);
     void moveEvent(QMoveEvent *pEvent);
@@ -203,7 +192,5 @@
 #endif
     void emitKeyboardStateChanged();
-    void emitMouseStateChanged();
     void captureKbd(bool fCapture, bool fEmitSignal = true);
-    void captureMouse(bool fCapture, bool fEmitSignal = true);
     void saveKeyStates();
     void releaseAllPressedKeys(bool aReleaseHostKey = true);
@@ -222,8 +209,4 @@
     QSize m_storedConsoleSize;
 
-    QPoint m_lastMousePos;
-    QPoint m_capturedMousePos;
-    int m_iLastMouseWheelDelta;
-
     uint8_t m_pressedKeys[128];
     uint8_t m_pressedKeysCopy[128];
@@ -239,7 +222,4 @@
 #endif
 
-#ifdef Q_WS_WIN
-    bool m_fItsMeWhoCapturedMouse;
-#endif /* Q_WS_WIN */
 #ifdef Q_WS_MAC
     /** The current modifier key mask. Used to figure out which modifier
@@ -252,4 +232,5 @@
 
     /* Friend classes: */
+    friend class UIMouseHandler;
     friend class UIMachineLogic;
     friend class UIFrameBuffer;
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMouseHandler.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMouseHandler.cpp	(revision 30408)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMouseHandler.cpp	(revision 30408)
@@ -0,0 +1,758 @@
+/* $Id$ */
+/** @file
+ *
+ * VBox frontends: Qt GUI ("VirtualBox"):
+ * UIMouseHandler class implementation
+ */
+
+/*
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+/* Global includes */
+#include <QDesktopWidget>
+#include <QMouseEvent>
+
+/* Local includes */
+#include "VBoxGlobal.h"
+#include "VBoxProblemReporter.h"
+#include "UIMouseHandler.h"
+#include "UISession.h"
+#include "UIMachineLogic.h"
+#include "UIMachineView.h"
+
+/* Factory function to create mouse-handler: */
+UIMouseHandler* UIMouseHandler::create(UIMachineLogic *pMachineLogic,
+                                       UIVisualStateType visualStateType)
+{
+    /* Prepare mouse-handler: */
+    UIMouseHandler *pMouseHandler = 0;
+    /* Depending on visual-state type: */
+    switch (visualStateType)
+    {
+        /* For now all the states using common mouse-handler: */
+        case UIVisualStateType_Normal:
+        case UIVisualStateType_Fullscreen:
+        case UIVisualStateType_Seamless:
+            pMouseHandler = new UIMouseHandler(pMachineLogic);
+            break;
+        default:
+            break;
+    }
+    /* Return prepared mouse-handler: */
+    return pMouseHandler;
+}
+
+/* Factory function to destroy mouse-handler: */
+void UIMouseHandler::destroy(UIMouseHandler *pMouseHandler)
+{
+    /* Delete mouse-handler: */
+    delete pMouseHandler;
+}
+
+/* Registers new machine-view: */
+void UIMouseHandler::addMachineView(ulong uViewIndex, UIMachineView *pMachineView)
+{
+    /* If that view is NOT registered yet: */
+    if (!m_views.contains(uViewIndex))
+    {
+        /* Register machine-view: */
+        m_views.insert(uViewIndex, pMachineView);
+        /* Install event-filter for machine-view: */
+        m_views[uViewIndex]->installEventFilter(this);
+        /* Make machine-view notify mouse-handler about resizeHintDone(): */
+        connect(m_views[uViewIndex], SIGNAL(resizeHintDone()), this, SLOT(sltMousePointerShapeChanged()));
+    }
+
+    /* If that viewport is NOT registered yet: */
+    if (!m_viewports.contains(uViewIndex))
+    {
+        /* Register machine-view-viewport: */
+        m_viewports.insert(uViewIndex, pMachineView->viewport());
+        /* Install event-filter for machine-view-viewport: */
+        m_viewports[uViewIndex]->installEventFilter(this);
+    }
+}
+
+/* Remove registered machine-view: */
+void UIMouseHandler::delMachineView(ulong uViewIndex)
+{
+    /* If that view is registered yet: */
+    if (m_views.contains(uViewIndex))
+    {
+        /* Unregister machine-view: */
+        m_views.remove(uViewIndex);
+    }
+
+    /* If that viewport is registered yet: */
+    if (m_viewports.contains(uViewIndex))
+    {
+        /* Unregister machine-view-viewport: */
+        m_viewports.remove(uViewIndex);
+    }
+}
+
+void UIMouseHandler::captureMouse(ulong uScreenId)
+{
+    /* Do not try to capture mouse if its captured already: */
+    if (uisession()->isMouseCaptured())
+        return;
+
+    /* If such viewport exists: */
+    if (m_viewports.contains(uScreenId))
+    {
+        /* Store mouse-capturing state value: */
+        uisession()->setMouseCaptured(true);
+
+        /* Memorize the index of machine-view-viewport captured mouse: */
+        m_iMouseCaptureViewIndex = uScreenId;
+
+        /* Memorize the host position where the cursor was captured: */
+        m_capturedMousePos = QCursor::pos();
+#ifdef Q_WS_WIN
+        /* Move the mouse to the center of the visible area: */
+        m_lastMousePos = m_views[m_iMouseCaptureViewIndex]->mapToGlobal(m_views[m_iMouseCaptureViewIndex]->visibleRegion().boundingRect().center());
+        QCursor::setPos(m_lastMousePos);
+        /* Update mouse clipping: */
+        updateMouseCursorClipping();
+#elif defined (Q_WS_MAC)
+        /* Move the mouse to the center of the visible area: */
+        m_lastMousePos = m_views[m_iMouseCaptureViewIndex]->mapToGlobal(m_views[m_iMouseCaptureViewIndex]->visibleRegion().boundingRect().center());
+        QCursor::setPos(m_lastMousePos);
+        /* Grab all mouse events: */
+        m_viewports[m_iMouseCaptureViewIndex]->grabMouse();
+#else /* Q_WS_MAC */
+        /* Remember current mouse position: */
+        m_lastMousePos = QCursor::pos();
+        /* Grab all mouse events: */
+        m_viewports[m_iMouseCaptureViewIndex]->grabMouse();
+#endif /* !Q_WS_MAC */
+
+        /* Switch guest mouse to the relative mode: */
+        CMouse mouse = session().GetConsole().GetMouse();
+        mouse.PutMouseEvent(0, 0, 0, 0, 0);
+
+        /* Emit signal if required: */
+        emit mouseStateChanged(mouseState());
+    }
+}
+
+void UIMouseHandler::releaseMouse()
+{
+    /* Do not try to release mouse if its released already: */
+    if (!uisession()->isMouseCaptured())
+        return;
+
+    /* If such viewport exists: */
+    if (m_viewports.contains(m_iMouseCaptureViewIndex))
+    {
+        /* Store mouse-capturing state value: */
+        uisession()->setMouseCaptured(false);
+
+        /* Return the cursor to where it was when we captured it: */
+        QCursor::setPos(m_capturedMousePos);
+#ifdef Q_WS_WIN
+        /* Update mouse clipping: */
+        updateMouseCursorClipping();
+#else /* Q_WS_WIN */
+        /* Releasing grabbed mouse from that view: */
+        m_viewports[m_iMouseCaptureViewIndex]->releaseMouse();
+#endif /* !Q_WS_WIN */
+        /* Reset mouse-capture index: */
+        m_iMouseCaptureViewIndex = -1;
+
+        /* Emit signal if required: */
+        emit mouseStateChanged(mouseState());
+    }
+}
+
+/* Setter for mouse-integration feature: */
+void UIMouseHandler::setMouseIntegrationEnabled(bool fEnabled)
+{
+    /* Do not do anything if its already done: */
+    if (uisession()->isMouseIntegrated() == fEnabled)
+        return;
+
+    /* Store mouse-integration state value: */
+    uisession()->setMouseIntegrated(fEnabled);
+
+    /* Reuse sltMouseCapabilityChanged() to update mouse state: */
+    sltMouseCapabilityChanged();
+}
+
+/* Current mouse state: */
+int UIMouseHandler::mouseState() const
+{
+    return (uisession()->isMouseCaptured() ? UIMouseStateType_MouseCaptured : 0) |
+           (uisession()->isMouseSupportsAbsolute() ? UIMouseStateType_MouseAbsolute : 0) |
+           (uisession()->isMouseIntegrated() ? 0 : UIMouseStateType_MouseAbsoluteDisabled);
+}
+
+/* Machine state-change handler: */
+void UIMouseHandler::sltMachineStateChanged()
+{
+    /* Get machine state: */
+    KMachineState state = uisession()->machineState();
+    /* Handle particular machine states: */
+    switch (state)
+    {
+        case KMachineState_Paused:
+        case KMachineState_TeleportingPausedVM:
+        case KMachineState_Stuck:
+        {
+            /* Release the mouse: */
+            releaseMouse();
+            break;
+        }
+        default:
+            break;
+    }
+}
+
+/* Mouse capability-change handler: */
+void UIMouseHandler::sltMouseCapabilityChanged()
+{
+    /* If mouse supports absolute pointing and mouse-integration activated: */
+    if (uisession()->isMouseSupportsAbsolute() && uisession()->isMouseIntegrated())
+    {
+        /* Release the mouse: */
+        releaseMouse();
+        /* Also we should switch guest mouse to the absolute mode: */
+        CMouse mouse = session().GetConsole().GetMouse();
+        mouse.PutMouseEventAbsolute(-1, -1, 0, 0, 0);
+    }
+    /* If mouse-integration deactivated or mouse doesn't supports absolute pointing: */
+    else
+    {
+        /* Search for the machine-view focused now: */
+        int iFocusedView = -1;
+        QList<ulong> screenIds = m_views.keys();
+        for (int i = 0; i < screenIds.size(); ++i)
+        {
+            if (m_views[screenIds[i]]->hasFocus())
+            {
+                iFocusedView = screenIds[i];
+                break;
+            }
+        }
+        /* If there is no focused view but views are present we will use the first one: */
+        if (iFocusedView == -1 && !screenIds.isEmpty())
+            iFocusedView = screenIds[0];
+        /* Capture mouse using that view: */
+        if (iFocusedView != -1)
+            captureMouse(iFocusedView);
+    }
+
+    /* Notify user about mouse supports or not absolute pointing if that method was called by signal: */
+    if (sender())
+        vboxProblem().remindAboutMouseIntegration(uisession()->isMouseSupportsAbsolute());
+
+    /* Notify all listeners: */
+    emit mouseStateChanged(mouseState());
+}
+
+/* Mouse pointer-shape-change handler: */
+void UIMouseHandler::sltMousePointerShapeChanged()
+{
+    /* First of all, we should check if the host pointer should be visible.
+     * We should hide host pointer in case of:
+     * 1. mouse is 'captured' or
+     * 2. mouse is 'not captured', 'integrated', 'absolute', host pointer is hidden by the guest. */
+    if (uisession()->isMouseCaptured() ||
+        (uisession()->isMouseIntegrated() &&
+         uisession()->isMouseSupportsAbsolute() &&
+         uisession()->isHidingHostPointer()))
+    {
+        QList<ulong> screenIds = m_viewports.keys();
+        for (int i = 0; i < screenIds.size(); ++i)
+            m_viewports[screenIds[i]]->setCursor(Qt::BlankCursor);
+    }
+
+    else
+
+    /* Otherwise we should show host pointer with guest shape assigned to it if:
+     * mouse is 'integrated', 'absolute', valid pointer shape is present. */
+    if (uisession()->isMouseIntegrated() &&
+        uisession()->isMouseSupportsAbsolute() &&
+        uisession()->isValidPointerShapePresent())
+    {
+        QList<ulong> screenIds = m_viewports.keys();
+        for (int i = 0; i < screenIds.size(); ++i)
+            m_viewports[screenIds[i]]->setCursor(uisession()->cursor());
+    }
+
+    else
+
+    /* There could be other states covering such situations as:
+     * 1. mouse is 'not captured', 'integrated', 'not absolute' or
+     * 2. mouse is 'not captured', 'not integrated', 'absolute'.
+     * We have nothing to do with that except just unset the cursor. */
+    {
+        QList<ulong> screenIds = m_viewports.keys();
+        for (int i = 0; i < screenIds.size(); ++i)
+            m_viewports[screenIds[i]]->unsetCursor();
+    }
+}
+
+/* Mouse-handler constructor: */
+UIMouseHandler::UIMouseHandler(UIMachineLogic *pMachineLogic)
+    : QObject(pMachineLogic)
+    , m_pMachineLogic(pMachineLogic)
+    , m_iLastMouseWheelDelta(0)
+    , m_iMouseCaptureViewIndex(-1)
+{
+    /* Machine state-change updater: */
+    connect(uisession(), SIGNAL(sigMachineStateChange()), this, SLOT(sltMachineStateChanged()));
+
+    /* Mouse capability state-change updater: */
+    connect(uisession(), SIGNAL(sigMouseCapabilityChange()), this, SLOT(sltMouseCapabilityChanged()));
+
+    /* Mouse pointer shape state-change updaters: */
+    connect(uisession(), SIGNAL(sigMousePointerShapeChange()), this, SLOT(sltMousePointerShapeChanged()));
+    connect(this, SIGNAL(mouseStateChanged(int)), this, SLOT(sltMousePointerShapeChanged()));
+
+    /* Initialize: */
+    sltMachineStateChanged();
+    sltMousePointerShapeChanged();
+    sltMouseCapabilityChanged();
+}
+
+/* Mouse-handler destructor: */
+UIMouseHandler::~UIMouseHandler()
+{
+}
+
+/* Machine-logic getter: */
+UIMachineLogic* UIMouseHandler::machineLogic() const
+{
+    return m_pMachineLogic;
+}
+
+/* UI Session getter: */
+UISession* UIMouseHandler::uisession() const
+{
+    return machineLogic()->uisession();
+}
+
+/* Main Session getter: */
+CSession& UIMouseHandler::session() const
+{
+    return uisession()->session();
+}
+
+/* Event handler for registered machine-view(s): */
+bool UIMouseHandler::eventFilter(QObject *pWatched, QEvent *pEvent)
+{
+    /* If that object is of QWidget type: */
+    if (QWidget *pWatchedWidget = qobject_cast<QWidget*>(pWatched))
+    {
+        /* If thats machine-view-viewport: */
+        if (m_viewports.values().contains(pWatchedWidget))
+        {
+            /* Get current watched widget screen id: */
+            ulong uScreenId = m_viewports.key(pWatchedWidget);
+            /* Handle viewport events: */
+            switch (pEvent->type())
+            {
+                case QEvent::MouseMove:
+                case QEvent::MouseButtonRelease:
+                {
+                    /* Check if we should propagate this event to another window: */
+                    QWidget *pHoveredWidget = QApplication::widgetAt(QCursor::pos());
+                    if (pHoveredWidget && pHoveredWidget != pWatchedWidget && m_viewports.values().contains(pHoveredWidget))
+                    {
+                        /* Get current mouse-move event: */
+                        QMouseEvent *pOldMouseEvent = static_cast<QMouseEvent*>(pEvent);
+
+                        /* Prepare redirected mouse-move event: */
+                        QMouseEvent *pNewMouseEvent = new QMouseEvent(pOldMouseEvent->type(),
+                                                                      pHoveredWidget->mapFromGlobal(pOldMouseEvent->globalPos()),
+                                                                      pOldMouseEvent->globalPos(),
+                                                                      pOldMouseEvent->button(),
+                                                                      pOldMouseEvent->buttons(),
+                                                                      pOldMouseEvent->modifiers());
+
+                        /* Send that event to real destination: */
+                        QApplication::postEvent(pHoveredWidget, pNewMouseEvent);
+
+                        /* Filter out that event: */
+                        return true;
+                    }
+
+                    /* Check if we should activate window under cursor: */
+                    if (!uisession()->isMouseCaptured() &&
+                        QApplication::activeWindow() &&
+                        QApplication::activeWindow()->inherits("UIMachineWindow") &&
+                        QApplication::activeWindow() != pWatchedWidget->window())
+                    {
+                        /* Activating hovered machine window: */
+                        pWatchedWidget->window()->activateWindow();
+#ifdef Q_WS_X11
+                        /* On X11 its not enough to just activate window if you
+                         * want to raise it also, so we will make it separately: */
+                        pWatchedWidget->window()->raise();
+#endif /* Q_WS_X11 */
+                    }
+
+                    /* This event should be also processed using next 'case': */
+                }
+                case QEvent::MouseButtonPress:
+                case QEvent::MouseButtonDblClick:
+                {
+                    QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(pEvent);
+                    m_iLastMouseWheelDelta = 0;
+                    if (mouseEvent(pMouseEvent->type(), uScreenId,
+                                   pMouseEvent->pos(), pMouseEvent->globalPos(),
+                                   pMouseEvent->buttons(), 0, Qt::Horizontal))
+                        return true;
+                    break;
+                }
+                case QEvent::Wheel:
+                {
+                    QWheelEvent *pWheelEvent = static_cast<QWheelEvent*>(pEvent);
+                    /* There are pointing devices which send smaller values for the delta than 120.
+                     * Here we sum them up until we are greater than 120. This allows to have finer control
+                     * over the speed acceleration & enables such devices to send a valid wheel event to our
+                     * guest mouse device at all: */
+                    int iDelta = 0;
+                    m_iLastMouseWheelDelta += pWheelEvent->delta();
+                    if (qAbs(m_iLastMouseWheelDelta) >= 120)
+                    {
+                        iDelta = m_iLastMouseWheelDelta;
+                        m_iLastMouseWheelDelta = m_iLastMouseWheelDelta % 120;
+                    }
+                    if (mouseEvent(pWheelEvent->type(), uScreenId,
+                                   pWheelEvent->pos(), pWheelEvent->globalPos(),
+#ifdef QT_MAC_USE_COCOA
+                                   /* Qt Cocoa is buggy. It always reports a left button pressed when the
+                                    * mouse wheel event occurs. A workaround is to ask the application which
+                                    * buttons are pressed currently: */
+                                   QApplication::mouseButtons(),
+#else /* QT_MAC_USE_COCOA */
+                                   pWheelEvent->buttons(),
+#endif /* !QT_MAC_USE_COCOA */
+                                   iDelta, pWheelEvent->orientation()))
+                        return true;
+                    break;
+                }
+#ifdef Q_WS_MAC
+                case QEvent::Leave:
+                {
+                    /* Enable mouse event compression if we leave the VM view.
+                     * This is necessary for having smooth resizing of the VM/other windows: */
+                    ::darwinSetMouseCoalescingEnabled(true);
+                    break;
+                }
+                case QEvent::Enter:
+                {
+                    /* Disable mouse event compression if we enter the VM view.
+                     * So all mouse events are registered in the VM.
+                     * Only do this if the keyboard/mouse is grabbed
+                     * (this is when we have a valid event handler): */
+                    if (m_views[uScreenId]->isKeyboardGrabbed())
+                        ::darwinSetMouseCoalescingEnabled(false);
+                    break;
+                }
+#endif /* Q_WS_MAC */
+#ifdef Q_WS_WIN
+                case QEvent::Resize:
+                {
+                    /* Update mouse clipping: */
+                    updateMouseCursorClipping();
+                    break;
+                }
+#endif /* Q_WS_WIN */
+                default:
+                    break;
+            }
+        }
+        /* If no => check if that widget is of UIMachineView type: */
+        else if (UIMachineView *pWatchedMachineView = qobject_cast<UIMachineView*>(pWatchedWidget))
+        {
+            /* If thats machine-view itself => handle machine-view events: */
+            if (m_views.values().contains(pWatchedMachineView))
+            {
+                switch (pEvent->type())
+                {
+                    case QEvent::FocusOut:
+                        /* Just release the mouse: */
+                        releaseMouse();
+                        break;
+                    default:
+                        break;
+                }
+            }
+        }
+    }
+    return QObject::eventFilter(pWatched, pEvent);
+}
+
+/* Separate function to handle most of existing mouse-events: */
+bool UIMouseHandler::mouseEvent(int iEventType, ulong uScreenId,
+                                const QPoint &relativePos, const QPoint &globalPos,
+                                Qt::MouseButtons mouseButtons,
+                                int wheelDelta, Qt::Orientation wheelDirection)
+{
+    /* Check if such view & viewport are registered: */
+    if (!m_views.contains(uScreenId) || !m_viewports.contains(uScreenId))
+        return true;
+
+    int iMouseButtonsState = 0;
+    if (mouseButtons & Qt::LeftButton)
+        iMouseButtonsState |= KMouseButtonState_LeftButton;
+    if (mouseButtons & Qt::RightButton)
+        iMouseButtonsState |= KMouseButtonState_RightButton;
+    if (mouseButtons & Qt::MidButton)
+        iMouseButtonsState |= KMouseButtonState_MiddleButton;
+    if (mouseButtons & Qt::XButton1)
+        iMouseButtonsState |= KMouseButtonState_XButton1;
+    if (mouseButtons & Qt::XButton2)
+        iMouseButtonsState |= KMouseButtonState_XButton2;
+
+#ifdef Q_WS_MAC
+    /* Simulate the right click on host-key + left-mouse-button: */
+    if (m_views[uScreenId]->isHostKeyPressed() &&
+        m_views[uScreenId]->isHostKeyAlone() &&
+        iMouseButtonsState == KMouseButtonState_LeftButton)
+        iMouseButtonsState = KMouseButtonState_RightButton;
+#endif /* Q_WS_MAC */
+
+    int iWheelVertical = 0;
+    int iWheelHorizontal = 0;
+    if (wheelDirection == Qt::Vertical)
+    {
+        /* The absolute value of wheel delta is 120 units per every wheel move;
+         * positive deltas correspond to counterclockwize rotations (usually up),
+         * negative deltas correspond to clockwize (usually down). */
+        iWheelVertical = - (wheelDelta / 120);
+    }
+    else if (wheelDirection == Qt::Horizontal)
+        iWheelHorizontal = wheelDelta / 120;
+
+    if (uisession()->isMouseCaptured())
+    {
+#ifdef Q_WS_WIN
+        /* Send pending WM_PAINT events: */
+        ::UpdateWindow(m_viewports[uScreenId]->winId());
+#endif
+
+        CMouse mouse = session().GetConsole().GetMouse();
+        mouse.PutMouseEvent(globalPos.x() - m_lastMousePos.x(),
+                            globalPos.y() - m_lastMousePos.y(),
+                            iWheelVertical, iWheelHorizontal, iMouseButtonsState);
+
+#ifdef Q_WS_MAC
+        /* Keep the mouse from leaving the widget.
+         * This is a bit tricky to get right because if it escapes we won't necessarily
+         * get mouse events any longer and can warp it back. So, we keep safety zone
+         * of up to 300 pixels around the borders of the widget to prevent this from
+         * happening. Also, the mouse is warped back to the center of the widget.
+         * (Note, relativePos seems to be unreliable, it caused endless recursion here at one points...)
+         * (Note, synergy and other remote clients might not like this cursor warping.) */
+        QRect rect = m_viewports[uScreenId]->visibleRegion().boundingRect();
+        QPoint pw = m_viewports[uScreenId]->mapToGlobal(m_viewports[uScreenId]->pos());
+        rect.translate(pw.x(), pw.y());
+
+        QRect dpRect = QApplication::desktop()->screenGeometry(m_viewports[uScreenId]);
+        if (rect.intersects(dpRect))
+            rect = rect.intersect(dpRect);
+
+        int iWsafe = rect.width() / 6;
+        rect.setWidth(rect.width() - iWsafe * 2);
+        rect.setLeft(rect.left() + iWsafe);
+
+        int iHsafe = rect.height() / 6;
+        rect.setWidth(rect.height() - iHsafe * 2);
+        rect.setTop(rect.top() + iHsafe);
+
+        if (rect.contains(globalPos, true))
+            m_lastMousePos = globalPos;
+        else
+        {
+            m_lastMousePos = rect.center();
+            QCursor::setPos(m_lastMousePos);
+        }
+#else /* Q_WS_MAC */
+
+        /* Bringing mouse to the opposite side to simulate the endless moving: */
+
+# ifdef Q_WS_WIN
+        int iWe = m_viewports[uScreenId]->width() - 1;
+        int iHe = m_viewports[uScreenId]->height() - 1;
+        QPoint p = relativePos;
+        if (relativePos.x() == 0)
+            p.setX(iWe - 1);
+        else if (relativePos.x() == iWe)
+            p.setX(1);
+        if (relativePos.y() == 0 )
+            p.setY(iHe - 1);
+        else if (relativePos.y() == iHe)
+            p.setY(1);
+
+        if (p != relativePos)
+        {
+            m_lastMousePos = m_viewports[uScreenId]->mapToGlobal(p);
+            QCursor::setPos(m_lastMousePos);
+        }
+        else
+        {
+            m_lastMousePos = globalPos;
+        }
+# else /* Q_WS_WIN */
+        int iWe = QApplication::desktop()->width() - 1;
+        int iHe = QApplication::desktop()->height() - 1;
+        QPoint p = globalPos;
+        if (globalPos.x() == 0)
+            p.setX(iWe - 1);
+        else if (globalPos.x() == iWe)
+            p.setX( 1 );
+        if (globalPos.y() == 0)
+            p.setY(iHe - 1);
+        else if (globalPos.y() == iHe)
+            p.setY(1);
+
+        if (p != globalPos)
+        {
+            m_lastMousePos =  p;
+            QCursor::setPos(m_lastMousePos);
+        }
+        else
+        {
+            m_lastMousePos = globalPos;
+        }
+# endif /* !Q_WS_WIN */
+#endif /* !Q_WS_MAC */
+        return true; /* stop further event handling */
+    }
+    else /* !uisession()->isMouseCaptured() */
+    {
+#if 0 // TODO: Move that to fullscreen event-handler:
+        if (vboxGlobal().vmRenderMode() != VBoxDefs::SDLMode)
+        {
+            /* try to automatically scroll the guest canvas if the
+             * mouse is on the screen border */
+            /// @todo (r=dmik) better use a timer for autoscroll
+            QRect scrGeo = QApplication::desktop()->screenGeometry (this);
+            int iDx = 0, iDy = 0;
+            if (scrGeo.width() < contentsWidth())
+            {
+                if (scrGeo.left() == globalPos.x()) iDx = -1;
+                if (scrGeo.right() == globalPos.x()) iDx = +1;
+            }
+            if (scrGeo.height() < contentsHeight())
+            {
+                if (scrGeo.top() == globalPos.y()) iDy = -1;
+                if (scrGeo.bottom() == globalPos.y()) iDy = +1;
+            }
+            if (iDx || iDy)
+                scrollBy(iDx, iDy);
+        }
+#endif
+
+        if (uisession()->isMouseSupportsAbsolute() && uisession()->isMouseIntegrated())
+        {
+            int iCw = m_views[uScreenId]->contentsWidth(), iCh = m_views[uScreenId]->contentsHeight();
+            int iVw = m_views[uScreenId]->visibleWidth(), iVh = m_views[uScreenId]->visibleHeight();
+
+            if (vboxGlobal().vmRenderMode() != VBoxDefs::SDLMode)
+            {
+                /* Try to automatically scroll the guest canvas if the
+                 * mouse goes outside its visible part: */
+                int iDx = 0;
+                if (relativePos.x() > iVw) iDx = relativePos.x() - iVw;
+                else if (relativePos.x() < 0) iDx = relativePos.x();
+                int iDy = 0;
+                if (relativePos.y() > iVh) iDy = relativePos.y() - iVh;
+                else if (relativePos.y() < 0) iDy = relativePos.y();
+                if (iDx != 0 || iDy != 0) m_views[uScreenId]->scrollBy(iDx, iDy);
+            }
+
+            QPoint cpnt = m_views[uScreenId]->viewportToContents(relativePos);
+            if (cpnt.x() < 0) cpnt.setX(0);
+            else if (cpnt.x() > iCw - 1) cpnt.setX(iCw - 1);
+            if (cpnt.y() < 0) cpnt.setY(0);
+            else if (cpnt.y() > iCh - 1) cpnt.setY(iCh - 1);
+
+            /* Get & Setup absolute-event shift: */
+            CFramebuffer framebuffer;
+            LONG xShift = 0, yShift = 0;
+            session().GetConsole().GetDisplay().GetFramebuffer(uScreenId, framebuffer, xShift, yShift);
+            cpnt.setX(cpnt.x() + xShift);
+            cpnt.setY(cpnt.y() + yShift);
+
+            CMouse mouse = session().GetConsole().GetMouse();
+            mouse.PutMouseEventAbsolute(cpnt.x() + 1, cpnt.y() + 1, iWheelVertical, iWheelHorizontal, iMouseButtonsState);
+            return true;
+        }
+        else
+        {
+            if (m_views[uScreenId]->hasFocus() && (iEventType == QEvent::MouseButtonRelease && mouseButtons == Qt::NoButton))
+            {
+                if (uisession()->isPaused())
+                {
+                    vboxProblem().remindAboutPausedVMInput();
+                }
+                else if (uisession()->isRunning())
+                {
+                    /* Temporarily disable auto capture that will take place after this dialog is dismissed because
+                     * the capture state is to be defined by the dialog result itself: */
+                    uisession()->setAutoCaptureDisabled(true);
+                    bool autoConfirmed = false;
+                    bool ok = vboxProblem().confirmInputCapture(&autoConfirmed);
+                    if (autoConfirmed)
+                        uisession()->setAutoCaptureDisabled(false);
+                    /* Otherwise, the disable flag will be reset in the next console view's foucs in event (since
+                     * may happen asynchronously on some platforms, after we return from this code): */
+                    if (ok)
+                    {
+#ifdef Q_WS_X11
+                        /* Make sure that pending FocusOut events from the previous message box are handled,
+                         * otherwise the mouse is immediately ungrabbed again: */
+                        qApp->processEvents();
+#endif
+                        /* Actually that will be a call to keyboard-handler, not no machine-view,
+                         * but now keyboard-handler is not implemented yet. */
+                        m_views[uScreenId]->captureKbd(true);
+
+                        captureMouse(uScreenId);
+                    }
+                }
+            }
+        }
+    }
+
+    return false;
+}
+
+#ifdef Q_WS_WIN
+/* This method is actually required only because under win-host
+ * we do not really grab the mouse in case of capturing it: */
+void UIMouseHandler::updateMouseCursorClipping()
+{
+    /* Check if such viewport is registered: */
+    if (!m_viewports.contains(m_iMouseCaptureViewIndex))
+        return;
+
+    if (uisession()->isMouseCaptured())
+    {
+        QWidget *pMachineViewViewport = m_viewports[m_iMouseCaptureViewIndex];
+        QRect r = pMachineViewViewport->rect();
+        r.moveTopLeft(pMachineViewViewport->mapToGlobal(QPoint(0, 0)));
+        RECT rect = { r.left(), r.top(), r.right() + 1, r.bottom() + 1 };
+        ::ClipCursor(&rect);
+    }
+    else
+    {
+        ::ClipCursor(NULL);
+    }
+}
+#endif /* Q_WS_WIN */
+
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMouseHandler.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMouseHandler.h	(revision 30408)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMouseHandler.h	(revision 30408)
@@ -0,0 +1,122 @@
+/** @file
+ *
+ * VBox frontends: Qt GUI ("VirtualBox"):
+ * UIMouseHandler class declaration
+ */
+
+/*
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+#ifndef ___UIMouseHandler_h___
+#define ___UIMouseHandler_h___
+
+/* Global includes */
+#include <QObject>
+#include <QPoint>
+#include <QMap>
+
+/* Local includes */
+#include "UIMachineDefs.h"
+
+/* Global forwards */
+class QWidget;
+
+/* Local forwards */
+class CSession;
+class UISession;
+class UIMachineLogic;
+class UIMachineView;
+
+/* Delegate to control VM mouse functionality: */
+class UIMouseHandler : public QObject
+{
+    Q_OBJECT;
+
+public:
+
+    /* Factory functions to create/destroy mouse-handler: */
+    static UIMouseHandler* create(UIMachineLogic *pMachineLogic, UIVisualStateType visualStateType);
+    static void destroy(UIMouseHandler *pMouseHandler);
+
+    /* Registers/Remove new machine-view: */
+    void addMachineView(ulong uViewIndex, UIMachineView *pMachineView);
+    void delMachineView(ulong uViewIndex);
+
+    /* Commands to capture/release mouse: */
+    void captureMouse(ulong uScreenId);
+    void releaseMouse();
+
+    /* Setter for mouse-integration feature: */
+    void setMouseIntegrationEnabled(bool fEnabled);
+
+    /* Current mouse state: */
+    int mouseState() const;
+
+signals:
+
+    /* Notifies listeners about mouse state-change: */
+    void mouseStateChanged(int iNewState);
+
+protected slots:
+
+    /* Machine state-change handler: */
+    virtual void sltMachineStateChanged();
+
+    /* Mouse capability-change handler: */
+    virtual void sltMouseCapabilityChanged();
+
+    /* Mouse pointer-shape-change handler: */
+    virtual void sltMousePointerShapeChanged();
+
+protected:
+
+    /* Mouse-handler constructor/destructor: */
+    UIMouseHandler(UIMachineLogic *pMachineLogic);
+    virtual ~UIMouseHandler();
+
+    /* Getters: */
+    UIMachineLogic* machineLogic() const;
+    UISession* uisession() const;
+    CSession& session() const;
+
+    /* Event handler for registered machine-view(s): */
+    bool eventFilter(QObject *pWatched, QEvent *pEvent);
+
+    /* Separate function to handle most of existing mouse-events: */
+    bool mouseEvent(int iEventType, ulong uScreenId,
+                    const QPoint &relativePos, const QPoint &globalPos,
+                    Qt::MouseButtons mouseButtons,
+                    int wheelDelta, Qt::Orientation wheelDirection);
+
+#ifdef Q_WS_WIN
+    /* This method is actually required only because under win-host
+     * we do not really grab the mouse in case of capturing it: */
+    void updateMouseCursorClipping();
+#endif /* Q_WS_WIN */
+
+    /* Machine logic parent: */
+    UIMachineLogic *m_pMachineLogic;
+
+    /* Registered machine-view(s): */
+    QMap<ulong, UIMachineView*> m_views;
+    /* Registered machine-view-viewport(s): */
+    QMap<ulong, QWidget*> m_viewports;
+
+    /* Other mouse variables: */
+    QPoint m_lastMousePos;
+    QPoint m_capturedMousePos;
+    int m_iLastMouseWheelDelta;
+    int m_iMouseCaptureViewIndex;
+};
+
+#endif // !___UIMouseHandler_h___
+
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h	(revision 30407)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h	(revision 30408)
@@ -138,5 +138,5 @@
 
     /* Mouse setters: */
-    void setMouseCaptured(bool fIsMouseCaptured) { m_fIsMouseCaptured = fIsMouseCaptured; emit sigMouseCapturedStatusChanged(); }
+    void setMouseCaptured(bool fIsMouseCaptured) { m_fIsMouseCaptured = fIsMouseCaptured; }
     void setMouseIntegrated(bool fIsMouseIntegrated) { m_fIsMouseIntegrated = fIsMouseIntegrated; }
 
@@ -176,5 +176,4 @@
     /* Session signals: */
     void sigMachineStarted();
-    void sigMouseCapturedStatusChanged();
 
 public slots:
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp	(revision 30407)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp	(revision 30408)
@@ -27,4 +27,5 @@
 
 #include "UIActionsPool.h"
+#include "UIMouseHandler.h"
 #include "UIMachineLogicFullscreen.h"
 #include "UIMachineWindow.h"
@@ -194,4 +195,8 @@
     m_pScreenLayout->update();
 
+    /* Create mouse-handler: */
+    UIMouseHandler *pMouseHandler = UIMouseHandler::create(this, visualStateType());
+    setMouseHandler(pMouseHandler);
+
     /* Create machine window(s): */
     for (int cScreenId = 0; cScreenId < m_pScreenLayout->guestScreenCount(); ++cScreenId)
@@ -225,4 +230,7 @@
     foreach (UIMachineWindow *pMachineWindow, machineWindows())
         UIMachineWindow::destroy(pMachineWindow);
+
+    /* Cleanup mouse-handler: */
+    UIMouseHandler::destroy(mouseHandler());
 
 #ifdef Q_WS_MAC
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.cpp	(revision 30407)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.cpp	(revision 30408)
@@ -74,6 +74,4 @@
     /* Initialization: */
     sltMachineStateChanged();
-    sltMousePointerShapeChanged();
-    sltMouseCapabilityChanged();
 }
 
@@ -188,7 +186,4 @@
 #endif /* Q_WS_MAC */
 
-            /* Update mouse cursor shape: */
-            updateMouseCursorShape();
-
             /* May be we have to restrict minimum size? */
             maybeRestrictMinimumSize();
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp	(revision 30407)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp	(revision 30408)
@@ -27,4 +27,5 @@
 
 #include "UIActionsPool.h"
+#include "UIMouseHandler.h"
 #include "UIDownloaderAdditions.h"
 #include "UIMachineLogicNormal.h"
@@ -142,4 +143,8 @@
 #endif /* Q_WS_MAC */
 
+    /* Create mouse-handler: */
+    UIMouseHandler *pMouseHandler = UIMouseHandler::create(this, visualStateType());
+    setMouseHandler(pMouseHandler);
+
     /* Get monitors count: */
     ulong uMonitorCount = session().GetMachine().GetMonitorCount();
@@ -164,4 +169,7 @@
     foreach (UIMachineWindow *pMachineWindow, machineWindows())
         UIMachineWindow::destroy(pMachineWindow);
+
+    /* Cleanup mouse-handler: */
+    UIMouseHandler::destroy(mouseHandler());
 }
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp	(revision 30407)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp	(revision 30408)
@@ -69,6 +69,4 @@
     sltMachineStateChanged();
     sltAdditionsStateChanged();
-    sltMousePointerShapeChanged();
-    sltMouseCapabilityChanged();
 }
 
@@ -176,7 +174,4 @@
             machineLogic()->updateDockIconSize(screenId(), pResizeEvent->width(), pResizeEvent->height());
 #endif /* Q_WS_MAC */
-
-            /* Update mouse cursor shape: */
-            updateMouseCursorShape();
 
             /* May be we have to restrict minimum size? */
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp	(revision 30407)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp	(revision 30408)
@@ -30,4 +30,5 @@
 
 #include "UIActionsPool.h"
+#include "UIMouseHandler.h"
 #include "UIDownloaderAdditions.h"
 #include "UIDownloaderUserManual.h"
@@ -489,9 +490,9 @@
 
         /* Mouse state-change updater: */
-        connect(machineView(), SIGNAL(mouseStateChanged(int)), indicatorsPool()->indicator(UIIndicatorIndex_Mouse), SLOT(setState(int)));
+        connect(machineLogic()->mouseHandler(), SIGNAL(mouseStateChanged(int)), indicatorsPool()->indicator(UIIndicatorIndex_Mouse), SLOT(setState(int)));
 
         /* Early initialize required connections: */
         indicatorsPool()->indicator(UIIndicatorIndex_Hostkey)->setState(machineView()->keyboardState());
-        indicatorsPool()->indicator(UIIndicatorIndex_Mouse)->setState(machineView()->mouseState());
+        indicatorsPool()->indicator(UIIndicatorIndex_Mouse)->setState(machineLogic()->mouseHandler()->mouseState());
     }
 }
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.cpp	(revision 30407)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.cpp	(revision 30408)
@@ -27,4 +27,5 @@
 
 #include "UIActionsPool.h"
+#include "UIMouseHandler.h"
 #include "UIMachineLogicSeamless.h"
 #include "UIMachineWindow.h"
@@ -184,4 +185,8 @@
     m_pScreenLayout->update();
 
+    /* Create machine mouse-handler: */
+    UIMouseHandler *pMouseHandler = UIMouseHandler::create(this, visualStateType());
+    setMouseHandler(pMouseHandler);
+
     /* Create machine window(s): */
     for (int cScreenId = 0; cScreenId < m_pScreenLayout->guestScreenCount(); ++cScreenId)
@@ -206,4 +211,7 @@
     foreach (UIMachineWindow *pMachineWindow, machineWindows())
         UIMachineWindow::destroy(pMachineWindow);
+
+    /* Cleanup mouse-handler: */
+    UIMouseHandler::destroy(mouseHandler());
 }
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp	(revision 30407)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp	(revision 30408)
@@ -76,6 +76,4 @@
     sltMachineStateChanged();
     sltAdditionsStateChanged();
-    sltMousePointerShapeChanged();
-    sltMouseCapabilityChanged();
 }
 
@@ -199,7 +197,4 @@
 #endif /* Q_WS_MAC */
 
-            /* Update mouse cursor shape: */
-            updateMouseCursorShape();
-
             /* Update machine-view sliders: */
             updateSliders();
