37

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.
  • 90,397
Adam
  • 501
  • 2
  • 5
  • 10
  • Did you tried with my answer? – 0x2b3bfa0 Mar 21 '15 at 18:09
  • The dconf-editor does not have the debug feature that you speak of. I did attempt to update the application but Ubuntu tells me that I have the newest version installed. I do appreciate your help though. It looks like I will have to wait a few weeks for the release of Ubuntu 15.04. – Adam Mar 22 '15 at 13:21
  • Sorry, I didn't put arrows in my answer. I meant org > gtk > Settings > Debug. I think that – 0x2b3bfa0 Mar 22 '15 at 13:24
  • No arrows were needed. I understood exactly what you were telling me. – Adam Mar 22 '15 at 13:27
  • I tried it on my computer and it couldn't find debug entry. However, did it work the 2nd method? – 0x2b3bfa0 Mar 22 '15 at 13:27
  • The org.gtk.settings.debug entry shows up in the gsettings schema after installing the libgtk-3-dev package. – Levente Jan 19 '21 at 14:45

3 Answers3

30

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
  • 42,548
  • 23
  • 127
  • 221
  • 1
    How do I open the inspector in browser that use ctrl+shit+i (or ctrl+shift+d) as shorcuts for other tasks? – euDennis Apr 01 '17 at 21:37
  • 2
    I can't inspect even after installing libgtk-3-dev. Looked in the help menu, no inspector help. Looked in key bindings and no option for opening the inspector. – Costa Michailidis Nov 18 '18 at 19:54
  • Cool. Do you know how much overhead this adds to running GTK3 apps? – NoBugs Apr 03 '22 at 15:58
16

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
  • 8,780
  • 6
  • 36
  • 55
4

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
  • 235
  • 2
  • 9
  • 1
    Nice, thanks. For gnome-terminal, select Advanced > Inspector. Ctrl/Shift/D appeared to work for me, but CSS changes didn't take effect. This whole thing is a real mess. – EML Mar 20 '23 at 17:38
  • @EML I guess Ctrl+Shift+d might depend on what your shortcuts bindings are set to... but on my system it doesn't work, despite not being listed anywhere as a bound shortcut. The terminal appears to interpret it the same as Ctrl+d. ...As for CSS, that should work... the trick is that the actual terminal session is run inside a black-box vte-terminal widget with no CSS support. But you can style other widgets, e.g. menubar { font-weight: bold; } or notebook box label { font-weight: bold; } worked for me, to bold the window's menu items / tab titles. – FeRD Mar 20 '23 at 22:38