VirtualBox

Changeset 34475 in vbox


Ignore:
Timestamp:
Nov 29, 2010 3:40:56 PM (14 years ago)
Author:
vboxsync
Message:

FE/Qt: 4718: Mouse cursor issues when mouse integration is disabled: Fixed for machine-window positioned partially off desktop boundaries (win host).

File:
1 edited

Legend:

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

    r34471 r34475  
    156156        /* Memorize the host position where the cursor was captured: */
    157157        m_capturedMousePos = QCursor::pos();
     158
     159        /* Acquiring visible viewport rectangle in global coodrinates: */
     160        QRect visibleRectangle = m_viewports[m_iMouseCaptureViewIndex]->visibleRegion().boundingRect();
     161        QPoint visibleRectanglePos = m_views[m_iMouseCaptureViewIndex]->mapToGlobal(m_viewports[m_iMouseCaptureViewIndex]->pos());
     162        visibleRectangle.translate(visibleRectanglePos);
     163        visibleRectangle = visibleRectangle.intersected(QApplication::desktop()->availableGeometry());
     164
    158165#ifdef Q_WS_WIN
    159166        /* Move the mouse to the center of the visible area: */
    160         m_lastMousePos = m_views[m_iMouseCaptureViewIndex]->mapToGlobal(m_views[m_iMouseCaptureViewIndex]->visibleRegion().boundingRect().center());
     167        m_lastMousePos = visibleRectangle.center();
    161168        QCursor::setPos(m_lastMousePos);
    162169        /* Update mouse clipping: */
     
    164171#elif defined (Q_WS_MAC)
    165172        /* Move the mouse to the center of the visible area: */
    166         m_lastMousePos = m_views[m_iMouseCaptureViewIndex]->mapToGlobal(m_views[m_iMouseCaptureViewIndex]->visibleRegion().boundingRect().center());
     173        m_lastMousePos = visibleRectangle.center();
    167174        QCursor::setPos(m_lastMousePos);
    168175        /* Grab all mouse events: */
     
    707714
    708715# ifdef Q_WS_WIN
    709         int iWe = m_viewports[uScreenId]->width() - 1;
    710         int iHe = m_viewports[uScreenId]->height() - 1;
     716        /* Acquiring visible viewport rectangle in local coordinates: */
     717        QRect viewportRectangle = m_viewports[uScreenId]->visibleRegion().boundingRect();
     718        QPoint viewportRectangleGlobalPos = m_views[uScreenId]->mapToGlobal(m_viewports[uScreenId]->pos());
     719        /* Shift viewport rectangle to global position to bound by available geometry: */
     720        viewportRectangle.translate(viewportRectangleGlobalPos);
     721        /* Acquiring viewport rectangle cropped by available geometry: */
     722        viewportRectangle = viewportRectangle.intersected(QApplication::desktop()->availableGeometry());
     723        /* Shift remaining viewport rectangle to local position as relative position is in local coordinates: */
     724        viewportRectangle.translate(-viewportRectangleGlobalPos);
     725
     726        /* Get boundaries: */
     727        int ix1 = viewportRectangle.left() + 1;
     728        int iy1 = viewportRectangle.top() + 1;
     729        int ix2 = viewportRectangle.right() - 1;
     730        int iy2 = viewportRectangle.bottom() - 1;
     731
     732        /* Simulate infinite movement: */
    711733        QPoint p = relativePos;
    712         if (relativePos.x() == 0)
    713             p.setX(iWe - 1);
    714         else if (relativePos.x() == iWe)
    715             p.setX(1);
    716         if (relativePos.y() == 0 )
    717             p.setY(iHe - 1);
    718         else if (relativePos.y() == iHe)
    719             p.setY(1);
    720 
     734        if (relativePos.x() == ix1)
     735            p.setX(ix2 - 1);
     736        else if (relativePos.x() == ix2)
     737            p.setX(ix1 + 1);
     738        if (relativePos.y() == iy1)
     739            p.setY(iy2 - 1);
     740        else if (relativePos.y() == iy2)
     741            p.setY(iy1 + 1);
    721742        if (p != relativePos)
    722743        {
     
    870891void UIMouseHandler::updateMouseCursorClipping()
    871892{
    872     /* Check if such viewport is registered: */
    873     if (!m_viewports.contains(m_iMouseCaptureViewIndex))
     893    /* Check if such view && viewport are registered: */
     894    if (!m_views.contains(m_iMouseCaptureViewIndex) || !m_viewports.contains(m_iMouseCaptureViewIndex))
    874895        return;
    875896
    876897    if (uisession()->isMouseCaptured())
    877898    {
    878         QWidget *pMachineViewViewport = m_viewports[m_iMouseCaptureViewIndex];
    879         QRect r = pMachineViewViewport->rect();
    880         r.moveTopLeft(pMachineViewViewport->mapToGlobal(QPoint(0, 0)));
    881         RECT rect = { r.left(), r.top(), r.right() + 1, r.bottom() + 1 };
     899        /* Acquiring visible viewport rectangle: */
     900        QRect viewportRectangle = m_viewports[m_iMouseCaptureViewIndex]->visibleRegion().boundingRect();
     901        QPoint viewportRectangleGlobalPos = m_views[m_iMouseCaptureViewIndex]->mapToGlobal(m_viewports[m_iMouseCaptureViewIndex]->pos());
     902        viewportRectangle.translate(viewportRectangleGlobalPos);
     903        viewportRectangle = viewportRectangle.intersected(QApplication::desktop()->availableGeometry());
     904        /* Prepare clipping area: */
     905        RECT rect = { viewportRectangle.left() + 1, viewportRectangle.top() + 1, viewportRectangle.right(), viewportRectangle.bottom() };
    882906        ::ClipCursor(&rect);
    883907    }
Note: See TracChangeset for help on using the changeset viewer.

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