Skip to content

Commit 54bf167

Browse files
committed
gwl: Update instances correctly when the monitor configuration
changes. - Use muffin's display to get the correct number of monitors - when the applet is refreshed, the GdkScreen doesn't have an accurate count at that point. - Don't refresh appLists asynchronously as their apps may have disappeared to another instance and are no longer valid for this one. - Make it possible to cancel the attention flash if the item gets destroyed before it completes. ref: #11106
1 parent 108b777 commit 54bf167

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const Tweener = imports.ui.tweener;
77
const DND = imports.ui.dnd;
88
const Tooltips = imports.ui.tooltips;
99
const PopupMenu = imports.ui.popupMenu;
10+
const Mainloop = imports.mainloop;
1011
const {SignalManager} = imports.misc.signalManager;
1112
const {each, findIndex, unref} = imports.misc.util;
1213
const {createStore} = imports.misc.state;
@@ -97,6 +98,7 @@ class AppGroup {
9798

9899
this.signals = new SignalManager(null);
99100
this.appKeyTimeout = 0;
101+
this.flashTimer = 0;
100102

101103
// TODO: This needs to be in state so it can be updated more reliably.
102104
this.labelVisiblePref = this.state.settings.titleDisplay !== TitleDisplay.None && this.state.isHorizontal;
@@ -318,15 +320,18 @@ class AppGroup {
318320
this.actor.remove_style_pseudo_class('active');
319321
this.actor.add_style_class_name('grouped-window-list-item-demands-attention');
320322
if (counter < FLASH_MAX_COUNT) {
321-
setTimeout(() => {
323+
this.flashTimer = Mainloop.timeout_add(FLASH_INTERVAL, () => {
322324
if (this.actor && this.actor.has_style_class_name('grouped-window-list-item-demands-attention')) {
323325
this.actor.remove_style_class_name('grouped-window-list-item-demands-attention');
324326
this.actor.add_style_pseudo_class('active');
325327
}
326-
setTimeout(() => {
328+
329+
this.flashTimer = Mainloop.timeout_add(FLASH_INTERVAL, () => {
327330
this.flashButton(++counter);
328-
}, FLASH_INTERVAL);
329-
}, FLASH_INTERVAL);
331+
});
332+
});
333+
} else {
334+
this.flashTimer = 0;
330335
}
331336
}
332337

@@ -1141,6 +1146,11 @@ class AppGroup {
11411146
this.signals.disconnectAllSignals();
11421147
this.groupState.set({willUnmount: true});
11431148

1149+
if (this.flashTimer > 0) {
1150+
Mainloop.source_remove(this.flashTimer);
1151+
this.flashTimer = 0;
1152+
}
1153+
11441154
if (this.rightClickMenu) {
11451155
if (this.rightClickMenu.isOpen) {
11461156
this.rightClickMenu.close();

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class GroupedWindowListApplet extends Applet.Applet {
295295
this.signals.connect(global.window_manager, 'switch-workspace', (...args) => this.onSwitchWorkspace(...args));
296296
this.signals.connect(global.screen, 'workspace-removed', (...args) => this.onWorkspaceRemoved(...args));
297297
this.signals.connect(global.screen, 'window-monitor-changed', (...args) => this.onWindowMonitorChanged(...args));
298-
this.signals.connect(Main.panelManager, 'monitors-changed', (...args) => this.on_applet_instances_changed(...args));
298+
this.signals.connect(Main.panelManager, 'monitors-changed', (...args) => this._onMonitorsChanged(...args));
299299
this.signals.connect(global.screen, 'window-skip-taskbar-changed', (...args) => this.onWindowSkipTaskbarChanged(...args));
300300
this.signals.connect(global.display, 'window-marked-urgent', (...args) => this.updateAttentionState(...args));
301301
this.signals.connect(global.display, 'window-demands-attention', (...args) => this.updateAttentionState(...args));
@@ -369,21 +369,29 @@ class GroupedWindowListApplet extends Applet.Applet {
369369
this.state.set({appletReady: true});
370370
}
371371

372-
on_applet_instances_changed(instance) {
372+
_updateState(initialUpdate) {
373373
if (!this.state.appletReady) {
374374
return;
375375
}
376376

377377
this.numberOfMonitors = null;
378378
this.updateMonitorWatchlist();
379379

380-
if (instance && instance.instance_id === this.instance_id) {
380+
if (initialUpdate) {
381381
this.onSwitchWorkspace();
382382
} else {
383383
this.refreshCurrentAppList();
384384
}
385385
}
386386

387+
on_applet_instances_changed(instance) {
388+
this._updateState(instance?.instance_id === this.instance_id);
389+
}
390+
391+
_onMonitorsChanged(panelManager) {
392+
this._updateState(false);
393+
}
394+
387395
on_panel_edit_mode_changed() {
388396
this.state.set({panelEditMode: !this.state.panelEditMode});
389397
each(this.appLists, (workspace) => {
@@ -506,7 +514,7 @@ class GroupedWindowListApplet extends Applet.Applet {
506514

507515
updateMonitorWatchlist() {
508516
if (!this.numberOfMonitors) {
509-
this.numberOfMonitors = Gdk.Screen.get_default().get_n_monitors();
517+
this.numberOfMonitors = global.display.get_n_monitors();
510518
}
511519
let onPrimary = this.panel.monitorIndex === Main.layoutManager.primaryIndex;
512520
let instances = Main.AppletManager.getRunningInstancesForUuid(this.state.uuid);
@@ -541,7 +549,7 @@ class GroupedWindowListApplet extends Applet.Applet {
541549

542550
refreshCurrentAppList() {
543551
let appList = this.appLists[this.state.currentWs];
544-
if (appList) setTimeout(() => appList.refreshList(), 0);
552+
if (appList) appList.refreshList();
545553
}
546554

547555
refreshAllAppLists() {

0 commit comments

Comments
 (0)