- Timestamp:
- Feb 9, 2018 2:26:50 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 120769
- 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 24 24 # include <QDesktopWidget> 25 25 # include <QScreen> 26 # ifdef VBOX_WS_WIN 27 # include <QLibrary> 28 # endif 26 29 # ifdef VBOX_WS_X11 27 30 # include <QTimer> … … 38 41 # include <VBox/log.h> 39 42 43 /* Platform includes: */ 44 # ifdef VBOX_WS_WIN 45 # include <iprt/win/windows.h> 46 # endif 47 40 48 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 49 50 51 #ifdef VBOX_WS_WIN 52 53 typedef 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 61 bool 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 */ 41 86 42 87 … … 355 400 #endif /* VBOX_WS_X11 */ 356 401 357 double UIDesktopWidgetWatchdog::devicePixelRatio(int iHostScreenIndex )402 double UIDesktopWidgetWatchdog::devicePixelRatio(int iHostScreenIndex /* = -1 */) 358 403 { 359 404 /* First, we should check whether the screen is valid: */ … … 362 407 : QGuiApplication::screens().value(iHostScreenIndex); 363 408 AssertPtrReturn(pScreen, 1.0); 409 364 410 /* Then acquire device-pixel-ratio: */ 365 411 return pScreen->devicePixelRatio(); … … 370 416 /* Redirect call to wrapper above: */ 371 417 return devicePixelRatio(screenNumber(pWidget)); 418 } 419 420 double 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 455 double UIDesktopWidgetWatchdog::devicePixelRatioActual(QWidget *pWidget) 456 { 457 /* Redirect call to wrapper above: */ 458 return devicePixelRatioActual(screenNumber(pWidget)); 372 459 } 373 460 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDesktopWidgetWatchdog.h
r69931 r70934 111 111 double devicePixelRatio(QWidget *pWidget); 112 112 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 113 118 private slots: 114 119
Note:
See TracChangeset
for help on using the changeset viewer.