2023-07-10 05:53:00 -04:00
|
|
|
import GObject from 'gi://GObject';
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
|
2022-03-05 18:30:16 -05:00
|
|
|
const destroyableTypes = [];
|
|
|
|
|
2022-03-04 17:32:24 -05:00
|
|
|
/**
|
|
|
|
* @private
|
2023-08-06 21:15:51 -04:00
|
|
|
* @param {object} obj - an object
|
2022-03-04 17:32:24 -05:00
|
|
|
* @returns {bool} - true if obj has a 'destroy' GObject signal
|
|
|
|
*/
|
|
|
|
function _hasDestroySignal(obj) {
|
2022-03-05 18:30:16 -05:00
|
|
|
return destroyableTypes.some(type => obj instanceof type);
|
2022-03-04 17:32:24 -05:00
|
|
|
}
|
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export const TransientSignalHolder = GObject.registerClass(
|
2022-03-04 17:32:24 -05:00
|
|
|
class TransientSignalHolder extends GObject.Object {
|
|
|
|
static [GObject.signals] = {
|
|
|
|
'destroy': {},
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(owner) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
if (_hasDestroySignal(owner))
|
|
|
|
owner.connectObject('destroy', () => this.destroy(), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
this.emit('destroy');
|
|
|
|
}
|
|
|
|
});
|
2022-03-05 18:30:16 -05:00
|
|
|
registerDestroyableType(TransientSignalHolder);
|
2022-03-04 17:32:24 -05:00
|
|
|
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
class SignalManager {
|
|
|
|
/**
|
|
|
|
* @returns {SignalManager} - the SignalManager singleton
|
|
|
|
*/
|
|
|
|
static getDefault() {
|
|
|
|
if (!this._singleton)
|
|
|
|
this._singleton = new SignalManager();
|
|
|
|
return this._singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor() {
|
2022-09-02 12:37:13 -04:00
|
|
|
this._signalTrackers = new Map();
|
2022-08-17 10:30:07 -04:00
|
|
|
|
|
|
|
global.connect_after('shutdown', () => {
|
|
|
|
[...this._signalTrackers.values()].forEach(
|
|
|
|
tracker => tracker.destroy());
|
|
|
|
this._signalTrackers.clear();
|
|
|
|
});
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-08-06 21:15:51 -04:00
|
|
|
* @param {object} obj - object to get signal tracker for
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
* @returns {SignalTracker} - the signal tracker for object
|
|
|
|
*/
|
|
|
|
getSignalTracker(obj) {
|
2022-07-06 11:44:48 -04:00
|
|
|
let signalTracker = this._signalTrackers.get(obj);
|
|
|
|
if (signalTracker === undefined) {
|
|
|
|
signalTracker = new SignalTracker(obj);
|
|
|
|
this._signalTrackers.set(obj, signalTracker);
|
|
|
|
}
|
|
|
|
return signalTracker;
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
}
|
2022-08-28 22:19:28 -04:00
|
|
|
|
|
|
|
/**
|
2023-08-06 21:15:51 -04:00
|
|
|
* @param {object} obj - object to get signal tracker for
|
2022-08-28 22:19:28 -04:00
|
|
|
* @returns {?SignalTracker} - the signal tracker for object if it exists
|
|
|
|
*/
|
|
|
|
maybeGetSignalTracker(obj) {
|
|
|
|
return this._signalTrackers.get(obj) ?? null;
|
|
|
|
}
|
2022-08-28 18:03:50 -04:00
|
|
|
|
|
|
|
/*
|
2023-08-06 21:15:51 -04:00
|
|
|
* @param {object} obj - object to remove signal tracker for
|
2022-08-28 18:03:50 -04:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
removeSignalTracker(obj) {
|
|
|
|
this._signalTrackers.delete(obj);
|
|
|
|
}
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class SignalTracker {
|
|
|
|
/**
|
2023-08-06 21:15:51 -04:00
|
|
|
* @param {object=} owner - object that owns the tracker
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
*/
|
|
|
|
constructor(owner) {
|
2022-03-04 17:32:24 -05:00
|
|
|
if (_hasDestroySignal(owner))
|
2022-03-04 17:34:59 -05:00
|
|
|
this._ownerDestroyId = owner.connect_after('destroy', () => this.clear());
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
|
|
|
|
this._owner = owner;
|
|
|
|
this._map = new Map();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef SignalData
|
|
|
|
* @property {number[]} ownerSignals - a list of handler IDs
|
|
|
|
* @property {number} destroyId - destroy handler ID of tracked object
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
2023-08-06 21:15:51 -04:00
|
|
|
* @param {object} obj - a tracked object
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
* @returns {SignalData} - signal data for object
|
|
|
|
*/
|
|
|
|
_getSignalData(obj) {
|
2022-07-06 11:44:48 -04:00
|
|
|
let data = this._map.get(obj);
|
|
|
|
if (data === undefined) {
|
2023-08-06 18:40:20 -04:00
|
|
|
data = {ownerSignals: [], destroyId: 0};
|
2022-07-06 11:44:48 -04:00
|
|
|
this._map.set(obj, data);
|
|
|
|
}
|
|
|
|
return data;
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {GObject.Object} obj - tracked widget
|
|
|
|
*/
|
|
|
|
_trackDestroy(obj) {
|
|
|
|
const signalData = this._getSignalData(obj);
|
|
|
|
if (signalData.destroyId)
|
|
|
|
return;
|
2022-03-04 17:34:59 -05:00
|
|
|
signalData.destroyId = obj.connect_after('destroy', () => this.untrack(obj));
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
}
|
|
|
|
|
2022-07-06 11:50:57 -04:00
|
|
|
_disconnectSignalForProto(proto, obj, id) {
|
|
|
|
proto['disconnect'].call(obj, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
_getObjectProto(obj) {
|
|
|
|
return obj instanceof GObject.Object
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
? GObject.Object.prototype
|
|
|
|
: Object.getPrototypeOf(obj);
|
2022-07-06 11:50:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_disconnectSignal(obj, id) {
|
|
|
|
this._disconnectSignalForProto(this._getObjectProto(obj), obj, id);
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
}
|
|
|
|
|
2022-08-28 18:03:50 -04:00
|
|
|
_removeTracker() {
|
|
|
|
if (this._ownerDestroyId)
|
|
|
|
this._disconnectSignal(this._owner, this._ownerDestroyId);
|
|
|
|
|
|
|
|
SignalManager.getDefault().removeSignalTracker(this._owner);
|
|
|
|
|
|
|
|
delete this._ownerDestroyId;
|
|
|
|
delete this._owner;
|
|
|
|
}
|
|
|
|
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
/**
|
2023-08-06 21:15:51 -04:00
|
|
|
* @param {object} obj - tracked object
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
* @param {...number} handlerIds - tracked handler IDs
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
track(obj, ...handlerIds) {
|
2022-03-04 17:32:24 -05:00
|
|
|
if (_hasDestroySignal(obj))
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
this._trackDestroy(obj);
|
|
|
|
|
|
|
|
this._getSignalData(obj).ownerSignals.push(...handlerIds);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-08-06 21:15:51 -04:00
|
|
|
* @param {object} obj - tracked object instance
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
untrack(obj) {
|
2023-08-06 18:40:20 -04:00
|
|
|
const {ownerSignals, destroyId} = this._getSignalData(obj);
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
this._map.delete(obj);
|
|
|
|
|
2022-07-06 11:50:57 -04:00
|
|
|
const ownerProto = this._getObjectProto(this._owner);
|
|
|
|
ownerSignals.forEach(id =>
|
|
|
|
this._disconnectSignalForProto(ownerProto, this._owner, id));
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
if (destroyId)
|
|
|
|
this._disconnectSignal(obj, destroyId);
|
2022-08-28 18:03:50 -04:00
|
|
|
|
|
|
|
if (this._map.size === 0)
|
|
|
|
this._removeTracker();
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
clear() {
|
2022-07-06 11:47:14 -04:00
|
|
|
this._map.forEach((_, obj) => this.untrack(obj));
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
destroy() {
|
|
|
|
this.clear();
|
2022-08-28 18:03:50 -04:00
|
|
|
this._removeTracker();
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Connect one or more signals, and associate the handlers
|
|
|
|
* with a tracked object.
|
|
|
|
*
|
|
|
|
* All handlers for a particular object can be disconnected
|
|
|
|
* by calling disconnectObject(). If object is a {Clutter.widget},
|
|
|
|
* this is done automatically when the widget is destroyed.
|
|
|
|
*
|
|
|
|
* @param {object} thisObj - the emitter object
|
|
|
|
* @param {...any} args - a sequence of signal-name/handler pairs
|
|
|
|
* with an optional flags value, followed by an object to track
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-07-10 05:53:00 -04:00
|
|
|
export function connectObject(thisObj, ...args) {
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
const getParams = argArray => {
|
|
|
|
const [signalName, handler, arg, ...rest] = argArray;
|
|
|
|
if (typeof arg !== 'number')
|
|
|
|
return [signalName, handler, 0, arg, ...rest];
|
|
|
|
|
|
|
|
const flags = arg;
|
2022-07-06 11:55:46 -04:00
|
|
|
let flagsMask = 0;
|
|
|
|
Object.values(GObject.ConnectFlags).forEach(v => (flagsMask |= v));
|
|
|
|
if (!(flags & flagsMask))
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
throw new Error(`Invalid flag value ${flags}`);
|
2022-07-06 11:55:46 -04:00
|
|
|
if (flags & GObject.ConnectFlags.SWAPPED)
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
throw new Error('Swapped signals are not supported');
|
|
|
|
return [signalName, handler, flags, ...rest];
|
|
|
|
};
|
|
|
|
|
|
|
|
const connectSignal = (emitter, signalName, handler, flags) => {
|
|
|
|
const isGObject = emitter instanceof GObject.Object;
|
2022-07-06 11:55:46 -04:00
|
|
|
const func = (flags & GObject.ConnectFlags.AFTER) && isGObject
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
? 'connect_after'
|
|
|
|
: 'connect';
|
|
|
|
const emitterProto = isGObject
|
|
|
|
? GObject.Object.prototype
|
|
|
|
: Object.getPrototypeOf(emitter);
|
|
|
|
return emitterProto[func].call(emitter, signalName, handler);
|
|
|
|
};
|
|
|
|
|
|
|
|
const signalIds = [];
|
|
|
|
while (args.length > 1) {
|
|
|
|
const [signalName, handler, flags, ...rest] = getParams(args);
|
|
|
|
signalIds.push(connectSignal(thisObj, signalName, handler, flags));
|
|
|
|
args = rest;
|
|
|
|
}
|
|
|
|
|
2022-07-06 11:59:39 -04:00
|
|
|
const obj = args.at(0) ?? globalThis;
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
const tracker = SignalManager.getDefault().getSignalTracker(thisObj);
|
|
|
|
tracker.track(obj, ...signalIds);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnect all signals that were connected for
|
|
|
|
* the specified tracked object
|
|
|
|
*
|
2023-08-06 21:15:51 -04:00
|
|
|
* @param {object} thisObj - the emitter object
|
|
|
|
* @param {object} obj - the tracked object
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-07-10 05:53:00 -04:00
|
|
|
export function disconnectObject(thisObj, obj) {
|
2022-08-28 22:19:28 -04:00
|
|
|
SignalManager.getDefault().maybeGetSignalTracker(thisObj)?.untrack(obj);
|
signalTracker: Provide monkey-patching for (dis)connectObject()
The module exports a `addObjectSignalMethods()` method that extends
the provided prototype with `connectObject()` and `disconnectObject()`
methods.
In its simplest form, `connectObject()` looks like the regular
`connect()` method, except for an additional parameter:
```js
this._button.connectObject('clicked',
() => this._onButtonClicked(), this);
```
The additional object can be used to disconnect all handlers on the
instance that were connected with that object, similar to
`g_signal_handlers_disconnect_by_data()` (which cannot be used
from introspection).
For objects that are subclasses of Clutter.Actor, that will happen
automatically when the actor is destroyed, similar to
`g_signal_connect_object()`.
Finally, `connectObject()` allows to conveniently connect multiple
signals at once, similar to `g_object_connect()`:
```js
this._toggleButton.connect(
'clicked', () => this._onClicked(),
'notify::checked', () => this._onChecked(), this);
```
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2021-08-15 18:01:40 -04:00
|
|
|
}
|
|
|
|
|
2022-03-05 18:30:16 -05:00
|
|
|
/**
|
|
|
|
* Register a GObject type as having a 'destroy' signal
|
|
|
|
* that should disconnect all handlers
|
|
|
|
*
|
|
|
|
* @param {GObject.Type} gtype - a GObject type
|
|
|
|
*/
|
2023-07-10 05:53:00 -04:00
|
|
|
export function registerDestroyableType(gtype) {
|
2022-03-05 18:30:16 -05:00
|
|
|
if (!GObject.type_is_a(gtype, GObject.Object))
|
|
|
|
throw new Error(`${gtype} is not a GObject subclass`);
|
|
|
|
|
|
|
|
if (!GObject.signal_lookup('destroy', gtype))
|
|
|
|
throw new Error(`${gtype} does not have a destroy signal`);
|
|
|
|
|
|
|
|
destroyableTypes.push(gtype);
|
|
|
|
}
|