From 69e478018278718ee2a6679d7725ee7dc0ae1a84 Mon Sep 17 00:00:00 2001 From: zetxx Date: Wed, 15 Mar 2017 22:55:05 +0200 Subject: [PATCH] feat: added volume level for amixer --- bumblebee/modules/amixer.py | 34 +++++++++++++++++++++++++++++++++ themes/icons/ascii.json | 4 ++++ themes/icons/awesome-fonts.json | 5 ++++- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 bumblebee/modules/amixer.py diff --git a/bumblebee/modules/amixer.py b/bumblebee/modules/amixer.py new file mode 100644 index 0000000..e8991fb --- /dev/null +++ b/bumblebee/modules/amixer.py @@ -0,0 +1,34 @@ +"""get volume level + +""" +import re + +import bumblebee.input +import bumblebee.output +import bumblebee.engine + +class Module(bumblebee.engine.Module): + def __init__(self, engine, config): + super(Module, self).__init__(engine, config, + bumblebee.output.Widget(full_text=self.volume) + ) + self._level = 0 + self._muted = False + device = self.parameter("device", "Master,0") + self._cmdString = "amixer get {}".format(device) + + def volume(self, widget): + m = re.search(r'([\d]+)\%', self._level) + self._muted = False + if m == "0": + self._muted = True + + return "{}%".format(m.group(1)) + + def update(self, widgets): + self._level = bumblebee.util.execute(self._cmdString) + + def state(self, widget): + if self._muted: + return [ "warning", "muted" ] + return [ "unmuted" ] diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json index de89921..c29c6d5 100644 --- a/themes/icons/ascii.json +++ b/themes/icons/ascii.json @@ -22,6 +22,10 @@ "muted": { "prefix": "audio(mute)" }, "unmuted": { "prefix": "audio" } }, + "amixer": { + "muted": { "prefix": "audio(mute)" }, + "unmuted": { "prefix": "audio" } + }, "pasource": { "muted": { "prefix": "mic(mute)" }, "unmuted": { "prefix": "mic" } diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 69dd60f..a6c1c90 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -9,7 +9,6 @@ "cpu": { "prefix": "" }, "disk": { "prefix": "" }, "dnf": { "prefix": "" }, - "pacman": { "prefix": "" }, "brightness": { "prefix": "" }, "load": { "prefix": "" }, "layout": { "prefix": "" }, @@ -35,6 +34,10 @@ "muted": { "prefix": "" }, "unmuted": { "prefix": "" } }, + "amixer": { + "muted": { "prefix": "" }, + "unmuted": { "prefix": "" } + }, "pasource": { "muted": { "prefix": "" }, "unmuted": { "prefix": "" }