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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
# -*- python -*-
import os
import sys
from plugins.application import Application
from plugins.clock import Clock
from plugins.cpuinfo import CPUInfo
from plugins.hdparm import HDParm
from plugins.image import Image
from plugins.kmsg import KMsg
from plugins.loadavg import AverageLoad
from plugins.lunar import Lunar
from plugins.menu import Menu
from plugins.ropty import ROPTY
from plugins.solar import Solar
sys.path.append(os.path.dirname(config_file) if '/' in config_file else '.')
from common import *
G.globals = globals()
G.clock = Clock(sync_to = 0.5)
%%>if test -x /usr/bin/terminator; then
G.TERMINAL = 'terminator'
%%>elif test -x /usr/bin/st; then
G.TERMINAL = 'st'
%%>else
G.TERMINAL = 'xterm'
%%>fi
G.OUTPUT, G.HEIGHT_PER_LINE, G.YPOS, G.TOP = 0, 12, 0, True
G.FONT = '-misc-fixed-medium-r-normal-*-10-*-*-*-c-*-iso10646-1'
from myalsa import MyALSA, MixerAction
from mybacklight import MyBacklight
from mybattery import MyBattery
from mybrilliance import MyBrilliance
from mycg import MyCGNegative
from myclock import MyClock
from mycomputer import MyComputer
from mycpu import MyCPU
from myio import MyIO
from myipaddress import MyIPAddress
from myirc import MyIRC
from mylid import MyLid
from myleapsec import MyLeapsec
from mymemory import MyMemory
from mymoc import MyMOC
from mynetwork import MyNetwork, Ping
from mynews import MyNews
from myscroll import MyScroll
from mystat import MyStat
from mysun import MySun
from mytimer import MyTimer
from mytop import MyTop
from myweather import MyWeather
from myxmonad import MyXMonad
%%>hostname="$(hostname | tr '[[:upper:]]' '[[:lower:]]')"
def mqueue_wait():
import posix_ipc
qkey = '/.xpybar.' + os.environ['DISPLAY'].split('.')[0]
q = posix_ipc.MessageQueue(qkey, posix_ipc.O_CREAT, 0o600, 8, 128)
while True:
try:
message = q.receive(None)[0].decode('utf-8', 'replace').split(' ')
if message[0] in mqueue_map:
try:
mqueue_map[message[0]](message)
except Exception as err:
print('%s: %s' % (sys.argv[0], str(err)), file = sys.stderr, flush = True)
else:
print('%s: unrecognised message: %s' % (sys.argv[0], ' '.join(message)), file = sys.stderr, flush = True)
except:
time.sleep(1)
myxmonad = MyXMonad(None)
myscroll = MyScroll(None)
myclock = MyClock (lambda f : Clocked(f, 1), format = '%Y-(%m)%b-%d %T, %a w%V, %Z', long_format = '%Y-%m-%d %T')
%%>if iswork; then
with open('/proc/cpuinfo', 'r') as f:
isvm = f.readlines()
isvm = [line.replace('\n', ' ').replace('\t', ' ').split(':') for line in isvm if line]
isvm = any('hypervisor' in ':'.join(line[1:]).split(' ') for line in isvm if line[0].strip().startswith('flags'))
card1 = 'Ensoniq AudioPCI' if isvm else 'HDA Intel PCH'
%%>elif test $hostname = hades; then
card1 = 'HDA Intel PCH'
%%>else
card1 = 'HD-Audio Generic'
%%>fi
mixers1 = ['Master', 'PCM'] ## TODO
%%>if iswork; then
#mixers1.append(('Headphone', 'Speaker'))
if not isvm:
mixers1.append(MixerAction('Headphone', lambda : spawn_read('headphones')))
mixers1.append(MixerAction('Speaker', lambda : spawn_read('speakers')))
%%>fi
card2 = 'Yeti Stereo Microphone'
mixers2 = ['Speaker', 'Mic']
#myii = ...
#myirc = ...
#from plugins.ii import II
#from myii import MyII
#def irc_watch(s):
# s = s.lower()
# return any(map(lambda x : x in s, ['mattias andrée', 'maandree', 'mandree', 'maandre', 'mandre']))
#ii = II('irc.oftc.net/#suckless', prefix = HOME + '/.irc')
#myii = MyII(None, channel = 'irc.oftc.net/#suckless', prefix = HOME + '/.irc', watch = irc_watch)
#myirc = MyIRC(None, ii = myii)
#myii.display = myirc
mylid = ...
mybattery = ...
%%>if test -d /proc/acpi/button/lid; then
mylid = MyLid (None)
%%>fi
%%>if test ! $(ls /sys/class/power_supply/ | wc -l) = 0; then
mybattery = MyBattery(None)
%%>fi
pingthese = []
%%>if test -r ~/.dotfiles/.secrets/ping-"$hostname"; then
%%> for address in $(cat ~/.dotfiles/.secrets/ping-"$hostname"); do
pingthese.append(Ping(targets = Ping.get_nics('%%{address}'), interval = 30))
%%> done
%%>fi
try:
with open(HOME + '/.config/metar', 'rb') as file:
metar_stations = file.read().decode('utf-8', 'strict').split('\n')
except:
raise
try:
with open('/etc/metar', 'rb') as file:
metar_stations = file.read().decode('utf-8', 'strict').split('\n')
except:
metar_stations = []
metar_stations = [x[0].upper() + x[1:].lower() for x in metar_stations if x != '']
netrenamemap = {
'lo' : None,
'veth42d1872' : None,
'enxc84bd6ba1a73' : None,
'enxc84bd6ba1a91' : None,
'enx00249b1e3c30' : 'Ctrl',
'ens33' : 'Nat', # VMWare
'ens37' : 'Ctrl', # VMWare
'enxc84d44213db2' : 'Home', # USB-C eth+usb dongle
'enx0050b6cbd51b' : 'Home', # USB-C eth dongle
'enxb44506e09918' : 'Eth',
'wlp0s20f3' : 'WiFi'
}
netignorelist = [k for k, v in netrenamemap.items() if v is None]
netrenamemap = {k: v for k, v in netrenamemap.items() if v is not None}
functions = [ [ myxmonad
, None
, MyTimer (None, alarms = [])
, MyALSA (None, cards = card1, mixers = mixers1, colours = {'Speaker' : '31'})
%%>if test "$hostname" = zenith; then
, MyALSA (None, cards = card2, mixers = mixers2, prefix = 'Y.')
%%>fi
, MyComputer (lambda f : Clocked(f, 20))
, myscroll
, None
, myclock
, MyCPU (lambda f : Clocked(f, 2))
, MyMemory (lambda f : Clocked(f, 2))
, None
, MyNetwork (lambda f : Clocked(f, 2), ignore = netignorelist, pings = pingthese, renamemap = netrenamemap)
#, myirc
%%>if test -x /usr/bin/featherweight; then
, MyNews (None)
%%>fi
, MyWeather (None, stations = metar_stations) if metar_stations else ...
#, MySun (None, clock = myclock)
]
, [ myxmonad
, None
%%>if test "$hostname" = zenith; then
, MyIPAddress (lambda f : Clocked(f, 20), public = False)
%%>else
, MyALSA (None, cards = card2, mixers = mixers2, prefix = 'Yeti.')
%%>fi
, MyMOC (None)
, myscroll
, None
, myclock
, mylid
, mybattery
#, myii
, None
, MyStat (lambda f : Clocked(f, 10))
%%>if test ! "$hostname" = zenith && test ! "$hostname" = north; then ## TODO how about east and hyperion?
, MyCGNegative()
%%>fi
, MyBrilliance(None)
%%>if test ! "$hostname" = zenith; then
, MyBacklight (None)
%%>fi
#, MyIO (lambda f : Clocked(f, 10), fs_ignore = [])
]
]
functions = [[mon for mon in group if mon != ...] for group in functions]
G.HEIGHT = 0
G.groups = [Group(f) for f in functions]
G.groupi = 0
G.group = G.groups[G.groupi]
G.semaphore = threading.Semaphore()
def update_per_clock():
if G.semaphore.acquire(blocking = False):
try:
for g in G.groups:
for f in g.functions:
if isinstance(f.wrapped, Clocked):
f(True)
finally:
G.semaphore.release()
invalidate()
start_ = start
def start():
start_()
#if myii is not ...:
# myii.start()
bar.clear()
get_display().flush()
xasync(lambda : G.clock.continuous_sync(t(update_per_clock)), name = 'clock')
xasync(mqueue_wait, name = 'mqueue')
def redraw():
if G.semaphore.acquire(blocking = False):
try:
gr = G.groups[G.groupi]
for g in G.groups:
if g is not gr:
for f in g.functions:
f()
values = gr.pattern % tuple(f() for f in gr.functions)
bar.partial_clear(0, bar.width, 10, 0, 2, values)
bar.draw_coloured_splitted_text(0, bar.width, 10, 0, 2, values)
finally:
G.semaphore.release()
return True
return False
def unhandled_event(e):
if isinstance(e, Xlib.protocol.event.ButtonPress):
y = e.event_y
x = e.event_x
row = y // HEIGHT_PER_LINE
lcol = x // bar.font_width
rcol = (bar.width - x) // bar.font_width
button = e.detail
if button in (FORWARD_BUTTON, BACKWARD_BUTTON):
G.groupi = (G.groupi + (+1 if button == BACKWARD_BUTTON else -1)) % len(G.groups)
G.group = G.groups[G.groupi]
invalidate()
else:
for f in G.group.posupdate:
f.update_position()
for f in G.group.functions:
if f.click(row, lcol, rcol, button, x, y):
break
|