Claude-skill-registry developing-gtk-apps
Use when building GTK 4/libadwaita applications; before writing app boilerplate; when debugging threading, signals, or lifecycle issues; when setting up GSettings, resources, or packaging; delegates UI/widget decisions to designing-gnome-ui skill
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/developing-gtk-apps" ~/.claude/skills/majiayu000-claude-skill-registry-developing-gtk-apps && rm -rf "$T"
skills/data/developing-gtk-apps/SKILL.mdDeveloping GTK Apps
Build robust GTK 4/libadwaita applications with correct architecture, lifecycle, and patterns.
Core principle: Get the foundation right before the UI. Application lifecycle, threading model, and resource management are where most GTK apps break.
Relationship to UI skill: This skill handles architecture and plumbing. For widget selection, layout, and HIG compliance, use
designing-gnome-ui.
Decision Flow
| Task | Use |
|---|---|
| Which widget for settings? | designing-gnome-ui |
| How to structure preferences window? | designing-gnome-ui |
| App crashes on startup | THIS SKILL |
| UI freezes during operation | THIS SKILL |
| How to save user preferences | THIS SKILL (GSettings) |
| Signal not firing/memory leak | THIS SKILL |
| Setting up new app boilerplate | THIS SKILL |
| Packaging for Flatpak | THIS SKILL |
What's Current (libadwaita 1.7+, GTK 4.18+)
API deprecations to avoid:
→ UseGtkShortcutsWindow
(libadwaita 1.8+)AdwShortcutsDialog
CSS class → Use.dim-label
class.dimmed- X11/Broadway backends are deprecated in GTK 4 (removal planned for GTK 5)
New patterns (libadwaita 1.6-1.8):
- Preferred overAdwSpinnerGtkSpinner
- Replaces multiple exclusiveAdwToggleGroup
instancesGtkToggleButton
- Persistent bottom sheetsAdwBottomSheet
- Box that wraps children to new linesAdwWrapBox
- For cards, sidebars, boxed listsAdwInlineViewSwitcher
Application Boilerplate
import gi gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') from gi.repository import Gtk, Adw, Gio class MyApp(Adw.Application): def __init__(self): super().__init__( application_id="com.example.MyApp", flags=Gio.ApplicationFlags.DEFAULT_FLAGS ) def do_activate(self): win = self.props.active_window if not win: win = MyWindow(application=self) win.present() class MyWindow(Adw.ApplicationWindow): def __init__(self, **kwargs): super().__init__(**kwargs) self.set_default_size(800, 600) def main(): app = MyApp() return app.run(None)
Application ID Rules
| Rule | Example |
|---|---|
| Reverse domain notation | |
| Only alphanumeric + dots | |
| Min 2 segments | (not ) |
| Match desktop file | |
Lifecycle Signals
| Signal | When | Use For |
|---|---|---|
| Once, app launches | Actions, CSS, GSettings |
| Each launch/raise | Create/present window |
| App exits | Save state, cleanup |
| Files passed to app | Handle file arguments |
def do_startup(self): Adw.Application.do_startup(self) # Chain up FIRST self.setup_actions()
Threading - The Critical Rule
GTK is single-threaded. All UI calls MUST happen on the main thread.
# WRONG - will crash def background_task(): result = slow_computation() self.label.set_text(result) # CRASH # RIGHT - use GLib.idle_add def background_task(): result = slow_computation() GLib.idle_add(self.label.set_text, result) # Safe threading.Thread(target=background_task).start()
For async patterns with
Gio.Task and cancellation, see gtk-patterns-reference.md.
Actions (Quick Reference)
Actions connect UI to behavior. Define at app level (
app.action) or window level (win.action).
# In do_startup - app-level action quit_action = Gio.SimpleAction.new("quit", None) quit_action.connect("activate", lambda a, p: self.quit()) self.add_action(quit_action) self.set_accels_for_action("app.quit", ["<Control>q"]) # In window __init__ - window-level action save_action = Gio.SimpleAction.new("save", None) save_action.connect("activate", self.on_save) self.add_action(save_action) self.get_application().set_accels_for_action("win.save", ["<Control>s"])
For stateful actions (toggles), parameterized actions, and menu integration, see
gtk-patterns-reference.md.
GSettings (Quick Reference)
Persist user preferences with GSettings. Requires a schema file.
# In app __init__ self.settings = Gio.Settings.new("com.example.MyApp") # Read/write values dark = self.settings.get_boolean("dark-mode") self.settings.set_boolean("dark-mode", True) # Bind to widget property (auto-syncs) self.settings.bind("window-width", window, "default-width", Gio.SettingsBindFlags.DEFAULT) # React to changes self.settings.connect("changed::dark-mode", self.on_dark_changed)
For schema XML format and installation, see
gtk-patterns-reference.md.
Debugging (Quick Reference)
GTK_DEBUG=interactive myapp # Open GTK Inspector (Ctrl+Shift+D) G_MESSAGES_DEBUG=all myapp # Show all debug messages G_DEBUG=fatal-criticals myapp # Abort on critical warnings GSETTINGS_BACKEND=memory myapp # Test without persisting settings
For full debugging patterns, profiling, and GDB integration, see
gtk-debugging-reference.md.
Red Flags - STOP
- Calling UI methods from threads (use
)GLib.idle_add - Missing
chain-updo_startup - Signal handlers without disconnect on destroy
- Blocking operations in signal handlers
- Hardcoded paths instead of XDG directories
- Missing application ID or wrong format
- Using
in main threadtime.sleep() - Using
(deprecated - useGtkShortcutsWindow
)AdwShortcutsDialog - Using
for libadwaita apps (useGtkSpinner
)AdwSpinner
Reference Files
| Need | File |
|---|---|
| GObject classes, properties, signals, list models, property bindings, factories | |
| Actions, GSettings, Resources, Blueprint, async file ops | |
| Desktop file, AppStream metadata, Meson, Flatpak, icons, Python deps | |
| Testing with pytest, async testing, headless/CI testing | |
| Internationalization, gettext, ngettext plurals, .po files, Blueprint i18n, RTL testing | |
| DBus activation, interface export, background services, Flatpak portals | |
| GTK Inspector, env vars, profiling, memory debugging | |
| UI patterns, widgets, HIG | Use skill |