gpt4 book ai didi

c - 检索物理屏幕尺寸

转载 作者:太空宇宙 更新时间:2023-11-03 23:25:14 24 4
gpt4 key购买 nike

Xorg 启动并创建虚拟屏幕

Virtual screen size determined to be 3120 x 1050

跨越 1680x1050 和 1440x900 的 2 个物理屏幕,我猜是使用 xinerama。

没有配置文件,我不想更改系统设置。

我的应用程序使用 DisplayWidth 和 DisplayHeight 来检索屏幕尺寸,这在单屏设置中很好。

maxwidth = DisplayWidth (dpy, scrnum);
maxheight = DisplayHeight (dpy, scrnum);

但是在自动创建虚拟屏幕的双屏设置中,这些函数返回虚拟屏幕的大小。

我尝试了不同的方法来检索物理屏幕尺寸,结果相同:

maxwidth = XWidthOfScreen (XScreenOfDisplay(dpy, scrnum));
maxheight = XHeightOfScreen (XScreenOfDisplay(dpy, scrnum));

XWindowAttributes attr;
XGetWindowAttributes(dpy, RootWindow(dpy, scrnum), &attr);
maxwidth = attr.width;
maxheight = attr.height;

是否可以仅使用 Xlib 检索物理屏幕的大小?我想避免添加更多的库依赖项来设置窗口的大小,但这可能可以使用 Xrand 扩展来实现吗?

最佳答案

我知道的唯一方法是使用您提到的 Xrandr 扩展。您将需要使用 XRRGetScreenResources 并循环遍历每个 Crtc 以获取所需的信息。

#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
#include <stdio.h>

int main()
{
Display *display = XOpenDisplay(NULL);
XRRScreenResources *screens = XRRGetScreenResources(display, DefaultRootWindow(display));
XRRCrtcInfo *info = NULL;
int i = 0;

for (i = 0; i < screens->ncrtc; i++) {
info = XRRGetCrtcInfo(display, screens, screens->crtcs[i]);
printf("%dx%d\n", info->width, info->height);
XRRFreeCrtcInfo(info);
}
XRRFreeScreenResources(screens);

return 0;
}

关于c - 检索物理屏幕尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28774830/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com