Don't bother looking up EnumDisplayMonitors and GetMonitorInfoA

2008-08-04  Tor Lillqvist  <tml@novell.com>

	* gdk/win32/gdkdisplay-win32.c: Don't bother looking up
	EnumDisplayMonitors and GetMonitorInfoA dynamically, they are
	present in NT-based Windows since Windows 2000.
	(enum_monitor): For some reason the MONITORINFOEX struct in
	mingw-win64 is different than the proper one as in MSDN and 32-bit
	mingw, so just copy the proper definition here.


svn path=/trunk/; revision=20953
This commit is contained in:
Tor Lillqvist
2008-08-03 23:05:37 +00:00
committed by Tor Lillqvist
parent 8303b4437e
commit 34159c417b
2 changed files with 69 additions and 72 deletions

View File

@ -1,3 +1,12 @@
2008-08-04 Tor Lillqvist <tml@novell.com>
* gdk/win32/gdkdisplay-win32.c: Don't bother looking up
EnumDisplayMonitors and GetMonitorInfoA dynamically, they are
present in NT-based Windows since Windows 2000.
(enum_monitor): For some reason the MONITORINFOEX struct in
mingw-win64 is different than the proper one as in MSDN and 32-bit
mingw, so just copy the proper definition here.
2008-08-03 Björn Lindqvist <bjourne@gmail.com> 2008-08-03 Björn Lindqvist <bjourne@gmail.com>
Bug 540379 gtk_tree_view_enable_model_drag_dest and Bug 540379 gtk_tree_view_enable_model_drag_dest and

View File

@ -30,14 +30,6 @@
#undef HAVE_MONITOR_INFO #undef HAVE_MONITOR_INFO
#endif #endif
#ifdef HAVE_MONITOR_INFO
typedef BOOL (WINAPI *t_EnumDisplayMonitors)(HDC, LPCRECT, MONITORENUMPROC, LPARAM);
typedef BOOL (WINAPI *t_GetMonitorInfoA)(HMONITOR, LPMONITORINFO);
static t_EnumDisplayMonitors p_EnumDisplayMonitors = NULL;
static t_GetMonitorInfoA p_GetMonitorInfoA = NULL;
#endif
void void
_gdk_windowing_set_default_display (GdkDisplay *display) _gdk_windowing_set_default_display (GdkDisplay *display)
{ {
@ -64,7 +56,21 @@ enum_monitor (HMONITOR hmonitor,
LPRECT rect, LPRECT rect,
LPARAM data) LPARAM data)
{ {
MONITORINFOEX monitor_info; /* The struct MONITORINFOEX definition is for some reason different
* in the winuser.h bundled with mingw64 from that in MSDN and the
* official 32-bit mingw (the MONITORINFO part is in a separate "mi"
* member). So to keep this easily compileable with either, repeat
* the MSDN definition it here.
*/
typedef struct tagMONITORINFOEXA2 {
DWORD cbSize;
RECT rcMonitor;
RECT rcWork;
DWORD dwFlags;
CHAR szDevice[CCHDEVICENAME];
} MONITORINFOEXA2;
MONITORINFOEXA2 monitor_info;
HDC hDC; HDC hDC;
gint *index = (gint *) data; gint *index = (gint *) data;
@ -75,7 +81,7 @@ enum_monitor (HMONITOR hmonitor,
monitor = _gdk_monitors + *index; monitor = _gdk_monitors + *index;
monitor_info.cbSize = sizeof (MONITORINFOEX); monitor_info.cbSize = sizeof (MONITORINFOEX);
(*p_GetMonitorInfoA) (hmonitor, (MONITORINFO *) &monitor_info); GetMonitorInfoA (hmonitor, (MONITORINFO *) &monitor_info);
#ifndef MONITORINFOF_PRIMARY #ifndef MONITORINFOF_PRIMARY
#define MONITORINFOF_PRIMARY 1 #define MONITORINFOF_PRIMARY 1
@ -112,76 +118,58 @@ void
_gdk_monitor_init (void) _gdk_monitor_init (void)
{ {
#ifdef HAVE_MONITOR_INFO #ifdef HAVE_MONITOR_INFO
static HMODULE user32 = NULL; gint i, index;
if (user32 == NULL) _gdk_num_monitors = 0;
EnumDisplayMonitors (NULL, NULL, count_monitor, (LPARAM) &_gdk_num_monitors);
_gdk_monitors = g_renew (GdkWin32Monitor, _gdk_monitors, _gdk_num_monitors);
index = 0;
EnumDisplayMonitors (NULL, NULL, enum_monitor, (LPARAM) &index);
_gdk_offset_x = G_MININT;
_gdk_offset_y = G_MININT;
/* Calculate offset */
for (i = 0; i < _gdk_num_monitors; i++)
{ {
user32 = GetModuleHandle ("user32.dll"); _gdk_offset_x = MAX (_gdk_offset_x, -_gdk_monitors[i].rect.x);
_gdk_offset_y = MAX (_gdk_offset_y, -_gdk_monitors[i].rect.y);
g_assert (user32 != NULL);
p_EnumDisplayMonitors = (t_EnumDisplayMonitors) GetProcAddress (user32, "EnumDisplayMonitors");
p_GetMonitorInfoA = (t_GetMonitorInfoA) GetProcAddress (user32, "GetMonitorInfoA");
} }
GDK_NOTE (MISC, g_print ("Multi-monitor offset: (%d,%d)\n",
_gdk_offset_x, _gdk_offset_y));
if (p_EnumDisplayMonitors != NULL && p_GetMonitorInfoA != NULL) /* Translate monitor coords into GDK coordinate space */
for (i = 0; i < _gdk_num_monitors; i++)
{ {
gint i, index; _gdk_monitors[i].rect.x += _gdk_offset_x;
_gdk_monitors[i].rect.y += _gdk_offset_y;
_gdk_num_monitors = 0; GDK_NOTE (MISC, g_print ("Monitor %d: %dx%d@%+d%+d\n",
i, _gdk_monitors[i].rect.width,
(*p_EnumDisplayMonitors) (NULL, NULL, count_monitor, (LPARAM) &_gdk_num_monitors); _gdk_monitors[i].rect.height,
_gdk_monitors[i].rect.x,
_gdk_monitors = g_renew (GdkWin32Monitor, _gdk_monitors, _gdk_num_monitors); _gdk_monitors[i].rect.y));
index = 0;
(*p_EnumDisplayMonitors) (NULL, NULL, enum_monitor, (LPARAM) &index);
_gdk_offset_x = G_MININT;
_gdk_offset_y = G_MININT;
/* Calculate offset */
for (i = 0; i < _gdk_num_monitors; i++)
{
_gdk_offset_x = MAX (_gdk_offset_x, -_gdk_monitors[i].rect.x);
_gdk_offset_y = MAX (_gdk_offset_y, -_gdk_monitors[i].rect.y);
}
GDK_NOTE (MISC, g_print ("Multi-monitor offset: (%d,%d)\n",
_gdk_offset_x, _gdk_offset_y));
/* Translate monitor coords into GDK coordinate space */
for (i = 0; i < _gdk_num_monitors; i++)
{
_gdk_monitors[i].rect.x += _gdk_offset_x;
_gdk_monitors[i].rect.y += _gdk_offset_y;
GDK_NOTE (MISC, g_print ("Monitor %d: %dx%d@%+d%+d\n",
i, _gdk_monitors[i].rect.width,
_gdk_monitors[i].rect.height,
_gdk_monitors[i].rect.x,
_gdk_monitors[i].rect.y));
}
} }
else #else
#endif /* HAVE_MONITOR_INFO */ HDC hDC;
{
HDC hDC;
_gdk_num_monitors = 1; _gdk_num_monitors = 1;
_gdk_monitors = g_renew (GdkWin32Monitor, _gdk_monitors, 1); _gdk_monitors = g_renew (GdkWin32Monitor, _gdk_monitors, 1);
_gdk_monitors[0].name = g_strdup ("DISPLAY");
hDC = GetDC (NULL);
_gdk_monitors[0].width_mm = GetDeviceCaps (hDC, HORZSIZE);
_gdk_monitors[0].height_mm = GetDeviceCaps (hDC, VERTSIZE);
ReleaseDC (NULL, hDC);
_gdk_monitors[0].rect.x = 0;
_gdk_monitors[0].rect.y = 0;
_gdk_monitors[0].rect.width = GetSystemMetrics (SM_CXSCREEN);
_gdk_monitors[0].rect.height = GetSystemMetrics (SM_CYSCREEN);
_gdk_offset_x = 0;
_gdk_offset_y = 0;
}
_gdk_monitors[0].name = g_strdup ("DISPLAY");
hDC = GetDC (NULL);
_gdk_monitors[0].width_mm = GetDeviceCaps (hDC, HORZSIZE);
_gdk_monitors[0].height_mm = GetDeviceCaps (hDC, VERTSIZE);
ReleaseDC (NULL, hDC);
_gdk_monitors[0].rect.x = 0;
_gdk_monitors[0].rect.y = 0;
_gdk_monitors[0].rect.width = GetSystemMetrics (SM_CXSCREEN);
_gdk_monitors[0].rect.height = GetSystemMetrics (SM_CYSCREEN);
_gdk_offset_x = 0;
_gdk_offset_y = 0;
#endif
} }
GdkDisplay * GdkDisplay *