简体   繁体   中英

How to get Windowed Window's Screen coordinate of each Corner in X-window?

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.

在此处输入图片说明

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); 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM