Skip to content

Conversation

winstonma
Copy link
Contributor

The replacement of connect with connectObject in GNOME Shell 42 and later versions allows signal connections to be automatically tracked and cleaned up, simplifying signal management in extensions or applications.

Key changes and benefits include:

  • Manual tracking of signal connections using arrays and custom methods like connectAndTrack, disconnectAndUntrack, and disconnectAllSignals are removed.
  • Signals are connected using connectObject(signal, handler, owner), where the owner (often this) is used to automatically track the connection.
  • Cleanup is simplified by calling disconnectObject(this), which disconnects all signal handlers associated with that owner without manually iterating signal IDs.
  • The destroy method is simplified to just call disconnectObject(this) on relevant objects rather than cleaning up each signal connection individually.
  • Before reconnecting signals (e.g., in methods like onAdjustmentChanged and onShowChanged), calling disconnectObject(this) ensures no duplicate signal handlers are present.

This approach can be applied not only in one place but throughout related components such as PanelButton.js, PlayerProxy.js, and ScrollingLabel.js in extensions or GNOME Shell modifications.

This mechanism is designed to prevent dangling signal handlers and improve code maintainability by leveraging signal handler tracking via the owner object and automatic cleanup when objects are destroyed. It requires the type to support a destroy signal, which is typical for GObject.Object subclasses or Clutter.Actor-based classes in GNOME Shell extensions.

@winstonma winstonma changed the title refactor(MenuSlider): improve signal handling with connectObject and … refactor(MenuSlider): improve signal handling with connectObject Oct 15, 2025
- Replace vfunc_destroy with regular destroy signal connection
- Add safety checks for disconnectObject and remove_transition calls
- Improve cleanup reliability in onDestroy method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant