代码之家  ›  专栏  ›  技术社区  ›  dicroce

如何查询X11显示分辨率?

  •  15
  • dicroce  · 技术社区  · 16 年前

    7 回复  |  直到 14 年前
        1
  •  14
  •   asveikau    16 年前

    退房 display macros screen macros Xlib manual .

    明确地:

        2
  •  13
  •   Grzegorz Wierzowiecki    15 年前

    这可能对cli和脚本编写有帮助

    xwininfo -root
    

    xrandr
    
        3
  •  5
  •   Nicholas Riley    16 年前

    如果正在使用Xinerama,请尝试 XineramaQueryScreens (X)WidthOfScreen / (X)HeightOfScreen.

    :x.0 , :x.1 (等)

        4
  •  4
  •   alanc    16 年前

    对于现代X服务器,还有XRandR扩展,它提供了最新的多屏幕布局信息模型,包括重叠屏幕和动态屏幕更改。

    其文档可在 XRandR 1.3.1 Protocol spec libXrandr man page

        5
  •  4
  •   Community Mohan Dere    6 年前

    清洁的 xrandr imagemagick使用的输出

    $ xrandr |grep \* |awk '{print $1}'
    

    结果如下:

    1920x1080
    
        6
  •  3
  •   Community Mohan Dere    9 年前

    库X11仅适用于类unix操作系统,因此它不是跨平台的解决方案。

    完整代码

    #include <stdio.h>
    
    #include <X11/Xlib.h>
    
    int
    main(const int argc, const char *argv[])
    {
    
        Display *display;
        Screen *screen;
    
        // open a display
        display = XOpenDisplay(NULL);
    
        // return the number of available screens
        int count_screens = ScreenCount(display);
    
        printf("Total count screens: %d\n", count_screens);
    
    
        for (int i = 0; i < count_screens; ++i) {
            screen = ScreenOfDisplay(display, i);
            printf("\tScreen %d: %dX%d\n", i + 1, screen->width, screen->height);
        }
    
        // close the display
        XCloseDisplay(display);
    
       return 0;
    }
    

    汇编

    gcc -o setup setup.c -std=c11 `pkg-config --cflags --libs x11`
    

    (我的计算机的实际值)

    Total count screens: 1
        Screen 1: 1366X768
    

    基于:

    1. https://tronche.com/gui/x/xlib/display/opening.html
    2. https://tronche.com/gui/x/xlib/display/display-macros.html
    3. https://tronche.com/gui/x/xlib/display/screen-information.html
    4. https://stackoverflow.com/a/1829747/6003870
        7
  •  3
  •   Antoine Boucher    7 年前

    python

    import os
    from Xlib import X, display
    d = display.Display()
    s = d.screen().root
    output = os.popen("xrandr --listmonitors | grep '*' | awk {'print $4'}").read().splitlines()
    num_sc = s.xinerama_get_screen_count().screen_count
    width = s.get_geometry().width
    height = s.get_geometry().height
    print("Total count screens: %s" % num_sc)
    for i in range(num_sc):
        print("\tScreen %s(%s): %sX%s" % (i, output[i], width, height))
    

    猛击

    $ xrandr --listmonitors
    $ xrandr
    $ xrandr | grep '*' | awk {'print $1'}
    
    推荐文章