小智 8
XGetWindowAttributes返回的结构的x,y组件相对于窗口父级的原点.这与屏幕左上角的相对不同.
调用XTranslateCoordinates传递根窗口和0,0给出窗口相对于屏幕的坐标.
我发现如果我写:
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 );
Run Code Online (Sandbox Code Playgroud)
printf显示的值是那些传递给XMoveWindow的值,它将窗口保持在当前位置.因此,这些坐标被合理地认为是窗口的位置.
使用Xlib:
XWindowAttributes xwa;
XGetWindowAttributes(display, window, &xwa);
printf("%d %d\n", xwa.x, xwa.y);
Run Code Online (Sandbox Code Playgroud)
还有很多其他信息XWindowAttributes.看到这里.
| 归档时间: |
|
| 查看次数: |
7434 次 |
| 最近记录: |