[Galago-commits] r2884 - in trunk/notification-daemon: . data src

galago-commits at freedesktop.org galago-commits at freedesktop.org
Sat Jul 29 03:48:35 PDT 2006


Author: chipx86
Date: 2006-07-29 03:48:31 -0700 (Sat, 29 Jul 2006)
New Revision: 2884

Modified:
   trunk/notification-daemon/ChangeLog
   trunk/notification-daemon/NEWS
   trunk/notification-daemon/data/notification-daemon.schemas.in
   trunk/notification-daemon/src/daemon.c
   trunk/notification-daemon/src/daemon.h
   trunk/notification-daemon/src/engines.c
Log:
Patch by M.S. to support custom corner stacking positions through a gconf key. Now users can specify that their notifications should originate from any corner they choose. This closes ticket #57.


Modified: trunk/notification-daemon/ChangeLog
===================================================================
--- trunk/notification-daemon/ChangeLog	2006-07-29 10:14:57 UTC (rev 2883)
+++ trunk/notification-daemon/ChangeLog	2006-07-29 10:48:31 UTC (rev 2884)
@@ -1,3 +1,13 @@
+Sat Jul 29 03:46:43 PDT 2006  Christian Hammond <chipx86 at chipx86.com>
+
+	* data/notification-daemon.schemas.in:
+	* src/daemon.c:
+	* src/daemon.h:
+	* src/engines.c:
+	  - Patch by M.S. to support custom corner stacking positions through a
+	    gconf key. Now users can specify that their notifications should
+	    originate from any corner they choose. This closes ticket #57.
+
 Sat Jul 29 03:11:15 PDT 2006  Christian Hammond <chipx86 at chipx86.com>
 
 	* src/daemon.c:

Modified: trunk/notification-daemon/NEWS
===================================================================
--- trunk/notification-daemon/NEWS	2006-07-29 10:14:57 UTC (rev 2883)
+++ trunk/notification-daemon/NEWS	2006-07-29 10:48:31 UTC (rev 2884)
@@ -1,4 +1,7 @@
 version 0.3.6:
+	* Added a GConf key to allow users to specify which corner of the screen
+	  notifications should appear in. Patch by M.S. (Ticket #57)
+	* Added a Dutch translation from Wouter Bolsterlee. (Bug #55)
 	* Fixed compatibility problems with D-BUS v0.61. (Bugs #67, #75)
 	* A notification's timeout will now pause while the mouse is hovering over
 	  the notification. This allows users to respond to notifications without
@@ -13,7 +16,6 @@
 	  notification would cause a broken notification where timeouts and
 	  action invoking fails. In this case, a new ID is generated. Patch by
 	  Ed Catmur. (Bug #76)
-	* Added a Dutch translation from Wouter Bolsterlee. (Bug #55)
 
 version 0.3.5 (26-April-2006):
 	* Add three new required theme functions:

Modified: trunk/notification-daemon/data/notification-daemon.schemas.in
===================================================================
--- trunk/notification-daemon/data/notification-daemon.schemas.in	2006-07-29 10:14:57 UTC (rev 2883)
+++ trunk/notification-daemon/data/notification-daemon.schemas.in	2006-07-29 10:48:31 UTC (rev 2884)
@@ -2,6 +2,18 @@
  <schemalist>
 
   <schema>
+   <key>/schemas/apps/notification-daemon/popup_location</key>
+   <applyto>/apps/notification-daemon/popup_location</applyto>
+   <owner>notification-daemon</owner>
+   <type>string</type>
+   <default>right_bottom</default>
+   <locale name="C">
+    <short>Popup location</short>
+    <long>Default popup location on the workspace for stack notifications. Allowed values: &quot;top_left&quot;,&quot;top_right&quot;,&quot;bottom_left&quot; and &quot;bottom_right&quot;</long>
+   </locale>
+  </schema>
+
+  <schema>
    <key>/schemas/apps/notification-daemon/theme</key>
    <applyto>/apps/notification-daemon/theme</applyto>
    <owner>notification-daemon</owner>

Modified: trunk/notification-daemon/src/daemon.c
===================================================================
--- trunk/notification-daemon/src/daemon.c	2006-07-29 10:14:57 UTC (rev 2883)
+++ trunk/notification-daemon/src/daemon.c	2006-07-29 10:48:31 UTC (rev 2884)
@@ -48,6 +48,32 @@
 
 #define IMAGE_SIZE 48
 
+enum {
+	POPUP_STACK_LOCATION_TOP_LEFT,
+	POPUP_STACK_LOCATION_TOP_RIGHT,
+	POPUP_STACK_LOCATION_BOTTOM_LEFT,
+	POPUP_STACK_LOCATION_BOTTOM_RIGHT,
+	POPUP_STACK_LOCATION_UNKNOWN
+};
+
+#define POPUP_STACK_LOCATION_DEFAULT \
+	POPUP_STACK_LOCATION_BOTTOM_RIGHT
+
+struct PopupStackLocation
+{
+	gchar id;
+	const gchar *identifier;
+};
+
+const struct PopupStackLocation popup_stack_locations[] =
+{
+	{ POPUP_STACK_LOCATION_TOP_LEFT,     "top_left"     },
+	{ POPUP_STACK_LOCATION_TOP_RIGHT,    "top_right"    },
+	{ POPUP_STACK_LOCATION_BOTTOM_LEFT,  "bottom_left"  },
+	{ POPUP_STACK_LOCATION_BOTTOM_RIGHT, "bottom_right" },
+	{ -1, NULL }
+};
+
 struct _NotifyTimeout
 {
 	GTimeVal expiration;
@@ -68,6 +94,8 @@
 	GHashTable *notification_hash;
 	GSList *poptart_stack;
 	gboolean url_clicked_lock;
+	gboolean stack_only;
+	gchar popup_stack_location;
 };
 
 static GConfClient *gconf_client = NULL;
@@ -87,6 +115,7 @@
 };
 #endif /* D-BUS < 0.60 */
 
+static gchar _notify_daemon_stack_location_from_string(const gchar *slocation);
 static void notify_daemon_finalize(GObject *object);
 static void _close_notification(NotifyDaemon *daemon, guint id,
 								gboolean hide_notification);
@@ -115,11 +144,34 @@
 static void
 notify_daemon_init(NotifyDaemon *daemon)
 {
+	GConfClient *client;
+
 	daemon->priv = G_TYPE_INSTANCE_GET_PRIVATE(daemon, NOTIFY_TYPE_DAEMON,
 											   NotifyDaemonPrivate);
 
 	daemon->priv->next_id = 1;
 	daemon->priv->timeout_source = 0;
+	daemon->priv->stack_only = FALSE;
+	daemon->priv->popup_stack_location = POPUP_STACK_LOCATION_DEFAULT;
+
+	client = get_gconf_client();
+
+	if (client != NULL)
+	{
+		gchar *slocation = gconf_client_get_string(client,
+												   GCONF_KEY_POPUP_LOCATION,
+												   NULL);
+
+		if (slocation != NULL && *slocation != '\0')
+		{
+			gchar location =
+				_notify_daemon_stack_location_from_string(slocation);
+
+			if (location != POPUP_STACK_LOCATION_UNKNOWN)
+				daemon->priv->popup_stack_location = location;
+		}
+	}
+
 	daemon->priv->notification_hash =
 		g_hash_table_new_full(g_int_hash, g_int_equal, g_free,
 							  (GDestroyNotify)_notify_timeout_destroy);
@@ -691,19 +743,142 @@
 	return TRUE;
 }
 
+static gchar
+_notify_daemon_stack_location_from_string(const gchar *slocation)
+{
+	const struct PopupStackLocation* l;
+
+	for (l = popup_stack_locations; l->id != -1; l++)
+	{
+		if (!strcmp(slocation, l->identifier))
+			return l->id;
+	}
+
+	return POPUP_STACK_LOCATION_UNKNOWN;
+}
+
 static void
+_pop_stack_get_origin_coordinates(const gchar location,
+                                  GdkRectangle workarea,
+                                  gint *x, gint *y, gint *shx, gint *shy,
+                                  const gint width, const gint height)
+{
+	switch (location)
+	{
+		case POPUP_STACK_LOCATION_TOP_LEFT:
+			*x = workarea.x;
+			*y = workarea.y;
+			*shy = height;
+			break;
+
+		case POPUP_STACK_LOCATION_TOP_RIGHT:
+			*x = workarea.x + workarea.width - width;
+			*y = workarea.y;
+			*shy = height;
+			break;
+
+		case POPUP_STACK_LOCATION_BOTTOM_LEFT:
+			*x = workarea.x;
+			*y = workarea.y + workarea.height - height;
+			break;
+
+		case POPUP_STACK_LOCATION_BOTTOM_RIGHT:
+			*x = workarea.x + workarea.width - width;
+			*y = workarea.y + workarea.height - height;
+			break;
+
+		default:
+			g_assert_not_reached();
+	}
+}
+
+static void
+_pop_stack_translate_coordinates(const gchar location,
+								 GdkRectangle workarea,
+								 gint *x, gint *y, gint *shx, gint *shy,
+								 const gint width, const gint height,
+								 const gint index)
+{
+	switch (location)
+	{
+		case POPUP_STACK_LOCATION_TOP_LEFT:
+			*x = workarea.x;
+			*y += *shy;
+			*shy = height;
+			break;
+
+		case POPUP_STACK_LOCATION_TOP_RIGHT:
+			*x = workarea.x + workarea.width - width;
+			*y += *shy;
+			*shy = height;
+			break;
+
+		case POPUP_STACK_LOCATION_BOTTOM_LEFT:
+			*x = workarea.x;
+			*y -= height;
+			break;
+
+		case POPUP_STACK_LOCATION_BOTTOM_RIGHT:
+			*x = workarea.x + workarea.width - width;
+			*y -= height;
+			break;
+
+		default:
+			g_assert_not_reached();
+	}
+}
+
+static void
+popup_location_changed_cb(GConfClient *client, guint cnxn_id,
+						  GConfEntry *entry, gpointer user_data)
+{
+	NotifyDaemon *daemon = (NotifyDaemon*)user_data;
+	GConfValue *value;
+
+	if (daemon == NULL)
+		return;
+
+	value = gconf_entry_get_value(entry);
+
+	if (value != NULL)
+	{
+		const char *slocation = gconf_value_get_string(value);
+
+		if (slocation != NULL)
+		{
+			gchar location =
+				_notify_daemon_stack_location_from_string(slocation);
+
+			if (location != POPUP_STACK_LOCATION_UNKNOWN)
+			{
+				daemon->priv->popup_stack_location = location;
+				return;
+			}
+		}
+	}
+
+	gconf_client_set_string(client,
+		"/apps/notification-daemon/popup_location",
+		popup_stack_locations[POPUP_STACK_LOCATION_DEFAULT].identifier,
+		NULL);
+
+	daemon->priv->popup_stack_location = POPUP_STACK_LOCATION_DEFAULT;
+}
+
+static void
 _remove_bubble_from_poptart_stack(GtkWindow *nw, NotifyDaemon *daemon)
 {
 	NotifyDaemonPrivate *priv = daemon->priv;
 	GdkRectangle workarea;
 	GSList *remove_link = NULL;
 	GSList *link;
-	gint x, y;
+	gint x, y, shiftx = 0, shifty = 0, index = 0;
 
 	get_work_area(GTK_WIDGET(nw), &workarea);
 
-	y = workarea.y + workarea.height;
-	x = 0;
+	_pop_stack_get_origin_coordinates(priv->popup_stack_location,
+									  workarea, &x, &y, &shiftx, &shifty,
+									  0, 0);
 
 	for (link = priv->poptart_stack; link != NULL; link = link->next)
 	{
@@ -714,8 +889,11 @@
 		{
 			gtk_widget_size_request(GTK_WIDGET(nw2), &req);
 
-			x = workarea.x + workarea.width - req.width;
-			y = y - req.height;
+			_pop_stack_translate_coordinates(priv->popup_stack_location,
+											 workarea, &x, &y,
+											 &shiftx, &shifty,
+											 req.width, req.height,
+											 index++);
 
 			theme_move_notification(nw2, x, y);
 		}
@@ -744,14 +922,15 @@
 	GtkRequisition req;
 	GdkRectangle workarea;
 	GSList *link;
-	gint x, y;
+	gint x, y, shiftx = 0, shifty = 0, index = 1;
 
 	gtk_widget_size_request(GTK_WIDGET(nw), &req);
 
 	get_work_area(GTK_WIDGET(nw), &workarea);
 
-	x = workarea.x + workarea.width - req.width;
-	y = workarea.y + workarea.height - req.height;
+	_pop_stack_get_origin_coordinates(priv->popup_stack_location, workarea,
+									  &x, &y, &shiftx, &shifty,
+									  req.width, req.height);
 
 	theme_move_notification(nw, x, y);
 
@@ -762,8 +941,13 @@
 		if (nw2 != nw)
 		{
 			gtk_widget_size_request(GTK_WIDGET(nw2), &req);
-			x = workarea.x + workarea.width - req.width;
-			y = y - req.height;
+
+			_pop_stack_translate_coordinates(priv->popup_stack_location,
+											 workarea, &x, &y,
+											 &shiftx, &shifty,
+											 req.width, req.height,
+											 index++);
+
 			theme_move_notification(nw2, x, y);
 		}
 	}
@@ -1152,10 +1336,11 @@
 	gconf_init(argc, argv, NULL);
 
 	gconf_client = gconf_client_get_default();
-	gconf_client_add_dir(gconf_client, "/apps/notification-daemon/theme",
+	gconf_client_add_dir(gconf_client, GCONF_KEY_DAEMON,
 						 GCONF_CLIENT_PRELOAD_NONE, NULL);
 
 	error = NULL;
+
 	connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
 
 	if (connection == NULL)
@@ -1186,6 +1371,13 @@
 
 	daemon = notify_daemon_new();
 
+	gconf_client_notify_add(gconf_client, GCONF_KEY_POPUP_LOCATION,
+							popup_location_changed_cb, daemon,
+							NULL, NULL);
+
+	/* Emit signal to verify/set current key */
+	gconf_client_notify(gconf_client, GCONF_KEY_POPUP_LOCATION);
+
 	dbus_g_connection_register_g_object(connection,
 										"/org/freedesktop/Notifications",
 										G_OBJECT(daemon));

Modified: trunk/notification-daemon/src/daemon.h
===================================================================
--- trunk/notification-daemon/src/daemon.h	2006-07-29 10:14:57 UTC (rev 2883)
+++ trunk/notification-daemon/src/daemon.h	2006-07-29 10:48:31 UTC (rev 2884)
@@ -29,6 +29,10 @@
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
+#define GCONF_KEY_DAEMON         "/apps/notification-daemon"
+#define GCONF_KEY_THEME          GCONF_KEY_DAEMON "/theme"
+#define GCONF_KEY_POPUP_LOCATION GCONF_KEY_DAEMON "/popup_location"
+
 G_BEGIN_DECLS
 
 #define NOTIFY_TYPE_DAEMON (notify_daemon_get_type())

Modified: trunk/notification-daemon/src/engines.c
===================================================================
--- trunk/notification-daemon/src/engines.c	2006-07-29 10:14:57 UTC (rev 2883)
+++ trunk/notification-daemon/src/engines.c	2006-07-29 10:48:31 UTC (rev 2884)
@@ -136,8 +136,8 @@
 	if (active_engine == NULL)
 	{
 		GConfClient *client = get_gconf_client();
-		char *enginename = gconf_client_get_string(client,
-			"/apps/notification-daemon/theme", NULL);
+		char *enginename = gconf_client_get_string(client, GCONF_KEY_THEME,
+												   NULL);
 
 		if (theme_prop_notify_id == 0)
 		{



More information about the galago-commits mailing list