【问题标题】:Obtaining Windowed window's Position in X-window System?获取窗口窗口在 X 窗口系统中的位置?
【发布时间】:2013-09-05 08:32:49
【问题描述】:

是的。我尝试了两种方法,使用“XGetWindowAttributes()”和“XGetGeometry()”,但它只给出 x,y 值始终为 0,0。

但是当我将窗口移动到整个屏幕的中间时,在这种情况下,如果我的屏幕分辨率为 1600、900,我的返回值应该是 800、450。但它总是返回 0,0。

以下是我测试的代码,下面我附上了一张照片,其中绘制的红点解释了我想要获取的 2D 屏幕坐标中的点。

int* getWindowPos(Display *dpy, Window *curWin) {
    int winPos[2]; 
    unsigned int width, height, bwidth, depth;
    Window root;

    root =  XRootWindow(GLWin.dpy, 0);
//    Window myWin;
//    myWin = XRootWindow(dpy, 0);

    //XWindowAttributes xwa;
    //XGetWindowAttributes(dpy, *curWin, &xwa);
    XGetGeometry(dpy, *curWin, &root, &winPos[0], &winPos[1], &width, &height, &bwidth, &depth );
   // printf("%d %d\n", xwa.x, xwa.y);

    return winPos;

}

【问题讨论】:

    标签: c++ linux user-interface xlib x11


    【解决方案1】:

    试试

    Window child;
    XTranslateCoordinates(dpy, *curWin, root, 0, 0, &winPos[0], &winPos[1], &child);
    

    这应该给你左上角。对其他角重复 (0, height-1), (width-1, 0) 和 (width-1, height-1)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-19
      • 1970-01-01
      • 2011-03-28
      • 2018-10-26
      相关资源
      最近更新 更多