diff options
Diffstat (limited to 'xpybar')
-rw-r--r-- | xpybar/config/Makefile | 3 | ||||
-rw-r--r-- | xpybar/config/myalsa.py | 16 | ||||
-rw-r--r-- | xpybar/config/mycg.py | 51 | ||||
-rw-r--r-- | xpybar/config/mynetwork.py | 19 | ||||
-rw-r--r-- | xpybar/config/xmonad-monitor.gpp | 62 |
5 files changed, 138 insertions, 13 deletions
diff --git a/xpybar/config/Makefile b/xpybar/config/Makefile index dc444aa..b5ce07a 100644 --- a/xpybar/config/Makefile +++ b/xpybar/config/Makefile @@ -3,6 +3,9 @@ all: xmonad-monitor xmonad-monitor: xmonad-monitor.gpp + @touch -- $@ + @chmod -- +w $@ gpp -s '%%' < $@.gpp > $@ + @chmod -- a-w $@ .PHONY: all diff --git a/xpybar/config/myalsa.py b/xpybar/config/myalsa.py index 14b8a7b..552c459 100644 --- a/xpybar/config/myalsa.py +++ b/xpybar/config/myalsa.py @@ -1,10 +1,11 @@ # -*- python -*- from plugins.alsa import ALSA +import alsaaudio from common import * class MyALSA(Entry): - def __init__(self, *args, timeout = None, sleep = None, cards = -1, mixers = None, colours = {}, **kwargs): ## TODO support multiple cards and all mixers + def __init__(self, *args, timeout = None, sleep = None, cards = -1, mixers = None, colours = {}, prefix = '', **kwargs): ## TODO support multiple cards and all mixers self.colours = colours if colours is not None else {} if timeout is not None: self.timeout = timeout @@ -27,7 +28,12 @@ class MyALSA(Entry): else: cards = cards self.alsa = [] + names = {} + for index in alsaaudio.card_indexes(): + for name in alsaaudio.card_name(index): + names[name] = index for card in cards: + card = names.get(card, card) for mixer in mixers: ## TODO support by name (and 'default') try: if isinstance(mixer, tuple) or isinstance(mixer, list): @@ -62,6 +68,7 @@ class MyALSA(Entry): break except: pass + self.prefix = prefix self.sep_width = Bar.coloured_length(SEPARATOR) self.get_volume() self.broadcast_update = None @@ -71,6 +78,9 @@ class MyALSA(Entry): xasync((self.refresh_bus, self.refresh_posix_ipc, self.refresh_cmdipc, self.refresh_wait)[method], name = 'alsa') def action(self, col, button, x, y): + if not self.alsa: + return + mixer = 0 mixer_text = self.text.split(SEPARATOR) while mixer < len(mixer_text): ## the limit is just a precaution @@ -173,8 +183,10 @@ class MyALSA(Entry): def get_volume(self): text_v = lambda v : '--%' if v is None else ('%2i%%' % v)[:3] - read_m = lambda m : '%s: %s' % (m.mixername, ' '.join(text_v(v) for v in m.get_volume())) + read_m = lambda m : '%s%s: %s' % (self.prefix, m.mixername, ' '.join(text_v(v) for v in m.get_volume())) text = SEPARATOR.join((self.get_exclusive(m) if isinstance(m, list) else read_m(m)) for m in self.alsa) + if not text: + text = '%s%s' % (self.prefix, 'disconnected') self.text = text def refresh_bus(self): diff --git a/xpybar/config/mycg.py b/xpybar/config/mycg.py new file mode 100644 index 0000000..5b5edee --- /dev/null +++ b/xpybar/config/mycg.py @@ -0,0 +1,51 @@ +# -*- python -*- +from common import * + +class MyCG(Entry): + def __init__(self, title, command, cg_class, *args, priority = None, **kwargs): + self.title = title + self.cg_class = cg_class + rule = '::'.join(cg_class.split('::')[2:]) + self.start_command = [command, '-R', rule] + if priority is not None: + self.start_command.extend(['-p', str(priority)]) + self.stop_command = [command, '-R', rule, '-x'] + Entry.__init__(self, *args, **kwargs) + + def action(self, col, button, x, y): + proc = subprocess.Popen(['cg-query', '-c', '?'], stdout = subprocess.PIPE) + output = [] + while True: + chunk = proc.stdout.read(128) + if not chunk: + break + output.append(chunk) + proc.stdout.close() + proc.wait() + output = b''.join(output).decode('utf-8', 'replace') + crtcs = output.split('\n') + output = [] + for crtc in crtcs: + if not crtc: + continue + proc = subprocess.Popen(['cg-query', '-c', crtc], stdout = subprocess.PIPE) + while True: + chunk = proc.stdout.read(128) + if not chunk: + break + output.append(chunk) + proc.stdout.close() + proc.wait() + output = b''.join(output).decode('utf-8', 'replace') + active = ('\n Class: %s\n' % self.cg_class) in output + del output + print(active) + print(repr(self.stop_command if active else self.start_command)) + subprocess.Popen(self.stop_command if active else self.start_command).wait() + + def function(self): + return self.title + +class MyCGNegative(MyCG): + def __init__(self, *args, title = 'Negative', rule = 'xpybar', priority = None, **kwargs): + MyCG.__init__(self, title, 'cg-negative', 'cg-tools::cg-negative::' + rule, *args, priority = priority, **kwargs) diff --git a/xpybar/config/mynetwork.py b/xpybar/config/mynetwork.py index 79cd271..ca4e18b 100644 --- a/xpybar/config/mynetwork.py +++ b/xpybar/config/mynetwork.py @@ -5,7 +5,7 @@ from plugins.ping import Ping from common import * class MyNetwork(Entry): - def __init__(self, *args, limits = None, ignore = None, pings = None, **kwargs): + def __init__(self, *args, limits = None, ignore = None, pings = None, renamemap = None, **kwargs): self.limits = { 'rx_bytes' : None # Download speed in bytes (not bits) , 'tx_bytes' : None # Upload speed in bytes (not bits) , 'rx_total' : None # Download cap in bytes @@ -25,7 +25,8 @@ class MyNetwork(Entry): self.pings[nic] = ping[nic] else: self.pings[nic] += ping[nic] - self.ignore = ['lo'] if ignore is None else ignore + self.ignore = ['lo'] if ignore is None else list(ignore) + self.renamemap = renamemap self.net_time = time.monotonic() self.net_last = {} self.show_all = True @@ -36,6 +37,15 @@ class MyNetwork(Entry): 'carrier', 'compressed', 'multicast'] self.in_bytes = False # in bits if showing total Entry.__init__(self, *args, **kwargs) + + def networkOK(self, name): + if name.startswith("docker"): + return False + if name.startswith("zcctun"): + return False + if name.startswith("veth"): + return False + return True; def action(self, col, button, x, y): if button == LEFT_BUTTON: @@ -144,6 +154,7 @@ class MyNetwork(Entry): net_now = time.monotonic() net_tdiff, self.net_time = net_now - self.net_time, net_now network = Network(*self.ignore).devices + network = {self.renamemap.get(dev, dev): stat for dev, stat in network.items() if self.networkOK(dev)} label = self.labels[self.show_value] show_total = label == 'total' show_bytes = label == 'bytes' @@ -184,9 +195,9 @@ class MyNetwork(Entry): return ret if self.show_all: if self.show_name: - net = [create(dev, dev) for dev in network] + net = [create(dev, dev) for dev in network if dev] else: - net = [create(None, dev) for dev in network] + net = [create(None, dev) for dev in network if dev] net = (SEPARATOR if self.show_name else ' ').join(net) else: devsum = {} diff --git a/xpybar/config/xmonad-monitor.gpp b/xpybar/config/xmonad-monitor.gpp index 337e661..4e9d0c4 100644 --- a/xpybar/config/xmonad-monitor.gpp +++ b/xpybar/config/xmonad-monitor.gpp @@ -36,6 +36,7 @@ from myalsa import MyALSA 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 @@ -57,6 +58,9 @@ 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] @@ -79,8 +83,23 @@ def mqueue_wait(): 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') -mixers = ['Master', 'PCM'] ## TODO -#mixers.append(('Headphone', 'Speaker')) +%%>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' +%%>else +card1 = 'HD-Audio Generic' +%%>fi +mixers1 = ['Master', 'PCM'] ## TODO +%%>if iswork; then +#mixers1.append(('Headphone', 'Speaker')) +if not isvm: + mixers1.extend(('Headphone', 'Speaker')) +%%>fi +card2 = 'Yeti Stereo Microphone' +mixers2 = ['Speaker', 'Mic'] #myii = ... #myirc = ... #from plugins.ii import II @@ -102,8 +121,8 @@ mybattery = MyBattery(None) %%>fi pingthese = [] -%%>if test -r ~/.dotfiles/.secrets/ping-"$(hostname | tr '[[:upper:]]' '[[:lower:]]')"; then -%%> for address in $(cat ~/.dotfiles/.secrets/ping-"$(hostname | tr '[[:upper:]]' '[[:lower:]]')"); do +%%>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 @@ -120,10 +139,29 @@ 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, mixers = mixers, colours = {'Speaker' : '31'}) + , 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 @@ -131,7 +169,7 @@ functions = [ [ myxmonad , MyCPU (lambda f : Clocked(f, 2)) , MyMemory (lambda f : Clocked(f, 2)) , None - , MyNetwork (lambda f : Clocked(f, 2), pings = pingthese) + , MyNetwork (lambda f : Clocked(f, 2), ignore = netignorelist, pings = pingthese, renamemap = netrenamemap) #, myirc %%>if test -x /usr/bin/featherweight; then , MyNews (None) @@ -141,7 +179,11 @@ functions = [ [ myxmonad ] , [ 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 @@ -151,8 +193,13 @@ functions = [ [ myxmonad #, myii , None , MyStat (lambda f : Clocked(f, 10)) +%%>if test ! "$hostname" = zenith; then + , MyCGNegative() +%%>fi , MyBrilliance(None) - #, MyBacklight (None) +%%>if test ! "$hostname" = zenith; then + , MyBacklight (None) +%%>fi #, MyIO (lambda f : Clocked(f, 10), fs_ignore = []) ] ] @@ -176,6 +223,7 @@ def update_per_clock(): G.semaphore.release() invalidate() + start_ = start def start(): start_() |