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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
#!/usr/bin/env python3
import sys, os, pwd
from subprocess import Popen, PIPE
from get import *
from set import *
args = sys.argv[1:]
home = os.environ['HOME'] if 'HOME' in os.environ else pwd.getpwuid(os.getuid()).pw_dir
session_ = os.environ['SESSION_'] if 'SESSION_' in os.environ else ''
hostname = os.uname().nodename.lower()
t = lambda lopt, sopt : any(arg in args for arg in (lopt, '-' + lopt, '--' + lopt, sopt, '-' + sopt))
mirror = t('mirror', 'm')
swap = t('swap', 's')
tv = t('tv', 't')
wide = t('wide', 'w')
crt = t('crt', 'c')
large = t('large', 'l')
single = t('single', '1')
pretend = t('pretend', 'P')
[screen] = get_setup()
ok = False
if pretend:
def apply_setup(display):
print(repr(display.to_xrandr()))
return True
### Configurations
if hostname == 'zenith':
prime = screen['DisplayPort-2' if not swap else 'DisplayPort-1']
sec = screen['DisplayPort-1' if not swap else 'DisplayPort-2']
embed = None
prime_alt = None
sec_alt = None
prime.want_mode = '1920x1200'
sec.want_mode = '1920x1200'
else:
print('%s: no configurations found for this machine' % sys.argv[0], file = sys.stderr)
sys.exit(1)
if not prime.connected and prime_alt is not None:
prime, prime_alt = prime_alt, prime
if not sec.connected and sec_alt is not None:
sec, sec_alt = sec_alt, sec
if large:
prime.want_mode = '1792x1344'
sec.want_mode = '1792x1344'
if crt:
prime.want_mode = '800x600'
sec.want_mode = '800x600'
if wide:
prime.want_mode = '1920x1080'
sec.want_mode = '1920x1080'
if tv:
sec.want_mode = '1920x1080'
if prime is not None:
prime.want_rate = prime.best_rate(prime.want_mode)
if sec is not None:
sec.want_rate = sec.best_rate(sec.want_mode)
if embed is not None:
embed.want_rate = embed.best_rate(embed.want_mode)
if '+prime' in args:
prime.connected = True
if '+sec' in args:
sec.connected = True
if '+embed' in args:
embed.connected = True
if '-prime' in args:
prime.connected = False
if '-sec' in args:
sec.connected = False
if '-embed' in args:
embed.connected = False
### Apply
if prime.connected and sec.connected and not single:
display = Display()
ok = True
output = Output(prime.name)
display.outputs.append(output)
output.mode = prime.want_mode
output.rate = prime.want_rate
output.primary = True
output.relpos = None
output.relto = None
output = Output(sec.name)
display.outputs.append(output)
output.mode = sec.want_mode
output.rate = sec.want_rate
output.primary = False
output.relpos = 'left-of' if not mirror else 'same-as'
output.relto = prime.name
if embed is not None:
output = Output(embed.name)
display.outputs.append(output)
output.off = True
elif prime.connected:
display = Display()
ok = True
output = Output(prime.name)
display.outputs.append(output)
output.mode = prime.want_mode
output.rate = prime.want_rate
output.primary = True
output = Output(sec.name)
display.outputs.append(output)
output.off = True
if embed is not None:
output = Output(embed.name)
display.outputs.append(output)
output.off = True
elif sec.connected:
display = Display()
ok = True
output = Output(sec.name)
display.outputs.append(output)
output.mode = sec.want_mode
output.rate = sec.want_rate
output.primary = True
output = Output(prime.name)
display.outputs.append(output)
output.off = True
if embed is not None:
output = Output(embed.name)
display.outputs.append(output)
output.off = True
elif embed is None or not embed.connected:
print('%s: don\'t know how to configure' % sys.argv[0], file = sys.stderr)
else:
display = Display()
ok = True
output = Output(embed.name)
display.outputs.append(output)
output.mode = embed.want_mode
output.rate = embed.want_rate
output.primary = True
output = Output(prime.name)
display.outputs.append(output)
output.off = True
output = Output(sec.name)
display.outputs.append(output)
output.off = True
if ok:
if prime_alt is not None:
output = Output(prime_alt.name)
display.outputs.append(output)
output.off = True
if sec_alt is not None:
output = Output(sec_alt.name)
display.outputs.append(output)
output.off = True
ok = apply_setup(display)
### Epilogue
if not ok:
sys.exit(1)
if pretend:
sys.exit(0)
[screen] = get_setup()
prime = screen[True]
if prime.position[0] > 0:
print(prime.position[0], flush = True)
for file in ('%s/.config/background.%s' % (home, session_), '%s/.config/background' % home):
if os.path.exists(file):
try:
os.execlp('xwallpaper', 'xwallpaper', '--zoom', file)
except:
pass
|