【问题标题】:retrieve physical screen size检索物理屏幕尺寸
【发布时间】:2015-02-27 21:44:05
【问题描述】:

Xorg 启动并创建一个虚拟屏幕

虚拟屏幕尺寸确定为 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 扩展来实现吗?

【问题讨论】:

    标签: c xlib


    【解决方案1】:

    我知道的唯一方法是使用您提到的 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;
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    • 2020-04-29
    • 1970-01-01
    • 2017-04-22
    • 2019-02-24
    • 2012-01-05
    • 1970-01-01
    相关资源
    最近更新 更多