js: Use connectObject()

gnome-shell added (dis)connectObject() methods to partially automate
signal handling. It doesn't only save a significant amount of code,
but also makes it harder to miss cleaning up on destroy.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/263>
This commit is contained in:
Florian Müllner
2021-01-16 01:07:29 +01:00
parent 37baccd9fc
commit 3bfaf6f88a
10 changed files with 198 additions and 416 deletions

View File

@@ -51,11 +51,8 @@ class ApplicationMenuItem extends PopupMenu.PopupBaseMenuItem {
this.label_actor = appLabel; this.label_actor = appLabel;
let textureCache = St.TextureCache.get_default(); let textureCache = St.TextureCache.get_default();
let iconThemeChangedId = textureCache.connect('icon-theme-changed', textureCache.connectObject('icon-theme-changed',
this._updateIcon.bind(this)); () => this._updateIcon(), this);
this.connect('destroy', () => {
textureCache.disconnect(iconThemeChangedId);
});
this._updateIcon(); this._updateIcon();
this._delegate = this; this._delegate = this;
@@ -274,9 +271,7 @@ class DesktopTarget extends EventEmitter {
_setDesktop(desktop) { _setDesktop(desktop) {
if (this._desktop) { if (this._desktop) {
this._desktop.disconnect(this._desktopDestroyedId); this._desktop.disconnectObject(this);
this._desktopDestroyedId = 0;
delete this._desktop._delegate; delete this._desktop._delegate;
} }
@@ -284,9 +279,9 @@ class DesktopTarget extends EventEmitter {
this.emit('desktop-changed'); this.emit('desktop-changed');
if (this._desktop) { if (this._desktop) {
this._desktopDestroyedId = this._desktop.connect('destroy', () => { this._desktop.connectObject('destroy', () => {
this._setDesktop(null); this._setDesktop(null);
}); }, this);
this._desktop._delegate = this; this._desktop._delegate = this;
} }
} }
@@ -326,10 +321,7 @@ class DesktopTarget extends EventEmitter {
} }
destroy() { destroy() {
if (this._windowAddedId) global.window_group.disconnectObject(this);
global.window_group.disconnect(this._windowAddedId);
this._windowAddedId = 0;
this._setDesktop(null); this._setDesktop(null);
} }
@@ -391,12 +383,11 @@ class ApplicationsButton extends PanelMenu.Button {
this.name = 'panelApplications'; this.name = 'panelApplications';
this.label_actor = this._label; this.label_actor = this._label;
this._showingId = Main.overview.connect('showing', () => { Main.overview.connect(
this.add_accessible_state(Atk.StateType.CHECKED); 'showing', () => this.add_accessible_state(Atk.StateType.CHECKED),
}); 'hiding', () => this.remove_accessible_state(Atk.StateType.CHECKED),
this._hidingId = Main.overview.connect('hiding', () => { this);
this.remove_accessible_state(Atk.StateType.CHECKED);
});
Main.wm.addKeybinding( Main.wm.addKeybinding(
'apps-menu-toggle-menu', 'apps-menu-toggle-menu',
ExtensionUtils.getSettings(), ExtensionUtils.getSettings(),
@@ -415,15 +406,15 @@ class ApplicationsButton extends PanelMenu.Button {
}); });
this._tree = new GMenu.Tree({menu_basename: 'applications.menu'}); this._tree = new GMenu.Tree({menu_basename: 'applications.menu'});
this._treeChangedId = this._tree.connect('changed', this._tree.connectObject('changed',
this._onTreeChanged.bind(this)); () => this._onTreeChanged(), this);
this._applicationsButtons = new Map(); this._applicationsButtons = new Map();
this.reloadFlag = false; this.reloadFlag = false;
this._createLayout(); this._createLayout();
this._display(); this._display();
this._installedChangedId = appSys.connect('installed-changed', appSys.connectObject('installed-changed',
this._onTreeChanged.bind(this)); () => this._onTreeChanged(), this);
} }
_onTreeChanged() { _onTreeChanged() {
@@ -447,11 +438,7 @@ class ApplicationsButton extends PanelMenu.Button {
_onDestroy() { _onDestroy() {
super._onDestroy(); super._onDestroy();
Main.overview.disconnect(this._showingId); delete this._tree;
Main.overview.disconnect(this._hidingId);
appSys.disconnect(this._installedChangedId);
this._tree.disconnect(this._treeChangedId);
this._tree = null;
Main.wm.removeKeybinding('apps-menu-toggle-menu'); Main.wm.removeKeybinding('apps-menu-toggle-menu');

View File

@@ -13,9 +13,8 @@ class WindowMover {
this._appConfigs = new Map(); this._appConfigs = new Map();
this._appData = new Map(); this._appData = new Map();
this._appsChangedId = this._appSystem.connectObject('installed-changed',
this._appSystem.connect('installed-changed', () => this._updateAppData(), this);
this._updateAppData.bind(this));
this._settings.connect('changed', this._updateAppConfigs.bind(this)); this._settings.connect('changed', this._updateAppConfigs.bind(this));
this._updateAppConfigs(); this._updateAppConfigs();
@@ -37,7 +36,7 @@ class WindowMover {
let removedApps = [...this._appData.keys()] let removedApps = [...this._appData.keys()]
.filter(a => !ids.includes(a.id)); .filter(a => !ids.includes(a.id));
removedApps.forEach(app => { removedApps.forEach(app => {
app.disconnect(this._appData.get(app).windowsChangedId); app.disconnectObject(this);
this._appData.delete(app); this._appData.delete(app);
}); });
@@ -45,21 +44,14 @@ class WindowMover {
.map(id => this._appSystem.lookup_app(id)) .map(id => this._appSystem.lookup_app(id))
.filter(app => app && !this._appData.has(app)); .filter(app => app && !this._appData.has(app));
addedApps.forEach(app => { addedApps.forEach(app => {
let data = { app.connectObject('window-changed',
windowsChangedId: app.connect('windows-changed', this._appWindowsChanged.bind(this), this);
this._appWindowsChanged.bind(this)), this._appData.set(app, {windows: app.get_windows()});
moveWindowsId: 0,
windows: app.get_windows(),
};
this._appData.set(app, data);
}); });
} }
destroy() { destroy() {
if (this._appsChangedId) { this._appSystem.disconnectObject(this);
this._appSystem.disconnect(this._appsChangedId);
this._appsChangedId = 0;
}
if (this._settings) { if (this._settings) {
this._settings.run_dispose(); this._settings.run_dispose();

View File

@@ -50,19 +50,11 @@ class MountMenuItem extends PopupMenu.PopupBaseMenuItem {
this.hide(); this.hide();
this._changedId = mount.connect('changed', this._syncVisibility.bind(this)); mount.connectObject('changed',
() => this._syncVisibility(), this);
this._syncVisibility(); this._syncVisibility();
} }
_onDestroy() {
if (this._changedId) {
this.mount.disconnect(this._changedId);
this._changedId = 0;
}
super.destroy();
}
async _isInteresting() { async _isInteresting() {
if (!this.mount.can_eject() && !this.mount.can_unmount()) if (!this.mount.can_eject() && !this.mount.can_unmount())
return false; return false;
@@ -155,12 +147,12 @@ class DriveMenu extends PanelMenu.Button {
this.add_child(icon); this.add_child(icon);
this._monitor = Gio.VolumeMonitor.get(); this._monitor = Gio.VolumeMonitor.get();
this._addedId = this._monitor.connect('mount-added', this._monitor.connectObject(
(monitor, mount) => this._addMount(mount)); 'mount-added', (monitor, mount) => this._addMount(mount),
this._removedId = this._monitor.connect('mount-removed', (monitor, mount) => { 'mount-removed', (monitor, mount) => {
this._removeMount(mount); this._removeMount(mount);
this._updateMenuVisibility(); this._updateMenuVisibility();
}); }, this);
this._mounts = []; this._mounts = [];
@@ -202,17 +194,6 @@ class DriveMenu extends PanelMenu.Button {
} }
log('Removing a mount that was never added to the menu'); log('Removing a mount that was never added to the menu');
} }
_onDestroy() {
if (this._addedId) {
this._monitor.disconnect(this._addedId);
this._monitor.disconnect(this._removedId);
this._addedId = 0;
this._removedId = 0;
}
super._onDestroy();
}
} }
export default class Extension { export default class Extension {

View File

@@ -52,17 +52,8 @@ class PlaceMenuItem extends PopupMenu.PopupBaseMenuItem {
this.add_child(this._ejectButton); this.add_child(this._ejectButton);
} }
this._changedId = info.connect('changed', info.connectObject('changed',
this._propertiesChanged.bind(this)); this._propertiesChanged.bind(this), this);
}
destroy() {
if (this._changedId) {
this._info.disconnect(this._changedId);
this._changedId = 0;
}
super.destroy();
} }
activate(event) { activate(event) {

View File

@@ -260,15 +260,25 @@ export class PlacesManager extends EventEmitter {
}; };
this._settings = new Gio.Settings({schema_id: BACKGROUND_SCHEMA}); this._settings = new Gio.Settings({schema_id: BACKGROUND_SCHEMA});
this._showDesktopIconsChangedId = this._settings.connect( this._settings.connectObject('changed::show-desktop-icons',
'changed::show-desktop-icons', this._updateSpecials.bind(this)); () => this._updateSpecials(), this);
this._updateSpecials(); this._updateSpecials();
/* /*
* Show devices, code more or less ported from nautilus-places-sidebar.c * Show devices, code more or less ported from nautilus-places-sidebar.c
*/ */
this._volumeMonitor = Gio.VolumeMonitor.get(); this._volumeMonitor = Gio.VolumeMonitor.get();
this._connectVolumeMonitorSignals(); this._volumeMonitor.connectObject(
'volume-added', () => this._updateMounts(),
'volume-removed', () => this._updateMounts(),
'volume-changed', () => this._updateMounts(),
'mount-added', () => this._updateMounts(),
'mount-removed', () => this._updateMounts(),
'mount-changed', () => this._updateMounts(),
'drive-connected', () => this._updateMounts(),
'drive-disconnected', () => this._updateMounts(),
'drive-changed', () => this._updateMounts(),
this);
this._updateMounts(); this._updateMounts();
this._bookmarksFile = this._findBookmarksFile(); this._bookmarksFile = this._findBookmarksFile();
@@ -293,34 +303,11 @@ export class PlacesManager extends EventEmitter {
} }
} }
_connectVolumeMonitorSignals() {
const signals = [
'volume-added',
'volume-removed',
'volume-changed',
'mount-added',
'mount-removed',
'mount-changed',
'drive-connected',
'drive-disconnected',
'drive-changed',
];
this._volumeMonitorSignals = [];
let func = this._updateMounts.bind(this);
for (let i = 0; i < signals.length; i++) {
let id = this._volumeMonitor.connect(signals[i], func);
this._volumeMonitorSignals.push(id);
}
}
destroy() { destroy() {
if (this._settings) this._settings?.disconnectObject(this);
this._settings.disconnect(this._showDesktopIconsChangedId);
this._settings = null; this._settings = null;
for (let i = 0; i < this._volumeMonitorSignals.length; i++) this._volumeMonitor.disconnectObject(this);
this._volumeMonitor.disconnect(this._volumeMonitorSignals[i]);
if (this._monitor) if (this._monitor)
this._monitor.cancel(); this._monitor.cancel();

View File

@@ -57,10 +57,6 @@ class WindowContextMenu extends PopupMenu.PopupMenu {
}); });
this.addMenuItem(this._minimizeItem); this.addMenuItem(this._minimizeItem);
this._notifyMinimizedId = this._metaWindow.connect(
'notify::minimized', this._updateMinimizeItem.bind(this));
this._updateMinimizeItem();
this._maximizeItem = new PopupMenu.PopupMenuItem(''); this._maximizeItem = new PopupMenu.PopupMenuItem('');
this._maximizeItem.connect('activate', () => { this._maximizeItem.connect('activate', () => {
if (this._metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH) if (this._metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH)
@@ -70,21 +66,20 @@ class WindowContextMenu extends PopupMenu.PopupMenu {
}); });
this.addMenuItem(this._maximizeItem); this.addMenuItem(this._maximizeItem);
this._notifyMaximizedHId = this._metaWindow.connect(
'notify::maximized-horizontally',
this._updateMaximizeItem.bind(this));
this._notifyMaximizedVId = this._metaWindow.connect(
'notify::maximized-vertically',
this._updateMaximizeItem.bind(this));
this._updateMaximizeItem();
this._closeItem = new PopupMenu.PopupMenuItem(_('Close')); this._closeItem = new PopupMenu.PopupMenuItem(_('Close'));
this._closeItem.connect('activate', () => { this._closeItem.connect('activate', () => {
this._metaWindow.delete(global.get_current_time()); this._metaWindow.delete(global.get_current_time());
}); });
this.addMenuItem(this._closeItem); this.addMenuItem(this._closeItem);
this.actor.connect('destroy', this._onDestroy.bind(this)); this._metaWindow.connectObject(
'notify::minimized', this._updateMinimizeItem.bind(this),
'notify::maximized-horizontally', this._updateMaximizeItem.bind(this),
'notify::maximized-vertically', this._updateMaximizeItem.bind(this),
this);
this._updateMinimizeItem();
this._updateMaximizeItem();
this.connect('open-state-changed', () => { this.connect('open-state-changed', () => {
if (!this.isOpen) if (!this.isOpen)
@@ -107,12 +102,6 @@ class WindowContextMenu extends PopupMenu.PopupMenu {
this._maximizeItem.label.text = maximized this._maximizeItem.label.text = maximized
? _('Unmaximize') : _('Maximize'); ? _('Unmaximize') : _('Maximize');
} }
_onDestroy() {
this._metaWindow.disconnect(this._notifyMinimizedId);
this._metaWindow.disconnect(this._notifyMaximizedHId);
this._metaWindow.disconnect(this._notifyMaximizedVId);
}
} }
class WindowTitle extends St.BoxLayout { class WindowTitle extends St.BoxLayout {
@@ -136,20 +125,19 @@ class WindowTitle extends St.BoxLayout {
this.add(this.label_actor); this.add(this.label_actor);
this._textureCache = St.TextureCache.get_default(); this._textureCache = St.TextureCache.get_default();
this._iconThemeChangedId = this._textureCache.connect( this._textureCache.connectObject('icon-theme-changed',
'icon-theme-changed', this._updateIcon.bind(this)); () => this._updateIcon(), this);
this._notifyWmClass = this._metaWindow.connect_after(
'notify::wm-class', this._updateIcon.bind(this)); this._metaWindow.connectObject(
this._notifyAppId = this._metaWindow.connect_after( 'notify::wm-class',
'notify::gtk-application-id', this._updateIcon.bind(this)); () => this._updateIcon(), GObject.ConnectFlags.AFTER,
'notify::gtk-application-id',
() => this._updateIcon(), GObject.ConnectFlags.AFTER,
'notify::title', () => this._updateTitle(),
'notify::minimized', () => this._minimizedChanged(),
this);
this._updateIcon(); this._updateIcon();
this.connect('destroy', this._onDestroy.bind(this));
this._notifyTitleId = this._metaWindow.connect(
'notify::title', this._updateTitle.bind(this));
this._notifyMinimizedId = this._metaWindow.connect(
'notify::minimized', this._minimizedChanged.bind(this));
this._minimizedChanged(); this._minimizedChanged();
} }
@@ -179,14 +167,6 @@ class WindowTitle extends St.BoxLayout {
}); });
} }
} }
_onDestroy() {
this._textureCache.disconnect(this._iconThemeChangedId);
this._metaWindow.disconnect(this._notifyTitleId);
this._metaWindow.disconnect(this._notifyMinimizedId);
this._metaWindow.disconnect(this._notifyWmClass);
this._metaWindow.disconnect(this._notifyAppId);
}
} }
class BaseButton extends St.Button { class BaseButton extends St.Button {
@@ -222,16 +202,16 @@ class BaseButton extends St.Button {
this._contextMenuManager = new PopupMenu.PopupMenuManager(this); this._contextMenuManager = new PopupMenu.PopupMenuManager(this);
this._switchWorkspaceId = global.window_manager.connect( global.window_manager.connectObject('switch-workspace',
'switch-workspace', this._updateVisibility.bind(this)); () => this._updateVisibility(), this);
if (this._perMonitor) { if (this._perMonitor) {
this._windowEnteredMonitorId = global.display.connect( global.display.connectObject(
'window-entered-monitor', 'window-entered-monitor',
this._windowEnteredOrLeftMonitor.bind(this)); this._windowEnteredOrLeftMonitor.bind(this),
this._windowLeftMonitorId = global.display.connect(
'window-left-monitor', 'window-left-monitor',
this._windowEnteredOrLeftMonitor.bind(this)); this._windowEnteredOrLeftMonitor.bind(this),
this);
} }
this._tooltip = new Tooltip(this, { this._tooltip = new Tooltip(this, {
@@ -397,16 +377,6 @@ class BaseButton extends St.Button {
} }
_onDestroy() { _onDestroy() {
global.window_manager.disconnect(this._switchWorkspaceId);
if (this._windowEnteredMonitorId)
global.display.disconnect(this._windowEnteredMonitorId);
this._windowEnteredMonitorId = 0;
if (this._windowLeftMonitorId)
global.display.disconnect(this._windowLeftMonitorId);
this._windowLeftMonitorId = 0;
this._tooltip.destroy(); this._tooltip.destroy();
} }
} }
@@ -420,9 +390,11 @@ class WindowButton extends BaseButton {
super(perMonitor, monitorIndex); super(perMonitor, monitorIndex);
this.metaWindow = metaWindow; this.metaWindow = metaWindow;
this._skipTaskbarId = metaWindow.connect('notify::skip-taskbar', () => { metaWindow.connectObject(
this._updateVisibility(); 'notify::skip-taskbar', () => this._updateVisibility(),
}); 'workspace-changed', () => this._updateVisibility(),
this);
this._updateVisibility(); this._updateVisibility();
this._windowTitle = new WindowTitle(this.metaWindow); this._windowTitle = new WindowTitle(this.metaWindow);
@@ -436,11 +408,8 @@ class WindowButton extends BaseButton {
this._contextMenuManager.addMenu(this._contextMenu); this._contextMenuManager.addMenu(this._contextMenu);
Main.uiGroup.add_actor(this._contextMenu.actor); Main.uiGroup.add_actor(this._contextMenu.actor);
this._workspaceChangedId = this.metaWindow.connect( global.display.connectObject('notify::focus-window',
'workspace-changed', this._updateVisibility.bind(this)); () => this._updateStyle(), this);
this._notifyFocusId = global.display.connect(
'notify::focus-window', this._updateStyle.bind(this));
this._updateStyle(); this._updateStyle();
} }
@@ -484,9 +453,6 @@ class WindowButton extends BaseButton {
_onDestroy() { _onDestroy() {
super._onDestroy(); super._onDestroy();
this.metaWindow.disconnect(this._skipTaskbarId);
this.metaWindow.disconnect(this._workspaceChangedId);
global.display.disconnect(this._notifyFocusId);
this._contextMenu.destroy(); this._contextMenu.destroy();
} }
} }
@@ -603,18 +569,17 @@ class AppButton extends BaseButton {
Main.uiGroup.add_actor(this._appContextMenu.actor); Main.uiGroup.add_actor(this._appContextMenu.actor);
this._textureCache = St.TextureCache.get_default(); this._textureCache = St.TextureCache.get_default();
this._iconThemeChangedId = this._textureCache.connectObject('icon-theme-changed', () => {
this._textureCache.connect('icon-theme-changed', () => { this._icon.child = app.create_icon_texture(ICON_TEXTURE_SIZE);
this._icon.child = app.create_icon_texture(ICON_TEXTURE_SIZE); }, this);
});
this._windowsChangedId = this.app.connect( this.app.connectObject('windows-changed',
'windows-changed', this._windowsChanged.bind(this)); () => this._windowsChanged(), this);
this._windowsChanged(); this._windowsChanged();
this._windowTracker = Shell.WindowTracker.get_default(); this._windowTracker = Shell.WindowTracker.get_default();
this._notifyFocusId = this._windowTracker.connect( this._windowTracker.connectObject('notify::focus-app',
'notify::focus-app', this._updateStyle.bind(this)); () => this._updateStyle(), this);
this._updateStyle(); this._updateStyle();
} }
@@ -734,9 +699,6 @@ class AppButton extends BaseButton {
_onDestroy() { _onDestroy() {
super._onDestroy(); super._onDestroy();
this._textureCache.disconnect(this._iconThemeChangedId);
this._windowTracker.disconnect(this._notifyFocusId);
this.app.disconnect(this._windowsChangedId);
this._menu.destroy(); this._menu.destroy();
} }
} }
@@ -793,12 +755,12 @@ class WindowList extends St.Widget {
indicatorsBox.add_child(this._workspaceIndicator.container); indicatorsBox.add_child(this._workspaceIndicator.container);
this._mutterSettings = new Gio.Settings({schema_id: 'org.gnome.mutter'}); this._mutterSettings = new Gio.Settings({schema_id: 'org.gnome.mutter'});
this._workspacesOnlyOnPrimaryChangedId = this._mutterSettings.connect( this._mutterSettings.connectObject(
'changed::workspaces-only-on-primary', 'changed::workspaces-only-on-primary',
this._updateWorkspaceIndicatorVisibility.bind(this)); () => this._updateWorkspaceIndicatorVisibility(),
this._dynamicWorkspacesChangedId = this._mutterSettings.connect(
'changed::dynamic-workspaces', 'changed::dynamic-workspaces',
this._updateWorkspaceIndicatorVisibility.bind(this)); () => this._updateWorkspaceIndicatorVisibility(),
this);
this._updateWorkspaceIndicatorVisibility(); this._updateWorkspaceIndicatorVisibility();
this._menuManager = new PopupMenu.PopupMenuManager(this); this._menuManager = new PopupMenu.PopupMenuManager(this);
@@ -816,59 +778,58 @@ class WindowList extends St.Widget {
this._updatePosition(); this._updatePosition();
this._appSystem = Shell.AppSystem.get_default(); this._appSystem = Shell.AppSystem.get_default();
this._appStateChangedId = this._appSystem.connect( this._appSystem.connectObject('app-state-changed',
'app-state-changed', this._onAppStateChanged.bind(this)); this._onAppStateChanged.bind(this), this);
// Hack: OSK gesture is tied to visibility, piggy-back on that // Hack: OSK gesture is tied to visibility, piggy-back on that
this._keyboardVisiblechangedId = Main.keyboard._bottomDragAction.connectObject('notify::enabled',
Main.keyboard._bottomDragAction.connect('notify::enabled', action => {
action => { const visible = !action.enabled;
const visible = !action.enabled; if (visible) {
if (visible) { Main.uiGroup.set_child_above_sibling(
Main.uiGroup.set_child_above_sibling( this, Main.layoutManager.keyboardBox);
this, Main.layoutManager.keyboardBox); } else {
} else { Main.uiGroup.set_child_above_sibling(
Main.uiGroup.set_child_above_sibling( this, Main.layoutManager.panelBox);
this, Main.layoutManager.panelBox); }
} this._updateKeyboardAnchor();
this._updateKeyboardAnchor(); }, this);
});
let workspaceManager = global.workspace_manager; let workspaceManager = global.workspace_manager;
this._nWorkspacesChangedId = workspaceManager.connect( workspaceManager.connectObject('notify::n-workspaces',
'notify::n-workspaces', this._updateWorkspaceIndicatorVisibility.bind(this)); () => this._updateWorkspaceIndicatorVisibility(), this);
this._updateWorkspaceIndicatorVisibility(); this._updateWorkspaceIndicatorVisibility();
this._switchWorkspaceId = global.window_manager.connect( global.window_manager.connectObject('switch-workspace',
'switch-workspace', this._checkGrouping.bind(this)); () => this._checkGrouping(), this);
this._overviewShowingId = Main.overview.connect('showing', () => { Main.overview.connectObject(
this.hide(); 'showing', () => {
this._updateKeyboardAnchor(); this.hide();
});
this._overviewHidingId = Main.overview.connect('hidden', () => {
this.visible = !this._monitor.inFullscreen;
this._updateKeyboardAnchor();
});
this._fullscreenChangedId =
global.display.connect('in-fullscreen-changed', () => {
// Work-around for initial change from unknown to !fullscreen
if (Main.overview.visible)
this.hide();
this._updateKeyboardAnchor(); this._updateKeyboardAnchor();
}); },
'hidden', () => {
this.visible = !this._monitor.inFullscreen;
this._updateKeyboardAnchor();
}, this);
global.display.connectObject('in-fullscreen-changed', () => {
// Work-around for initial change from unknown to !fullscreen
if (Main.overview.visible)
this.hide();
this._updateKeyboardAnchor();
}, this);
this._windowSignals = new Map(); this._windowSignals = new Map();
this._windowCreatedId = global.display.connect( this._windowCreatedId = global.display.connect(
'window-created', (dsp, win) => this._addWindow(win)); 'window-created', (dsp, win) => this._addWindow(win));
this._dragBeginId = Main.xdndHandler.connect('drag-begin', Main.xdndHandler.connectObject(
this._monitorDrag.bind(this)); 'drag-begin', () => this._monitorDrag(),
this._dragEndId = Main.xdndHandler.connect('drag-end', 'drag-end', () => this._stopMonitoringDrag(),
this._stopMonitoringDrag.bind(this)); this);
this._dragMonitor = { this._dragMonitor = {
dragMotion: this._onDragMotion.bind(this), dragMotion: this._onDragMotion.bind(this),
}; };
@@ -1115,37 +1076,14 @@ class WindowList extends St.Widget {
} }
_onDestroy() { _onDestroy() {
this._mutterSettings.disconnect(this._workspacesOnlyOnPrimaryChangedId);
this._mutterSettings.disconnect(this._dynamicWorkspacesChangedId);
this._workspaceIndicator.destroy(); this._workspaceIndicator.destroy();
Main.ctrlAltTabManager.removeGroup(this); Main.ctrlAltTabManager.removeGroup(this);
this._appSystem.disconnect(this._appStateChangedId);
this._appStateChangedId = 0;
Main.keyboard._bottomDragAction.disconnect(this._keyboardVisiblechangedId);
this._keyboardVisiblechangedId = 0;
global.workspace_manager.disconnect(this._nWorkspacesChangedId);
this._nWorkspacesChangedId = 0;
global.window_manager.disconnect(this._switchWorkspaceId);
this._switchWorkspaceId = 0;
this._windowSignals.forEach((id, win) => win.disconnect(id)); this._windowSignals.forEach((id, win) => win.disconnect(id));
this._windowSignals.clear(); this._windowSignals.clear();
Main.overview.disconnect(this._overviewShowingId);
Main.overview.disconnect(this._overviewHidingId);
global.display.disconnect(this._fullscreenChangedId);
global.display.disconnect(this._windowCreatedId);
this._stopMonitoringDrag(); this._stopMonitoringDrag();
Main.xdndHandler.disconnect(this._dragBeginId);
Main.xdndHandler.disconnect(this._dragEndId);
this._settings.run_dispose(); this._settings.run_dispose();
@@ -1167,11 +1105,11 @@ export default class Extension {
this._windowLists = []; this._windowLists = [];
this._settings = ExtensionUtils.getSettings(); this._settings = ExtensionUtils.getSettings();
this._showOnAllMonitorsChangedId = this._settings.connect( this._settings.connectObject('changed::show-on-all-monitors',
'changed::show-on-all-monitors', this._buildWindowLists.bind(this)); () => this._buildWindowLists(), this);
this._monitorsChangedId = Main.layoutManager.connect( Main.layoutManager.connectObject('monitors-changed',
'monitors-changed', this._buildWindowLists.bind(this)); () => this._buildWindowLists(), this);
Main.windowPicker = new WindowPicker(); Main.windowPicker = new WindowPicker();
@@ -1199,11 +1137,8 @@ export default class Extension {
if (!this._windowLists) if (!this._windowLists)
return; return;
this._settings.disconnect(this._showOnAllMonitorsChangedId); this._settings.disconnectObject(this);
this._showOnAllMonitorsChangedId = 0; Main.layoutManager.disconnectObject(this);
Main.layoutManager.disconnect(this._monitorsChangedId);
this._monitorsChangedId = 0;
this._windowLists.forEach(windowList => { this._windowLists.forEach(windowList => {
windowList.hide(); windowList.hide();

View File

@@ -37,9 +37,8 @@ class MyWorkspacesDisplay extends WorkspacesDisplay {
this._workspaceAdjustment = workspaceAdjustment; this._workspaceAdjustment = workspaceAdjustment;
this._workspaceAdjustment.actor = this; this._workspaceAdjustment.actor = this;
this._nWorkspacesChangedId = workspaceManager.connectObject('notify::n-workspaces',
workspaceManager.connect('notify::n-workspaces', () => this._updateAdjustment(), this);
this._updateAdjustment.bind(this));
this.add_constraint( this.add_constraint(
new Layout.MonitorConstraint({ new Layout.MonitorConstraint({
@@ -72,14 +71,6 @@ class MyWorkspacesDisplay extends WorkspacesDisplay {
value: workspaceManager.get_active_workspace_index(), value: workspaceManager.get_active_workspace_index(),
}); });
} }
_onDestroy() {
if (this._nWorkspacesChangedId)
global.workspace_manager.disconnect(this._nWorkspacesChangedId);
this._nWorkspacesChangedId = 0;
super._onDestroy();
}
} }
class MyWorkspace extends Workspace.Workspace { class MyWorkspace extends Workspace.Workspace {
@@ -90,25 +81,16 @@ class MyWorkspace extends Workspace.Workspace {
constructor(...args) { constructor(...args) {
super(...args); super(...args);
this._adjChangedId = this._overviewAdjustment.connectObject('notify::value', () => {
this._overviewAdjustment.connect('notify::value', () => { const {value: progress} = this._overviewAdjustment;
const {value: progress} = this._overviewAdjustment; const brightness = 1 - (1 - VIGNETTE_BRIGHTNESS) * progress;
const brightness = 1 - (1 - VIGNETTE_BRIGHTNESS) * progress; for (const bg of this._background?._backgroundGroup ?? []) {
for (const bg of this._background?._backgroundGroup ?? []) { bg.content.set({
bg.content.set({ vignette: true,
vignette: true, brightness,
brightness, });
}); }
} }, this);
});
}
_onDestroy() {
super._onDestroy();
if (this._adjChangedId)
this._overviewAdjustment.disconnect(this._adjChangedId);
this._adjChangedId = 0;
} }
} }
@@ -166,7 +148,6 @@ export class WindowPicker extends Clutter.Actor {
this._visible = false; this._visible = false;
this._modal = false; this._modal = false;
this._overlayKeyId = 0;
this._stageKeyPressId = 0; this._stageKeyPressId = 0;
this._adjustment = new OverviewAdjustment(this); this._adjustment = new OverviewAdjustment(this);
@@ -188,12 +169,12 @@ export class WindowPicker extends Clutter.Actor {
if (!Main.sessionMode.hasOverview) { if (!Main.sessionMode.hasOverview) {
this._injectBackgroundShade(); this._injectBackgroundShade();
this._overlayKeyId = global.display.connect('overlay-key', () => { global.display.connectObject('overlay-key', () => {
if (!this._visible) if (!this._visible)
this.open(); this.open();
else else
this.close(); this.close();
}); }, this);
} }
} }
@@ -314,10 +295,6 @@ export class WindowPicker extends Clutter.Actor {
if (this._origWorkspaceBackground) if (this._origWorkspaceBackground)
Workspace.WorkspaceBackground = this._origWorkspaceBackground; Workspace.WorkspaceBackground = this._origWorkspaceBackground;
if (this._overlayKeyId)
global.display.disconnect(this._overlayKeyId);
this._overlayKeyId = 0;
if (this._stageKeyPressId) if (this._stageKeyPressId)
global.stage.disconnect(this._stageKeyPressId); global.stage.disconnect(this._stageKeyPressId);
this._stageKeyPressId = 0; this._stageKeyPressId = 0;

View File

@@ -32,20 +32,17 @@ class WindowPreview extends St.Button {
this._window = window; this._window = window;
this.connect('destroy', this._onDestroy.bind(this)); this._window.connectObject(
'size-changed', () => this.queue_relayout(),
this._sizeChangedId = this._window.connect('size-changed', 'position-changed', () => {
() => this.queue_relayout());
this._positionChangedId = this._window.connect('position-changed',
() => {
this._updateVisible(); this._updateVisible();
this.queue_relayout(); this.queue_relayout();
}); },
this._minimizedChangedId = this._window.connect('notify::minimized', 'notify::minimized', this._updateVisible.bind(this),
this._updateVisible.bind(this)); this);
this._focusChangedId = global.display.connect('notify::focus-window', global.display.connectObject('notify::focus-window',
this._onFocusChanged.bind(this)); this._onFocusChanged.bind(this), this);
this._onFocusChanged(); this._onFocusChanged();
} }
@@ -54,13 +51,6 @@ class WindowPreview extends St.Button {
return this._window; return this._window;
} }
_onDestroy() {
this._window.disconnect(this._sizeChangedId);
this._window.disconnect(this._positionChangedId);
this._window.disconnect(this._minimizedChangedId);
global.display.disconnect(this._focusChangedId);
}
_onFocusChanged() { _onFocusChanged() {
if (global.display.focus_window === this._window) if (global.display.focus_window === this._window)
this.add_style_class_name('active'); this.add_style_class_name('active');
@@ -141,16 +131,13 @@ class WorkspaceThumbnail extends St.Button {
let workspaceManager = global.workspace_manager; let workspaceManager = global.workspace_manager;
this._workspace = workspaceManager.get_workspace_by_index(index); this._workspace = workspaceManager.get_workspace_by_index(index);
this._windowAddedId = this._workspace.connect('window-added', this._workspace.connectObject(
(ws, window) => { 'window-added', (ws, window) => this._addWindow(window),
this._addWindow(window); 'window-removed', (ws, window) => this._removeWindow(window),
}); this);
this._windowRemovedId = this._workspace.connect('window-removed',
(ws, window) => { global.display.connectObject('restacked',
this._removeWindow(window); this._onRestacked.bind(this), this);
});
this._restackedId = global.display.connect('restacked',
this._onRestacked.bind(this));
this._workspace.list_windows().forEach(w => this._addWindow(w)); this._workspace.list_windows().forEach(w => this._addWindow(w));
this._onRestacked(); this._onRestacked();
@@ -248,10 +235,6 @@ class WorkspaceThumbnail extends St.Button {
_onDestroy() { _onDestroy() {
this._tooltip.destroy(); this._tooltip.destroy();
this._workspace.disconnect(this._windowAddedId);
this._workspace.disconnect(this._windowRemovedId);
global.display.disconnect(this._restackedId);
} }
} }
@@ -298,14 +281,11 @@ export class WorkspaceIndicator extends PanelMenu.Button {
this._workspacesItems = []; this._workspacesItems = [];
this._workspaceManagerSignals = [ workspaceManager.connectObject(
workspaceManager.connect('notify::n-workspaces', 'notify::n-workspaces', this._nWorkspacesChanged.bind(this), GObject.ConnectFlags.AFTER,
this._nWorkspacesChanged.bind(this)), 'workspace-switched', this._onWorkspaceSwitched.bind(this), GObject.ConnectFlags.AFTER,
workspaceManager.connect_after('workspace-switched', 'notify::layout-rows', this._updateThumbnailVisibility.bind(this),
this._onWorkspaceSwitched.bind(this)), this);
workspaceManager.connect('notify::layout-rows',
this._updateThumbnailVisibility.bind(this)),
];
this.connect('scroll-event', this._onScrollEvent.bind(this)); this.connect('scroll-event', this._onScrollEvent.bind(this));
this._updateMenu(); this._updateMenu();
@@ -313,20 +293,8 @@ export class WorkspaceIndicator extends PanelMenu.Button {
this._updateThumbnailVisibility(); this._updateThumbnailVisibility();
this._settings = new Gio.Settings({schema_id: 'org.gnome.desktop.wm.preferences'}); this._settings = new Gio.Settings({schema_id: 'org.gnome.desktop.wm.preferences'});
this._settingsChangedId = this._settings.connect( this._settings.connectObject('changed::workspace-names',
'changed::workspace-names', this._updateMenuLabels.bind(this)); () => this._updateMenuLabels(), this);
}
_onDestroy() {
for (let i = 0; i < this._workspaceManagerSignals.length; i++)
global.workspace_manager.disconnect(this._workspaceManagerSignals[i]);
if (this._settingsChangedId) {
this._settings.disconnect(this._settingsChangedId);
this._settingsChangedId = 0;
}
super._onDestroy();
} }
_updateThumbnailVisibility() { _updateThumbnailVisibility() {

View File

@@ -132,17 +132,10 @@ class MyWorkspacesView extends WorkspacesView.WorkspacesView {
this._pickWorkspace = false; this._pickWorkspace = false;
this._pickWindow = false; this._pickWindow = false;
this._keyPressEventId = global.stage.connect(
global.stage.connect('key-press-event', this._onKeyPress.bind(this)); 'key-press-event', this._onKeyPress.bind(this),
this._keyReleaseEventId = 'key-release-event', this._onKeyRelease.bind(this),
global.stage.connect('key-release-event', this._onKeyRelease.bind(this)); this);
}
_onDestroy() {
super._onDestroy();
global.stage.disconnect(this._keyPressEventId);
global.stage.disconnect(this._keyReleaseEventId);
} }
_hideTooltips() { _hideTooltips() {

View File

@@ -36,20 +36,17 @@ class WindowPreview extends St.Button {
this._window = window; this._window = window;
this.connect('destroy', this._onDestroy.bind(this)); this._window.connectObject(
'size-changed', () => this.queue_relayout(),
this._sizeChangedId = this._window.connect('size-changed', 'position-changed', () => {
() => this.queue_relayout());
this._positionChangedId = this._window.connect('position-changed',
() => {
this._updateVisible(); this._updateVisible();
this.queue_relayout(); this.queue_relayout();
}); },
this._minimizedChangedId = this._window.connect('notify::minimized', 'notify::minimized', this._updateVisible.bind(this),
this._updateVisible.bind(this)); this);
this._focusChangedId = global.display.connect('notify::focus-window', global.display.connectObject('notify::focus-window',
this._onFocusChanged.bind(this)); this._onFocusChanged.bind(this), this);
this._onFocusChanged(); this._onFocusChanged();
} }
@@ -58,13 +55,6 @@ class WindowPreview extends St.Button {
return this._window; return this._window;
} }
_onDestroy() {
this._window.disconnect(this._sizeChangedId);
this._window.disconnect(this._positionChangedId);
this._window.disconnect(this._minimizedChangedId);
global.display.disconnect(this._focusChangedId);
}
_onFocusChanged() { _onFocusChanged() {
if (global.display.focus_window === this._window) if (global.display.focus_window === this._window)
this.add_style_class_name('active'); this.add_style_class_name('active');
@@ -145,16 +135,13 @@ class WorkspaceThumbnail extends St.Button {
let workspaceManager = global.workspace_manager; let workspaceManager = global.workspace_manager;
this._workspace = workspaceManager.get_workspace_by_index(index); this._workspace = workspaceManager.get_workspace_by_index(index);
this._windowAddedId = this._workspace.connect('window-added', this._workspace.connectObject(
(ws, window) => { 'window-added', (ws, window) => this._addWindow(window),
this._addWindow(window); 'window-removed', (ws, window) => this._removeWindow(window),
}); this);
this._windowRemovedId = this._workspace.connect('window-removed',
(ws, window) => { global.display.connectObject('restacked',
this._removeWindow(window); this._onRestacked.bind(this), this);
});
this._restackedId = global.display.connect('restacked',
this._onRestacked.bind(this));
this._workspace.list_windows().forEach(w => this._addWindow(w)); this._workspace.list_windows().forEach(w => this._addWindow(w));
this._onRestacked(); this._onRestacked();
@@ -252,10 +239,6 @@ class WorkspaceThumbnail extends St.Button {
_onDestroy() { _onDestroy() {
this._tooltip.destroy(); this._tooltip.destroy();
this._workspace.disconnect(this._windowAddedId);
this._workspace.disconnect(this._windowRemovedId);
global.display.disconnect(this._restackedId);
} }
} }
@@ -297,14 +280,11 @@ class WorkspaceIndicator extends PanelMenu.Button {
this._workspaceSection = new PopupMenu.PopupMenuSection(); this._workspaceSection = new PopupMenu.PopupMenuSection();
this.menu.addMenuItem(this._workspaceSection); this.menu.addMenuItem(this._workspaceSection);
this._workspaceManagerSignals = [ workspaceManager.connectObject(
workspaceManager.connect_after('notify::n-workspaces', 'notify::n-workspaces', this._nWorkspacesChanged.bind(this), GObject.ConnectFlags.AFTER,
this._nWorkspacesChanged.bind(this)), 'workspace-switched', this._onWorkspaceSwitched.bind(this), GObject.ConnectFlags.AFTER,
workspaceManager.connect_after('workspace-switched', 'notify::layout-rows', this._updateThumbnailVisibility.bind(this),
this._onWorkspaceSwitched.bind(this)), this);
workspaceManager.connect('notify::layout-rows',
this._updateThumbnailVisibility.bind(this)),
];
this.connect('scroll-event', this._onScrollEvent.bind(this)); this.connect('scroll-event', this._onScrollEvent.bind(this));
this._thumbnailsBox.connect('scroll-event', this._onScrollEvent.bind(this)); this._thumbnailsBox.connect('scroll-event', this._onScrollEvent.bind(this));
@@ -313,20 +293,11 @@ class WorkspaceIndicator extends PanelMenu.Button {
this._updateThumbnailVisibility(); this._updateThumbnailVisibility();
this._settings = new Gio.Settings({schema_id: WORKSPACE_SCHEMA}); this._settings = new Gio.Settings({schema_id: WORKSPACE_SCHEMA});
this._settingsChangedId = this._settings.connect( this._settings.connectObject(`changed::${WORKSPACE_KEY}`,
`changed::${WORKSPACE_KEY}`, this._updateMenuLabels.bind(this), this);
this._updateMenuLabels.bind(this));
} }
_onDestroy() { _onDestroy() {
for (let i = 0; i < this._workspaceManagerSignals.length; i++)
global.workspace_manager.disconnect(this._workspaceManagerSignals[i]);
if (this._settingsChangedId) {
this._settings.disconnect(this._settingsChangedId);
this._settingsChangedId = 0;
}
Main.panel.set_offscreen_redirect(Clutter.OffscreenRedirect.ALWAYS); Main.panel.set_offscreen_redirect(Clutter.OffscreenRedirect.ALWAYS);
super._onDestroy(); super._onDestroy();