43

I am using GTK.3.15. When attempting to open GTK Inspector using the Ctrl+Shift+I or Ctrl+Shift+D, nothing happens. Does not matter what application or widget I am using. Nothing happens

and my understanding is that this option comes standard on GTK 3.15. Does anyone know how

to use this tool in GTK 3.15?

A.B.
  • 92,125
Adam
  • 571

3 Answers3

38

I got this from https://wiki.gnome.org/Projects/GTK%2B/Inspector:

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

The debugger is disabled by default. To enable it run in a terminal:

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

And launch it pressing on the keyboard Control-Shift-I or Control-Shift-D.

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

GTK_DEBUG=interactive your-app

Looking further, I found Bug #1523929 which indicates that users can install libgtk-3-dev which then provides the schema. Note that installing libgtk-3-dev may bring in a lot of dependencies.

DK Bose
  • 44,553
17

Method 1:


Enable the shortcut:

  1. Install dconf-editor with sudo apt-get install dconf-editor
  2. Navigate to org > gtk > settings > debug
  3. Set enable-inspector-keybinding to true
  4. Try the shortcut.

Method 2:


Run the program to debug with the GTK_DEBUG variable:

Instead of running the program to debug as usual (myprogram --argument) you only need to run it of this way (GTK_DEBUG=interactive myprogram --argument)

Also you can export that variable with export GTK_DEBUG=interactive and then run the program.

0x2b3bfa0
  • 9,110
  • 7
  • 38
  • 55
6

Updated: 2023-01

The wiki page for the Inspector seems to be a bit out of date, and at times bugs interfere with documented functionality. What's more, a lot of this functionality is implemented inconsistently in applications, which has clearly led to a lot of people being steered in a lot of wrong directions. (Including by previous versions of this answer.)

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

The handling of GTK_DEBUG does appear to have been fixed, so that GTK_DEBUG=interactive in the environment will auto-open the inspector. That wasn't working for me in the past, but in Fedora 37 it works as described.

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.

So, turns out these statements are correct-ish, but they should be accompanied by a whole bunch of caveats.

  • Ctrl+Shift+D might work, if the application hasn't bound it to something else.

  • Similarly, Ctrl+Shift+I might work, under the same conditions.

    And while it is, technically, a context-sensitive shortcut that will inspect "the widget under the mouse cursor", many applications draw their entire interface inside a big GtkDrawingArea so don't be surprised if that's the widget that pops up for most mouse locations. (You won't be able to inspect anything inside that area, anyway, as the contents are not Gtk widgets.)

  • If an application has bound away one or both of the shortcuts, its local bindings will override and there's nothing you can do about that.

    • Nautilus, in particular, has a different binding for Ctrl+Shift+I (it's "Invert selection"), so that shortcut will never work to open the inspector in Nautilus, and you have to use only Ctrl+Shift+D.

    • Gnome Terminal actually binds both Ctrl+Shift+D and Ctrl+Shift+I, so neither shortcut will work... which is why they provide a handy Help > Inspector option in the application menubar (if you activate that).

  • Last but not least, there's a bug in Gtk's handling of Ctrl+Shift+D that might prevent it from working every other time you try to use it. (Ctrl+Shift+I doesn't seem to be affected.)

To get to the inspector, you'll need to satisfy the items on this list:

  1. Install the appropriate gtk3-devel / libgtk-3-dev or gtk4-devel / libgtk-4-dev package. Non-optional.

  2. If using Gtk3, enable the dconf key /org/gtk/settings/debug/enable-inspector-keybinding / GSettings key org.gtk.Settings.Debug enable-inspector-keybinding. (They're the same setting.) Optionally, you can disable org.gtk.Settings.Debug inspector-warning.

    Gtk4 has its own enable-inspector-keybinding key at org.gtk.gtk4.settings.debug, but it now defaults True so you're probably already good there. org.gtk.gtk4.settings.debug.inspector-warning still also defaults to True, though, so you may want to turn that off.

  3. Either:

    • Run a program with GTK_DEBUG=interactive in the environment.
    • When the application is open and focused, type Ctrl+Shift+D or Ctrl+Shift+I and hope one of them works. Or look for a menu option to do the same thing.
FeRD
  • 283
  • 3
  • 9