VirtualBox

Ignore:
Timestamp:
Nov 1, 2019 5:58:34 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134379
Message:

FE/Qt: bugref:9598: Windows: Adjust mouse integration pointer according to formal/actual device-pixel-ratio and GUI scale-factor.

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

Legend:

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

    r81593 r81622  
    16941694
    16951695        m_cursorPixmap = QPixmap::fromImage(image);
     1696        updateMousePointerPixmapScaling(m_cursorPixmap, uXHot, uYHot);
    16961697        m_cursor = QCursor(m_cursorPixmap, uXHot, uYHot);
    16971698    }
     
    17841785
    17851786            m_cursorPixmap = QBitmap::fromImage(bitmap);
     1787            updateMousePointerPixmapScaling(m_cursorPixmap, uXHot, uYHot);
    17861788            m_cursor = QCursor(m_cursorPixmap, QBitmap::fromImage(mask), uXHot, uYHot);
    17871789        }
     
    18151817
    18161818            m_cursorPixmap = QPixmap::fromImage(image);
     1819            updateMousePointerPixmapScaling(m_cursorPixmap, uXHot, uYHot);
    18171820            m_cursor = QCursor(m_cursorPixmap, uXHot, uYHot);
    18181821        }
     
    18851888    /* Cache cursor pixmap size: */
    18861889    m_cursorSize = m_cursorPixmap.size();
     1890}
     1891
     1892void UISession::updateMousePointerPixmapScaling(QPixmap &pixmap, uint &uXHot, uint &uYHot)
     1893{
     1894#if defined(VBOX_WS_WIN)
     1895
     1896    /* Get screen-id of active machine-window: */
     1897    /// @todo In case of multi-monitor setup check whether parameters are screen specific.
     1898    const ulong uScreenID = activeMachineWindow()->screenId();
     1899
     1900    /* We want to scale the pixmap just once, so let's prepare cumulative multiplier: */
     1901    double dScaleMultiplier = 1.0;
     1902
     1903    /* Take into account scale-factor if necessary: */
     1904    const double dScaleFactor = frameBuffer(uScreenID)->scaleFactor();
     1905    //printf("Scale-factor: %f\n", dScaleFactor);
     1906    if (dScaleFactor > 1.0)
     1907        dScaleMultiplier *= dScaleFactor;
     1908
     1909    /* Take into account device-pixel-ratio if necessary: */
     1910    const double dDevicePixelRatio = frameBuffer(uScreenID)->devicePixelRatio();
     1911    const double dDevicePixelRatioActual = frameBuffer(uScreenID)->devicePixelRatioActual();
     1912    const bool fUseUnscaledHiDPIOutput = frameBuffer(uScreenID)->useUnscaledHiDPIOutput();
     1913    //printf("Device-pixel-ratio/actual: %f/%f, Unscaled HiDPI Output: %d\n",
     1914    //       dDevicePixelRatio, dDevicePixelRatioActual, fUseUnscaledHiDPIOutput);
     1915    if (dDevicePixelRatioActual > 1.0 && !fUseUnscaledHiDPIOutput)
     1916        dScaleMultiplier *= dDevicePixelRatioActual;
     1917
     1918    /* If scale multiplier was set: */
     1919    if (dScaleMultiplier > 1.0)
     1920    {
     1921        /* Scale the pixmap up: */
     1922        pixmap = pixmap.scaled(pixmap.width() * dScaleMultiplier, pixmap.height() * dScaleMultiplier,
     1923                               Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
     1924        uXHot *= dScaleMultiplier;
     1925        uYHot *= dScaleMultiplier;
     1926    }
     1927
     1928    /* If device pixel ratio was set: */
     1929    if (dDevicePixelRatio > 1.0)
     1930    {
     1931        /* Scale the pixmap down: */
     1932        pixmap.setDevicePixelRatio(dDevicePixelRatio);
     1933        uXHot /= dDevicePixelRatio;
     1934        uYHot /= dDevicePixelRatio;
     1935    }
     1936
     1937#else
     1938
     1939    Q_UNUSED(pixmap);
     1940    Q_UNUSED(uXHot);
     1941    Q_UNUSED(uYHot);
     1942
     1943#endif
    18871944}
    18881945
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r81592 r81622  
    444444#endif /* VBOX_WS_MAC */
    445445
    446     /* Common helpers: */
    447446    /** Updates mouse pointer shape. */
    448447    void updateMousePointerShape();
     448    /** Updates mouse pointer @a pixmap, @a uXHot and @a uYHot according to scaling attributes. */
     449    void updateMousePointerPixmapScaling(QPixmap &pixmap, uint &uXHot, uint &uYHot);
     450
     451    /* Common helpers: */
    449452    bool preprocessInitialization();
    450453    bool mountAdHocImage(KDeviceType enmDeviceType, UIMediumDeviceType enmMediumType, const QString &strMediumName);
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