Skip to content

Commit 6e4b6a0

Browse files
committed
Make notifications applet multi-instance
1 parent 501a250 commit 6e4b6a0

3 files changed

Lines changed: 18 additions & 33 deletions

File tree

files/usr/share/cinnamon/applets/notifications@cinnamon.org/applet.js

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
2828
this.settings.bind("keyOpen", "keyOpen", this._setKeybinding);
2929
this.settings.bind("keyClear", "keyClear", this._setKeybinding);
3030
this.settings.bind("showNotificationCount", "showNotificationCount", this.update_list);
31-
this.settings.bind("showNewestFirst", "showNewestFirst", this.update_list);
31+
this.settings.bind("showNewestFirst", "showNewestFirst", null);
3232
this._setKeybinding();
3333

3434
// Layout
@@ -65,6 +65,18 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
6565

6666
_openMenu() {
6767
this._update_timestamp();
68+
69+
this._notificationbin.remove_all_children();
70+
if (this.showNewestFirst) {
71+
for (let i = this.notifications.length - 1; i >= 0; i--) {
72+
global.reparentActor(this.notifications[i].actor, this._notificationbin);
73+
}
74+
} else {
75+
this.notifications.forEach(notification => {
76+
global.reparentActor(notification.actor, this._notificationbin);
77+
});
78+
}
79+
6880
this.menu.toggle();
6981
}
7082

@@ -138,8 +150,6 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
138150
if (notification._destroyed) {
139151
this.notifications.splice(existing_index, 1);
140152
} else {
141-
notification._inNotificationBin = true;
142-
global.reparentActor(notification.actor, this._notificationbin);
143153
notification._timeLabel.show();
144154
}
145155
this.update_list();
@@ -148,11 +158,8 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
148158
return;
149159
}
150160
// Add notification to list.
151-
notification._inNotificationBin = true;
152161
this.notifications.push(notification);
153-
// Steal the notification panel.
154-
this._notificationbin.add(notification.actor);
155-
notification.actor._parent_container = this._notificationbin;
162+
156163
notification.actor.add_style_class_name('notification-applet-padding');
157164
// Register for destruction.
158165
notification.connect('scrolling-changed', (notif, scrolling) => { this.menu.passEvents = scrolling });
@@ -174,7 +181,6 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
174181
this.actor.show();
175182
this.clear_action.actor.show();
176183
this.set_applet_label(count.toString());
177-
this._reorderNotifications();
178184
// Find max urgency and derive list icon.
179185
let max_urgency = -1;
180186
for (let i = 0; i < count; i++) {
@@ -233,25 +239,6 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
233239
this.update_list();
234240
}
235241

236-
_reorderNotifications() {
237-
let orderedNotifications = this.notifications.slice();
238-
239-
if (this.showNewestFirst) {
240-
orderedNotifications.reverse();
241-
}
242-
243-
// Remove all children without destroying them.
244-
let children = this._notificationbin.get_children();
245-
for (let i = 0; i < children.length; i++) {
246-
this._notificationbin.remove_child(children[i]);
247-
}
248-
249-
// Add them back in desired order.
250-
for (let i = 0; i < orderedNotifications.length; i++) {
251-
this._notificationbin.add_child(orderedNotifications[i].actor);
252-
}
253-
}
254-
255242
_show_hide_tray() { // Show or hide the notification tray.
256243
if(!global.settings.get_boolean(PANEL_EDIT_MODE_KEY)) {
257244
if (this.notifications.length || this.showEmptyTray) {

files/usr/share/cinnamon/applets/notifications@cinnamon.org/metadata.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"uuid": "notifications@cinnamon.org",
33
"name": "Notifications",
44
"description": "Click to display and manage system notifications",
5-
"icon": "cs-notifications"
5+
"icon": "cs-notifications",
6+
"max-instances": -1
67
}

js/ui/messageTray.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,10 @@ var Notification = class Notification {
262262
this._actionArea = null;
263263
this._imageBin = null;
264264
this._timestamp = new Date();
265-
this._inNotificationBin = false;
266265

267266
source.connect('destroy', (source, reason) => { this.destroy(reason) });
268267

269268
this.actor = new St.Button({ accessible_role: Atk.Role.NOTIFICATION });
270-
this.actor._parent_container = null;
271269
this.actor.connect('clicked', () => this._onClicked());
272270
this.actor.connect('destroy', () => this._onDestroy());
273271

@@ -348,7 +346,6 @@ var Notification = class Notification {
348346
*/
349347
update(title, body, params) {
350348
this._timestamp = new Date();
351-
this._inNotificationBin = false;
352349
params = Params.parse(params, {
353350
icon: null,
354351
titleMarkup: false,
@@ -929,8 +926,8 @@ MessageTray.prototype = {
929926

930927
_showNotification: function () {
931928
this._notification = this._notificationQueue.shift();
932-
if (this._notification.actor._parent_container) {
933-
this._notification.actor._parent_container.remove_actor(this._notification.actor);
929+
if (this._notification.actor.get_parent()) {
930+
this._notification.actor.get_parent().remove_actor(this._notification.actor);
934931
}
935932

936933
this._notificationBin.child = this._notification.actor;

0 commit comments

Comments
 (0)