Skip to content

Commit 63d3679

Browse files
committed
Do not recreate menu on orientation change.
1 parent 9972a85 commit 63d3679

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
3232
// Layout
3333
this._orientation = orientation;
3434
this.menuManager = new PopupMenu.PopupMenuManager(this);
35+
this.menu = new Applet.AppletPopupMenu(this, orientation);
36+
this.menuManager.addMenu(this.menu);
3537

3638
// Lists
3739
this.notifications = []; // The list of notifications, in order from oldest to newest.
3840

3941
// Events
4042
Main.messageTray.connect('notify-applet-update', Lang.bind(this, this._notification_added));
4143
global.settings.connect('changed::' + PANEL_EDIT_MODE_KEY, Lang.bind(this, this._on_panel_edit_mode_changed));
44+
this.menu.connect('menu-animated-closed', this._onMenuClosed.bind(this));
4245

4346
// States
4447
this._blinking = false;
4548
this._blink_toggle = false;
49+
50+
this._display();
4651
}
4752

4853
_setKeybinding() {
@@ -58,14 +63,17 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
5863
_openMenu() {
5964
this._update_timestamp();
6065

61-
this._notificationbin.remove_all_children();
6266
this.notifications.forEach(notification => {
6367
global.reparentActor(notification.actor, this._notificationbin);
6468
});
6569

6670
this.menu.toggle();
6771
}
6872

73+
_onMenuClosed() {
74+
this._notificationbin.remove_all_children();
75+
}
76+
6977
_display() {
7078
// Always start the applet empty, void of any notifications.
7179
this.set_applet_icon_symbolic_name("empty-notif");
@@ -88,18 +96,11 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
8896
this.clear_action.connect('activate', Lang.bind(this, this._clear_all));
8997
this.clear_action.actor.hide();
9098

91-
if (this._orientation == St.Side.BOTTOM) {
92-
this.menu.addMenuItem(this.menu_label);
93-
this.menu.addActor(this._maincontainer);
94-
this.menu.addMenuItem(this.clear_separator);
95-
this.menu.addMenuItem(this.clear_action);
96-
} else {
97-
this.menu.addMenuItem(this.clear_action);
98-
this.menu.addMenuItem(this.clear_separator);
99-
this.menu.addMenuItem(this.menu_label);
100-
this.menu.addActor(this._maincontainer);
101-
}
102-
99+
this.menu.addMenuItem(this.clear_action);
100+
this.menu.addMenuItem(this.clear_separator);
101+
this.menu.addMenuItem(this.menu_label);
102+
this.menu.addActor(this._maincontainer);
103+
103104
this.scrollview = new St.ScrollView({ x_fill: true, y_fill: true, y_align: St.Align.START, style_class: "vfade"});
104105
this._maincontainer.add(this.scrollview);
105106
this.scrollview.add_actor(this._notificationbin);
@@ -120,7 +121,27 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
120121

121122
this._on_panel_edit_mode_changed();
122123

123-
this.menu.addSettingsAction(_("Notification Settings"), 'notifications');
124+
this.settingsMenuItem = this.menu.addSettingsAction(_("Notification Settings"), 'notifications');
125+
}
126+
127+
_arrangeDisplay() {
128+
// Remove menu actors so we can put tham back in a different order according
129+
// to orientation
130+
this.menu.box.remove_all_children();
131+
132+
if (this._orientation == St.Side.BOTTOM) {
133+
this.menu.box.add(this.menu_label.actor);
134+
this.menu.addActor(this._maincontainer);
135+
this.menu.box.add(this.clear_separator.actor);
136+
this.menu.box.add(this.clear_action.actor);
137+
} else {
138+
this.menu.box.add(this.clear_action.actor);
139+
this.menu.box.add(this.clear_separator.actor);
140+
this.menu.box.add(this.menu_label.actor);
141+
this.menu.addActor(this._maincontainer);
142+
}
143+
144+
this.menu.box.add(this.settingsMenuItem.actor);
124145
}
125146

126147
_notification_added (mtray, notification) { // Notification event handler.
@@ -250,12 +271,7 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
250271
on_orientation_changed (orientation) {
251272
this._orientation = orientation;
252273

253-
if (this.menu) {
254-
this.menu.destroy();
255-
}
256-
this.menu = new Applet.AppletPopupMenu(this, orientation);
257-
this.menuManager.addMenu(this.menu);
258-
this._display();
274+
this._arrangeDisplay();
259275
}
260276

261277
on_applet_clicked(event) {

0 commit comments

Comments
 (0)