Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 38 lines (30 sloc) 0.995 kB
048a673 @rep monitor.py!
authored
1 #!/usr/bin/python
2 # -*- coding: utf8 -*-
3
4 import sys
5 import subprocess
6
7 INT = 'LVDS1'
8
9 def xrandr(*args):
10 return subprocess.check_output(['xrandr',]+list(args))
11
12 def get_connected_screens():
13 o = xrandr()
14 tmp = filter(lambda x: 'connected' in x, [i.split() for i in o.splitlines()])
15 tmp = filter(lambda x: x != INT, [i[0] for i in tmp])
16 return tmp
17
18 if __name__ == '__main__':
19 if len(sys.argv) > 1:
20 arg1 = sys.argv[1]
21 if arg1 == 'off':
22 print 'setting {0} only'.format(INT)
23 args = [['--output', i, '--off'] for i in get_connected_screens()]
24 xrandr('--output', INT, '--auto', *reduce(lambda x,y: x+y, args,[]))
25
26 elif arg1 == 'left' or arg1 == 'right':
27 print 'setting extern {1}-of {0}'.format(INT, arg1)
28 args = []
29 for e in get_connected_screens():
30 args += ['--output', e, '--{0}-of'.format(arg1), INT, '--auto']
31 xrandr(*args)
32 else:
33 print 'command not recognized:', arg1
34 else:
35 print 'resetting {0} --auto'.format(INT)
36 xrandr('--output', INT, '--auto')
37
Something went wrong with that request. Please try again.