diff options
author | Colomban Wendling <[email protected]> | 2017-01-19 18:46:10 +0100 |
---|---|---|
committer | lukefromdc <[email protected]> | 2017-01-23 13:49:34 -0500 |
commit | 7d39b2e82f46777efa67224f078c1cec9e827654 (patch) | |
tree | 7a415a153f4a3afb52358ed8a34ced08c25bdc5c /applets/notification_area/testtray.c | |
parent | a506150684ad2e71b1f70190ee70fe9eda7a4ba9 (diff) | |
download | mate-panel-7d39b2e82f46777efa67224f078c1cec9e827654.tar.bz2 mate-panel-7d39b2e82f46777efa67224f078c1cec9e827654.tar.xz |
Add StatusNotifier support to the Notification Area applet
The StatusNotifier part of the implementation is based off
gnome-panel's status-notifier applet.
Diffstat (limited to 'applets/notification_area/testtray.c')
-rw-r--r-- | applets/notification_area/testtray.c | 88 |
1 files changed, 74 insertions, 14 deletions
diff --git a/applets/notification_area/testtray.c b/applets/notification_area/testtray.c index f3724025..b2ce0fa2 100644 --- a/applets/notification_area/testtray.c +++ b/applets/notification_area/testtray.c @@ -23,9 +23,14 @@ #include <string.h> #include <stdio.h> +#include <signal.h> +#include <glib-unix.h> #include <gtk/gtk.h> -#include "na-tray-manager.h" -#include "na-tray.h" +#include "system-tray/na-tray-manager.h" +#ifdef PROVIDE_WATCHER_SERVICE +# include "libstatus-notifier-watcher/gf-status-notifier-watcher.h" +#endif +#include "na-box.h" #define NOTIFICATION_AREA_ICON "mate-panel-notification-area" @@ -36,8 +41,7 @@ typedef struct GdkScreen *screen; guint screen_num; GtkWidget *window; - NaTray *tray; - GtkWidget *box; + GtkWidget *traybox; GtkLabel *count_label; } TrayData; @@ -56,7 +60,7 @@ update_child_count (TrayData *data) if (!gtk_widget_get_realized (data->window)) return; - gtk_container_foreach (GTK_CONTAINER (data->box), (GtkCallback) do_add, &n_children); + gtk_container_foreach (GTK_CONTAINER (data->traybox), (GtkCallback) do_add, &n_children); g_snprintf (text, sizeof (text), "%u icons", n_children); gtk_label_set_text (data->count_label, text); @@ -66,7 +70,7 @@ static void tray_added_cb (GtkContainer *box, GtkWidget *icon, TrayData *data) { g_print ("[Screen %u tray %p] Child %p added to tray: \"%s\"\n", - data->screen_num, data->tray, icon, "XXX");//na_tray_child_get_title (icon)); + data->screen_num, data->traybox, icon, "XXX");//na_tray_child_get_title (icon)); update_child_count (data); } @@ -75,7 +79,7 @@ static void tray_removed_cb (GtkContainer *box, GtkWidget *icon, TrayData *data) { g_print ("[Screen %u tray %p] Child %p removed from tray\n", - data->screen_num, data->tray, icon); + data->screen_num, data->traybox, icon); update_child_count (data); } @@ -85,9 +89,9 @@ static void orientation_changed_cb (GtkComboBox *combo, TrayData *data) GtkOrientation orientation = (GtkOrientation) gtk_combo_box_get_active (combo); g_print ("[Screen %u tray %p] Setting orientation to \"%s\"\n", - data->screen_num, data->tray, orientation == 0 ? "horizontal" : "vertical"); + data->screen_num, data->traybox, orientation == 0 ? "horizontal" : "vertical"); - na_tray_set_orientation (data->tray, orientation); + gtk_orientable_set_orientation (GTK_ORIENTABLE (data->traybox), orientation); } static void @@ -184,12 +188,11 @@ create_tray_on_screen (GdkScreen *screen, #endif gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - data->tray = na_tray_new_for_screen (screen, GTK_ORIENTATION_HORIZONTAL); - gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (data->tray), TRUE, TRUE, 0); + data->traybox = na_box_new (GTK_ORIENTATION_HORIZONTAL); + gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (data->traybox), TRUE, TRUE, 0); - data->box = gtk_bin_get_child (GTK_BIN (gtk_bin_get_child (GTK_BIN (data->tray)))); - g_signal_connect_after (data->box, "add", G_CALLBACK (tray_added_cb), data); - g_signal_connect_after (data->box, "remove", G_CALLBACK (tray_removed_cb), data); + g_signal_connect_after (data->traybox, "add", G_CALLBACK (tray_added_cb), data); + g_signal_connect_after (data->traybox, "remove", G_CALLBACK (tray_removed_cb), data); gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0); @@ -205,14 +208,66 @@ create_tray_on_screen (GdkScreen *screen, return data; } +static gboolean +signal_handler (gpointer data G_GNUC_UNUSED) +{ + gtk_main_quit (); + + return FALSE; +} + +#ifdef PROVIDE_WATCHER_SERVICE +static GfStatusNotifierWatcher * +status_notifier_watcher_maybe_new (void) +{ + GDBusProxy *proxy; + GError *error = NULL; + GfStatusNotifierWatcher *service = NULL; + + /* check if the service already exists + * FIXME: is that a not-too-stupid way of doing it? bah, so long as it works. + * it's for testing purposes only anyway. */ + proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS | + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + "org.kde.StatusNotifierWatcher", + "/StatusNotifierWatcher", + "org.kde.StatusNotifierWatcher", + NULL, &error); + if (proxy) + g_object_unref (proxy); + else + { + g_warning ("Failed to connect to org.kde.StatusNotifierWatcher (%s), starting our own.", + error->message); + g_clear_error (&error); + + service = gf_status_notifier_watcher_new (); + } + + return service; +} +#endif + int main (int argc, char *argv[]) { GdkDisplay *display; GdkScreen *screen; +#ifdef PROVIDE_WATCHER_SERVICE + GfStatusNotifierWatcher *service; +#endif gtk_init (&argc, &argv); + g_unix_signal_add (SIGTERM, signal_handler, NULL); + g_unix_signal_add (SIGINT, signal_handler, NULL); + +#ifdef PROVIDE_WATCHER_SERVICE + service = status_notifier_watcher_maybe_new (); +#endif + gtk_window_set_default_icon_name (NOTIFICATION_AREA_ICON); display = gdk_display_get_default (); @@ -222,5 +277,10 @@ main (int argc, char *argv[]) gtk_main (); +#ifdef PROVIDE_WATCHER_SERVICE + if (service) + g_object_unref (service); +#endif + return 0; } |