Re: Capturing & Displaying Screen Images with XGetImage & XPutImage
Re: Capturing & Displaying Screen Images with XGetImage & XPutImage
Dean N. Williams wrote:
> Instead of specifying the root window ID, I used the drawable window ID.
> By doing so, I had to set the start location to (0,0). The only problem
> with solution is the positioning of the drawable window on the rootless X
> server. That is, if the drawable window is too far to the left and
> partially not visible, then a BadMatch error is the result.
Yeah, XGetImage requires that all of the image grabbed be visible on
screen, or you get a BadMatch. But you figured that out already.
> XGetWindowAttributes doesn't detect the window's position in
> relationship to the rootless screen when the drawable window is
> partially not shown from the left. The X position value is always 0. I
> would have expected it to be a negative number for the x start position
> when too far to the left. Is there another function that will detect the
> absolution position of the drawable window in relationship to the
> rootless screen?
XGetWindowAttributes is pretty much the "gold standard". There are a couple
of other things you could try, which I'll mention below. But you should
check one thing, first.
Many times, the application window you're querying isn't actually a child of
the root window. The window manager oftentimes creates a secondary window
between "you" and the root window to draw the titlebar, decorations, etc. If
so, when you do an XGetWindowAttributes, you're going to get the offset from
your window to the window manager window. That's generally a fixed offset,
and not what you're looking for.
To get the offset of any window in relation to the root, you have to do
one of two things:
+ Use XGetWindowAttributes and XQueryTree to get the offset and the parent
window ID. Iterate up all the parents and ancestors until you get to the
root, accumulating offsets as you go.
+ Use XQueryPointer(). This is a clever trick. The call returns two sets
of coordinates: the pointer's location in relation to some window, and one
in relation to the root. Subtract the two and you're done. This is what
I use in my applications.
If your window really is a child of the root, here are some other things to
try:
+ XQueryPointer(), as mentioned above. Can't really hurt.
+ XGetGeometry()
+ Watch for ConfigureNotify events that tell you when your window has been
moved and resized. You have to watch for ConfigureNotify on all
ancestors, too. A pain to keep track of, but I've known it to work.
Note: I haven't tried all of these with Apple's X11. I'm pretty sure the
XQueryPointer() trick works, though.
-Sean
__
email@hidden
925-422-1648
_______________________________________________
x11-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/x11-users
Do not post admin requests to the list. They will be ignored.