История изменений
Исправление Darth_Revan, (текущая версия) :
Вот, решение без уродования с процессами и без Qt/GDK (и без поддержки Wayland, да):
#!/usr/bin/env python
import sys
import yaml
import Xlib.display
if __name__ == "__main__":
out = {}
display = Xlib.display.Display()
if not display.has_extension("RANDR"):
raise OSError("XRandR is not available")
window = display.screen().root
screen_res = window.xrandr_get_screen_resources()
timestamp = screen_res.config_timestamp
primary_num = window.xrandr_get_output_primary().output
for i in screen_res.outputs:
monitor = display.xrandr_get_output_info(i, timestamp)
if monitor.crtc == 0:
continue
crtc = display.xrandr_get_crtc_info(monitor.crtc, timestamp)
out[monitor.name] = {
"name" : monitor.name,
"w" : crtc.width,
"h" : crtc.height,
"x" : crtc.x,
"y" : crtc.y,
"primary" : 1 if i == primary_num else 0,
}
yaml.dump(out, sys.stdout, default_flow_style=False)
Исправление Darth_Revan, :
Вот, решение без уродования с процессами и без Qt/GDK (и без поддержки Wayland, да):
#!/usr/bin/env python
import sys
import yaml
import Xlib.display
if __name__ == "__main__":
out = {}
dpy = Xlib.display.Display()
if not dpy.has_extension("RANDR"):
raise OSError("XRandR is not available")
window = dpy.screen().root
screen_res = window.xrandr_get_screen_resources()
timestamp = screen_res.config_timestamp
primary_num = window.xrandr_get_output_primary().output
for i in screen_res.outputs:
monitor = dpy.xrandr_get_output_info(i, timestamp)
if monitor.crtc == 0:
continue
crtc = dpy.xrandr_get_crtc_info(monitor.crtc, timestamp)
out[monitor.name] = {
"name" : monitor.name,
"w" : crtc.width,
"h" : crtc.height,
"x" : crtc.x,
"y" : crtc.y,
"primary" : 1 if i == primary_num else 0,
}
yaml.dump(out, sys.stdout, default_flow_style=False)
Исходная версия Darth_Revan, :
Вот, решение без уродования с процессами и без Qt/GDK (и без поддержки Wayland, да):
#!/usr/bin/env python
import sys
import yaml
import Xlib.display
if __name__ == "__main__":
out = {}
dpy = Xlib.display.Display()
if not dpy.has_extension('RANDR'):
raise OSError("XRandR is not available")
window = dpy.screen().root
screen_res = window.xrandr_get_screen_resources()
timestamp = screen_res.config_timestamp
primary_num = window.xrandr_get_output_primary().output
for i in screen_res.outputs:
monitor = dpy.xrandr_get_output_info(i, timestamp)
if monitor.crtc == 0:
continue
crtc = dpy.xrandr_get_crtc_info(monitor.crtc, timestamp)
out[monitor.name] = {
"name" : monitor.name,
"w" : crtc.width,
"h" : crtc.height,
"x" : crtc.x,
"y" : crtc.y,
"primary" : 1 if i == primary_num else 0,
}
yaml.dump(out, sys.stdout, default_flow_style=False)