Merge lp:~3v1n0/notify-osd/fix-notifications-replacing into lp:notify-osd

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: 506
Merged at revision: 504
Proposed branch: lp:~3v1n0/notify-osd/fix-notifications-replacing
Merge into: lp:notify-osd
Diff against target: 83 lines (+29/-8)
1 file modified
src/stack.c (+29/-8)
To merge this branch: bzr merge lp:~3v1n0/notify-osd/fix-notifications-replacing
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: mp+291707@code.launchpad.net

Commit message

Stack: allow to replace a notification when the replace_id has been provided

This fixes the case where we want to replace a notification with a given
ID that is about to show or currently visible. As the NotifyOSD and Desktop
Notification protocols expect.

To post a comment you must log in.
506. By Marco Trevisan (Treviño)

Stack: indentation fix

Revision history for this message
Andrea Azzarone (azzar1) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/stack.c'
2--- src/stack.c 2015-11-12 08:51:08 +0000
3+++ src/stack.c 2016-04-13 05:32:07 +0000
4@@ -388,8 +388,10 @@
5 if (!self || !IS_BUBBLE (bubble))
6 return -1;
7
8+ notification_id = bubble_get_id (bubble);
9+
10 /* check if this is just an update */
11- if (find_bubble_by_id (self, bubble_get_id (bubble)))
12+ if (find_bubble_by_id (self, notification_id))
13 {
14 bubble_start_timer (bubble, TRUE);
15 bubble_refresh (bubble);
16@@ -400,11 +402,17 @@
17 if (stack_is_at_top_corner (self, sync_bubble))
18 bubble_sync_with (sync_bubble, bubble);
19
20- return bubble_get_id (bubble);
21+ return notification_id;
22 }
23
24 /* add bubble/id to stack */
25- notification_id = self->next_id++;
26+ if (notification_id == 0)
27+ {
28+ do
29+ {
30+ notification_id = self->next_id++;
31+ } while (find_bubble_by_id (self, notification_id));
32+ }
33
34 // FIXME: migrate stack to use abstract notification object and don't
35 // keep heavy bubble objects around, at anyone time at max. only two
36@@ -582,6 +590,7 @@
37 gboolean new_bubble = FALSE;
38 gboolean turn_into_dialog;
39 guint real_id;
40+ gchar *sender;
41
42 // check max. allowed limit queue-size
43 if (g_list_length (self->list) > MAX_STACK_SIZE)
44@@ -620,22 +629,34 @@
45 return TRUE;
46 }
47
48- // check if a bubble exists with same id
49+ // check if a bubble exists with same id
50 bubble = find_bubble_by_id (self, id);
51+ sender = dbus_g_method_get_sender (context);
52+
53+ if (bubble)
54+ {
55+ if (g_strcmp0 (bubble_get_sender (bubble), sender) != 0)
56+ {
57+ // Another sender is trying to replace a notification, let's block it!
58+ id = 0;
59+ bubble = NULL;
60+ }
61+ }
62+
63 if (bubble == NULL)
64 {
65- gchar *sender;
66 new_bubble = TRUE;
67 bubble = bubble_new (self->defaults);
68 g_object_weak_ref (G_OBJECT (bubble),
69 _weak_notify_cb,
70 (gpointer) self);
71-
72- sender = dbus_g_method_get_sender (context);
73+
74 bubble_set_sender (bubble, sender);
75- g_free (sender);
76+ bubble_set_id (bubble, id);
77 }
78
79+ g_free (sender);
80+
81 if (new_bubble && hints)
82 {
83 data = (GValue*) g_hash_table_lookup (hints, "x-canonical-append");

Subscribers

People subscribed via source and target branches