diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | applets/systray/Makefile.am | 3 | ||||
-rw-r--r-- | applets/systray/systray.c | 128 | ||||
-rw-r--r-- | configure.ac | 11 |
4 files changed, 149 insertions, 3 deletions
@@ -1,5 +1,15 @@ 2006-08-21 Jorn Baayen <jorn@openedhand.com> + * applets/systray/Makefile.am: + * applets/systray/systray.c: (tray_icon_added_cb), + (message_sent_cb), (message_cancelled_cb), (screen_changed_cb), + (mb_panel_applet_create): + * configure.ac: + + Added optional support for tray icon messages using libnotify. + +2006-08-21 Jorn Baayen <jorn@openedhand.com> + * applets/Makefile.am: * applets/clock.c: * applets/clock/Makefile.am: diff --git a/applets/systray/Makefile.am b/applets/systray/Makefile.am index e1cea11..c99efee 100644 --- a/applets/systray/Makefile.am +++ b/applets/systray/Makefile.am @@ -1,5 +1,5 @@ AM_CPPFLAGS=-DPKGDATADIR=\"$(pkgdatadir)\" -DGETTEXT_PACKAGE=\"matchbox-panel\" -AM_CFLAGS = -Wall -g $(MATCHBOX_PANEL_CFLAGS) \ +AM_CFLAGS = -Wall -g $(MATCHBOX_PANEL_CFLAGS) $(LIBNOTIFY_CFLAGS) \ -I$(top_srcdir) -I$(top_builddir) appletdir = $(libdir)/matchbox-panel @@ -23,6 +23,7 @@ libsystray_la_SOURCES = $(BUILT_SOURCES) \ eggtraymanager.c \ eggtraymanager.h \ systray.c +libsystray_la_LIBADD = $(LIBNOTIFY_LIBS) EXTRA_DIST = eggmarshalers.list diff --git a/applets/systray/systray.c b/applets/systray/systray.c index ac94bf5..78c6b29 100644 --- a/applets/systray/systray.c +++ b/applets/systray/systray.c @@ -6,13 +6,16 @@ * Licensed under the GPL v2 or greater. */ +#include <config.h> #include <gtk/gtkhbox.h> #include <gtk/gtkvbox.h> #include <matchbox-panel/mb-panel.h> -#include "eggtraymanager.h" +#ifdef USE_LIBNOTIFY + #include <libnotify/notify.h> +#endif -/* TODO: messages */ +#include "eggtraymanager.h" /* Tray icon added */ static void @@ -23,6 +26,111 @@ tray_icon_added_cb (EggTrayManager *manager, gtk_box_pack_start (box, icon, FALSE, FALSE, 0); } +#ifdef USE_LIBNOTIFY +/* Notification closed */ +static void +notification_closed_cb (NotifyNotification *n, + GtkWidget *icon) +{ + GHashTable *hash; + gpointer id; + + /* Remove reference to notification */ + hash = g_object_get_data (G_OBJECT (icon), "notification-hash"); + g_assert (hash); + + id = g_object_get_data (G_OBJECT (n), "id"); + + g_hash_table_remove (hash, id); +} + +/* Message sent */ +static void +message_sent_cb (EggTrayManager *manager, + GtkWidget *icon, + const char *message, + long id, + long timeout, + gpointer user_data) +{ + GHashTable *hash; + NotifyNotification *n; + GError *error; + + /* Create notification */ + n = notify_notification_new (message, + NULL, + NULL, + icon); + notify_notification_set_timeout (n, timeout); + + error = NULL; + if (!notify_notification_show (n, &error)) { + g_warning (error->message); + + g_error_free (error); + + g_object_unref (n); + + return; + } + + /* Keep a reference to the notification */ + hash = g_object_get_data (G_OBJECT (icon), "notification-hash"); + if (!hash) { + hash = g_hash_table_new_full (g_int_hash, + g_int_equal, + NULL, + (GDestroyNotify) g_object_unref); + + g_object_set_data_full (G_OBJECT (icon), + "notification-hash", + hash, + (GDestroyNotify) g_hash_table_destroy); + } + + g_hash_table_insert (hash, GINT_TO_POINTER (id), n); + + /* Make sure the notification is removed from the hash once + * closed */ + g_object_set_data (G_OBJECT (n), "id", GINT_TO_POINTER (id)); + g_signal_connect (n, + "closed", + G_CALLBACK (notification_closed_cb), + icon); +} + +/* Message cancelled */ +static void +message_cancelled_cb (EggTrayManager *manager, + GtkWidget *icon, + long id, + gpointer user_data) +{ + GHashTable *hash; + NotifyNotification *n; + GError *error; + + /* Look up reference to notification */ + hash = g_object_get_data (G_OBJECT (icon), "notification-hash"); + if (!hash) + return; + + n = g_hash_table_lookup (hash, GINT_TO_POINTER (id)); + if (!n) + return; + + /* Close it */ + error = NULL; + notify_notification_close (n, &error); + if (error) { + g_warning (error->message); + + g_error_free (error); + } +} +#endif + /* Screen changed */ static void screen_changed_cb (GtkWidget *widget, @@ -51,6 +159,11 @@ mb_panel_applet_create (const char *id, GtkOrientation orientation; GtkWidget *box; +#ifdef USE_LIBNOTIFY + if (!notify_is_initted ()) + notify_init ("matchbox-panel"); +#endif + /* Is this a vertical panel? */ if (panel_width >= panel_height) { orientation = GTK_ORIENTATION_HORIZONTAL; @@ -73,6 +186,17 @@ mb_panel_applet_create (const char *id, G_CALLBACK (tray_icon_added_cb), box); +#ifdef USE_LIBNOTIFY + g_signal_connect (manager, + "message-sent", + G_CALLBACK (message_sent_cb), + NULL); + g_signal_connect (manager, + "message-cancelled", + G_CALLBACK (message_cancelled_cb), + NULL); +#endif + g_signal_connect (box, "screen-changed", G_CALLBACK (screen_changed_cb), diff --git a/configure.ac b/configure.ac index 969ac6b..ab0c899 100644 --- a/configure.ac +++ b/configure.ac @@ -26,6 +26,17 @@ if test x$enable_startup_notification != xno; then AC_DEFINE(USE_LIBSN, [1], [Has Startup Notification Support]) fi +AC_ARG_ENABLE(libnotify, + [ --enable-libnotify enable libnotify support], + enable_libnotify=$enableval, enable_libnotify=yes ) + +if test x$enable_libnotify != xno; then + PKG_CHECK_MODULES(LIBNOTIFY, libnotify, , + AC_MSG_ERROR([*** Required libnotify library not installed ***])) + + AC_DEFINE(USE_LIBNOTIFY, [1], [Has libnotify Support]) +fi + GLIB_GENMARSHAL=`$PKG_CONFIG --variable=glib_genmarshal glib-2.0` AC_SUBST(GLIB_GENMARSHAL) |