rubenvb
rubenvb

Reputation: 76519

Get Window ID from xcb using a class or name

I want to use Qt's QWindow::fromWinID function to draw widgets onto an external window (hopefully this will work).

Unfortunately, I need to draw on a window which has a certain name/class (I can show it using xwininfo and xprop). The only code I can find to do this is inside the source of xwininfo and xprop, but it seems like a bunch of unnecessary code to do a simple thing: find the window with a certain property equal to some string, and return its window ID for Qt to use. Unfortunately, I'm very badly versed in XCB, and wouldn't know how to start.

How can I do this without 200 lines of code?

Upvotes: 0

Views: 1481

Answers (1)

Ingo Bürk
Ingo Bürk

Reputation: 20033

The only code I can find to do this is inside the source of xwininfo and xprop

Which really is a great resource, alongside with xdotool.

find the window with a certain property equal to some string

Yeah, but there's no X11 built-in that does this, which is why those tools go that way. Then there's things to consider like reparenting and non-reparenting window managers, i.e., whether or not you need to descend into the client window and so on.

I'm afraid there's no much easier way. Low-level X programming, whether with Xlib or XCB, just brings some verbosity.

One thing you could consider is using the library extracted from (and used by) xdotool, called libxdo. It would offer this functionality for you in xdo_search_windows. The library uses (and therefore pulls in) Xlib rather than XCB, though.

Here's a sample program you can compile with gcc -lxdo test.c:

#include <xdo.h>

int main() {
    xdo_t *xdo = xdo_new(NULL);
    xdo_enter_text_window(xdo, CURRENTWINDOW, "A", 0);
    return 0;
}

Upvotes: 1

Related Questions