简体   繁体   English

如何获取X窗口中每个角的窗口窗口的屏幕坐标?

[英]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". 就像附上我的照片一样,我想获取“ X窗口中每个角的窗口窗口的屏幕坐标”。 (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. (我在下图中绘制了要作为屏幕坐标的红点。我以后要做的是在2D屏幕坐标中获取OpenGL窗口的精确中间点。

在此处输入图片说明

I tried following code already: 我已经尝试了以下代码:

int* getWindowPos(Display *dpy) { int winPos[2]; 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. 但是此“ XWindowAttributes”始终在x点上给我0,在y点上给我0,宽度1600和高度900,这与我的屏幕分辨率相同。

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. 您正在将窗口存储到GLWin.win ,但正在查询根窗口的大小和位置。 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. 如果需要这些尺寸,只需将实际窗口(GLWin.win)传递给XGetAttributes()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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