diff --git a/extensions/apps-menu/extension.js b/extensions/apps-menu/extension.js index 2e4738c5..999335cb 100644 --- a/extensions/apps-menu/extension.js +++ b/extensions/apps-menu/extension.js @@ -51,11 +51,8 @@ class ApplicationMenuItem extends PopupMenu.PopupBaseMenuItem { this.label_actor = appLabel; let textureCache = St.TextureCache.get_default(); - let iconThemeChangedId = textureCache.connect('icon-theme-changed', - this._updateIcon.bind(this)); - this.connect('destroy', () => { - textureCache.disconnect(iconThemeChangedId); - }); + textureCache.connectObject('icon-theme-changed', + () => this._updateIcon(), this); this._updateIcon(); this._delegate = this; @@ -274,9 +271,7 @@ class DesktopTarget extends EventEmitter { _setDesktop(desktop) { if (this._desktop) { - this._desktop.disconnect(this._desktopDestroyedId); - this._desktopDestroyedId = 0; - + this._desktop.disconnectObject(this); delete this._desktop._delegate; } @@ -284,9 +279,9 @@ class DesktopTarget extends EventEmitter { this.emit('desktop-changed'); if (this._desktop) { - this._desktopDestroyedId = this._desktop.connect('destroy', () => { + this._desktop.connectObject('destroy', () => { this._setDesktop(null); - }); + }, this); this._desktop._delegate = this; } } @@ -326,10 +321,7 @@ class DesktopTarget extends EventEmitter { } destroy() { - if (this._windowAddedId) - global.window_group.disconnect(this._windowAddedId); - this._windowAddedId = 0; - + global.window_group.disconnectObject(this); this._setDesktop(null); } @@ -391,12 +383,11 @@ class ApplicationsButton extends PanelMenu.Button { this.name = 'panelApplications'; this.label_actor = this._label; - this._showingId = Main.overview.connect('showing', () => { - this.add_accessible_state(Atk.StateType.CHECKED); - }); - this._hidingId = Main.overview.connect('hiding', () => { - this.remove_accessible_state(Atk.StateType.CHECKED); - }); + Main.overview.connect( + 'showing', () => this.add_accessible_state(Atk.StateType.CHECKED), + 'hiding', () => this.remove_accessible_state(Atk.StateType.CHECKED), + this); + Main.wm.addKeybinding( 'apps-menu-toggle-menu', ExtensionUtils.getSettings(), @@ -415,15 +406,15 @@ class ApplicationsButton extends PanelMenu.Button { }); this._tree = new GMenu.Tree({menu_basename: 'applications.menu'}); - this._treeChangedId = this._tree.connect('changed', - this._onTreeChanged.bind(this)); + this._tree.connectObject('changed', + () => this._onTreeChanged(), this); this._applicationsButtons = new Map(); this.reloadFlag = false; this._createLayout(); this._display(); - this._installedChangedId = appSys.connect('installed-changed', - this._onTreeChanged.bind(this)); + appSys.connectObject('installed-changed', + () => this._onTreeChanged(), this); } _onTreeChanged() { @@ -447,11 +438,7 @@ class ApplicationsButton extends PanelMenu.Button { _onDestroy() { super._onDestroy(); - Main.overview.disconnect(this._showingId); - Main.overview.disconnect(this._hidingId); - appSys.disconnect(this._installedChangedId); - this._tree.disconnect(this._treeChangedId); - this._tree = null; + delete this._tree; Main.wm.removeKeybinding('apps-menu-toggle-menu'); diff --git a/extensions/auto-move-windows/extension.js b/extensions/auto-move-windows/extension.js index c97c825d..53d614a4 100644 --- a/extensions/auto-move-windows/extension.js +++ b/extensions/auto-move-windows/extension.js @@ -13,9 +13,8 @@ class WindowMover { this._appConfigs = new Map(); this._appData = new Map(); - this._appsChangedId = - this._appSystem.connect('installed-changed', - this._updateAppData.bind(this)); + this._appSystem.connectObject('installed-changed', + () => this._updateAppData(), this); this._settings.connect('changed', this._updateAppConfigs.bind(this)); this._updateAppConfigs(); @@ -37,7 +36,7 @@ class WindowMover { let removedApps = [...this._appData.keys()] .filter(a => !ids.includes(a.id)); removedApps.forEach(app => { - app.disconnect(this._appData.get(app).windowsChangedId); + app.disconnectObject(this); this._appData.delete(app); }); @@ -45,21 +44,14 @@ class WindowMover { .map(id => this._appSystem.lookup_app(id)) .filter(app => app && !this._appData.has(app)); addedApps.forEach(app => { - let data = { - windowsChangedId: app.connect('windows-changed', - this._appWindowsChanged.bind(this)), - moveWindowsId: 0, - windows: app.get_windows(), - }; - this._appData.set(app, data); + app.connectObject('window-changed', + this._appWindowsChanged.bind(this), this); + this._appData.set(app, {windows: app.get_windows()}); }); } destroy() { - if (this._appsChangedId) { - this._appSystem.disconnect(this._appsChangedId); - this._appsChangedId = 0; - } + this._appSystem.disconnectObject(this); if (this._settings) { this._settings.run_dispose(); diff --git a/extensions/drive-menu/extension.js b/extensions/drive-menu/extension.js index 57c10a4d..8e9f479d 100644 --- a/extensions/drive-menu/extension.js +++ b/extensions/drive-menu/extension.js @@ -50,19 +50,11 @@ class MountMenuItem extends PopupMenu.PopupBaseMenuItem { this.hide(); - this._changedId = mount.connect('changed', this._syncVisibility.bind(this)); + mount.connectObject('changed', + () => this._syncVisibility(), this); this._syncVisibility(); } - _onDestroy() { - if (this._changedId) { - this.mount.disconnect(this._changedId); - this._changedId = 0; - } - - super.destroy(); - } - async _isInteresting() { if (!this.mount.can_eject() && !this.mount.can_unmount()) return false; @@ -155,12 +147,12 @@ class DriveMenu extends PanelMenu.Button { this.add_child(icon); this._monitor = Gio.VolumeMonitor.get(); - this._addedId = this._monitor.connect('mount-added', - (monitor, mount) => this._addMount(mount)); - this._removedId = this._monitor.connect('mount-removed', (monitor, mount) => { - this._removeMount(mount); - this._updateMenuVisibility(); - }); + this._monitor.connectObject( + 'mount-added', (monitor, mount) => this._addMount(mount), + 'mount-removed', (monitor, mount) => { + this._removeMount(mount); + this._updateMenuVisibility(); + }, this); this._mounts = []; @@ -202,17 +194,6 @@ class DriveMenu extends PanelMenu.Button { } 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 { diff --git a/extensions/places-menu/extension.js b/extensions/places-menu/extension.js index 9c526361..159e61ad 100644 --- a/extensions/places-menu/extension.js +++ b/extensions/places-menu/extension.js @@ -52,17 +52,8 @@ class PlaceMenuItem extends PopupMenu.PopupBaseMenuItem { this.add_child(this._ejectButton); } - this._changedId = info.connect('changed', - this._propertiesChanged.bind(this)); - } - - destroy() { - if (this._changedId) { - this._info.disconnect(this._changedId); - this._changedId = 0; - } - - super.destroy(); + info.connectObject('changed', + this._propertiesChanged.bind(this), this); } activate(event) { diff --git a/extensions/places-menu/placeDisplay.js b/extensions/places-menu/placeDisplay.js index 304ccd74..7fd96757 100644 --- a/extensions/places-menu/placeDisplay.js +++ b/extensions/places-menu/placeDisplay.js @@ -260,15 +260,25 @@ export class PlacesManager extends EventEmitter { }; this._settings = new Gio.Settings({schema_id: BACKGROUND_SCHEMA}); - this._showDesktopIconsChangedId = this._settings.connect( - 'changed::show-desktop-icons', this._updateSpecials.bind(this)); + this._settings.connectObject('changed::show-desktop-icons', + () => this._updateSpecials(), this); this._updateSpecials(); /* * Show devices, code more or less ported from nautilus-places-sidebar.c */ 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._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() { - if (this._settings) - this._settings.disconnect(this._showDesktopIconsChangedId); + this._settings?.disconnectObject(this); this._settings = null; - for (let i = 0; i < this._volumeMonitorSignals.length; i++) - this._volumeMonitor.disconnect(this._volumeMonitorSignals[i]); + this._volumeMonitor.disconnectObject(this); if (this._monitor) this._monitor.cancel(); diff --git a/extensions/window-list/extension.js b/extensions/window-list/extension.js index 05528396..e233e096 100644 --- a/extensions/window-list/extension.js +++ b/extensions/window-list/extension.js @@ -57,10 +57,6 @@ class WindowContextMenu extends PopupMenu.PopupMenu { }); this.addMenuItem(this._minimizeItem); - this._notifyMinimizedId = this._metaWindow.connect( - 'notify::minimized', this._updateMinimizeItem.bind(this)); - this._updateMinimizeItem(); - this._maximizeItem = new PopupMenu.PopupMenuItem(''); this._maximizeItem.connect('activate', () => { if (this._metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH) @@ -70,21 +66,20 @@ class WindowContextMenu extends PopupMenu.PopupMenu { }); 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.connect('activate', () => { this._metaWindow.delete(global.get_current_time()); }); 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', () => { if (!this.isOpen) @@ -107,12 +102,6 @@ class WindowContextMenu extends PopupMenu.PopupMenu { this._maximizeItem.label.text = maximized ? _('Unmaximize') : _('Maximize'); } - - _onDestroy() { - this._metaWindow.disconnect(this._notifyMinimizedId); - this._metaWindow.disconnect(this._notifyMaximizedHId); - this._metaWindow.disconnect(this._notifyMaximizedVId); - } } class WindowTitle extends St.BoxLayout { @@ -136,20 +125,19 @@ class WindowTitle extends St.BoxLayout { this.add(this.label_actor); this._textureCache = St.TextureCache.get_default(); - this._iconThemeChangedId = this._textureCache.connect( - 'icon-theme-changed', this._updateIcon.bind(this)); - this._notifyWmClass = this._metaWindow.connect_after( - 'notify::wm-class', this._updateIcon.bind(this)); - this._notifyAppId = this._metaWindow.connect_after( - 'notify::gtk-application-id', this._updateIcon.bind(this)); + this._textureCache.connectObject('icon-theme-changed', + () => this._updateIcon(), this); + + this._metaWindow.connectObject( + 'notify::wm-class', + () => 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.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(); } @@ -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 { @@ -222,16 +202,16 @@ class BaseButton extends St.Button { this._contextMenuManager = new PopupMenu.PopupMenuManager(this); - this._switchWorkspaceId = global.window_manager.connect( - 'switch-workspace', this._updateVisibility.bind(this)); + global.window_manager.connectObject('switch-workspace', + () => this._updateVisibility(), this); if (this._perMonitor) { - this._windowEnteredMonitorId = global.display.connect( + global.display.connectObject( 'window-entered-monitor', - this._windowEnteredOrLeftMonitor.bind(this)); - this._windowLeftMonitorId = global.display.connect( + this._windowEnteredOrLeftMonitor.bind(this), 'window-left-monitor', - this._windowEnteredOrLeftMonitor.bind(this)); + this._windowEnteredOrLeftMonitor.bind(this), + this); } this._tooltip = new Tooltip(this, { @@ -397,16 +377,6 @@ class BaseButton extends St.Button { } _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(); } } @@ -420,9 +390,11 @@ class WindowButton extends BaseButton { super(perMonitor, monitorIndex); this.metaWindow = metaWindow; - this._skipTaskbarId = metaWindow.connect('notify::skip-taskbar', () => { - this._updateVisibility(); - }); + metaWindow.connectObject( + 'notify::skip-taskbar', () => this._updateVisibility(), + 'workspace-changed', () => this._updateVisibility(), + this); + this._updateVisibility(); this._windowTitle = new WindowTitle(this.metaWindow); @@ -436,11 +408,8 @@ class WindowButton extends BaseButton { this._contextMenuManager.addMenu(this._contextMenu); Main.uiGroup.add_actor(this._contextMenu.actor); - this._workspaceChangedId = this.metaWindow.connect( - 'workspace-changed', this._updateVisibility.bind(this)); - - this._notifyFocusId = global.display.connect( - 'notify::focus-window', this._updateStyle.bind(this)); + global.display.connectObject('notify::focus-window', + () => this._updateStyle(), this); this._updateStyle(); } @@ -484,9 +453,6 @@ class WindowButton extends BaseButton { _onDestroy() { super._onDestroy(); - this.metaWindow.disconnect(this._skipTaskbarId); - this.metaWindow.disconnect(this._workspaceChangedId); - global.display.disconnect(this._notifyFocusId); this._contextMenu.destroy(); } } @@ -603,18 +569,17 @@ class AppButton extends BaseButton { Main.uiGroup.add_actor(this._appContextMenu.actor); this._textureCache = St.TextureCache.get_default(); - this._iconThemeChangedId = - this._textureCache.connect('icon-theme-changed', () => { - this._icon.child = app.create_icon_texture(ICON_TEXTURE_SIZE); - }); + this._textureCache.connectObject('icon-theme-changed', () => { + this._icon.child = app.create_icon_texture(ICON_TEXTURE_SIZE); + }, this); - this._windowsChangedId = this.app.connect( - 'windows-changed', this._windowsChanged.bind(this)); + this.app.connectObject('windows-changed', + () => this._windowsChanged(), this); this._windowsChanged(); this._windowTracker = Shell.WindowTracker.get_default(); - this._notifyFocusId = this._windowTracker.connect( - 'notify::focus-app', this._updateStyle.bind(this)); + this._windowTracker.connectObject('notify::focus-app', + () => this._updateStyle(), this); this._updateStyle(); } @@ -734,9 +699,6 @@ class AppButton extends BaseButton { _onDestroy() { super._onDestroy(); - this._textureCache.disconnect(this._iconThemeChangedId); - this._windowTracker.disconnect(this._notifyFocusId); - this.app.disconnect(this._windowsChangedId); this._menu.destroy(); } } @@ -793,12 +755,12 @@ class WindowList extends St.Widget { indicatorsBox.add_child(this._workspaceIndicator.container); this._mutterSettings = new Gio.Settings({schema_id: 'org.gnome.mutter'}); - this._workspacesOnlyOnPrimaryChangedId = this._mutterSettings.connect( + this._mutterSettings.connectObject( 'changed::workspaces-only-on-primary', - this._updateWorkspaceIndicatorVisibility.bind(this)); - this._dynamicWorkspacesChangedId = this._mutterSettings.connect( + () => this._updateWorkspaceIndicatorVisibility(), 'changed::dynamic-workspaces', - this._updateWorkspaceIndicatorVisibility.bind(this)); + () => this._updateWorkspaceIndicatorVisibility(), + this); this._updateWorkspaceIndicatorVisibility(); this._menuManager = new PopupMenu.PopupMenuManager(this); @@ -816,59 +778,58 @@ class WindowList extends St.Widget { this._updatePosition(); this._appSystem = Shell.AppSystem.get_default(); - this._appStateChangedId = this._appSystem.connect( - 'app-state-changed', this._onAppStateChanged.bind(this)); + this._appSystem.connectObject('app-state-changed', + this._onAppStateChanged.bind(this), this); // Hack: OSK gesture is tied to visibility, piggy-back on that - this._keyboardVisiblechangedId = - Main.keyboard._bottomDragAction.connect('notify::enabled', - action => { - const visible = !action.enabled; - if (visible) { - Main.uiGroup.set_child_above_sibling( - this, Main.layoutManager.keyboardBox); - } else { - Main.uiGroup.set_child_above_sibling( - this, Main.layoutManager.panelBox); - } - this._updateKeyboardAnchor(); - }); + Main.keyboard._bottomDragAction.connectObject('notify::enabled', + action => { + const visible = !action.enabled; + if (visible) { + Main.uiGroup.set_child_above_sibling( + this, Main.layoutManager.keyboardBox); + } else { + Main.uiGroup.set_child_above_sibling( + this, Main.layoutManager.panelBox); + } + this._updateKeyboardAnchor(); + }, this); let workspaceManager = global.workspace_manager; - this._nWorkspacesChangedId = workspaceManager.connect( - 'notify::n-workspaces', this._updateWorkspaceIndicatorVisibility.bind(this)); + workspaceManager.connectObject('notify::n-workspaces', + () => this._updateWorkspaceIndicatorVisibility(), this); this._updateWorkspaceIndicatorVisibility(); - this._switchWorkspaceId = global.window_manager.connect( - 'switch-workspace', this._checkGrouping.bind(this)); + global.window_manager.connectObject('switch-workspace', + () => this._checkGrouping(), this); - this._overviewShowingId = Main.overview.connect('showing', () => { - this.hide(); - this._updateKeyboardAnchor(); - }); - - 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(); + Main.overview.connectObject( + 'showing', () => { + this.hide(); 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._windowCreatedId = global.display.connect( 'window-created', (dsp, win) => this._addWindow(win)); - this._dragBeginId = Main.xdndHandler.connect('drag-begin', - this._monitorDrag.bind(this)); - this._dragEndId = Main.xdndHandler.connect('drag-end', - this._stopMonitoringDrag.bind(this)); + Main.xdndHandler.connectObject( + 'drag-begin', () => this._monitorDrag(), + 'drag-end', () => this._stopMonitoringDrag(), + this); + this._dragMonitor = { dragMotion: this._onDragMotion.bind(this), }; @@ -1115,37 +1076,14 @@ class WindowList extends St.Widget { } _onDestroy() { - this._mutterSettings.disconnect(this._workspacesOnlyOnPrimaryChangedId); - this._mutterSettings.disconnect(this._dynamicWorkspacesChangedId); - this._workspaceIndicator.destroy(); 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.clear(); - Main.overview.disconnect(this._overviewShowingId); - Main.overview.disconnect(this._overviewHidingId); - - global.display.disconnect(this._fullscreenChangedId); - global.display.disconnect(this._windowCreatedId); - this._stopMonitoringDrag(); - Main.xdndHandler.disconnect(this._dragBeginId); - Main.xdndHandler.disconnect(this._dragEndId); this._settings.run_dispose(); @@ -1167,11 +1105,11 @@ export default class Extension { this._windowLists = []; this._settings = ExtensionUtils.getSettings(); - this._showOnAllMonitorsChangedId = this._settings.connect( - 'changed::show-on-all-monitors', this._buildWindowLists.bind(this)); + this._settings.connectObject('changed::show-on-all-monitors', + () => this._buildWindowLists(), this); - this._monitorsChangedId = Main.layoutManager.connect( - 'monitors-changed', this._buildWindowLists.bind(this)); + Main.layoutManager.connectObject('monitors-changed', + () => this._buildWindowLists(), this); Main.windowPicker = new WindowPicker(); @@ -1199,11 +1137,8 @@ export default class Extension { if (!this._windowLists) return; - this._settings.disconnect(this._showOnAllMonitorsChangedId); - this._showOnAllMonitorsChangedId = 0; - - Main.layoutManager.disconnect(this._monitorsChangedId); - this._monitorsChangedId = 0; + this._settings.disconnectObject(this); + Main.layoutManager.disconnectObject(this); this._windowLists.forEach(windowList => { windowList.hide(); diff --git a/extensions/window-list/windowPicker.js b/extensions/window-list/windowPicker.js index 6ca21526..17802c14 100644 --- a/extensions/window-list/windowPicker.js +++ b/extensions/window-list/windowPicker.js @@ -37,9 +37,8 @@ class MyWorkspacesDisplay extends WorkspacesDisplay { this._workspaceAdjustment = workspaceAdjustment; this._workspaceAdjustment.actor = this; - this._nWorkspacesChangedId = - workspaceManager.connect('notify::n-workspaces', - this._updateAdjustment.bind(this)); + workspaceManager.connectObject('notify::n-workspaces', + () => this._updateAdjustment(), this); this.add_constraint( new Layout.MonitorConstraint({ @@ -72,14 +71,6 @@ class MyWorkspacesDisplay extends WorkspacesDisplay { 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 { @@ -90,25 +81,16 @@ class MyWorkspace extends Workspace.Workspace { constructor(...args) { super(...args); - this._adjChangedId = - this._overviewAdjustment.connect('notify::value', () => { - const {value: progress} = this._overviewAdjustment; - const brightness = 1 - (1 - VIGNETTE_BRIGHTNESS) * progress; - for (const bg of this._background?._backgroundGroup ?? []) { - bg.content.set({ - vignette: true, - brightness, - }); - } - }); - } - - _onDestroy() { - super._onDestroy(); - - if (this._adjChangedId) - this._overviewAdjustment.disconnect(this._adjChangedId); - this._adjChangedId = 0; + this._overviewAdjustment.connectObject('notify::value', () => { + const {value: progress} = this._overviewAdjustment; + const brightness = 1 - (1 - VIGNETTE_BRIGHTNESS) * progress; + for (const bg of this._background?._backgroundGroup ?? []) { + bg.content.set({ + vignette: true, + brightness, + }); + } + }, this); } } @@ -166,7 +148,6 @@ export class WindowPicker extends Clutter.Actor { this._visible = false; this._modal = false; - this._overlayKeyId = 0; this._stageKeyPressId = 0; this._adjustment = new OverviewAdjustment(this); @@ -188,12 +169,12 @@ export class WindowPicker extends Clutter.Actor { if (!Main.sessionMode.hasOverview) { this._injectBackgroundShade(); - this._overlayKeyId = global.display.connect('overlay-key', () => { + global.display.connectObject('overlay-key', () => { if (!this._visible) this.open(); else this.close(); - }); + }, this); } } @@ -314,10 +295,6 @@ export class WindowPicker extends Clutter.Actor { if (this._origWorkspaceBackground) Workspace.WorkspaceBackground = this._origWorkspaceBackground; - if (this._overlayKeyId) - global.display.disconnect(this._overlayKeyId); - this._overlayKeyId = 0; - if (this._stageKeyPressId) global.stage.disconnect(this._stageKeyPressId); this._stageKeyPressId = 0; diff --git a/extensions/window-list/workspaceIndicator.js b/extensions/window-list/workspaceIndicator.js index ff278685..1f78db0a 100644 --- a/extensions/window-list/workspaceIndicator.js +++ b/extensions/window-list/workspaceIndicator.js @@ -32,20 +32,17 @@ class WindowPreview extends St.Button { this._window = window; - this.connect('destroy', this._onDestroy.bind(this)); - - this._sizeChangedId = this._window.connect('size-changed', - () => this.queue_relayout()); - this._positionChangedId = this._window.connect('position-changed', - () => { + this._window.connectObject( + 'size-changed', () => this.queue_relayout(), + 'position-changed', () => { this._updateVisible(); this.queue_relayout(); - }); - this._minimizedChangedId = this._window.connect('notify::minimized', - this._updateVisible.bind(this)); + }, + 'notify::minimized', this._updateVisible.bind(this), + this); - this._focusChangedId = global.display.connect('notify::focus-window', - this._onFocusChanged.bind(this)); + global.display.connectObject('notify::focus-window', + this._onFocusChanged.bind(this), this); this._onFocusChanged(); } @@ -54,13 +51,6 @@ class WindowPreview extends St.Button { 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() { if (global.display.focus_window === this._window) this.add_style_class_name('active'); @@ -141,16 +131,13 @@ class WorkspaceThumbnail extends St.Button { let workspaceManager = global.workspace_manager; this._workspace = workspaceManager.get_workspace_by_index(index); - this._windowAddedId = this._workspace.connect('window-added', - (ws, window) => { - this._addWindow(window); - }); - this._windowRemovedId = this._workspace.connect('window-removed', - (ws, window) => { - this._removeWindow(window); - }); - this._restackedId = global.display.connect('restacked', - this._onRestacked.bind(this)); + this._workspace.connectObject( + 'window-added', (ws, window) => this._addWindow(window), + 'window-removed', (ws, window) => this._removeWindow(window), + this); + + global.display.connectObject('restacked', + this._onRestacked.bind(this), this); this._workspace.list_windows().forEach(w => this._addWindow(w)); this._onRestacked(); @@ -248,10 +235,6 @@ class WorkspaceThumbnail extends St.Button { _onDestroy() { 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._workspaceManagerSignals = [ - workspaceManager.connect('notify::n-workspaces', - this._nWorkspacesChanged.bind(this)), - workspaceManager.connect_after('workspace-switched', - this._onWorkspaceSwitched.bind(this)), - workspaceManager.connect('notify::layout-rows', - this._updateThumbnailVisibility.bind(this)), - ]; + workspaceManager.connectObject( + 'notify::n-workspaces', this._nWorkspacesChanged.bind(this), GObject.ConnectFlags.AFTER, + 'workspace-switched', this._onWorkspaceSwitched.bind(this), GObject.ConnectFlags.AFTER, + 'notify::layout-rows', this._updateThumbnailVisibility.bind(this), + this); this.connect('scroll-event', this._onScrollEvent.bind(this)); this._updateMenu(); @@ -313,20 +293,8 @@ export class WorkspaceIndicator extends PanelMenu.Button { this._updateThumbnailVisibility(); this._settings = new Gio.Settings({schema_id: 'org.gnome.desktop.wm.preferences'}); - this._settingsChangedId = this._settings.connect( - 'changed::workspace-names', this._updateMenuLabels.bind(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(); + this._settings.connectObject('changed::workspace-names', + () => this._updateMenuLabels(), this); } _updateThumbnailVisibility() { diff --git a/extensions/windowsNavigator/extension.js b/extensions/windowsNavigator/extension.js index cd2dfd74..83b933ff 100644 --- a/extensions/windowsNavigator/extension.js +++ b/extensions/windowsNavigator/extension.js @@ -132,17 +132,10 @@ class MyWorkspacesView extends WorkspacesView.WorkspacesView { this._pickWorkspace = false; this._pickWindow = false; - this._keyPressEventId = - global.stage.connect('key-press-event', this._onKeyPress.bind(this)); - this._keyReleaseEventId = - global.stage.connect('key-release-event', this._onKeyRelease.bind(this)); - } - - _onDestroy() { - super._onDestroy(); - - global.stage.disconnect(this._keyPressEventId); - global.stage.disconnect(this._keyReleaseEventId); + global.stage.connect( + 'key-press-event', this._onKeyPress.bind(this), + 'key-release-event', this._onKeyRelease.bind(this), + this); } _hideTooltips() { diff --git a/extensions/workspace-indicator/extension.js b/extensions/workspace-indicator/extension.js index effa8f01..d6543599 100644 --- a/extensions/workspace-indicator/extension.js +++ b/extensions/workspace-indicator/extension.js @@ -36,20 +36,17 @@ class WindowPreview extends St.Button { this._window = window; - this.connect('destroy', this._onDestroy.bind(this)); - - this._sizeChangedId = this._window.connect('size-changed', - () => this.queue_relayout()); - this._positionChangedId = this._window.connect('position-changed', - () => { + this._window.connectObject( + 'size-changed', () => this.queue_relayout(), + 'position-changed', () => { this._updateVisible(); this.queue_relayout(); - }); - this._minimizedChangedId = this._window.connect('notify::minimized', - this._updateVisible.bind(this)); + }, + 'notify::minimized', this._updateVisible.bind(this), + this); - this._focusChangedId = global.display.connect('notify::focus-window', - this._onFocusChanged.bind(this)); + global.display.connectObject('notify::focus-window', + this._onFocusChanged.bind(this), this); this._onFocusChanged(); } @@ -58,13 +55,6 @@ class WindowPreview extends St.Button { 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() { if (global.display.focus_window === this._window) this.add_style_class_name('active'); @@ -145,16 +135,13 @@ class WorkspaceThumbnail extends St.Button { let workspaceManager = global.workspace_manager; this._workspace = workspaceManager.get_workspace_by_index(index); - this._windowAddedId = this._workspace.connect('window-added', - (ws, window) => { - this._addWindow(window); - }); - this._windowRemovedId = this._workspace.connect('window-removed', - (ws, window) => { - this._removeWindow(window); - }); - this._restackedId = global.display.connect('restacked', - this._onRestacked.bind(this)); + this._workspace.connectObject( + 'window-added', (ws, window) => this._addWindow(window), + 'window-removed', (ws, window) => this._removeWindow(window), + this); + + global.display.connectObject('restacked', + this._onRestacked.bind(this), this); this._workspace.list_windows().forEach(w => this._addWindow(w)); this._onRestacked(); @@ -252,10 +239,6 @@ class WorkspaceThumbnail extends St.Button { _onDestroy() { 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.menu.addMenuItem(this._workspaceSection); - this._workspaceManagerSignals = [ - workspaceManager.connect_after('notify::n-workspaces', - this._nWorkspacesChanged.bind(this)), - workspaceManager.connect_after('workspace-switched', - this._onWorkspaceSwitched.bind(this)), - workspaceManager.connect('notify::layout-rows', - this._updateThumbnailVisibility.bind(this)), - ]; + workspaceManager.connectObject( + 'notify::n-workspaces', this._nWorkspacesChanged.bind(this), GObject.ConnectFlags.AFTER, + 'workspace-switched', this._onWorkspaceSwitched.bind(this), GObject.ConnectFlags.AFTER, + 'notify::layout-rows', this._updateThumbnailVisibility.bind(this), + this); this.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._settings = new Gio.Settings({schema_id: WORKSPACE_SCHEMA}); - this._settingsChangedId = this._settings.connect( - `changed::${WORKSPACE_KEY}`, - this._updateMenuLabels.bind(this)); + this._settings.connectObject(`changed::${WORKSPACE_KEY}`, + this._updateMenuLabels.bind(this), 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; - } - Main.panel.set_offscreen_redirect(Clutter.OffscreenRedirect.ALWAYS); super._onDestroy();