Skip to content

Commit

Permalink
fix: disconnect workspace switch connections when extension is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
flexagoon committed Nov 27, 2024
1 parent ee43bdd commit c98ca50
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {logDebug} from './utils/log.js';
import {getPref, initPrefs, prefs, uninitPrefs} from './utils/settings.js';
import {WindowPicker} from './window_picker/service.js';

import type GObject from 'gi://GObject';
import type Gio from 'gi://Gio';

export default class RoundedWindowCornersReborn extends Extension {
Expand All @@ -31,6 +32,8 @@ export default class RoundedWindowCornersReborn extends Extension {
#windowPicker: WindowPicker | null = null;

#layoutManagerStartupConnection: number | null = null;
#workspaceSwitchConnections: {object: GObject.Object; id: number}[] | null =
null;

enable() {
// Initialize extension preferences
Expand Down Expand Up @@ -87,7 +90,8 @@ export default class RoundedWindowCornersReborn extends Extension {
self.#originalPrepareWorkspaceSwitch.apply(this, [
workspaceIndices,
]);
addShadowsInWorkspaceSwitch(this);
self.#workspaceSwitchConnections =
addShadowsInWorkspaceSwitch(this);
};
WorkspaceAnimationController.prototype._finishWorkspaceSwitch =
function (switchData) {
Expand Down Expand Up @@ -129,6 +133,10 @@ export default class RoundedWindowCornersReborn extends Extension {
this.#layoutManagerStartupConnection = null;
}

for (const connection of this.#workspaceSwitchConnections ?? []) {
connection.object.disconnect(connection.id);
}

logDebug('Disabled');

uninitPrefs();
Expand Down
12 changes: 12 additions & 0 deletions src/patch/workspace_switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Clutter from 'gi://Clutter';
import {getRoundedCornersEffect, windowScaleFactor} from '../manager/utils.js';
import {SHADOW_PADDING} from '../utils/constants.js';

import type GObject from 'gi://GObject';
import type {WorkspaceAnimationController} from 'resource:///org/gnome/shell/ui/workspaceAnimation.js';
import type {RoundedWindowActor} from '../utils/types.js';

Expand All @@ -13,10 +14,13 @@ type WsAnimationActor = Clutter.Actor & {shadowClone?: Clutter.Actor};
/**
* Add shadows to windows when switching workspaces.
* @param self - The workspace animation controller.
* @returns A set of connections to be disconnected on extension disable.
*/
export function addShadowsInWorkspaceSwitch(
self: WorkspaceAnimationController,
) {
const connections: {object: GObject.Object; id: number}[] = [];

for (const monitor of self._switchData.monitors) {
for (const workspace of monitor._workspaceGroups) {
const windowRecords = workspace._windowRecords;
Expand All @@ -40,6 +44,9 @@ export function addShadowsInWorkspaceSwitch(
workspace.disconnect(destroyConnection);
});

connections.push({object: global.display, id: restackedConnection});
connections.push({object: workspace, id: destroyConnection});

for (const {windowActor: actor, clone} of windowRecords) {
const win = actor.metaWindow;

Expand Down Expand Up @@ -74,6 +81,9 @@ export function addShadowsInWorkspaceSwitch(
clone.disconnect(destroyConnection);
});

connections.push({object: clone, id: notifyId});
connections.push({object: clone, id: destroyConnection});

// Store the reference to the shadow clone. This allows restacking
// them, as you can see at the top of this function.
(clone as WsAnimationActor).shadowClone = shadowClone;
Expand All @@ -83,6 +93,8 @@ export function addShadowsInWorkspaceSwitch(
}
}
}

return connections;
}

/**
Expand Down

0 comments on commit c98ca50

Please sign in to comment.