From 9489aa2cbda25bb1ed87e87d2fcf550ac0b6142a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 16:23:08 -0600 Subject: Adding in a get_menu function. --- src/libappindicator/app-indicator.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index e38e760..4852633 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -776,7 +776,7 @@ fallback (AppIndicator * self) static void status_icon_activate (GtkStatusIcon * icon, gpointer data) { - g_debug("Status Icon Activate"); + return; } @@ -1267,3 +1267,23 @@ app_indicator_get_attention_icon (AppIndicator *self) return self->priv->attention_icon_name; } + +/** + app_indicator_get_menu: + @self: The #AppIndicator object to use + + Gets the menu being used for this application indicator. + + Return value: A menu object or #NULL if one hasn't been set. +*/ +GtkMenu * +app_indicator_get_menu (AppIndicator *self) +{ + AppIndicatorPrivate *priv; + + g_return_val_if_fail (IS_APP_INDICATOR (self), NULL); + + priv = self->priv; + + return GTK_MENU(priv->menu); +} -- cgit v1.2.3 From 6068e6cdb6fa92235c662706c8eabcff4207e1fa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 16:28:53 -0600 Subject: Popping up menu on activate. --- src/libappindicator/app-indicator.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 4852633..f330870 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -776,6 +776,17 @@ fallback (AppIndicator * self) static void status_icon_activate (GtkStatusIcon * icon, gpointer data) { + GtkMenu * menu = app_indicator_get_menu(APP_INDICATOR(data)); + if (menu == NULL) + return; + + gtk_menu_popup(menu, + NULL, /* Parent Menu */ + NULL, /* Parent item */ + gtk_status_icon_position_menu, + icon, + 1, /* Button */ + gtk_get_current_event_time()); return; } -- cgit v1.2.3 From c26cab9055e9d909babb509e606b35ec47574c78 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 19:52:02 -0600 Subject: Making it so that the icon will update in the fallback case with changes to the properties of the AppIndicator. --- src/libappindicator/app-indicator.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index f330870..f66888f 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -136,6 +136,7 @@ static void register_service_cb (DBusGProxy * proxy, GError * error, gpointer da static void start_fallback_timer (AppIndicator * self, gboolean do_it_now); static gboolean fallback_timer_expire (gpointer data); static GtkStatusIcon * fallback (AppIndicator * self); +static void status_icon_changes (GObject * icon, GParamSpec * pspec, gpointer data); static void status_icon_activate (GtkStatusIcon * icon, gpointer data); static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon); static void watcher_proxy_destroyed (GObject * object, gpointer data); @@ -751,6 +752,28 @@ fallback (AppIndicator * self) gtk_status_icon_set_title(icon, app_indicator_get_id(self)); + g_signal_connect(G_OBJECT(self), "notify::" PROP_STATUS_S, + G_CALLBACK(status_icon_changes), icon); + g_signal_connect(G_OBJECT(self), "notify::" PROP_ICON_NAME_S, + G_CALLBACK(status_icon_changes), icon); + g_signal_connect(G_OBJECT(self), "notify::" PROP_ATTENTION_ICON_NAME_S, + G_CALLBACK(status_icon_changes), icon); + + status_icon_changes(G_OBJECT(icon), NULL, self); + + g_signal_connect(G_OBJECT(icon), "activate", G_CALLBACK(status_icon_activate), self); + + return NULL; +} + +/* This tracks changes to either the status or the icons + that are associated with the app indicator */ +static void +status_icon_changes (GObject * oicon, GParamSpec * pspec, gpointer data) +{ + AppIndicator * self = APP_INDICATOR(data); + GtkStatusIcon * icon = GTK_STATUS_ICON(oicon); + switch (app_indicator_get_status(self)) { case APP_INDICATOR_STATUS_PASSIVE: gtk_status_icon_set_visible(icon, FALSE); @@ -766,9 +789,7 @@ fallback (AppIndicator * self) break; }; - g_signal_connect(G_OBJECT(icon), "activate", G_CALLBACK(status_icon_activate), self); - - return NULL; + return; } /* Handles the activate action by the status icon by showing @@ -796,6 +817,7 @@ status_icon_activate (GtkStatusIcon * icon, gpointer data) static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon) { + g_signal_handlers_disconnect_by_func(G_OBJECT(self), status_icon_changes, status_icon); g_object_unref(G_OBJECT(status_icon)); return; } -- cgit v1.2.3 From c303c0c49f7ab1b0747e5cb12111f8b3ac4cd46e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 20:25:33 -0600 Subject: Realized that we didn't really use the 'notify' signal... now using the better ones anyway. --- src/libappindicator/app-indicator.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index f66888f..e1b332a 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -136,7 +136,8 @@ static void register_service_cb (DBusGProxy * proxy, GError * error, gpointer da static void start_fallback_timer (AppIndicator * self, gboolean do_it_now); static gboolean fallback_timer_expire (gpointer data); static GtkStatusIcon * fallback (AppIndicator * self); -static void status_icon_changes (GObject * icon, GParamSpec * pspec, gpointer data); +static void status_icon_status_wrapper (AppIndicator * self, const gchar * status, gpointer data); +static void status_icon_changes (AppIndicator * self, gpointer data); static void status_icon_activate (GtkStatusIcon * icon, gpointer data); static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon); static void watcher_proxy_destroyed (GObject * object, gpointer data); @@ -752,27 +753,34 @@ fallback (AppIndicator * self) gtk_status_icon_set_title(icon, app_indicator_get_id(self)); - g_signal_connect(G_OBJECT(self), "notify::" PROP_STATUS_S, + g_signal_connect(G_OBJECT(self), APP_INDICATOR_SIGNAL_NEW_STATUS, G_CALLBACK(status_icon_changes), icon); - g_signal_connect(G_OBJECT(self), "notify::" PROP_ICON_NAME_S, + g_signal_connect(G_OBJECT(self), APP_INDICATOR_SIGNAL_NEW_ICON, G_CALLBACK(status_icon_changes), icon); - g_signal_connect(G_OBJECT(self), "notify::" PROP_ATTENTION_ICON_NAME_S, + g_signal_connect(G_OBJECT(self), APP_INDICATOR_SIGNAL_NEW_ATTENTION_ICON, G_CALLBACK(status_icon_changes), icon); - status_icon_changes(G_OBJECT(icon), NULL, self); + status_icon_changes(self, icon); g_signal_connect(G_OBJECT(icon), "activate", G_CALLBACK(status_icon_activate), self); return NULL; } +/* A wrapper as the status update prototype is a little + bit different, but we want to handle it the same. */ +static void +status_icon_status_wrapper (AppIndicator * self, const gchar * status, gpointer data) +{ + return status_icon_changes(self, data); +} + /* This tracks changes to either the status or the icons that are associated with the app indicator */ static void -status_icon_changes (GObject * oicon, GParamSpec * pspec, gpointer data) +status_icon_changes (AppIndicator * self, gpointer data) { - AppIndicator * self = APP_INDICATOR(data); - GtkStatusIcon * icon = GTK_STATUS_ICON(oicon); + GtkStatusIcon * icon = GTK_STATUS_ICON(data); switch (app_indicator_get_status(self)) { case APP_INDICATOR_STATUS_PASSIVE: @@ -817,6 +825,7 @@ status_icon_activate (GtkStatusIcon * icon, gpointer data) static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon) { + g_signal_handlers_disconnect_by_func(G_OBJECT(self), status_icon_status_wrapper, status_icon); g_signal_handlers_disconnect_by_func(G_OBJECT(self), status_icon_changes, status_icon); g_object_unref(G_OBJECT(status_icon)); return; -- cgit v1.2.3 From 544ac3aa1cae817a4ec66fa4a880ba283298cabf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Jan 2010 09:52:51 -0600 Subject: Using better naming for 'do_it_now' parameter. --- src/libappindicator/app-indicator.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index e1b332a..40c7c3e 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -133,7 +133,7 @@ static void app_indicator_get_property (GObject * object, guint prop_id, GValue /* Other stuff */ static void check_connect (AppIndicator * self); static void register_service_cb (DBusGProxy * proxy, GError * error, gpointer data); -static void start_fallback_timer (AppIndicator * self, gboolean do_it_now); +static void start_fallback_timer (AppIndicator * self, gboolean disable_timeout); static gboolean fallback_timer_expire (gpointer data); static GtkStatusIcon * fallback (AppIndicator * self); static void status_icon_status_wrapper (AppIndicator * self, const gchar * status, gpointer data); @@ -685,7 +685,7 @@ dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, c there is a change. Also, provides an override mode for cases where it's unlikely that a timer will help anything. */ static void -start_fallback_timer (AppIndicator * self, gboolean do_it_now) +start_fallback_timer (AppIndicator * self, gboolean disable_timeout) { g_return_if_fail(IS_APP_INDICATOR(self)); AppIndicatorPrivate * priv = APP_INDICATOR(self)->priv; @@ -708,7 +708,7 @@ start_fallback_timer (AppIndicator * self, gboolean do_it_now) G_CALLBACK(dbus_owner_change), self, NULL); } - if (do_it_now) { + if (disable_timeout) { fallback_timer_expire(self); } else { priv->fallback_timer = g_timeout_add(DEFAULT_FALLBACK_TIMER, fallback_timer_expire, self); -- cgit v1.2.3 From 2bfabeb52a894375a76be19cbd034ad56214b766 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Jan 2010 09:54:59 -0600 Subject: Making a more descriptive error on 'unfallback' not existing. --- src/libappindicator/app-indicator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 40c7c3e..c3bce35 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -736,7 +736,7 @@ fallback_timer_expire (gpointer data) class->unfallback(APP_INDICATOR(data), priv->status_icon); priv->status_icon = NULL; } else { - g_warning("Can't 'unfallback' and I have an allocated status_icon. Might be a memory leak!"); + g_warning("No 'unfallback' function but the 'fallback' function returned a non-NULL result."); } } -- cgit v1.2.3 From 09442ab9099e7a35394ec692560c19672bdbc2d2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Jan 2010 09:55:42 -0600 Subject: Returning the icon we've created. --- src/libappindicator/app-indicator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index c3bce35..6c969c2 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -764,7 +764,7 @@ fallback (AppIndicator * self) g_signal_connect(G_OBJECT(icon), "activate", G_CALLBACK(status_icon_activate), self); - return NULL; + return icon; } /* A wrapper as the status update prototype is a little -- cgit v1.2.3