js: Use (dis)connectObject()
Start using the new methods to simplify signal cleanup. For now, focus on replacing existing cleanups; in most cases this means signals connected in the constructor and disconnected on destroy, but also other cases with a similarly defined lifetime (say: from show to hide). This doesn't change signal connections that only exist for a short time (say: once), handlers that are connected on-demand (say: the first time a particular method is called), or connections that aren't tracked (read: disconnected) at all. We will eventually replace the latter with connectObject() as well - especially from actor subclasses - but the changeset is already big enough as-is :-) Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
This commit is contained in:

committed by
Marge Bot

parent
f45ccc9143
commit
26235bbe54
@ -652,24 +652,25 @@ var PadOsd = GObject.registerClass({
|
||||
this._padChooser = null;
|
||||
|
||||
let seat = Clutter.get_default_backend().get_default_seat();
|
||||
this._deviceAddedId = seat.connect('device-added', (_seat, device) => {
|
||||
if (device.get_device_type() == Clutter.InputDeviceType.PAD_DEVICE &&
|
||||
this.padDevice.is_grouped(device)) {
|
||||
this._groupPads.push(device);
|
||||
this._updatePadChooser();
|
||||
}
|
||||
});
|
||||
this._deviceRemovedId = seat.connect('device-removed', (_seat, device) => {
|
||||
// If the device is being removed, destroy the padOsd.
|
||||
if (device == this.padDevice) {
|
||||
this.destroy();
|
||||
} else if (this._groupPads.includes(device)) {
|
||||
// Or update the pad chooser if the device belongs to
|
||||
// the same group.
|
||||
this._groupPads.splice(this._groupPads.indexOf(device), 1);
|
||||
this._updatePadChooser();
|
||||
}
|
||||
});
|
||||
seat.connectObject(
|
||||
'device-added', (_seat, device) => {
|
||||
if (device.get_device_type() === Clutter.InputDeviceType.PAD_DEVICE &&
|
||||
this.padDevice.is_grouped(device)) {
|
||||
this._groupPads.push(device);
|
||||
this._updatePadChooser();
|
||||
}
|
||||
},
|
||||
'device-removed', (_seat, device) => {
|
||||
// If the device is being removed, destroy the padOsd.
|
||||
if (device === this.padDevice) {
|
||||
this.destroy();
|
||||
} else if (this._groupPads.includes(device)) {
|
||||
// Or update the pad chooser if the device belongs to
|
||||
// the same group.
|
||||
this._groupPads.splice(this._groupPads.indexOf(device), 1);
|
||||
this._updatePadChooser();
|
||||
}
|
||||
}, this);
|
||||
|
||||
seat.list_devices().forEach(device => {
|
||||
if (device != this.padDevice &&
|
||||
@ -944,16 +945,6 @@ var PadOsd = GObject.registerClass({
|
||||
this._grab = null;
|
||||
this._actionEditor.close();
|
||||
|
||||
let seat = Clutter.get_default_backend().get_default_seat();
|
||||
if (this._deviceRemovedId != 0) {
|
||||
seat.disconnect(this._deviceRemovedId);
|
||||
this._deviceRemovedId = 0;
|
||||
}
|
||||
if (this._deviceAddedId != 0) {
|
||||
seat.disconnect(this._deviceAddedId);
|
||||
this._deviceAddedId = 0;
|
||||
}
|
||||
|
||||
this.emit('closed');
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user