Pointers returned by xlib don't match any existing window IDs

Viewed 24

I'm using some X11 bindings to query some window information and later pass it to FFmpeg. FFmpeg expects a "window ID" given in hexadecimal notation.

This notation seems somewhat standard, as it is returned by programs like xwininfo or wmctrl. I haven't found much information about it, but it seems to just be the hexadecimal representation of the window pointer? If I take the ID string given by these programs and give it to FFmpeg, it is able to capture the window correctly:

$ xwininfo

xwininfo: Please select the window about which you
          would like information by clicking the
          mouse in that window.

xwininfo: Window id: 0x2800014 "Desktop — Plasma"

$ ffmpeg -f x11grab -window_id 0x2800014 -i :0+0,0 -f apng -vframes 1 out.png
# works fine

However, if I try listing all the windows in code:

var root = Window.None;
var parent = Window.None;
Xlib.XQueryTree(_display, Xlib.XDefaultRootWindow(_display), ref root, ref parent, out var children);

var ids = children
    .Select(ptr => $"0x{(ulong) ptr:x}")
    .ToArray();

I don't see 0x2800014 in the results (even disregardingleading zeroes), and if I try running FFmpeg on one of those results, it fails terribly:

$ ffmpeg -f x11grab -window_id 0x4400003 -i :0+0,0 -f apng -vframes 1

# snipped for brevity

Trailing option(s) found in the command: may be ignored.
[x11grab @ 0x55b811a8da40] Cannot get the image data event_error: response_type:0 error_code:8 sequence:10 resource_id:167772160 minor_code:4 major_code:130.
[x11grab @ 0x55b811a8da40] Continuing without shared memory.
[x11grab @ 0x55b811a8da40] Cannot get the image data event_error: response_type:0 error_code:8 sequence:11 resource_id:71303171 minor_code:0 major_code:73.
Input #0, x11grab, from ':0+0,0':
  Duration: N/A, bitrate: 38361 kb/s
  Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 200x200, 38361 kb/s, 29.97 fps, 1000k tbr, 1000k tbn
At least one output file must be specified

So I must conclude my guess that they are hex pointers is incorrect, or that the Window type is not the pointer itself, but then the question stands, how can I get the actual window IDs so I can pass them to FFmpeg?

1 Answers

I must have missed the documentation. XQueryTree returns only children windows (direct descendants), not all descendants. You have to recursively call it on the returned children array to gather the entire tree.

Related