How can I non-interactively access the widget tree of an existing GTK application? I'd like to query the coordinates of a widget, and if possible send events (hover, click, key press, …).
Using GTKInspector, I can do browse the widget tree interactively and see the size and coordinates of a widget. I'd like to access this info using a command-line tool, or using some GTK API in any language.
# Steps to do this interactively, I'd like a non-interactive version.
sudo apt install libgtk-3-dev
gsettings set org.gtk.Settings.Debug enable-inspector-keybinding true
GTK_DEBUG=interactive mate-calc
# Then go to `MathWindow → GtkBox → GtkMenuBar`
# click on the (i) icon to show the details view
# `allocation` indicates the `width×height+x+y`, here it's `312×25+0+0`
Solutions I've considered:
- Use xdotool to control the GTKInspector automatically (expect poor performance + the need to have an extra GTKInspector window on the side).
- Use dbus, but
d-feetdoes not show the widget tree and I suspect the things it shows aboutinterfaceare about OOP or the d-bus interface, not about some user interface. - Back in the good old days, we could do similar things with
dcopfor QT applications, but of course it won't work for GTK.
