It's just used in this one place, and isn't very large. Also move things around a bit to avoid having to define new complex types.tags/v1.12.90
@@ -347,13 +347,47 @@ std::string MonitorArrangement::description(int m) | |||
return ss.str(); | |||
} | |||
#if defined(WIN32) | |||
static BOOL CALLBACK EnumDisplayMonitorsCallback( | |||
HMONITOR monitor, HDC deviceContext, LPRECT rect, LPARAM userData) | |||
{ | |||
std::set<HMONITOR>* sys_monitors = (std::set<HMONITOR>*)userData; | |||
sys_monitors->insert(monitor); | |||
return TRUE; | |||
} | |||
#endif | |||
int MonitorArrangement::get_monitor_name(int m, char name[], size_t name_len) | |||
{ | |||
#if defined(WIN32) | |||
std::set<HMONITOR> sys_monitors; | |||
std::set<HMONITOR>::const_iterator iter; | |||
int x, y, w, h; | |||
Fl::screen_xywh(x, y, w, h, m); | |||
return win32_get_monitor_name(x, y, w, h, name, name_len); | |||
EnumDisplayMonitors(NULL, NULL, EnumDisplayMonitorsCallback, | |||
(LPARAM)&sys_monitors); | |||
for (iter = sys_monitors.begin(); iter != sys_monitors.end(); ++iter) { | |||
MONITORINFOEX info; | |||
info.cbSize = sizeof(info); | |||
GetMonitorInfo(*iter, (LPMONITORINFO)&info); | |||
if (info.rcMonitor.left != x) | |||
continue; | |||
if (info.rcMonitor.top != y) | |||
continue; | |||
if ((info.rcMonitor.right - info.rcMonitor.left) != w) | |||
continue; | |||
if ((info.rcMonitor.bottom - info.rcMonitor.top) != h) | |||
continue; | |||
return snprintf(name, name_len, "%.*s", (int)(name_len - 1), info.szDevice); | |||
} | |||
return -1; | |||
#elif defined(__APPLE__) | |||
CGDisplayCount count; | |||
int bytes_written = 0; |
@@ -419,54 +419,3 @@ int win32_has_altgr(void) | |||
return has_altgr; | |||
} | |||
typedef struct { | |||
int x, y, w, h; | |||
char* name; | |||
size_t name_len; | |||
int bytes_written; | |||
} EnumCallbackData; | |||
static BOOL CALLBACK EnumDisplayMonitorsCallback( | |||
HMONITOR monitor, HDC deviceContext, LPRECT rect, LPARAM userData) | |||
{ | |||
EnumCallbackData *data = (EnumCallbackData *)userData; | |||
MONITORINFOEX info; | |||
info.cbSize = sizeof(info); | |||
GetMonitorInfo(monitor, (LPMONITORINFO)&info); | |||
int x = info.rcMonitor.left; | |||
int y = info.rcMonitor.top; | |||
int w = info.rcMonitor.right - info.rcMonitor.left; | |||
int h = info.rcMonitor.bottom - info.rcMonitor.top; | |||
if ((data->x == x) && (data->y == y) && (data->w == w) && (data->h == h)) { | |||
data->bytes_written = snprintf(data->name, data->name_len, | |||
"%.*s", (int)(data->name_len - 1), info.szDevice); | |||
if (data->bytes_written < 0) | |||
return FALSE; | |||
// Stop the iteration. | |||
return FALSE; | |||
} | |||
// Keep iterating. | |||
return TRUE; | |||
} | |||
int win32_get_monitor_name(int x, int y, int w, int h, char name[], size_t name_len) | |||
{ | |||
EnumCallbackData data = { | |||
.x = x, | |||
.y = y, | |||
.w = w, | |||
.h = h, | |||
.name = name, | |||
.name_len = name_len, | |||
.bytes_written = -1 | |||
}; | |||
EnumDisplayMonitors(NULL, NULL, EnumDisplayMonitorsCallback, (LPARAM) &data); | |||
return data.bytes_written; | |||
} |
@@ -33,8 +33,6 @@ void win32_disable_lowlevel_keyboard(HWND hwnd); | |||
int win32_vkey_to_keysym(UINT vkey, int extended); | |||
int win32_has_altgr(void); | |||
int win32_get_monitor_name(int x, int y, int w, int h, char name[], size_t name_len); | |||
}; | |||
#endif |