GtkInspector is the built-in interactive debugging support in GTK+. It was added in GTK+ 3.14, based on a copy of the well-established gtkparasite.

The debugger is disabled by default. To enable it, make sure you have the libgtk-3-dev(debian-naming) or gtk3-devel(fedora-naming) package installed and run in a terminal:

gsettings set org.gtk.Settings.Debug enable-inspector-keybinding true

If the application you are using happens to be a Flatpak it will likely have a separate GSettings storage than your host system, you will need to modify that environment separately like the following.

flatpak run --command='sh' org.gnome.Polari
gsettings set org.gtk.Settings.Debug enable-inspector-keybinding true

If you are developing the application via Gnome Builder, open the "Runtime terminal" from the "Open Menu", and run the same gsetting command.

gsettings set org.gtk.Settings.Debug enable-inspector-keybinding true

To launch the GTK Inspector, focus your GTK application and press Control-Shift-D. Alternatively, move your mouse cursor to your desired widget and press Control-Shift-I to specifically inspect the widget under the mouse cursor.

If you don't want to use the shortcuts, you can also open the Inspector directly when running your app with:

GTK_DEBUG=interactive your-app

Ideas for further development

GtkInspector is already pretty useful, but it could be even better. Here are some ideas for things to work on, in no particular order. Your help is appreciated!

  • Show mainloop statistics: how many sources are attached, how often do they fire, how long they take ... Needs support in GLib 710723

  • Add a more structured css editor. Look at any major web browser for ideas
  • Show overridden styles
  • Capture g_log output and show it - recursion danger here, if showing the log generates more logs
  • Add logging (property changes, traced signal emissions, etc)
  • Visual box model debugging: highlight margin, borders, etc
  • Add a D-Bus api; being able to introspect the application and inject changes from an IDE is a powerful idea
  • Isolate the inspector window from global state changes (style, text direction, visual debugging,...) if they come from the inspector itself. This has been improved by using a separate display connection for the inspector. Left to do are baselines, pixel cache and touch simulation.
  • Show child types (ie. 'center', 'title', 'tab' etc). Needs GTK+ api
  • Indicate modified properties in the UI, and add a way to reset them
  • Store the ui file/resource foshortcuts Controlr each object constructed by GtkBuilder, and have a 'jump to definition' link in the inspector

  • Recorder: Record a widget and allow playing back the recording. Allows debugging animations.

Relevant art

Projects/GTK/Inspector (last edited 2020-12-29 19:57:24 by JordanPetridis)