VirtualBox

Changeset 70934 in vbox for trunk


Ignore:
Timestamp:
Feb 9, 2018 2:26:50 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120769
Message:

FE/Qt: bugref:8694: UIDesktopWidgetWatchdog: A way to acquire actual HiDPI scale-factor on Windows host (not used yet).

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDesktopWidgetWatchdog.cpp

    r69931 r70934  
    2424# include <QDesktopWidget>
    2525# include <QScreen>
     26# ifdef VBOX_WS_WIN
     27#  include <QLibrary>
     28# endif
    2629# ifdef VBOX_WS_X11
    2730#  include <QTimer>
     
    3841# include <VBox/log.h>
    3942
     43/* Platform includes: */
     44# ifdef VBOX_WS_WIN
     45#  include <iprt/win/windows.h>
     46# endif
     47
    4048#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     49
     50
     51#ifdef VBOX_WS_WIN
     52
     53typedef enum _MONITOR_DPI_TYPE // gently stolen from MSDN
     54{
     55    MDT_EFFECTIVE_DPI  = 0,
     56    MDT_ANGULAR_DPI    = 1,
     57    MDT_RAW_DPI        = 2,
     58    MDT_DEFAULT        = MDT_EFFECTIVE_DPI
     59} MONITOR_DPI_TYPE;
     60
     61bool MonitorEnumProcF(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lpClipRect, LPARAM dwData)
     62{
     63    /* These required for clipped screens only: */
     64    RT_NOREF(hdcMonitor, lpClipRect);
     65
     66    /* Dynamically access Shcore.dll: */
     67    QLibrary shcore("Shcore.dll", NULL);
     68
     69    /* Acquire effective DPI (available since Windows 8.1): */
     70    typedef void (*GetDpiForMonitorFP)(HMONITOR hMonitor, MONITOR_DPI_TYPE enmDpiType, uint *puOutX, uint *puOutY);
     71    GetDpiForMonitorFP GetDpiForMonitorF = (GetDpiForMonitorFP)shcore.resolve("GetDpiForMonitor");
     72    if (GetDpiForMonitorF)
     73    {
     74        uint uOutX = 0;
     75        uint uOutY = 0;
     76        GetDpiForMonitorF(hMonitor, MDT_EFFECTIVE_DPI, &uOutX, &uOutY);
     77        reinterpret_cast<QList<QPair<int, int> >*>(dwData)->append(qMakePair(uOutX, uOutY));
     78        return true;
     79    }
     80
     81    /* False by default: */
     82    return false;
     83}
     84
     85#endif /* VBOX_WS_WIN */
    4186
    4287
     
    355400#endif /* VBOX_WS_X11 */
    356401
    357 double UIDesktopWidgetWatchdog::devicePixelRatio(int iHostScreenIndex)
     402double UIDesktopWidgetWatchdog::devicePixelRatio(int iHostScreenIndex /* = -1 */)
    358403{
    359404    /* First, we should check whether the screen is valid: */
     
    362407                     : QGuiApplication::screens().value(iHostScreenIndex);
    363408    AssertPtrReturn(pScreen, 1.0);
     409
    364410    /* Then acquire device-pixel-ratio: */
    365411    return pScreen->devicePixelRatio();
     
    370416    /* Redirect call to wrapper above: */
    371417    return devicePixelRatio(screenNumber(pWidget));
     418}
     419
     420double UIDesktopWidgetWatchdog::devicePixelRatioActual(int iHostScreenIndex /* = -1 */)
     421{
     422    /* First, we should check whether the screen is valid: */
     423    QScreen *pScreen = iHostScreenIndex == -1
     424                     ? QGuiApplication::primaryScreen()
     425                     : QGuiApplication::screens().value(iHostScreenIndex);
     426    AssertPtrReturn(pScreen, 1.0);
     427
     428#ifdef VBOX_WS_WIN
     429
     430    /* Dynamically access User32.dll: */
     431    QLibrary user32("User32.dll", NULL);
     432
     433    /* Enumerate available monitors through EnumDisplayMonitors (available since Windows 2k): */
     434    typedef bool (*MonitorEnumProcFP)(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lpClipRect, LPARAM dwData);
     435    typedef bool (*EnumDisplayMonitorsFP)(HDC hdc, LPCRECT lprcRect, MonitorEnumProcFP lpfnEnum, LPARAM dwData);
     436    EnumDisplayMonitorsFP EnumDisplayMonitorsF = (EnumDisplayMonitorsFP)user32.resolve("EnumDisplayMonitors");
     437    if (EnumDisplayMonitorsF)
     438    {
     439        QList<QPair<int, int> > listOfScreenDPI;
     440        EnumDisplayMonitorsF(0, 0, MonitorEnumProcF, (LPARAM)&listOfScreenDPI);
     441        if (iHostScreenIndex >= 0 && iHostScreenIndex < listOfScreenDPI.size())
     442        {
     443            const QPair<int, int> dpiPair = listOfScreenDPI.at(iHostScreenIndex);
     444            if (dpiPair.first > 0)
     445                return (double)dpiPair.first / 96 /* dpi unawarness value */;
     446        }
     447    }
     448
     449#endif /* VBOX_WS_WIN */
     450
     451    /* Then acquire device-pixel-ratio: */
     452    return pScreen->devicePixelRatio();
     453}
     454
     455double UIDesktopWidgetWatchdog::devicePixelRatioActual(QWidget *pWidget)
     456{
     457    /* Redirect call to wrapper above: */
     458    return devicePixelRatioActual(screenNumber(pWidget));
    372459}
    373460
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDesktopWidgetWatchdog.h

    r69931 r70934  
    111111    double devicePixelRatio(QWidget *pWidget);
    112112
     113    /** Returns actual device-pixel-ratio of the host-screen with @a iHostScreenIndex. */
     114    double devicePixelRatioActual(int iHostScreenIndex = -1);
     115    /** Returns actual device-pixel-ratio of the host-screen which contains @a pWidget. */
     116    double devicePixelRatioActual(QWidget *pWidget);
     117
    113118private slots:
    114119
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