Skip to content

Commit

Permalink
Misc: Use connectObject instead of connect
Browse files Browse the repository at this point in the history
so that we don't need to track the signals ourselves with a variable.
  • Loading branch information
Leleat committed Apr 7, 2024
1 parent 773e423 commit e9a68e7
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ class AlwaysActiveWindowHint extends Hint {
super._init();

this._window = null;
this._signalIds = [];

this._updateGeometry();
this._updateStyle();
Expand Down Expand Up @@ -271,8 +270,8 @@ class AlwaysActiveWindowHint extends Hint {

_reset() {
this._cancelShowLater();
this._signalIds.forEach(id => this._window.disconnect(id));
this._signalIds = [];

this._window?.disconnectObject(this);
this._window = null;
}

Expand All @@ -296,8 +295,16 @@ class AlwaysActiveWindowHint extends Hint {
}

this._window = window;
this._signalIds.push(window.connect('position-changed', () => this._updateGeometry()));
this._signalIds.push(window.connect('size-changed', () => this._updateGeometry()));
this._window.connectObject(
'position-changed',
() => this._updateGeometry(),
this
);
this._window.connectObject(
'size-changed',
() => this._updateGeometry(),
this
);

// Don't show hint on maximzed/fullscreen windows
if (window.is_fullscreen() || Twm.isMaximized(window)) {
Expand Down
28 changes: 17 additions & 11 deletions tiling-assistant@leleat-on-github/src/extension/moveHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ export default class TilingMoveHandler {
constructor() {
const moveOps = [Meta.GrabOp.MOVING, Meta.GrabOp.KEYBOARD_MOVING];

this._displaySignals = [];
const g1Id = global.display.connect('grab-op-begin', (src, window, grabOp) => {
grabOp &= ~1024; // META_GRAB_OP_WINDOW_FLAG_UNCONSTRAINED

if (window && moveOps.includes(grabOp))
this._onMoveStarted(window, grabOp);
});
this._displaySignals.push(g1Id);
global.display.connectObject(
'grab-op-begin',
(src, window, grabOp) => {
grabOp &= ~1024; // META_GRAB_OP_WINDOW_FLAG_UNCONSTRAINED

if (window && moveOps.includes(grabOp))
this._onMoveStarted(window, grabOp);
},
this
);

const wId = global.display.connect('window-entered-monitor', this._onMonitorEntered.bind(this));
this._displaySignals.push(wId);
global.display.connectObject(
'window-entered-monitor',
this._onMonitorEntered.bind(this),
this
);

// Save the windows, which need to make space for the
// grabbed window (this is for the so called 'adaptive mode'):
Expand Down Expand Up @@ -82,7 +87,8 @@ export default class TilingMoveHandler {
this._wmPrefs.disconnectObject(this);
this._wmPrefs = null;

this._displaySignals.forEach(sId => global.display.disconnect(sId));
global.display.disconnectObject(this);

this._tilePreview.destroy();

if (this._latestMonitorLockTimerId) {
Expand Down
83 changes: 54 additions & 29 deletions tiling-assistant@leleat-on-github/src/extension/resizeHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,27 @@ export default class TilingResizeHandler {
}
};

const g1 = global.display.connect('grab-op-begin', (d, window, grabOp) => {
global.display.connectObject(
'grab-op-begin',
(d, window, grabOp) => {
grabOp &= ~1024; // META_GRAB_OP_WINDOW_FLAG_UNCONSTRAINED

if (window && isResizing(grabOp))
this._onResizeStarted(window, grabOp);
});
const g2 = global.display.connect('grab-op-end', (d, window, grabOp) => {
},
this
);
global.display.connectObject(
'grab-op-end',
(d, window, grabOp) => {
grabOp &= ~1024; // META_GRAB_OP_WINDOW_FLAG_UNCONSTRAINED

if (window && isResizing(grabOp))
this._onResizeFinished(window, grabOp);
});
this._displaySignals = [];
this._displaySignals.push(g1);
this._displaySignals.push(g2);
},
this
);

this._sizeChangedId = 0;
this._preGrabRects = new Map();
// Save the windows, which are to be resized (passively) along the
// actively grabbed one, and a resizeOp. A resizeOp saves the side
Expand All @@ -64,7 +68,7 @@ export default class TilingResizeHandler {
}

destroy() {
this._displaySignals.forEach(sId => global.display.disconnect(sId));
global.display.disconnectObject(this);
}

_onResizeStarted(window, grabOp) {
Expand Down Expand Up @@ -147,8 +151,11 @@ export default class TilingResizeHandler {
resizeOp && this._resizeOps.set(otherWindow, resizeOp);
}

this._sizeChangedId = window.connect('size-changed',
this._onResizing.bind(this, window, grabOp, null));
window.connectObject(
'size-changed',
this._onResizing.bind(this, window, grabOp, null),
this
);
break;

case Meta.GrabOp.RESIZING_S:
Expand All @@ -163,8 +170,11 @@ export default class TilingResizeHandler {
resizeOp && this._resizeOps.set(otherWindow, resizeOp);
}

this._sizeChangedId = window.connect('size-changed',
this._onResizing.bind(this, window, grabOp, null));
window.connectObject(
'size-changed',
this._onResizing.bind(this, window, grabOp, null),
this
);
break;

case Meta.GrabOp.RESIZING_E:
Expand All @@ -179,8 +189,11 @@ export default class TilingResizeHandler {
resizeOp && this._resizeOps.set(otherWindow, resizeOp);
}

this._sizeChangedId = window.connect('size-changed',
this._onResizing.bind(this, window, null, grabOp));
window.connectObject(
'size-changed',
this._onResizing.bind(this, window, null, grabOp),
this
);
break;

case Meta.GrabOp.RESIZING_W:
Expand All @@ -195,8 +208,11 @@ export default class TilingResizeHandler {
resizeOp && this._resizeOps.set(otherWindow, resizeOp);
}

this._sizeChangedId = window.connect('size-changed',
this._onResizing.bind(this, window, null, grabOp));
window.connectObject(
'size-changed',
this._onResizing.bind(this, window, null, grabOp),
this
);
break;

// Resizing intercardinal directions:
Expand All @@ -212,8 +228,11 @@ export default class TilingResizeHandler {
resizeOp && this._resizeOps.set(otherWindow, resizeOp);
}

this._sizeChangedId = window.connect('size-changed',
this._onResizing.bind(this, window, Meta.GrabOp.RESIZING_N, Meta.GrabOp.RESIZING_W));
window.connectObject(
'size-changed',
this._onResizing.bind(this, window, Meta.GrabOp.RESIZING_N, Meta.GrabOp.RESIZING_W),
this
);
break;

case Meta.GrabOp.RESIZING_NE:
Expand All @@ -228,8 +247,11 @@ export default class TilingResizeHandler {
resizeOp && this._resizeOps.set(otherWindow, resizeOp);
}

this._sizeChangedId = window.connect('size-changed',
this._onResizing.bind(this, window, Meta.GrabOp.RESIZING_N, Meta.GrabOp.RESIZING_E));
window.connectObject(
'size-changed',
this._onResizing.bind(this, window, Meta.GrabOp.RESIZING_N, Meta.GrabOp.RESIZING_E),
this
);
break;

case Meta.GrabOp.RESIZING_SW:
Expand All @@ -244,8 +266,11 @@ export default class TilingResizeHandler {
resizeOp && this._resizeOps.set(otherWindow, resizeOp);
}

this._sizeChangedId = window.connect('size-changed',
this._onResizing.bind(this, window, Meta.GrabOp.RESIZING_S, Meta.GrabOp.RESIZING_W));
window.connectObject(
'size-changed',
this._onResizing.bind(this, window, Meta.GrabOp.RESIZING_S, Meta.GrabOp.RESIZING_W),
this
);
break;

case Meta.GrabOp.RESIZING_SE:
Expand All @@ -260,17 +285,17 @@ export default class TilingResizeHandler {
resizeOp && this._resizeOps.set(otherWindow, resizeOp);
}

this._sizeChangedId = window.connect('size-changed',
this._onResizing.bind(this, window, Meta.GrabOp.RESIZING_S, Meta.GrabOp.RESIZING_E));
window.connectObject(
'size-changed',
this._onResizing.bind(this, window, Meta.GrabOp.RESIZING_S, Meta.GrabOp.RESIZING_E),
this
);
}
}

// Update the windows' tiledRects
_onResizeFinished(window, grabOp) {
if (this._sizeChangedId) {
window.disconnect(this._sizeChangedId);
this._sizeChangedId = 0;
}
window.disconnectObject(this);

if (!window.isTiled)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@ export class TilingWindowManager {
// [windowIds]
this._unmanagingWindows = [];

this._wsAddedId = global.workspace_manager.connect('workspace-added', this._onWorkspaceAdded.bind(this));
this._wsRemovedId = global.workspace_manager.connect('workspace-removed', this._onWorkspaceRemoved.bind(this));
global.workspace_manager.connectObject(
'workspace-added',
this._onWorkspaceAdded.bind(this),
this
);
global.workspace_manager.connectObject(
'workspace-removed',
this._onWorkspaceRemoved.bind(this),
this
);
}

static destroy() {
this._signals.destroy();
this._signals = null;

global.workspace_manager.disconnect(this._wsAddedId);
global.workspace_manager.disconnect(this._wsRemovedId);
global.workspace_manager.disconnectObject(this);

this._tileGroups.clear();
this._unmanagingWindows = [];
Expand Down

0 comments on commit e9a68e7

Please sign in to comment.