Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top