-
Notifications
You must be signed in to change notification settings - Fork 0
/
display_check.py
executable file
·69 lines (54 loc) · 1.64 KB
/
display_check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/python3
# NOT USING THIS SCRIPT ANY MORE
from Xlib import display
from Xlib.ext import randr
from sys import argv as a
# Make sure that params are correct
if len(a) != 3:
print("ERROR: Invalid usage")
print(f"Correct usage: {a[0]} OutputName HxV")
exit()
output = a[1]
res_to_set = a[2]
# Get all the modes
def find_mode(id, modes):
for mode in modes:
if id == mode.id:
return "{}x{}".format(mode.width, mode.height)
# Get info on all the screens
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 = set()
for mode in params.modes:
modes.add(find_mode(mode, res.modes))
result.append({
'name': params.name,
'resolution': "{}x{}".format(crtc.width, crtc.height),
'available_resolutions': list(modes)
})
return result
outputs = get_display_info()
monitor = ''
for dev in range(0, len(outputs)):
if outputs[dev].get('name').lower() == a[1].lower():
monitor = dev
if monitor == '':
print("ERROR: Output is not active!")
else:
dev_modes = outputs[monitor].get('available_resolutions')
_set = False
if res_to_set in dev_modes:
_set = True
print(_set)