Question

Like attached my photo, I want to get "Windowed Window's Screen coordinate of each Corner in X-window". (I draw red dots, which I want to get as Screen coordinates, in the following image. What I am going to do later is to get exact middle point of my OpenGL window in 2D screen coordinate.

enter image description here

I tried following code already:

int* getWindowPos(Display *dpy) { int winPos[2];

Window myWin;
myWin = XRootWindow(dpy, 0);

XWindowAttributes xwa;
XGetWindowAttributes(dpy, myWin, &xwa);
    // printf("%d %d\n", xwa.x, xwa.y);

return winPos;
 }

but this "XWindowAttributes" always gives me 0 in x point ,0 in y point, and width 1600 and height 900, which is same as my screen resolution.

following is what I coded to create this windowed window.

   GLWin.win = XCreateWindow(GLWin.dpy, RootWindow(GLWin.dpy, vi->screen),
            0, 0, 800, 600, 0, vi->depth, InputOutput, vi->visual,
            CWBorderPixel | CWColormap | CWEventMask, &GLWin.attr);
Was it helpful?

Solution

You're storing your window into GLWin.win, but are querying the root window for its size and location. The "root window" is the full screen background window (desktop), so it makes sense that it's returning your screen resolution. Just pass your actual window (GLWin.win) to XGetAttributes() if you want those dimensions.

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