VirtualBox

Changeset 26929 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Mar 2, 2010 12:27:24 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
58216
Message:

FE/Qt4: New running VM core: mm support extended to use absolute mouse-coordinates, few cosmetics also.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r26921 r26929  
    283283}
    284284
     285QSize UIMachineView::desktopGeometry() const
     286{
     287    QSize geometry;
     288    switch (m_desktopGeometryType)
     289    {
     290        case DesktopGeo_Fixed:
     291        case DesktopGeo_Automatic:
     292            geometry = QSize(qMax(m_desktopGeometry.width(), m_storedConsoleSize.width()),
     293                             qMax(m_desktopGeometry.height(), m_storedConsoleSize.height()));
     294            break;
     295        case DesktopGeo_Any:
     296            geometry = QSize(0, 0);
     297            break;
     298        default:
     299            AssertMsgFailed(("Bad geometry type %d!\n", m_desktopGeometryType));
     300    }
     301    return geometry;
     302}
     303
     304void UIMachineView::setDesktopGeometry(DesktopGeo geometry, int aWidth, int aHeight)
     305{
     306    switch (geometry)
     307    {
     308        case DesktopGeo_Fixed:
     309            m_desktopGeometryType = DesktopGeo_Fixed;
     310            if (aWidth != 0 && aHeight != 0)
     311                m_desktopGeometry = QSize(aWidth, aHeight);
     312            else
     313                m_desktopGeometry = QSize(0, 0);
     314            storeConsoleSize(0, 0);
     315            break;
     316        case DesktopGeo_Automatic:
     317            m_desktopGeometryType = DesktopGeo_Automatic;
     318            m_desktopGeometry = QSize(0, 0);
     319            storeConsoleSize(0, 0);
     320            break;
     321        case DesktopGeo_Any:
     322            m_desktopGeometryType = DesktopGeo_Any;
     323            m_desktopGeometry = QSize(0, 0);
     324            break;
     325        default:
     326            AssertMsgFailed(("Invalid desktop geometry type %d\n", geometry));
     327            m_desktopGeometryType = DesktopGeo_Invalid;
     328    }
     329}
     330
     331void UIMachineView::storeConsoleSize(int iWidth, int iHeight)
     332{
     333    m_storedConsoleSize = QSize(iWidth, iHeight);
     334}
     335
     336void UIMachineView::calculateDesktopGeometry()
     337{
     338    /* This method should not get called until we have initially set up the m_desktopGeometryType: */
     339    Assert((m_desktopGeometryType != DesktopGeo_Invalid));
     340    /* If we are not doing automatic geometry calculation then there is nothing to do: */
     341    if (DesktopGeo_Automatic == m_desktopGeometryType)
     342    {
     343        /* Available geometry of the desktop.  If the desktop is a single
     344         * screen, this will exclude space taken up by desktop taskbars
     345         * and things, but this is unfortunately not true for the more
     346         * complex case of a desktop spanning multiple screens: */
     347        QRect desktop = availableGeometry();
     348        /* The area taken up by the machine window on the desktop,
     349         * including window frame, title and menu bar and whatnot: */
     350        QRect frame = machineWindowWrapper()->machineWindow()->frameGeometry();
     351        /* The area taken up by the machine view, so excluding all decorations: */
     352        QRect window = geometry();
     353        /* To work out how big we can make the console window while still
     354         * fitting on the desktop, we calculate desktop - frame + window.
     355         * This works because the difference between frame and window
     356         * (or at least its width and height) is a constant. */
     357        m_desktopGeometry = QSize(desktop.width() - frame.width() + window.width(),
     358                                  desktop.height() - frame.height() + window.height());
     359    }
     360}
     361
    285362void UIMachineView::updateMouseClipping()
    286363{
     
    312389
    313390    QSize v = QSize(m_pFrameBuffer->width(), m_pFrameBuffer->height());
    314     /* no scroll bars needed */
     391    /* No scroll bars needed: */
    315392    if (m.expandedTo(v) == m)
    316393        p = m;
     
    553630}
    554631
    555 QSize UIMachineView::desktopGeometry() const
    556 {
    557     QSize geometry;
    558     switch (m_desktopGeometryType)
    559     {
    560         case DesktopGeo_Fixed:
    561         case DesktopGeo_Automatic:
    562             geometry = QSize(qMax(m_desktopGeometry.width(), m_storedConsoleSize.width()),
    563                              qMax(m_desktopGeometry.height(), m_storedConsoleSize.height()));
    564             break;
    565         case DesktopGeo_Any:
    566             geometry = QSize(0, 0);
    567             break;
    568         default:
    569             AssertMsgFailed(("Bad geometry type %d!\n", m_desktopGeometryType));
    570     }
    571     return geometry;
    572 }
    573 
    574 void UIMachineView::setDesktopGeometry(DesktopGeo geometry, int aWidth, int aHeight)
    575 {
    576     switch (geometry)
    577     {
    578         case DesktopGeo_Fixed:
    579             m_desktopGeometryType = DesktopGeo_Fixed;
    580             if (aWidth != 0 && aHeight != 0)
    581                 m_desktopGeometry = QSize(aWidth, aHeight);
    582             else
    583                 m_desktopGeometry = QSize(0, 0);
    584             storeConsoleSize(0, 0);
    585             break;
    586         case DesktopGeo_Automatic:
    587             m_desktopGeometryType = DesktopGeo_Automatic;
    588             m_desktopGeometry = QSize(0, 0);
    589             storeConsoleSize(0, 0);
    590             break;
    591         case DesktopGeo_Any:
    592             m_desktopGeometryType = DesktopGeo_Any;
    593             m_desktopGeometry = QSize(0, 0);
    594             break;
    595         default:
    596             AssertMsgFailed(("Invalid desktop geometry type %d\n", geometry));
    597             m_desktopGeometryType = DesktopGeo_Invalid;
    598     }
    599 }
    600 
    601 void UIMachineView::calculateDesktopGeometry()
    602 {
    603     /* This method should not get called until we have initially set up the m_desktopGeometryType: */
    604     Assert((m_desktopGeometryType != DesktopGeo_Invalid));
    605     /* If we are not doing automatic geometry calculation then there is nothing to do: */
    606     if (DesktopGeo_Automatic == m_desktopGeometryType)
    607     {
    608         /* Available geometry of the desktop.  If the desktop is a single
    609          * screen, this will exclude space taken up by desktop taskbars
    610          * and things, but this is unfortunately not true for the more
    611          * complex case of a desktop spanning multiple screens: */
    612         QRect desktop = availableGeometry();
    613         /* The area taken up by the machine window on the desktop,
    614          * including window frame, title and menu bar and whatnot: */
    615         QRect frame = machineWindowWrapper()->machineWindow()->frameGeometry();
    616         /* The area taken up by the machine view, so excluding all decorations: */
    617         QRect window = geometry();
    618         /* To work out how big we can make the console window while still
    619          * fitting on the desktop, we calculate desktop - frame + window.
    620          * This works because the difference between frame and window
    621          * (or at least its width and height) is a constant. */
    622         m_desktopGeometry = QSize(desktop.width() - frame.width() + window.width(),
    623                                   desktop.height() - frame.height() + window.height());
    624     }
    625 }
    626 
    627 void UIMachineView::storeConsoleSize(int iWidth, int iHeight)
    628 {
    629     m_storedConsoleSize = QSize(iWidth, iHeight);
    630 }
    631 
    632 
    633632void UIMachineView::cleanupCommon()
    634633{
     
    671670        /* Detach framebuffer from Display: */
    672671        CDisplay display = session().GetConsole().GetDisplay();
    673         display.SetFramebuffer(VBOX_VIDEO_PRIMARY_SCREEN, CFramebuffer(NULL));
     672        display.SetFramebuffer(m_uScreenId, CFramebuffer(NULL));
    674673        /* Release the reference: */
    675674        m_pFrameBuffer->Release();
     
    695694            else
    696695            {
    697                 /* Release the host key and all other pressed keys too even when paused (otherwise, we will get stuck
    698                  * keys in the guest when doing sendChangedKeyStates() on resume because key presses were already
    699                  * recorded in m_pressedKeys but key releases will most likely not reach us but the new focus window instead): */
    700                 releaseAllPressedKeys(true /* fReleaseHostKey */);
     696                /* Release the host key and all other pressed keys too even when paused
     697                 * (otherwise, we will get stuck keys in the guest when doing sendChangedKeyStates() on resume
     698                 * because key presses were already recorded in m_pressedKeys but key releases will most likely
     699                 * not reach us but the new focus window instead): */
     700                releaseAllPressedKeys(true /* including host key? */);
    701701            }
    702702            break;
     
    708708            viewport()->repaint(pPaintEvent->x() - contentsX(), pPaintEvent->y() - contentsY(),
    709709                                pPaintEvent->width(), pPaintEvent->height());
    710             /* session().GetConsole().GetDisplay().UpdateCompleted(); - the event was acked already */
    711710            return true;
    712711        }
     
    855854                {
    856855                    /* Process hot keys not processed in keyEvent() (as in case of non-alphanumeric keys): */
    857                     machineWindowWrapper()->machineLogic()->actionsPool()->processHotKey(QKeySequence (pKeyEvent->key()));
     856                    machineWindowWrapper()->machineLogic()->actionsPool()->processHotKey(QKeySequence(pKeyEvent->key()));
    858857                }
    859858            }
     
    955954                 * registered in the VM. Only do this if the keyboard/mouse is grabbed (this is when
    956955                 * we have a valid event handler): */
    957                 setMouseCoalescingEnabled (false);
     956                setMouseCoalescingEnabled(false);
    958957                break;
    959958            }
     
    14971496    if (aWheelDir == Qt::Vertical)
    14981497    {
    1499         /* the absolute value of wheel delta is 120 units per every wheel
    1500          * move; positive deltas correspond to counterclockwize rotations
    1501          * (usually up), negative -- to clockwize (usually down). */
     1498        /* The absolute value of wheel delta is 120 units per every wheel move;
     1499         * positive deltas correspond to counterclockwize rotations (usually up),
     1500         * negative deltas correspond to clockwize (usually down). */
    15021501        wheelVertical = - (aWheelDelta / 120);
    15031502    }
     
    15081507    {
    15091508#ifdef Q_WS_WIN32
    1510         /* send pending WM_PAINT events */
     1509        /* Send pending WM_PAINT events: */
    15111510        ::UpdateWindow(viewport()->winId());
    15121511#endif
     
    16391638                /* Try to automatically scroll the guest canvas if the
    16401639                 * mouse goes outside its visible part: */
    1641 
    16421640                int dx = 0;
    16431641                if (aPos.x() > vw) dx = aPos.x() - vw;
     
    16491647            }
    16501648
    1651             QPoint cpnt = viewportToContents (aPos);
    1652             if (cpnt.x() < 0) cpnt.setX (0);
    1653             else if (cpnt.x() > cw) cpnt.setX (cw);
    1654             if (cpnt.y() < 0) cpnt.setY (0);
    1655             else if (cpnt.y() > ch) cpnt.setY (ch);
     1649            QPoint cpnt = viewportToContents(aPos);
     1650            if (cpnt.x() < 0) cpnt.setX(0);
     1651            else if (cpnt.x() > cw) cpnt.setX(cw);
     1652            if (cpnt.y() < 0) cpnt.setY(0);
     1653            else if (cpnt.y() > ch) cpnt.setY(ch);
     1654
     1655            // TODO: Where to put that actually?
     1656            /* Get & Setup absolute-event shift: */
     1657            CFramebuffer framebuffer;
     1658            LONG xShift = 0, yShift = 0;
     1659            session().GetConsole().GetDisplay().GetFramebuffer(screenId(), framebuffer, xShift, yShift);
     1660            cpnt.setX(cpnt.x() + xShift);
     1661            cpnt.setY(cpnt.y() + yShift);
    16561662
    16571663            CMouse mouse = session().GetConsole().GetMouse();
    1658             mouse.PutMouseEventAbsolute (cpnt.x(), cpnt.y(), wheelVertical,
    1659                                         wheelHorizontal, state);
     1664            // AssertMsgFailed(("x=%d, y=%d", cpnt.x(), cpnt.y())); // this shows what absolute coordinates are correct!
     1665            mouse.PutMouseEventAbsolute(cpnt.x(), cpnt.y(), wheelVertical, wheelHorizontal, state);
    16601666            return true;
    16611667        }
     
    16741680                    m_bIsAutoCaptureDisabled = true;
    16751681                    bool autoConfirmed = false;
    1676                     bool ok = vboxProblem().confirmInputCapture (&autoConfirmed);
     1682                    bool ok = vboxProblem().confirmInputCapture(&autoConfirmed);
    16771683                    if (autoConfirmed)
    16781684                        m_bIsAutoCaptureDisabled = false;
     
    17421748#endif
    17431749//    {
    1744 //        /* We have a snapshot for the paused state: */
    1745 //        QRect r = pPaintEvent->rect().intersect (viewport()->rect());
    1746 //        /* We have to disable paint on screen if we are using the regular painter */
    1747 //        bool paintOnScreen = viewport()->testAttribute(Qt::WA_PaintOnScreen);
    1748 //        viewport()->setAttribute(Qt::WA_PaintOnScreen, false);
    1749 //        QPainter pnt(viewport());
    1750 //        pnt.drawPixmap(r.x(), r.y(), m_pauseShot, r.x() + contentsX(), r.y() + contentsY(), r.width(), r.height());
    1751 //        /* Restore the attribute to its previous state */
    1752 //        viewport()->setAttribute(Qt::WA_PaintOnScreen, paintOnScreen);
     1750#if 0 // TODO: Paint pause-shot on screen during pause!
     1751        /* We have a snapshot for the paused state: */
     1752        QRect r = pPaintEvent->rect().intersect(viewport()->rect());
     1753        /* We have to disable paint on screen if we are using the regular painter: */
     1754        bool paintOnScreen = viewport()->testAttribute(Qt::WA_PaintOnScreen);
     1755        viewport()->setAttribute(Qt::WA_PaintOnScreen, false);
     1756        QPainter pnt(viewport());
     1757        pnt.drawPixmap(r.x(), r.y(), m_pauseShot, r.x() + contentsX(), r.y() + contentsY(), r.width(), r.height());
     1758        /* Restore the attribute to its previous state: */
     1759        viewport()->setAttribute(Qt::WA_PaintOnScreen, paintOnScreen);
     1760#endif
    17531761#ifdef Q_WS_MAC
    17541762//        updateDockIcon();
     
    23702378QPoint UIMachineView::viewportToContents(const QPoint &vp) const
    23712379{
    2372     return QPoint (vp.x() + contentsX(), vp.y() + contentsY());
     2380    return QPoint(vp.x() + contentsX(), vp.y() + contentsY());
    23732381}
    23742382
     
    24522460        m_capturedMousePos = QCursor::pos();
    24532461#ifdef Q_WS_WIN32
    2454         viewport()->setCursor (QCursor (Qt::BlankCursor));
     2462        viewport()->setCursor(QCursor(Qt::BlankCursor));
    24552463        /* Move the mouse to the center of the visible area: */
    2456         QCursor::setPos (mapToGlobal (visibleRegion().boundingRect().center()));
     2464        QCursor::setPos(mapToGlobal(visibleRegion().boundingRect().center()));
    24572465        m_lastMousePos = QCursor::pos();
    24582466#elif defined (Q_WS_MAC)
    24592467        /* Move the mouse to the center of the visible area: */
    24602468        m_lastMousePos = mapToGlobal (visibleRegion().boundingRect().center());
    2461         QCursor::setPos (m_lastMousePos);
     2469        QCursor::setPos(m_lastMousePos);
    24622470        /* Grab all mouse events: */
    24632471        viewport()->grabMouse();
     
    24742482        /* Release mouse buttons: */
    24752483        CMouse mouse = session().GetConsole().GetMouse();
    2476         mouse.PutMouseEvent(0, 0, 0, 0 /* Horizontal wheel */, 0);
     2484        mouse.PutMouseEvent(0, 0, 0, 0, 0);
    24772485    }
    24782486
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h

    r26921 r26929  
    118118    bool isFrameBufferResizeIgnored() const { return m_bIsFrameBufferResizeIgnored; }
    119119    const QPixmap& pauseShot() const { return m_pauseShot; }
    120     void calculateDesktopGeometry();
    121120    virtual QSize desktopGeometry() const;
     121
     122    /* Protected setters: */
    122123    void setDesktopGeometry(DesktopGeo geometry, int iWidth, int iHeight);
    123124    void storeConsoleSize(int iWidth, int iHeight);
    124 
    125     /* Protected setters: */
    126125    void setMachineWindowResizeIgnored(bool fIgnore = true) { m_bIsMachineWindowResizeIgnored = fIgnore; }
    127126    void setFrameBufferResizeIgnored(bool fIgnore = true) { m_bIsFrameBufferResizeIgnored = fIgnore; }
    128127
    129128    /* Protected helpers: */
     129    void calculateDesktopGeometry();
    130130    void updateMouseClipping();
    131131    void updateSliders();
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette