Skip to content

Instantly share code, notes, and snippets.

@h4k1m0u
Last active May 5, 2025 20:43
Show Gist options
  • Save h4k1m0u/08ecffbb8ee8a8dc5812e222552b06bd to your computer and use it in GitHub Desktop.
Save h4k1m0u/08ecffbb8ee8a8dc5812e222552b06bd to your computer and use it in GitHub Desktop.
Notions about Gnome to develop extensions in GJS (from https://gjs.guide/extensions/)

D-Bus

  • Interprocess communication (IPC) system for apps.
  • Runs as a service.
  • Two buses:
    • System bus: e.g. to notify about hardware connect/disconnect. Its service: systemctl status dbus.
    • Session bus: Specific to user sessions, e.g. communication between Gnome components. Its service: systemctl --user status dbus.
  • dbus-run-session <cmd>: Starts a new session bus and run cmd in that session (to have access to the session dbus for IPC):
    • e.g gnome-shell --nested: Start Gnome within an existing session (for dev. & testing) without affecting the primary UI.

Settings

  • GSettings: System for Gnome apps to manage their settings.
  • dconf: underlying backend database for GSettings, with parameters stored in key-value format.

GVariant

  • Variant type (like C's union and C++'s std::variant) that may contain:
    • Simple types: int, bool.
    • Complex types: array of dict.
  • Usage: data to be serialized:
    • Data sent over D-Bus.
    • Saved settings with GSettings.

Extensions

Create a new extension: gnome-extension create --interactive

Files

  • Two mandatory files: metadata.json, and extension.js
  • extension.js:
    • Runs in the same process as gnome-shell.
    • Uses Clutter and St toolkits (latter builds on Clutter to provide more Widgets & CSS), like gnome-shell.
  • prefs.json: Preferences for extension.
    • Runs in a separate process from Gnome-shell.
    • Uses GTK4 and Adwaita.
    • Adwaita: Toolkit that offers widgets to build Gnome apps (extends GTK base widgets).

Location

  • Local: ~/.local/share/gnome-shell/extensions

  • System-wide: /usr/share/gnome-shell/extensions/

Imports

  • gi:// is used to load bindings to C libraries (Gtk, St, Clutter...) generated via GObject introspection.

  • resource:///org/gnome/shell/... is used to load a file embedded in Gnome-shell iteself.

Debug

  • Looking Glass (lg): Inspector tool and js console, run with Alt-F2 > lg.
  • Logs: $ journalctl -f /usr/bin/gnome-shell.
  • Console: $ gjs-console

Glib utilities

  • glib-compile-schemas: compiles an xml file (GSettings schema) into a binary file (that defines app settings).

  • glib-compile-resources: compiles resources listed in an xml file into binary files that can be accessed dynamically at runtime (to avoid issues with file locations and relative paths).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment