]> code.delx.au - bg-scripts/blob - lib/x11_helpers.py
RandomBG: Make Listener non-writeable
[bg-scripts] / lib / x11_helpers.py
1 #! python
2 # Copyright 2007 Greg Darke <starstuff@optusnet.com.au>
3 # Licensed for distribution under the GPL version 2, check COPYING for details
4 # Some little helper utils
5
6 import subprocess, commands, itertools
7
8 __all__ = ('getResolutions', )
9
10 def _seperateGroups(lines):
11 ret = []
12 current_section = []
13 for line in lines:
14 if line.strip() == '':
15 ret.append(current_section)
16 current_section = []
17 continue
18 current_section.append(line)
19 if current_section:
20 ret.append(current_section)
21 return ret
22
23 def getResolutions():
24 xdpyinfo_status, xdpyinfo_output = commands.getstatusoutput('xdpyinfo')
25 lines = xdpyinfo_output.splitlines()
26 groups = _seperateGroups(xdpyinfo_output.splitlines())
27
28 screens = []
29 for screen_data in itertools.islice(groups, 1, None, None):
30 _, screen_number = screen_data[0].split()
31 # remove the leading and trailing characters
32 screen_number = screen_number[1:-1]
33
34 _, screen_resolution_str, _, _, _ = screen_data[1].strip().split()
35 screen_resolution = screen_resolution_str.split('x')
36
37 screens.append( (screen_number, tuple(int(val) for val in screen_resolution)))
38 return dict(screens)