[notification-daemon] Don't crash if new monitors appear



commit b1fc6026e68c16cb49c61f74c57782d3eb09b5b8
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jan 8 19:49:43 2010 -0500

    Don't crash if new monitors appear

 src/daemon/daemon.c |   59 ++++++++++++++++++++++++++++++++------------------
 1 files changed, 38 insertions(+), 21 deletions(-)
---
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index 6c16cd5..ff774f0 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -162,44 +162,59 @@ _notify_timeout_destroy(NotifyTimeout *nt)
 }
 
 static void
-notify_daemon_init(NotifyDaemon *daemon)
+reallocate_stacks (NotifyDaemon *daemon)
 {
-	NotifyStackLocation location;
-	GConfClient *client = get_gconf_client();
 	GdkDisplay *display;
 	GdkScreen *screen;
+	gint old_stacks_size;
+	GConfClient *client = get_gconf_client();
+	NotifyStackLocation location;
 	gchar *slocation;
 	gint i;
 
+	display = gdk_display_get_default();
+	screen = gdk_display_get_default_screen(display);
+
+	if (daemon->priv->stacks_size < gdk_screen_get_n_monitors (screen)) {
+		slocation = gconf_client_get_string(client, GCONF_KEY_POPUP_LOCATION,
+						    NULL);
+		location = get_stack_location_from_string(slocation);
+		g_free(slocation);
+
+		old_stacks_size = daemon->priv->stacks_size;
+		daemon->priv->stacks_size = gdk_screen_get_n_monitors(screen);
+		daemon->priv->stacks = g_renew(NotifyStack *, daemon->priv->stacks, daemon->priv->stacks_size);
+		for (i = old_stacks_size; i < daemon->priv->stacks_size; i++) {
+			daemon->priv->stacks[i] = notify_stack_new(daemon,
+								   screen,
+								   i,
+								   location);
+		}
+	}
+
+
+}
+
+static void
+notify_daemon_init(NotifyDaemon *daemon)
+{
 	daemon->priv = G_TYPE_INSTANCE_GET_PRIVATE(daemon, NOTIFY_TYPE_DAEMON,
-											   NotifyDaemonPrivate);
+						   NotifyDaemonPrivate);
 
 	daemon->priv->next_id = 1;
 	daemon->priv->timeout_source = 0;
 
-	slocation = gconf_client_get_string(client, GCONF_KEY_POPUP_LOCATION,
-										NULL);
-	location = get_stack_location_from_string(slocation);
-	g_free(slocation);
+	daemon->priv->stacks_size = 0;
+	daemon->priv->stacks = NULL;
 
-	display = gdk_display_get_default();
-	screen = gdk_display_get_default_screen(display);
-	daemon->priv->stacks_size = gdk_screen_get_n_monitors(screen);
-	daemon->priv->stacks = g_new0(NotifyStack *, daemon->priv->stacks_size);
+	reallocate_stacks (daemon);
 
 	daemon->priv->idle_reposition_notify_ids = g_hash_table_new(NULL, NULL);
 	daemon->priv->monitored_window_hash = g_hash_table_new(NULL, NULL);
 	gdk_window_add_filter(NULL, _notify_x11_filter, daemon);
-
-	for (i = 0; i < daemon->priv->stacks_size; i++)
-	{
-		daemon->priv->stacks[i] = notify_stack_new(daemon, screen,
-												   i, location);
-	}
-
 	daemon->priv->notification_hash =
 		g_hash_table_new_full(g_int_hash, g_int_equal, g_free,
-							  (GDestroyNotify)_notify_timeout_destroy);
+				  (GDestroyNotify)_notify_timeout_destroy);
 }
 
 static void
@@ -1304,7 +1319,9 @@ notify_daemon_notify_handler(NotifyDaemon *daemon,
 		gdk_display_get_pointer(gdk_display_get_default(),
 								&screen, &x, &y, NULL);
 		monitor = gdk_screen_get_monitor_at_point(screen, x, y);
-		g_assert(monitor >= 0 && monitor < priv->stacks_size);
+		if (monitor >= priv->stacks_size) {
+			reallocate_stacks (daemon);
+		}
 
 		notify_stack_add_window(priv->stacks[monitor], nw, new_notification);
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]