From d568ef36228e074b75f277b0aab197b6c588877a Mon Sep 17 00:00:00 2001 From: Cristian Miranda Date: Fri, 4 Sep 2020 17:30:46 -0300 Subject: [PATCH] [modules/dunstctl]: Toggle dunst v1.5.0+ notifications using dunstctl --- bumblebee_status/modules/contrib/dunstctl.py | 42 ++++++++++++++++++++ themes/icons/awesome-fonts.json | 4 ++ 2 files changed, 46 insertions(+) create mode 100644 bumblebee_status/modules/contrib/dunstctl.py diff --git a/bumblebee_status/modules/contrib/dunstctl.py b/bumblebee_status/modules/contrib/dunstctl.py new file mode 100644 index 0000000..1b7649c --- /dev/null +++ b/bumblebee_status/modules/contrib/dunstctl.py @@ -0,0 +1,42 @@ +# pylint: disable=C0111,R0903 + +""" +Toggle dunst notifications using dunstctl. + +When notifications are paused using this module dunst doesn't get killed and you'll keep getting notifications on the background that will be displayed when unpausing. +This is specially useful if you're using dunst's scripting (https://wiki.archlinux.org/index.php/Dunst#Scripting), which requires dunst to be running. Scripts will be executed when dunst gets unpaused. + +Requires: + * dunst v1.5.0+ + +contributed by `cristianmiranda `_ - many thanks! +""" + +import core.module +import core.widget +import core.input + +import util.cli + + +class Module(core.module.Module): + def __init__(self, config, theme): + super().__init__(config, theme, core.widget.Widget("")) + self._paused = self.__isPaused() + core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.toggle_status) + + def toggle_status(self, event): + self._paused = self.__isPaused() + if self._paused: + util.cli.execute("dunstctl set-paused false") + else: + util.cli.execute("dunstctl set-paused true") + self._paused = not self._paused + + def __isPaused(self): + return util.cli.execute("dunstctl is-paused").strip() == "true" + + def state(self, widget): + if self._paused: + return ["muted", "warning"] + return ["unmuted"] diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index ca8d38f..963bcea 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -257,6 +257,10 @@ "muted": { "prefix": "" }, "unmuted": { "prefix": "" } }, + "dunstctl": { + "muted": { "prefix": "" }, + "unmuted": { "prefix": "" } + }, "twmn": { "muted": { "prefix": "" }, "unmuted": { "prefix": "" }