Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.5367.2.212
diff -u -2 -r1.5367.2.212 ChangeLog
--- ChangeLog	31 Aug 2004 19:10:47 -0000	1.5367.2.212
+++ ChangeLog	2 Sep 2004 05:03:42 -0000
@@ -1,6 +1,23 @@
+2004-09-02  Tor Lillqvist  <tml@iki.fi>
+
+	* gdk/win32/gdkwindow-win32.c (_gdk_windowing_window_init,
+	_gdk_root_window_size_init): Factor out setting the root window's
+	size (as the size of the union of all monitors) to a new function.
+
+	* gdk/win32/gdkdisplay-win32.c (gdk_display_oper,
+	_gdk_monitor_init): Factor out the multiple-monitor initialisation
+	to a new function.
+
+	* gdk/win32/gdkprivate-win32.h: Declare above new functions.
+
+	* gdk/win32/gdkevents-win32.c (gdk_event_translate,
+	handle_display_change): Handle WM_DISPLAYCHANGE by calling the
+	above functions, and emitting the "size_changed" signal on the
+	GdkScreen.
+
 2004-08-28  Robert Ögren  <gtk@roboros.com>
 
 	On Win32, do not produce tablet motion or button events while a
-	window is being moved or resized. (#151090, reported by Shaneyfelt)
+	window is being moved or resized. (#151090, reported by	Shaneyfelt)
 
 	* gdk/win32/gdkprivate-win32.h
Index: gdk/win32/gdkwindow-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkwindow-win32.c,v
retrieving revision 1.116.2.2
diff -u -2 -r1.116.2.2 gdkwindow-win32.c
--- gdk/win32/gdkwindow-win32.c	22 Aug 2004 19:12:46 -0000	1.116.2.2
+++ gdk/win32/gdkwindow-win32.c	2 Sep 2004 05:03:44 -0000
@@ -281,11 +281,24 @@
 
 void
+_gdk_root_window_size_init (void)
+{
+  GdkWindowImplWin32 *impl;
+  GdkRectangle rect;
+  int i;
+
+  impl = GDK_WINDOW_IMPL_WIN32 ((GdkWindowObject *) _gdk_parent_root);
+  rect = _gdk_monitors[0];
+  for (i = 1; i < _gdk_num_monitors; i++)
+    gdk_rectangle_union (&rect, _gdk_monitors+i, &rect);
+
+  impl->width = rect.width;
+  impl->height = rect.height;
+}
+
+void
 _gdk_windowing_window_init (void)
 {
   GdkWindowObject *private;
-  GdkWindowImplWin32 *impl;
   GdkDrawableImplWin32 *draw_impl;
-  GdkRectangle rect;
-  gint i;
 
   g_assert (_gdk_parent_root == NULL);
@@ -293,5 +306,4 @@
   _gdk_parent_root = g_object_new (GDK_TYPE_WINDOW, NULL);
   private = (GdkWindowObject *)_gdk_parent_root;
-  impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
   draw_impl = GDK_DRAWABLE_IMPL_WIN32 (private->impl);
   
@@ -304,11 +316,6 @@
   private->depth = gdk_visual_get_system ()->depth;
 
-  rect = _gdk_monitors[0];
-  for (i = 1; i < _gdk_num_monitors; i++)
-    gdk_rectangle_union (&rect, _gdk_monitors+i, &rect);
-
-  impl->width = rect.width;
-  impl->height = rect.height;
-
+  _gdk_root_window_size_init ();
+ 
   _gdk_window_init_position (GDK_WINDOW (private));
 
Index: gdk/win32/gdkdisplay-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkdisplay-win32.c,v
retrieving revision 1.14.2.1
diff -u -2 -r1.14.2.1 gdkdisplay-win32.c
--- gdk/win32/gdkdisplay-win32.c	22 Aug 2004 16:56:48 -0000	1.14.2.1
+++ gdk/win32/gdkdisplay-win32.c	2 Sep 2004 05:03:44 -0000
@@ -103,21 +103,19 @@
 #endif /* HAVE_MONITOR_INFO */
 
-GdkDisplay *
-gdk_display_open (const gchar *display_name)
+void
+_gdk_monitor_init (void)
 {
-  HMODULE user32;
-
-  if (_gdk_display != NULL)
-    return NULL; /* single display only */
+#ifdef HAVE_MONITOR_INFO
+  static HMODULE user32 = NULL;
 
-  _gdk_display = g_object_new (GDK_TYPE_DISPLAY, NULL);
-  _gdk_screen = g_object_new (GDK_TYPE_SCREEN, NULL);
+  if (user32 == NULL)
+    {
+      user32 = GetModuleHandle ("user32.dll");
 
-#ifdef HAVE_MONITOR_INFO
-  user32 = GetModuleHandle ("user32.dll");
-  g_assert (user32 != NULL);
+      g_assert (user32 != NULL);
 
-  p_EnumDisplayMonitors = (t_EnumDisplayMonitors) GetProcAddress (user32, "EnumDisplayMonitors");
-  p_GetMonitorInfoA = (t_GetMonitorInfoA) GetProcAddress (user32, "GetMonitorInfoA");
+      p_EnumDisplayMonitors = (t_EnumDisplayMonitors) GetProcAddress (user32, "EnumDisplayMonitors");
+      p_GetMonitorInfoA = (t_GetMonitorInfoA) GetProcAddress (user32, "GetMonitorInfoA");
+    }
 
   if (p_EnumDisplayMonitors != NULL && p_GetMonitorInfoA != NULL)
@@ -129,8 +127,9 @@
       (*p_EnumDisplayMonitors) (NULL, NULL, count_monitor, (LPARAM) &_gdk_num_monitors);
 
-      _gdk_monitors = g_new (GdkRectangle, _gdk_num_monitors);
+      _gdk_monitors = g_renew (GdkRectangle, _gdk_monitors, _gdk_num_monitors);
+
       index = 0;
       (*p_EnumDisplayMonitors) (NULL, NULL, enum_monitor, (LPARAM) &index);
-#if 1
+
       _gdk_offset_x = G_MININT;
       _gdk_offset_y = G_MININT;
@@ -155,5 +154,4 @@
 				   _gdk_monitors[i].x, _gdk_monitors[i].y));
 	}
-#endif
     }
   else
@@ -163,5 +161,5 @@
 
       _gdk_num_monitors = 1;
-      _gdk_monitors = g_new (GdkRectangle, 1);
+      _gdk_monitors = g_renew (GdkRectangle, _gdk_monitors, 1);
 
       width = GetSystemMetrics (SM_CXSCREEN);
@@ -176,4 +174,16 @@
     }
 
+}
+
+GdkDisplay *
+gdk_display_open (const gchar *display_name)
+{
+  if (_gdk_display != NULL)
+    return NULL; /* single display only */
+
+  _gdk_display = g_object_new (GDK_TYPE_DISPLAY, NULL);
+  _gdk_screen = g_object_new (GDK_TYPE_SCREEN, NULL);
+
+  _gdk_monitor_init ();
   _gdk_visual_init ();
   gdk_screen_set_default_colormap (_gdk_screen,
Index: gdk/win32/gdkprivate-win32.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkprivate-win32.h,v
retrieving revision 1.60.2.2
diff -u -2 -r1.60.2.2 gdkprivate-win32.h
--- gdk/win32/gdkprivate-win32.h	31 Aug 2004 19:10:48 -0000	1.60.2.2
+++ gdk/win32/gdkprivate-win32.h	2 Sep 2004 05:03:44 -0000
@@ -503,4 +503,6 @@
 /* Initialization */
 void _gdk_windowing_window_init (void);
+void _gdk_root_window_size_init (void);
+void _gdk_monitor_init(void);
 void _gdk_visual_init (void);
 void _gdk_dnd_init    (void);
Index: gdk/win32/gdkglobals-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkglobals-win32.c,v
retrieving revision 1.29.2.2
diff -u -2 -r1.29.2.2 gdkglobals-win32.c
--- gdk/win32/gdkglobals-win32.c	31 Aug 2004 19:10:48 -0000	1.29.2.2
+++ gdk/win32/gdkglobals-win32.c	2 Sep 2004 05:03:44 -0000
@@ -35,5 +35,5 @@
 
 gint		  _gdk_num_monitors;
-GdkRectangle     *_gdk_monitors;
+GdkRectangle     *_gdk_monitors = NULL;
 
 gint		 _gdk_offset_x, _gdk_offset_y;
Index: gdk/win32/gdkevents-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkevents-win32.c,v
retrieving revision 1.131.2.4
diff -u -2 -r1.131.2.4 gdkevents-win32.c
--- gdk/win32/gdkevents-win32.c	31 Aug 2004 19:10:49 -0000	1.131.2.4
+++ gdk/win32/gdkevents-win32.c	2 Sep 2004 05:03:46 -0000
@@ -2058,4 +2058,12 @@
 }
 
+static void
+handle_display_change (void)
+{
+  _gdk_monitor_init ();
+  _gdk_root_window_size_init ();
+  g_signal_emit_by_name (_gdk_screen, "size_changed");
+}
+
 static gboolean
 gdk_event_translate (GdkDisplay *display,
@@ -3277,4 +3285,9 @@
       return_val = TRUE;
       break;
+
+    case WM_DISPLAYCHANGE:
+      handle_display_change ();
+      break;
+      
 
 #ifdef HAVE_WINTAB
