Xlib中的窗口位置 [英] Window position in Xlib

查看:468
本文介绍了Xlib中的窗口位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用普通的xlib(或全新的XCB)获取相对于根窗口(即整个屏幕)的顶级窗口位置?

How to get top-level window position relative to root window (i.e. whole screen) using plain ol' xlib (or brand new XCB)?

推荐答案

XGetWindowAttributes返回的结构的x,y分量相对于窗口父级的原点.相对于屏幕左上方而言,这是不同的.

The x,y components of the structure returned by XGetWindowAttributes are relative to the origin of the window's parent. That's not the same as relative to the top left of the screen.

调用XTranslateCoordinates传递根窗口,0,0给出窗口相对于屏幕的坐标.

Calling XTranslateCoordinates passing the root window and 0,0 gives coordinates of the window relative to the screen.

我发现如果我写:

int x, y;
Window child;
XWindowAttributes xwa;
XTranslateCoordinates( display, window, root_window, 0, 0, &x, &y, &child );
XGetWindowAttributes( display, window, &xwa );
printf( "%d %d\n", x - xwa.x, y - xwa.y );

printf显示的值是那些如果传递给XMoveWindow则将窗口保持在当前位置的值.因此,这些坐标被合理地认为是窗口的位置.

The values displayed by the printf are those which, if passed to XMoveWindow, keep the window at its current position. Thus those coordinates are reasonably considered to be the position of the window.

这篇关于Xlib中的窗口位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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