Skip to content

Commit a8f7626

Browse files
committed
gwl: Improve state handling during window removal
This fixes some annyoing issues during the removal of windows that would some time leave a ghost window instance in app groups. I've also improved the handled of some signals to ensure the window is only added again if it is inside a valid workspace and the workspace is similar to the current workspace receiving the signal.
1 parent 5213f3f commit a8f7626

3 files changed

Lines changed: 53 additions & 28 deletions

File tree

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

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ const getFocusState = function(metaWindow) {
6060
return false;
6161
};
6262

63+
const getLastFocusedWindow = function(metaWindows) {
64+
let lastFocusedWindow = null;
65+
for (let i = 0; i < metaWindows.length; i++) {
66+
if (!lastFocusedWindow || (metaWindows[i].get_user_time() > lastFocusedWindow.get_user_time())) {
67+
lastFocusedWindow = metaWindows[i];
68+
}
69+
}
70+
return lastFocusedWindow;
71+
}
72+
6373
class AppGroup {
6474
constructor(params) {
6575
this.state = params.state;
@@ -991,19 +1001,21 @@ class AppGroup {
9911001
this.signals.disconnect('notify::icon', metaWindow);
9921002
this.signals.disconnect('notify::progress', metaWindow);
9931003

994-
this.groupState.metaWindows.splice(refWindow, 1);
1004+
const metaWindows = this.groupState.metaWindows.filter((w) => w != metaWindow);
9951005

9961006
if (this.progressOverlay.visible) this.onProgressChange();
9971007

998-
if (this.groupState.metaWindows.length > 0 && !this.groupState.willUnmount) {
999-
this.onWindowTitleChanged(this.groupState.lastFocused);
1000-
this.groupState.set({
1001-
metaWindows: this.groupState.metaWindows,
1002-
lastFocused: this.groupState.metaWindows[this.groupState.metaWindows.length - 1]
1003-
}, true);
1008+
if (!this.groupState.willUnmount) {
1009+
const lastFocused = this.groupState.lastFocused === metaWindow
1010+
? getLastFocusedWindow(metaWindows)
1011+
: this.groupState.lastFocused;
1012+
this.groupState.set({metaWindows: metaWindows, lastFocused: lastFocused}, true);
1013+
this.onWindowTitleChanged(lastFocused);
10041014
if (this.hoverMenu) this.groupState.trigger('removeThumbnailFromMenu', metaWindow);
10051015
this.calcWindowNumber();
1006-
} else {
1016+
}
1017+
1018+
if (metaWindows.length === 0) {
10071019
// This is the last window, so this group needs to be destroyed. We'll call back windowRemoved
10081020
// in workspace to put the final nail in the coffin.
10091021
if (typeof cb === 'function') {
@@ -1124,10 +1136,12 @@ class AppGroup {
11241136
calcWindowNumber() {
11251137
if (this.groupState.willUnmount) return;
11261138

1127-
this.groupState.set({windowCount: this.groupState.metaWindows ? this.groupState.metaWindows.length : 0});
1128-
1129-
if (this.groupState.windowCount > 1 && this.state.settings.enableWindowCountBadges) {
1130-
this.windowsBadgeLabel.text = this.groupState.windowCount.toString();
1139+
const windowCount = this.groupState.metaWindows ? this.groupState.metaWindows.length : 0;
1140+
1141+
this.groupState.set({windowCount: windowCount});
1142+
1143+
if (windowCount > 1 && this.state.settings.enableWindowCountBadges) {
1144+
this.windowsBadgeLabel.text = windowCount.toString();
11311145
this.windowsBadge.show();
11321146
} else {
11331147
this.windowsBadge.hide();

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,16 @@ class GroupedWindowListApplet extends Applet.Applet {
447447
return false;
448448
}
449449

450-
onWindowMonitorChanged(display, metaWindow, metaWorkspace) {
451-
if (this.state.monitorWatchList.length !== this.numberOfMonitors) {
452-
const currentWorkspace = this.getCurrentWorkspace();
453-
if (currentWorkspace !== null) {
454-
currentWorkspace.windowRemoved(metaWorkspace, metaWindow);
455-
currentWorkspace.windowAdded(metaWorkspace, metaWindow);
450+
onWindowMonitorChanged(display, metaWindow, monitor) {
451+
const metaWorkspace = metaWindow.get_workspace();
452+
if ((this.state.monitorWatchList.length !== this.numberOfMonitors) && metaWorkspace) {
453+
const windowWorkspace = this.workspaces.find(
454+
workspace => workspace.metaWorkspace && workspace.metaWorkspace.index() === metaWorkspace.index()
455+
);
456+
457+
if (windowWorkspace !== null) {
458+
windowWorkspace.windowRemoved(metaWorkspace, metaWindow);
459+
windowWorkspace.windowAdded(metaWorkspace, metaWindow);
456460
}
457461
}
458462
}
@@ -768,7 +772,7 @@ class GroupedWindowListApplet extends Applet.Applet {
768772
currentWorkspace.appGroups[z].groupState.lastFocused
769773
: source.groupState.metaWindows[z];
770774
Main.activateWindow(_window, global.get_current_time());
771-
setTimeout(() => this.state.set({scrollActive: false}, 4000));
775+
setTimeout(() => this.state.set({scrollActive: false}), 4000);
772776
}
773777
}
774778

@@ -1017,10 +1021,14 @@ class GroupedWindowListApplet extends Applet.Applet {
10171021
_onWindowAppChanged(tracker, metaWindow) {
10181022
if (!metaWindow) return;
10191023

1024+
const windowWorkspace = metaWindow.get_workspace();
1025+
10201026
this.workspaces.forEach(workspace => {
10211027
if (!workspace) return;
1022-
workspace.windowRemoved(workspace.metaWorkspace, metaWindow);
1023-
workspace.windowAdded(workspace.metaWorkspace, metaWindow);
1028+
if (windowWorkspace && (workspace.metaWorkspace.index() === windowWorkspace.index())) {
1029+
workspace.windowRemoved(workspace.metaWorkspace, metaWindow);
1030+
workspace.windowAdded(workspace.metaWorkspace, metaWindow);
1031+
}
10241032
});
10251033
}
10261034

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ class Workspace {
242242
windowWorkspaceChanged(display, metaWindow, metaWorkspace) {
243243
// If the window is removed the metaWorkspace will be null, in that
244244
// case we wouldn't want to add the window again.
245-
if (metaWorkspace) this.windowAdded(metaWorkspace, metaWindow);
245+
if (metaWorkspace && this.metaWorkspace.index() === metaWorkspace.index()) {
246+
this.windowAdded(metaWorkspace, metaWindow);
247+
} else {
248+
this.windowRemoved(metaWorkspace, metaWindow);
249+
}
246250
}
247251

248252
windowAdded(metaWorkspace, metaWindow, app, isFavoriteApp) {
@@ -355,10 +359,9 @@ class Workspace {
355359

356360
// Abort the remove if the window is just changing workspaces, window
357361
// should always remain indexed on all workspaces while its mapped.
358-
// if (!metaWindow.showing_on_its_workspace()) return;
359-
if ((this.state.settings.showAllWorkspaces) && (metaWindow.has_focus()
360-
&& global.workspace_manager.get_active_workspace_index()
361-
!== metaWorkspace.index())) return;
362+
if (this.state.settings.showAllWorkspaces && !this.state.removingWindowFromWorkspaces &&
363+
metaWindow.has_focus() && (global.workspace_manager.get_active_workspace_index() !== metaWorkspace.index()))
364+
return;
362365

363366
// If the window is on all workspaces or we're showing windows in all workspaces,
364367
// make sure to remove the window from all workspaces.
@@ -395,7 +398,7 @@ class Workspace {
395398

396399
const refAppId = this.appGroups[refApp].groupState.appId;
397400

398-
this.appGroups[refApp].destroy(true);
401+
this.appGroups[refApp].destroy();
399402
this.appGroups[refApp] = undefined;
400403
this.appGroups.splice(refApp, 1);
401404

@@ -415,7 +418,7 @@ class Workspace {
415418
}
416419
}
417420
} else {
418-
this.appGroups[refApp].destroy(true);
421+
this.appGroups[refApp].destroy();
419422
this.appGroups[refApp] = undefined;
420423
this.appGroups.splice(refApp, 1);
421424
}

0 commit comments

Comments
 (0)