Created
October 15, 2022 09:36
-
-
Save Hammer2900/4060fa0c30d7bf2b393a60b163a859d4 to your computer and use it in GitHub Desktop.
Get all monitors with x11 lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Xlib import display | |
from Xlib.ext import randr | |
def find_mode(id, modes): | |
for mode in modes: | |
if id == mode.id: | |
return f'{mode.width}x{mode.height}' | |
def get_display_info(): | |
d = display.Display(':0') | |
screen_count = d.screen_count() | |
default_screen = d.get_default_screen() | |
result = [] | |
screen = 0 | |
info = d.screen(screen) | |
window = info.root | |
res = randr.get_screen_resources(window) | |
for output in res.outputs: | |
params = d.xrandr_get_output_info(output, res.config_timestamp) | |
if not params.crtc: | |
continue | |
crtc = d.xrandr_get_crtc_info(params.crtc, res.config_timestamp) | |
modes = {find_mode(mode, res.modes) for mode in params.modes} | |
result.append({'name': params.name, 'resolution': f'{crtc.width}x{crtc.height}', 'available_resolutions': list(modes)}) | |
return result | |
print(get_display_info()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment