X11 ConfigureNotify() always returning x,y = (0,0)

偶尔善良 提交于 2019-12-14 02:22:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!