online.0227
online.0227

Reputation: 648

Obtaining Windowed window's Position in X-window System?

Yes. I tried both, that using "XGetWindowAttributes()" and "XGetGeometry()", but it gives only x,y value at always 0,0.

But when I moved my window to middle of the entire screen, in that case my returning value should be 800, 450 around those values if my screen resolution is 1600, 900. However it always return 0,0.

Following is the code I tested and below that I attached a photo where drawn red dot explains the point in 2D screen coordinate I want to get.

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;

}

I want to get at least 2D screen coordinate of top-left position of this window!

Upvotes: 2

Views: 1282

Answers (1)

parkydr
parkydr

Reputation: 7784

Try

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

This should give you the top left corner. Repeat with (0, height-1), (width-1, 0) and (width-1, height-1) for the other corners.

Upvotes: 3

Related Questions