-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dpi unaware placement bug - multimontior with same DPI settings fix (#…
…2156) * Dpi unaware placement bug - multimontior with same DPI settings fix * Using different enumerating method * Changed AllMonitorHaveSameDpiScaling method * Removed accidental file * small rename * Changed some methods to CamelCase * Review comments fixes
- Loading branch information
1 parent
af4678f
commit dcee505
Showing
3 changed files
with
68 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,64 @@ | ||
#include "pch.h" | ||
|
||
#include "common.h" | ||
#include "monitors.h" | ||
|
||
#include "common.h" | ||
|
||
bool operator==(const ScreenSize& lhs, const ScreenSize& rhs) | ||
{ | ||
auto lhs_tuple = std::make_tuple(lhs.rect.left, lhs.rect.right, lhs.rect.top, lhs.rect.bottom); | ||
auto rhs_tuple = std::make_tuple(rhs.rect.left, rhs.rect.right, rhs.rect.top, rhs.rect.bottom); | ||
return lhs_tuple == rhs_tuple; | ||
} | ||
|
||
static BOOL CALLBACK get_displays_enum_cb(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data) | ||
static BOOL CALLBACK GetDisplaysEnumCb(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data) | ||
{ | ||
MONITORINFOEX monitor_info; | ||
monitor_info.cbSize = sizeof(MONITORINFOEX); | ||
GetMonitorInfo(monitor, &monitor_info); | ||
reinterpret_cast<std::vector<MonitorInfo>*>(data)->emplace_back(monitor, monitor_info.rcWork); | ||
MONITORINFOEX monitorInfo; | ||
monitorInfo.cbSize = sizeof(MONITORINFOEX); | ||
if (GetMonitorInfo(monitor, &monitorInfo)) | ||
{ | ||
reinterpret_cast<std::vector<MonitorInfo>*>(data)->emplace_back(monitor, monitorInfo.rcWork); | ||
} | ||
return true; | ||
}; | ||
|
||
static BOOL CALLBACK get_displays_enum_cb_with_toolbar(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data) | ||
static BOOL CALLBACK GetDisplaysEnumCbWithNonWorkingArea(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data) | ||
{ | ||
MONITORINFOEX monitor_info; | ||
monitor_info.cbSize = sizeof(MONITORINFOEX); | ||
GetMonitorInfo(monitor, &monitor_info); | ||
reinterpret_cast<std::vector<MonitorInfo>*>(data)->emplace_back(monitor, monitor_info.rcMonitor); | ||
MONITORINFOEX monitorInfo; | ||
monitorInfo.cbSize = sizeof(MONITORINFOEX); | ||
if (GetMonitorInfo(monitor, &monitorInfo)) | ||
{ | ||
reinterpret_cast<std::vector<MonitorInfo>*>(data)->emplace_back(monitor, monitorInfo.rcMonitor); | ||
} | ||
return true; | ||
}; | ||
|
||
std::vector<MonitorInfo> MonitorInfo::GetMonitors(bool include_toolbar) | ||
std::vector<MonitorInfo> MonitorInfo::GetMonitors(bool includeNonWorkingArea) | ||
{ | ||
std::vector<MonitorInfo> monitors; | ||
EnumDisplayMonitors(NULL, NULL, include_toolbar ? get_displays_enum_cb_with_toolbar : get_displays_enum_cb, reinterpret_cast<LPARAM>(&monitors)); | ||
EnumDisplayMonitors(NULL, NULL, includeNonWorkingArea ? GetDisplaysEnumCbWithNonWorkingArea : GetDisplaysEnumCb, reinterpret_cast<LPARAM>(&monitors)); | ||
std::sort(begin(monitors), end(monitors), [](const MonitorInfo& lhs, const MonitorInfo& rhs) { | ||
return lhs.rect < rhs.rect; | ||
}); | ||
return monitors; | ||
} | ||
|
||
int MonitorInfo::GetMonitorsCount() | ||
static BOOL CALLBACK GetPrimaryDisplayEnumCb(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data) | ||
{ | ||
return GetMonitors(true).size(); | ||
} | ||
MONITORINFOEX monitorInfo; | ||
monitorInfo.cbSize = sizeof(MONITORINFOEX); | ||
|
||
static BOOL CALLBACK get_primary_display_enum_cb(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data) | ||
{ | ||
MONITORINFOEX monitor_info; | ||
monitor_info.cbSize = sizeof(MONITORINFOEX); | ||
GetMonitorInfo(monitor, &monitor_info); | ||
if (monitor_info.dwFlags & MONITORINFOF_PRIMARY) | ||
if (GetMonitorInfo(monitor, &monitorInfo) && (monitorInfo.dwFlags & MONITORINFOF_PRIMARY)) | ||
{ | ||
reinterpret_cast<MonitorInfo*>(data)->handle = monitor; | ||
reinterpret_cast<MonitorInfo*>(data)->rect = monitor_info.rcWork; | ||
reinterpret_cast<MonitorInfo*>(data)->rect = monitorInfo.rcWork; | ||
} | ||
return true; | ||
}; | ||
|
||
MonitorInfo MonitorInfo::GetPrimaryMonitor() | ||
{ | ||
MonitorInfo primary({}, {}); | ||
EnumDisplayMonitors(NULL, NULL, get_primary_display_enum_cb, reinterpret_cast<LPARAM>(&primary)); | ||
EnumDisplayMonitors(NULL, NULL, GetPrimaryDisplayEnumCb, reinterpret_cast<LPARAM>(&primary)); | ||
return primary; | ||
} | ||
|
||
MonitorInfo MonitorInfo::GetFromWindow(HWND hwnd) | ||
{ | ||
auto monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); | ||
return GetFromHandle(monitor); | ||
} | ||
|
||
MonitorInfo MonitorInfo::GetFromPoint(POINT p) | ||
{ | ||
auto monitor = MonitorFromPoint(p, MONITOR_DEFAULTTONEAREST); | ||
return GetFromHandle(monitor); | ||
} | ||
|
||
MonitorInfo MonitorInfo::GetFromHandle(HMONITOR monitor) | ||
{ | ||
MONITORINFOEX monitor_info; | ||
monitor_info.cbSize = sizeof(MONITORINFOEX); | ||
GetMonitorInfo(monitor, &monitor_info); | ||
return MonitorInfo(monitor, monitor_info.rcWork); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters