Unsure how to find widget by location
Ingo Krabbe
ikrabbe.ask at gmail.com
Fri Apr 10 00:21:38 PDT 2015
Hi Mike,
it's some years ago that I used Xlib directly. Actually you should check some of the Xlib tutorials and books in the internet. But to find windows coordinates you either have to check the whole tree of Windows with
XGetGeometry
and you should translate the Coordinates from the parent windows space to root space with
XTranslateCoordinates
or you can listen to
XConfigureEvent (s)
to keep track of each windows size and position, that you are interested in.
Check the manual pages of all these functions and Event structures. The Xlib is a piece of quite old code, that is far from being state of the art and as Xlib is a kind of GUI Kernel for the X11 Windows System you should expect some behaviours you are not used to from other libraries.
Maybe it would be better to work with a toolkit, but with Xlib directly. If you really want to work on that low level, also check XCB Functions, that provide better performance for remote access.
Regards,
Ingo Krabbe
> So fair warning, I've recently been asked to do some display work and I'm
> not extremely familiar with it.
>
> I am currently in the midst of trying to write something that can identify
> the lowest level visible widget at the location and return the window ID,
> but find I'm having a wee bit of trouble. Using the known display and the
> default root window of that display, I was attempting to find the window ID
> of a button widget by recursively calling XQueryTree. I am calling
> XQueryTree, then use XGetWindowAttributes to check the child windows for
> visibility and if the given x,y pairing are inside of them, and then
> repeating to the bottom child. The problem I've run into is I have a
> situation where two buttons are stacked on top of each other. I have no
> idea how to tell the difference between an exposed window and one that is
> covered up. Both end up having identical attributes returned from
> XGetWindowAttributes, so I have no idea how to tell which one is actually
> exposed.
>
> Clearly there is some way to do this, but I do not understand it. I can get
> to the correct window if I instead depend on XQueryPointer and recursively
> call it with the subwindow of the previous XQueryPointer's results, however
> I'm trying to do this without moving the mouse.
>
> Attached is the source for a small test app I'm trying this in, case my
> description wasn't particularly clear. When I run this test app and mouse
> over buttonA stacked on top of buttonB, the XQueryTree ends up returning
> the window id of buttonB regardless of if its the exposed button, or if
> buttonA is the exposed button. the XQueryPointer always gets the right
> window however. Clearly checking for the dimensions and visibility isn't
> enough to pick the correct, exposed window.
>
> --
> Mike Stewart
> mstewart at altroninc.com
> 703-263-7306
>
> This electronic mail transmission, including any attachments, may contain
> certain information (technical data, proprietary information, etc.) whose
> dissemination is controlled by US export laws and regulations, DOD
> Distribution D statements, or non-disclosure agreements. Unauthorized
> review, use, disclosure, or distribution is prohibited.
More information about the xorg
mailing list