如何在C中获得屏幕高度和宽度

时间:2013-01-25 16:51:48

标签: c xorg xserver

我得到以下代码。

typedef struct _display {
int fd;         /* Network socket. */
Window root;        /* Root window id. */
int vnumber;        /* X protocol version number. */
int dtype;      /* X server display device type. */
int dplanes;        /* Number of display bit planes. */
int dcells;     /* Number of display color map cells. */
_QEvent *head, *tail;   /* Input event queue. */
int qlen;       /* Length of input event queue */
int request;        /* Id of last request. */
char * lastdraw;    /* Last draw request. */
char *buffer;       /* Output buffer starting address. */
char *bufptr;       /* Output buffer index pointer. */
char *bufmax;       /* Output buffer maximum+1 address. */
int squish;     /* Squish MouseMoved events? */
Pixmap black, white;    /* Constant tile pixmaps */
char *displayname;  /* "host:display" string used on this connect*/
int width, height;  /* width and height of display */
} Display;

但是我得不到的是X获取显示器的宽度和高度的地方。有人会碰巧知道答案,或者能指出我正确的方向吗?

谢谢,Arch

2 个答案:

答案 0 :(得分:4)

为什么不获取root窗口的属性?

XWindowAttributes ra;
XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &ra);
w = ra.width;
h = ra.height;

答案 1 :(得分:2)

获取屏幕尺寸