]> Pileus Git - ~andy/gtk/commitdiff
Don't bother looking up EnumDisplayMonitors and GetMonitorInfoA
authorTor Lillqvist <tml@novell.com>
Sun, 3 Aug 2008 23:05:37 +0000 (23:05 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Sun, 3 Aug 2008 23:05:37 +0000 (23:05 +0000)
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

ChangeLog
gdk/win32/gdkdisplay-win32.c

index 91236991ed908bc318d039ffdf2de10cccb29479..ff01544145dd0c39f3c462ce8502f656de338e06 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        Bug 540379 – gtk_tree_view_enable_model_drag_dest and
index 1f09e00ce7720a45c43dcdfb64128c8fda32ddc6..4d70897a2b94709625ff12ccd41fa305b0bc334c 100644 (file)
 #undef HAVE_MONITOR_INFO
 #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
 _gdk_windowing_set_default_display (GdkDisplay *display)
 {
@@ -64,7 +56,21 @@ enum_monitor (HMONITOR hmonitor,
              LPRECT   rect,
              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;
 
   gint *index = (gint *) data;
@@ -75,7 +81,7 @@ enum_monitor (HMONITOR hmonitor,
   monitor = _gdk_monitors + *index;
 
   monitor_info.cbSize = sizeof (MONITORINFOEX);
-  (*p_GetMonitorInfoA) (hmonitor, (MONITORINFO *) &monitor_info);
+  GetMonitorInfoA (hmonitor, (MONITORINFO *) &monitor_info);
 
 #ifndef MONITORINFOF_PRIMARY
 #define MONITORINFOF_PRIMARY 1
@@ -112,76 +118,58 @@ void
 _gdk_monitor_init (void)
 {
 #ifdef HAVE_MONITOR_INFO
-  static HMODULE user32 = NULL;
+  gint i, index;
 
-  if (user32 == NULL)
-    {
-      user32 = GetModuleHandle ("user32.dll");
+  _gdk_num_monitors = 0;
 
-      g_assert (user32 != NULL);
+  EnumDisplayMonitors (NULL, NULL, count_monitor, (LPARAM) &_gdk_num_monitors);
 
-      p_EnumDisplayMonitors = (t_EnumDisplayMonitors) GetProcAddress (user32, "EnumDisplayMonitors");
-      p_GetMonitorInfoA = (t_GetMonitorInfoA) GetProcAddress (user32, "GetMonitorInfoA");
-    }
+  _gdk_monitors = g_renew (GdkWin32Monitor, _gdk_monitors, _gdk_num_monitors);
 
-  if (p_EnumDisplayMonitors != NULL && p_GetMonitorInfoA != NULL)
+  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++)
     {
-      gint i, index;
-
-      _gdk_num_monitors = 0;
-
-      (*p_EnumDisplayMonitors) (NULL, NULL, count_monitor, (LPARAM) &_gdk_num_monitors);
-
-      _gdk_monitors = g_renew (GdkWin32Monitor, _gdk_monitors, _gdk_num_monitors);
-
-      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));
-        }
+      _gdk_offset_x = MAX (_gdk_offset_x, -_gdk_monitors[i].rect.x);
+      _gdk_offset_y = MAX (_gdk_offset_y, -_gdk_monitors[i].rect.y);
     }
-  else
-#endif /* HAVE_MONITOR_INFO */
+  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++)
     {
-      HDC hDC;
-
-      _gdk_num_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[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
+  HDC hDC;
 
+  _gdk_num_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;
+#endif
 }
 
 GdkDisplay *