aboutsummaryrefslogtreecommitdiffstats
path: root/xpybar/config/myalsa.py
diff options
context:
space:
mode:
Diffstat (limited to 'xpybar/config/myalsa.py')
-rw-r--r--xpybar/config/myalsa.py16
1 files changed, 14 insertions, 2 deletions
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):