2020-09-04 22:30:46 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
2020-10-18 15:34:52 +02:00
|
|
|
"""Toggle dunst notifications using dunstctl.
|
2020-09-04 22:30:46 +02:00
|
|
|
|
2020-10-18 15:34:52 +02:00
|
|
|
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.
|
2020-09-04 22:30:46 +02:00
|
|
|
|
|
|
|
Requires:
|
|
|
|
* dunst v1.5.0+
|
|
|
|
|
|
|
|
contributed by `cristianmiranda <https://github.com/cristianmiranda>`_ - many thanks!
|
2020-10-18 15:34:52 +02:00
|
|
|
contributed by `joachimmathes <https://github.com/joachimmathes>`_ - many thanks!
|
2020-09-04 22:30:46 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
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(""))
|
2020-10-18 15:34:52 +02:00
|
|
|
core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.__toggle_state)
|
|
|
|
self.__states = {"unknown": ["unknown", "critical"],
|
|
|
|
"true": ["muted", "warning"],
|
|
|
|
"false": ["unmuted"]}
|
2020-10-04 20:57:48 +02:00
|
|
|
|
2020-10-18 15:34:52 +02:00
|
|
|
def __toggle_state(self, event):
|
|
|
|
util.cli.execute("dunstctl set-paused toggle", ignore_errors=True)
|
2020-09-04 22:30:46 +02:00
|
|
|
|
|
|
|
def state(self, widget):
|
2020-10-18 15:34:52 +02:00
|
|
|
return self.__states[self.__is_dunst_paused()]
|
|
|
|
|
|
|
|
def __is_dunst_paused(self):
|
|
|
|
result = util.cli.execute("dunstctl is-paused",
|
|
|
|
return_exitcode=True,
|
|
|
|
ignore_errors=True)
|
|
|
|
return result[1].rstrip() if result[0] == 0 else "unknown"
|