How to query X11 display resolution?

前端 未结 7 862
一整个雨季
一整个雨季 2021-02-05 09:24

It seems like an simple problem, but I can\'t find the answer: How do you query (via X11) what monitors exist and their resolutions?

7条回答
  •  粉色の甜心
    2021-02-05 10:05

    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))
    

    Bash

    $ xrandr --listmonitors
    $ xrandr
    $ xrandr | grep '*' | awk {'print $1'}
    

提交回复
热议问题