且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

X11 ConfigureNotify()始终返回x,y =(0,0)

更新时间:2022-03-28 21:53:37

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

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.