Skip to content

Commit bc85e28

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 f90012a commit bc85e28

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
@@ -61,6 +61,16 @@ const getFocusState = function(metaWindow) {
6161
return false;
6262
};
6363

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

995-
this.groupState.metaWindows.splice(refWindow, 1);
1005+
const metaWindows = this.groupState.metaWindows.filter((w) => w != metaWindow);
9961006

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

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

1128-
this.groupState.set({windowCount: this.groupState.metaWindows ? this.groupState.metaWindows.length : 0});
1129-
1130-
if (this.groupState.windowCount > 1 && this.state.settings.enableWindowCountBadges) {
1131-
this.windowsBadgeLabel.text = this.groupState.windowCount.toString();
1140+
const windowCount = this.groupState.metaWindows ? this.groupState.metaWindows.length : 0;
1141+
1142+
this.groupState.set({windowCount: windowCount});
1143+
1144+
if (windowCount > 1 && this.state.settings.enableWindowCountBadges) {
1145+
this.windowsBadgeLabel.text = windowCount.toString();
11321146
this.windowsBadge.show();
11331147
} else {
11341148
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
@@ -448,12 +448,16 @@ class GroupedWindowListApplet extends Applet.Applet {
448448
return false;
449449
}
450450

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

@@ -1018,10 +1022,14 @@ class GroupedWindowListApplet extends Applet.Applet {
10181022
_onWindowAppChanged(tracker, metaWindow) {
10191023
if (!metaWindow) return;
10201024

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

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

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

249253
windowAdded(metaWorkspace, metaWindow, app, isFavoriteApp) {
@@ -356,10 +360,9 @@ var Workspace = class Workspace {
356360

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

364367
// If the window is on all workspaces or we're showing windows in all workspaces,
365368
// make sure to remove the window from all workspaces.
@@ -396,7 +399,7 @@ var Workspace = class Workspace {
396399

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

399-
this.appGroups[refApp].destroy(true);
402+
this.appGroups[refApp].destroy();
400403
this.appGroups[refApp] = undefined;
401404
this.appGroups.splice(refApp, 1);
402405

@@ -416,7 +419,7 @@ var Workspace = class Workspace {
416419
}
417420
}
418421
} else {
419-
this.appGroups[refApp].destroy(true);
422+
this.appGroups[refApp].destroy();
420423
this.appGroups[refApp] = undefined;
421424
this.appGroups.splice(refApp, 1);
422425
}

0 commit comments

Comments
 (0)