【问题标题】:How to get screen height and width in C如何在C中获取屏幕高度和宽度
【发布时间】:2013-01-25 16:51:48
【问题描述】:

我得到以下代码。

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 在哪里获得了显示器的宽度和高度。有没有人碰巧知道答案,或者能指出我正确的方向?

谢谢,阿奇

【问题讨论】:

  • 最后一行是两个属性:显示的宽度和高度。这不工作吗?

标签: c xorg xserver


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    获取屏幕尺寸

    【讨论】:

    • 所以它会解析 Xrandr 的屏幕尺寸?
    • 没关系,谢谢你的指点(哈哈,明白了吗?我做了一个编程参考......)我现在明白了!
    • @Archxiao 显示范围内的“屏幕尺寸”毫无意义,因此您最好避免依赖这些值。顺便说一句,你从哪里得到这样的标题?我这里有另一个定义(libx11 1.5.0),没有宽度和高度。 (顺便说一句,不同的 Xlib 实现具有完全不同的内部结构是合法的)。
    • 我是从早期版本的 XServer (X.V10R3) 获得的。
    • linux 的答案不见了。 ;) :/
    猜你喜欢
    • 2021-02-07
    • 2011-09-25
    • 1970-01-01
    • 2011-08-06
    • 2011-06-12
    • 1970-01-01
    • 2010-11-25
    • 1970-01-01
    相关资源
    最近更新 更多