How to find a gtkwindow by title
I'm working on the Ubuntu. I'm writing an app to capture a gtkwindow screen s开发者_如何学Pythonhot. But now, I can't get the gtkwindow pointer by the window title. Is there way to find a gtkwindow by the title?
Gtk has no API for doing this. You only get GtkWindow objects for windows you create yourself. You have to do it more low level and use xlib directly. First you must get the Display object for the your display (basically an object representing the connection to your Xserver and is needed because an Xclient can show windows on several Xservers at once). Use gdk_x11_get_default_xdisplay()
to get the default screen if you don't have any other ide of how to get a certain screen. Then you get the root window with DefaultRootWindow()
. To get a list of child windows use XQueryTree()
. And to get the name of the window for comparison use XFetchName()
. Note that windows in the context of X is not identical to what is perceived as windows. The window manager frames are windows (sometimes in multible levels) containing the actual application windows as children so XQueryTree()
might need to be used recurively.
You might also be interested in libwnck which can simplify this a bit.
精彩评论