X11 ConfigureNotify()始终返回x,y =(0,0) [英] X11 ConfigureNotify() always returning x,y = (0,0)

查看:81
本文介绍了X11 ConfigureNotify()始终返回x,y =(0,0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个X11窗口,该窗口是使用XCreateWindow创建的,其父级设置为DefaultRootWindow(dpy).该窗口接收ConfigureNotify事件.但是,无论将窗口移到何处,ConfigureNotify都将位置报告为0,0.对于XGetWindowAttributes()的调用也是如此.这是怎么回事?

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?

还有其他一些因素使我发疯.我告诉CreateWindow将窗口放置在特定的坐标处.但是,任何人都在猜测窗口实际出现的位置.很烦人.有这个想法吗?

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?

(不,我不能使用 Qt 或其他 API.这是 Xlib.)

(no, I can't use Qt or other APIs. It's Xlib for this.)

推荐答案

您的窗口管理器负责这两种现象.

Your window manager is responsible for both phenomena.

第一个是由于重制.WM可以重设顶层窗口,以便它们不再是根的直接子级.这样做是为了创建窗户装饰等.您的窗口成为装饰窗口的子代或孙代.因此,顶层窗口的相对位置是无用的.您需要绝对职位.使用 XTranslateCoordinates 获取它们.

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.

第二个原因是因为WM了解得更多.不完全是.这是 the WM.应该很聪明.它属于用户.用户(至少在理论上)配置了他的WM,但是他认为合适.应用程序编写者不必理会.如果用户希望他的窗口始终居中显示,那就这样吧.如果他希望它们出现在任意位置,那是他的选择.

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.

在更罕见的情况下,必须将托管窗口放置在已知坐标处.在这种情况下,请参见此答案一个相关的问题(无耻的插件:是我的).您要指定 PPosition PSize .

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.

这篇关于X11 ConfigureNotify()始终返回x,y =(0,0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆