Merge lp:~donadigo/wingpanel-indicator-notifications/notification-open-app into lp:~elementary-pantheon/wingpanel-indicator-notifications/loki-rc

Proposed by Adam Bieńkowski
Status: Merged
Approved by: Felipe Escoto
Approved revision: 97
Merged at revision: 97
Proposed branch: lp:~donadigo/wingpanel-indicator-notifications/notification-open-app
Merge into: lp:~elementary-pantheon/wingpanel-indicator-notifications/loki-rc
Diff against target: 308 lines (+97/-61)
6 files modified
src/CMakeLists.txt (+1/-1)
src/Services/Notification.vala (+7/-4)
src/Services/NotificationMonitor.vala (+29/-9)
src/Widgets/AppEntry.vala (+9/-0)
src/Widgets/NotificationEntry.vala (+12/-0)
src/Widgets/NotificationsList.vala (+39/-47)
To merge this branch: bzr merge lp:~donadigo/wingpanel-indicator-notifications/notification-open-app
Reviewer Review Type Date Requested Status
WingPanel Devs Pending
Review via email: mp+297946@code.launchpad.net

Commit message

* Fix bug #1594227: "Clicking a notification should open/focus the app".
* General code improvements.

Description of the change

Fixes bug #1594227: "Clicking a notification should open/focus the app".

This branch enables functionality to open / focus the app by clicking on the notification, if the notification has a default action, it will be launched instead of the app.

It also contains a large code improvements, simplifies the method names and makes it more easier to read.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2016-05-27 15:10:53 +0000
3+++ src/CMakeLists.txt 2016-06-20 18:57:25 +0000
4@@ -20,7 +20,7 @@
5 Widgets/NotificationEntry.vala
6 Widgets/AppEntry.vala
7 Widgets/SeparatorEntry.vala
8- Services/NotificationsMonitor.vala
9+ Services/NotificationMonitor.vala
10 Services/Notification.vala
11 Services/NotifySettings.vala
12 Services/Session.vala
13
14=== modified file 'src/Services/Notification.vala'
15--- src/Services/Notification.vala 2016-05-27 15:10:53 +0000
16+++ src/Services/Notification.vala 2016-06-20 18:57:25 +0000
17@@ -145,7 +145,7 @@
18 }
19
20 try {
21- IDBus? dbus_iface = Bus.get_proxy_sync (BusType.SESSION, "org.freedesktop.DBus", "/");
22+ IDBus? dbus_iface = NotificationMonitor.get_dbus_iface ();
23 if (dbus_iface != null && dbus_iface.name_has_owner (sender)) {
24 pid = dbus_iface.get_connection_unix_process_id (sender);
25 }
26@@ -157,9 +157,12 @@
27 }
28
29 public bool run_default_action () {
30- if (DEFAULT_ACTION in actions && NotificationMonitor.get_instance ().notifications_iface != null) {
31- NotificationMonitor.get_instance ().notifications_iface.action_invoked (DEFAULT_ACTION, id);
32- return true;
33+ if (DEFAULT_ACTION in actions) {
34+ INotifications? notifications_iface = NotificationMonitor.get_notifications_iface ();
35+ if (notifications_iface != null) {
36+ notifications_iface.action_invoked (DEFAULT_ACTION, id);
37+ return true;
38+ }
39 }
40
41 return false;
42
43=== renamed file 'src/Services/NotificationsMonitor.vala' => 'src/Services/NotificationMonitor.vala'
44--- src/Services/NotificationsMonitor.vala 2016-06-20 12:40:25 +0000
45+++ src/Services/NotificationMonitor.vala 2016-06-20 18:57:25 +0000
46@@ -23,14 +23,16 @@
47 public class NotificationMonitor : Object {
48 private const string NOTIFY_IFACE = "org.freedesktop.Notifications";
49 private const string NOTIFY_PATH = "/org/freedesktop/Notifications";
50+ private const string DBUS_IFACE = "org.freedesktop.DBus";
51+ private const string DBUS_PATH = "/";
52 private const string MATCH_STRING = "eavesdrop='true',type='method_call',interface='org.freedesktop.Notifications',member='Notify'";
53 private const uint32 REASON_DISMISSED = 2;
54
55 private static NotificationMonitor? instance = null;
56+ private static INotifications? notifications_iface = null;
57+ private static IDBus? dbus_iface = null;
58
59 private DBusConnection connection;
60- public INotifications? notifications_iface = null;
61- public IDBus? dbus_iface = null;
62 private uint32 id_counter = 0;
63
64 public signal void received (DBusMessage message, uint32 id);
65@@ -43,6 +45,30 @@
66 return instance;
67 }
68
69+ public static INotifications? get_notifications_iface () {
70+ if (notifications_iface == null) {
71+ try {
72+ notifications_iface = Bus.get_proxy_sync (BusType.SESSION, NOTIFY_IFACE, NOTIFY_PATH);
73+ } catch (Error e) {
74+ warning ("%s\n", e.message);
75+ }
76+ }
77+
78+ return notifications_iface;
79+ }
80+
81+ public static IDBus? get_dbus_iface () {
82+ if (dbus_iface == null) {
83+ try {
84+ dbus_iface = Bus.get_proxy_sync (BusType.SESSION, DBUS_IFACE, DBUS_PATH);
85+ } catch (Error e) {
86+ warning ("%s\n", e.message);
87+ }
88+ }
89+
90+ return dbus_iface;
91+ }
92+
93 private NotificationMonitor () {
94 try {
95 connection = Bus.get_sync (BusType.SESSION);
96@@ -61,12 +87,6 @@
97 var body = new Variant.parsed ("(%s,)", MATCH_STRING);
98 message.set_body (body);
99
100- try {
101- notifications_iface = Bus.get_proxy_sync (BusType.SESSION, NOTIFY_IFACE, NOTIFY_PATH);
102- } catch (Error e) {
103- error ("%s\n", e.message);
104- }
105-
106 id_counter = get_current_notification_id ();
107 try {
108 connection.send_message (message, DBusSendMessageFlags.NONE, null);
109@@ -109,7 +129,7 @@
110 hints.insert ("suppress-sound", new Variant.boolean (true));
111 string[] actions = {};
112 try {
113- return notifications_iface.notify ("", 0, "", "", "", actions, hints, 1);
114+ return get_notifications_iface ().notify ("", 0, "", "", "", actions, hints, 1);
115 } catch (Error e) {
116 error ("%s\n", e.message);
117 }
118
119=== modified file 'src/Widgets/AppEntry.vala'
120--- src/Widgets/AppEntry.vala 2016-05-27 15:10:53 +0000
121+++ src/Widgets/AppEntry.vala 2016-06-20 18:57:25 +0000
122@@ -89,6 +89,15 @@
123 });
124 }
125
126+ public void update_app_window () {
127+ if (app_notifications.length () == 0) {
128+ return;
129+ }
130+
131+ var notification_entry = app_notifications.nth_data (0);
132+ app_window = notification_entry.get_app_window ();
133+ }
134+
135 public unowned List<NotificationEntry> get_notifications () {
136 return app_notifications;
137 }
138
139=== modified file 'src/Widgets/NotificationEntry.vala'
140--- src/Widgets/NotificationEntry.vala 2016-05-27 15:10:53 +0000
141+++ src/Widgets/NotificationEntry.vala 2016-06-20 18:57:25 +0000
142@@ -61,6 +61,18 @@
143 }
144 }
145
146+ public Wnck.Window? get_app_window () {
147+ Wnck.Window? window = null;
148+ Wnck.Screen.get_default ().get_windows ().@foreach ((_window) => {
149+ if (_window.get_pid () == notification.pid) {
150+ window = _window;
151+ return;
152+ }
153+ });
154+
155+ return window;
156+ }
157+
158 private void add_widgets () {
159 var grid = new Gtk.Grid ();
160 grid.margin_start = 40;
161
162=== modified file 'src/Widgets/NotificationsList.vala'
163--- src/Widgets/NotificationsList.vala 2016-06-20 12:37:34 +0000
164+++ src/Widgets/NotificationsList.vala 2016-06-20 18:57:25 +0000
165@@ -49,7 +49,7 @@
166 switch_stack (true);
167
168 app_entry.add_notification_entry (entry);
169- resort_from_app_entry (app_entry);
170+ resort_app_entry (app_entry);
171
172 entry.clear.connect (() => {
173 destroy_notification_entry (entry);
174@@ -59,7 +59,7 @@
175 destroy_app_entry (app_entry);
176 });
177
178- counter = counter + 2;
179+ counter += 2;
180
181 Session.get_instance ().add_notification (entry.notification);
182 entry.show_all ();
183@@ -116,7 +116,7 @@
184 AppEntry app_entry;
185 bool add = !(entry.notification.app_name in construct_app_names ());
186 if (add) {
187- var window = get_window_from_entry (entry);
188+ var window = entry.get_app_window ();
189 app_entry = new AppEntry (entry, window);
190
191 screen.active_window_changed.connect (() => {
192@@ -130,7 +130,7 @@
193 insert (entry, 1);
194 table.insert (app_entry.app_name, 0);
195 } else {
196- app_entry = get_app_entry_from_app_name (entry.notification.app_name);
197+ app_entry = get_from_app_name (entry.notification.app_name);
198 if (app_entry != null) {
199 int insert_pos = table.@get (app_entry.app_name);
200 insert (entry, insert_pos + 1);
201@@ -140,18 +140,6 @@
202 return app_entry;
203 }
204
205- private Wnck.Window? get_window_from_entry (NotificationEntry entry) {
206- Wnck.Window? window = null;
207- screen.get_windows ().@foreach ((_window) => {
208- if (_window.get_pid () == entry.notification.pid) {
209- window = _window;
210- return;
211- }
212- });
213-
214- return window;
215- }
216-
217 private async void destroy_notification_entry (NotificationEntry entry) {
218 entry.destroy ();
219 items.remove (entry);
220@@ -186,7 +174,7 @@
221 update_separators ();
222 }
223
224- private void resort_from_app_entry (AppEntry app_entry) {
225+ private void resort_app_entry (AppEntry app_entry) {
226 if (get_row_at_index (0) != app_entry) {
227 remove (app_entry);
228 prepend (app_entry);
229@@ -199,7 +187,7 @@
230 }
231 }
232
233- private AppEntry? get_app_entry_from_app_name (string app_name) {
234+ private AppEntry? get_from_app_name (string app_name) {
235 AppEntry? entry = null;
236 app_entries.@foreach ((_entry) => {
237 if (_entry.app_name == app_name) {
238@@ -221,37 +209,41 @@
239 }
240
241 private void on_row_activated (Gtk.ListBoxRow row) {
242- if (row.get_path ().get_object_type () == typeof (AppEntry)) {
243- if (((AppEntry) row).app_window == null) {
244- var window = get_window_from_entry (((AppEntry) row).get_notifications ().nth_data (0));
245- if (window != null) {
246- ((AppEntry) row).app_window = window;
247- }
248- }
249-
250- if (((AppEntry) row).app_window != null) {
251- ((AppEntry) row).app_window.unminimize (Gtk.get_current_event_time ());
252- ((AppEntry) row).clear_btn_entry.clicked ();
253- close_popover ();
254- } else if (((AppEntry) row).appinfo != null) {
255- try {
256- ((AppEntry) row).appinfo.launch (null, null);
257- } catch (Error e) {
258- error ("%s\n", e.message);
259- }
260-
261- ((AppEntry) row).clear_btn_entry.clicked ();
262- close_popover ();
263- }
264- } else {
265- if (((NotificationEntry) row).notification.run_default_action ()) {
266- ((NotificationEntry) row).active = false;
267- close_popover ();
268- }
269-
270- ((NotificationEntry) row).clear ();
271+ if (row is AppEntry) {
272+ var app_entry = (AppEntry)row;
273+ if (app_entry.app_window == null) {
274+ app_entry.update_app_window ();
275+ }
276+
277+ focus_notification_app (app_entry.app_window,
278+ app_entry.appinfo);
279+
280+ app_entry.clear_btn_entry.clicked ();
281+ close_popover ();
282+ } else if (row is NotificationEntry) {
283+ var notification_entry = (NotificationEntry)row;
284+ if (!notification_entry.notification.run_default_action ()) {
285+ focus_notification_app (notification_entry.get_app_window (),
286+ notification_entry.notification.appinfo);
287+ }
288+
289+ notification_entry.clear ();
290+ notification_entry.active = false;
291+ close_popover ();
292 }
293
294 update_separators ();
295 }
296+
297+ private void focus_notification_app (Wnck.Window? app_window, AppInfo? appinfo) {
298+ if (app_window != null) {
299+ app_window.unminimize (Gtk.get_current_event_time ());
300+ } else if (appinfo != null) {
301+ try {
302+ appinfo.launch (null, null);
303+ } catch (Error e) {
304+ warning ("%s\n", e.message);
305+ }
306+ }
307+ }
308 }

Subscribers

People subscribed via source and target branches