Skip to content

Commit

Permalink
gwl: Update instances correctly when the monitor configuration
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mtwebster committed Dec 14, 2022
1 parent 108b777 commit 54bf167
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
18 changes: 14 additions & 4 deletions files/usr/share/cinnamon/applets/[email protected]/appGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Tweener = imports.ui.tweener;
const DND = imports.ui.dnd;
const Tooltips = imports.ui.tooltips;
const PopupMenu = imports.ui.popupMenu;
const Mainloop = imports.mainloop;
const {SignalManager} = imports.misc.signalManager;
const {each, findIndex, unref} = imports.misc.util;
const {createStore} = imports.misc.state;
Expand Down Expand Up @@ -97,6 +98,7 @@ class AppGroup {

this.signals = new SignalManager(null);
this.appKeyTimeout = 0;
this.flashTimer = 0;

// TODO: This needs to be in state so it can be updated more reliably.
this.labelVisiblePref = this.state.settings.titleDisplay !== TitleDisplay.None && this.state.isHorizontal;
Expand Down Expand Up @@ -318,15 +320,18 @@ class AppGroup {
this.actor.remove_style_pseudo_class('active');
this.actor.add_style_class_name('grouped-window-list-item-demands-attention');
if (counter < FLASH_MAX_COUNT) {
setTimeout(() => {
this.flashTimer = Mainloop.timeout_add(FLASH_INTERVAL, () => {
if (this.actor && this.actor.has_style_class_name('grouped-window-list-item-demands-attention')) {
this.actor.remove_style_class_name('grouped-window-list-item-demands-attention');
this.actor.add_style_pseudo_class('active');
}
setTimeout(() => {

this.flashTimer = Mainloop.timeout_add(FLASH_INTERVAL, () => {
this.flashButton(++counter);
}, FLASH_INTERVAL);
}, FLASH_INTERVAL);
});
});
} else {
this.flashTimer = 0;
}
}

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

if (this.flashTimer > 0) {
Mainloop.source_remove(this.flashTimer);
this.flashTimer = 0;
}

if (this.rightClickMenu) {
if (this.rightClickMenu.isOpen) {
this.rightClickMenu.close();
Expand Down
18 changes: 13 additions & 5 deletions files/usr/share/cinnamon/applets/[email protected]/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class GroupedWindowListApplet extends Applet.Applet {
this.signals.connect(global.window_manager, 'switch-workspace', (...args) => this.onSwitchWorkspace(...args));
this.signals.connect(global.screen, 'workspace-removed', (...args) => this.onWorkspaceRemoved(...args));
this.signals.connect(global.screen, 'window-monitor-changed', (...args) => this.onWindowMonitorChanged(...args));
this.signals.connect(Main.panelManager, 'monitors-changed', (...args) => this.on_applet_instances_changed(...args));
this.signals.connect(Main.panelManager, 'monitors-changed', (...args) => this._onMonitorsChanged(...args));
this.signals.connect(global.screen, 'window-skip-taskbar-changed', (...args) => this.onWindowSkipTaskbarChanged(...args));
this.signals.connect(global.display, 'window-marked-urgent', (...args) => this.updateAttentionState(...args));
this.signals.connect(global.display, 'window-demands-attention', (...args) => this.updateAttentionState(...args));
Expand Down Expand Up @@ -369,21 +369,29 @@ class GroupedWindowListApplet extends Applet.Applet {
this.state.set({appletReady: true});
}

on_applet_instances_changed(instance) {
_updateState(initialUpdate) {
if (!this.state.appletReady) {
return;
}

this.numberOfMonitors = null;
this.updateMonitorWatchlist();

if (instance && instance.instance_id === this.instance_id) {
if (initialUpdate) {
this.onSwitchWorkspace();
} else {
this.refreshCurrentAppList();
}
}

on_applet_instances_changed(instance) {
this._updateState(instance?.instance_id === this.instance_id);
}

_onMonitorsChanged(panelManager) {
this._updateState(false);
}

on_panel_edit_mode_changed() {
this.state.set({panelEditMode: !this.state.panelEditMode});
each(this.appLists, (workspace) => {
Expand Down Expand Up @@ -506,7 +514,7 @@ class GroupedWindowListApplet extends Applet.Applet {

updateMonitorWatchlist() {
if (!this.numberOfMonitors) {
this.numberOfMonitors = Gdk.Screen.get_default().get_n_monitors();
this.numberOfMonitors = global.display.get_n_monitors();
}
let onPrimary = this.panel.monitorIndex === Main.layoutManager.primaryIndex;
let instances = Main.AppletManager.getRunningInstancesForUuid(this.state.uuid);
Expand Down Expand Up @@ -541,7 +549,7 @@ class GroupedWindowListApplet extends Applet.Applet {

refreshCurrentAppList() {
let appList = this.appLists[this.state.currentWs];
if (appList) setTimeout(() => appList.refreshList(), 0);
if (appList) appList.refreshList();
}

refreshAllAppLists() {
Expand Down

0 comments on commit 54bf167

Please sign in to comment.