Merge lp:~gber/libappindicator/fallback-tooltip into lp:libappindicator

Proposed by Guido Berhoerster on 2018-07-13
Status: Needs review
Proposed branch: lp:~gber/libappindicator/fallback-tooltip
Merge into: lp:libappindicator
Diff against target: 109 lines (+42/-0)
1 file modified
src/app-indicator.c (+42/-0)
To merge this branch: bzr merge lp:~gber/libappindicator/fallback-tooltip
Reviewer Review Type Date Requested Status
Indicator Applet Developers 2018-07-13 Pending
Review via email: mp+349501@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

289. By Guido Berhoerster on 2018-07-13

Display a tooltip in fallback mode

This replicates the behavior of KDE Plasma or the Xfce Status Notifier
Plugin in fallback mode by displaying a tooltip with the contents of the
"title" and "icon-desc" or "attention-icon-desc" properties if set.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app-indicator.c'
2--- src/app-indicator.c 2018-03-20 12:38:59 +0000
3+++ src/app-indicator.c 2018-07-13 19:47:46 +0000
4@@ -190,6 +190,7 @@
5 static void status_icon_status_wrapper (AppIndicator * self, const gchar * status, gpointer data);
6 static gboolean scroll_event_wrapper(GtkWidget *status_icon, GdkEventScroll *event, gpointer user_data);
7 static gboolean middle_click_wrapper(GtkWidget *status_icon, GdkEventButton *event, gpointer user_data);
8+static void status_icon_desc_changes (GObject * gobject, GParamSpec * pspec, gpointer data);
9 static void status_icon_changes (AppIndicator * self, gpointer data);
10 static void status_icon_activate (GtkStatusIcon * icon, gpointer data);
11 static void status_icon_menu_activate (GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data);
12@@ -1540,6 +1541,10 @@
13 G_CALLBACK(status_icon_changes), icon);
14 g_signal_connect(G_OBJECT(self), APP_INDICATOR_SIGNAL_NEW_ATTENTION_ICON,
15 G_CALLBACK(status_icon_changes), icon);
16+ g_signal_connect(G_OBJECT(self), "notify::icon-desc",
17+ G_CALLBACK(status_icon_desc_changes), icon);
18+ g_signal_connect(G_OBJECT(self), "notify::attention-icon-desc",
19+ G_CALLBACK(status_icon_desc_changes), icon);
20
21 status_icon_changes(self, icon);
22
23@@ -1551,6 +1556,13 @@
24 return icon;
25 }
26
27+static void
28+status_icon_desc_changes (GObject * gobject, GParamSpec * pspec, gpointer data)
29+{
30+ AppIndicator * self = APP_INDICATOR(gobject);
31+ status_icon_changes(self, data);
32+}
33+
34 /* A wrapper as the status update prototype is a little
35 bit different, but we want to handle it the same. */
36 static void
37@@ -1598,6 +1610,27 @@
38 return FALSE;
39 }
40
41+static gchar *
42+status_icon_tooltip_new (const gchar * title, const gchar * desc)
43+{
44+ gchar * tooltip;
45+ gchar * title_escaped;
46+ gchar * desc_escaped;
47+
48+ if (title == NULL && desc == NULL) {
49+ return (NULL);
50+ }
51+
52+ title_escaped = (title != NULL) ? g_markup_escape_text(title, -1) : g_strdup("");
53+ desc_escaped = (desc != NULL) ? g_markup_escape_text(desc, -1) : g_strdup("");
54+ tooltip = g_strdup_printf("<b>%s</b>%s%s", title_escaped,
55+ (title != NULL) && (desc != NULL) ? "\n" : "", desc_escaped);
56+ g_free(desc_escaped);
57+ g_free(title_escaped);
58+
59+ return tooltip;
60+}
61+
62 /* This tracks changes to either the status or the icons
63 that are associated with the app indicator */
64 static void
65@@ -1628,6 +1661,7 @@
66 g_strfreev (path);
67 }
68
69+ gchar * tooltip = NULL;
70 const gchar * icon_name = NULL;
71 switch (app_indicator_get_status(self)) {
72 case APP_INDICATOR_STATUS_PASSIVE:
73@@ -1637,14 +1671,19 @@
74 break;
75 case APP_INDICATOR_STATUS_ACTIVE:
76 icon_name = app_indicator_get_icon(self);
77+ tooltip = status_icon_tooltip_new(app_indicator_get_title(self),
78+ app_indicator_get_icon_desc(self));
79 gtk_status_icon_set_visible(icon, TRUE);
80 break;
81 case APP_INDICATOR_STATUS_ATTENTION:
82 /* get the _attention_ icon here */
83 icon_name = app_indicator_get_attention_icon(self);
84+ tooltip = status_icon_tooltip_new(app_indicator_get_title(self),
85+ app_indicator_get_attention_icon_desc(self));
86 gtk_status_icon_set_visible(icon, TRUE);
87 break;
88 };
89+ gtk_status_icon_set_tooltip_markup(icon, tooltip);
90
91 if (icon_name != NULL) {
92 gchar *snapped_icon = append_snap_prefix(icon_name);
93@@ -1668,6 +1707,8 @@
94 g_free(snapped_icon);
95 }
96
97+ g_free(tooltip);
98+
99 return;
100 }
101
102@@ -1706,6 +1747,7 @@
103 {
104 g_signal_handlers_disconnect_by_func(G_OBJECT(self), status_icon_status_wrapper, status_icon);
105 g_signal_handlers_disconnect_by_func(G_OBJECT(self), status_icon_changes, status_icon);
106+ g_signal_handlers_disconnect_by_func(G_OBJECT(self), status_icon_desc_changes, status_icon);
107 g_signal_handlers_disconnect_by_func(G_OBJECT(self), scroll_event_wrapper, status_icon);
108 g_signal_handlers_disconnect_by_func(G_OBJECT(self), middle_click_wrapper, status_icon);
109 gtk_status_icon_set_visible(status_icon, FALSE);

Subscribers

People subscribed via source and target branches