问题
I have an X11 window that was created using XCreateWindow with the parent set to DefaultRootWindow(dpy). The window receives ConfigureNotify events. However, no matter where the window is moved, the ConfigureNotify reports the position as 0,0. The same is true for calls to XGetWindowAttributes(). What's going on here?
There's also something else that's driving me nuts. I'm telling CreateWindow to place the window at a particular coordinates. But it's anyone's guess where the window actually appears. Very irritating. Thoughts on this?
(no, I can't use Qt or other APIs. It's Xlib for this.)
回答1:
Your window manager is responsible for both phenomena.
The first one is because of reparenting. The WM can reparent top-level windows, so that they are no longer direct children of the root. It does so to create window decorations and the like. Your window becomes a child, or a grandchild, of the decorations window. For this reason, relative positions of top-level windows are useless. You need absolute positions. Use XTranslateCoordinates
to obtain them.
The second one is because the WM just knows better. No, really. It's the WM. It's supposed to be smart. It belongs to the user. The user (at least in theory) configures his WM however he sees fit. Application writers shouldn't care. If the user wants his window to always appear centered, then so be it. If he wants them appear at random positions, it's his choice.
In rare circumstances windows should appear at fixed positions, and such windows should nearly always be override-redirect.
In yet more rare circumstances you must position a managed window at known coordinates. In such cases, see this answer to a related question (shameless plug: it's mine). You want to specify PPosition
and PSize
.
来源:https://stackoverflow.com/questions/25391791/x11-configurenotify-always-returning-x-y-0-0