summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2021-02-15 21:07:24 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2021-02-15 21:07:24 +0100
commita723c0e8896e197b4d48f915f609e6749fc1807c (patch)
tree839e8edfb5dbffd38ecab6aebe30c7dbfade5e41 /src
parentbbaec9bd88b309fbeec80d6d0118997f5b32def3 (diff)
PR #174: Skip the call to MonitorFromRect when it is not needed.
Diffstat (limited to 'src')
-rw-r--r--src/Fl_win32.cxx16
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx4
2 files changed, 13 insertions, 7 deletions
diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx
index 8b67d076b..49f71567d 100644
--- a/src/Fl_win32.cxx
+++ b/src/Fl_win32.cxx
@@ -565,13 +565,21 @@ void Fl_WinAPI_Screen_Driver::open_display_platform() {
void Fl_WinAPI_Screen_Driver::desktop_scale_factor() {
typedef HRESULT(WINAPI * GetDpiForMonitor_type)(HMONITOR, int, UINT *, UINT *);
+ typedef HMONITOR(WINAPI * MonitorFromRect_type)(LPCRECT, DWORD);
GetDpiForMonitor_type fl_GetDpiForMonitor = NULL;
- if (is_dpi_aware)
- fl_GetDpiForMonitor = (GetDpiForMonitor_type)GetProcAddress(LoadLibrary("Shcore.DLL"), "GetDpiForMonitor");
+ MonitorFromRect_type fl_MonitorFromRect = NULL;
+ if (is_dpi_aware) {
+ fl_GetDpiForMonitor = (GetDpiForMonitor_type)GetProcAddress(LoadLibrary("Shcore.DLL"), "GetDpiForMonitor");
+ if (fl_GetDpiForMonitor)
+ fl_MonitorFromRect = (MonitorFromRect_type)GetProcAddress(LoadLibrary("User32.DLL"), "MonitorFromRect");
+ }
for (int ns = 0; ns < screen_count(); ns++) {
- HMONITOR hm = MonitorFromRect(&screens[ns], MONITOR_DEFAULTTONEAREST);
UINT dpiX, dpiY;
- HRESULT r = fl_GetDpiForMonitor ? fl_GetDpiForMonitor(hm, 0, &dpiX, &dpiY) : !S_OK;
+ HRESULT r = E_INVALIDARG;
+ if (fl_GetDpiForMonitor && fl_MonitorFromRect) {
+ HMONITOR hm = fl_MonitorFromRect(&screens[ns], MONITOR_DEFAULTTONEAREST);
+ r = fl_GetDpiForMonitor(hm, 0, &dpiX, &dpiY);
+ }
if (r != S_OK) { dpiX = dpiY = 96; }
dpi[ns][0] = float(dpiX);
dpi[ns][1] = float(dpiY);
diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx
index 9720c2594..d28cccae8 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx
+++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx
@@ -125,7 +125,7 @@ void Fl_WinAPI_Screen_Driver::init()
// NOTE: num_screens is incremented in screen_cb so we must first reset it here...
num_screens = 0;
fl_edm(0, 0, screen_cb, (LPARAM)this);
- goto way_out;
+ return;
}
}
}
@@ -137,8 +137,6 @@ void Fl_WinAPI_Screen_Driver::init()
screens[0].right = GetSystemMetrics(SM_CXSCREEN);
screens[0].bottom = GetSystemMetrics(SM_CYSCREEN);
work_area[0] = screens[0];
-way_out:
- desktop_scale_factor();
}