2020-05-03 11:15:52 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
2020-03-07 13:48:54 +01:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
"""Toggle dunst notifications."""
|
2020-03-07 13:48:54 +01:00
|
|
|
|
2020-03-07 13:54:45 +01:00
|
|
|
import core.module
|
|
|
|
import core.widget
|
|
|
|
import core.input
|
2020-03-07 13:48:54 +01:00
|
|
|
|
2020-03-07 13:54:45 +01:00
|
|
|
import util.cli
|
2020-03-07 13:48:54 +01:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-03-07 13:54:45 +01:00
|
|
|
class Module(core.module.Module):
|
2020-04-26 16:39:24 +02:00
|
|
|
def __init__(self, config, theme):
|
2020-05-03 11:15:52 +02:00
|
|
|
super().__init__(config, theme, core.widget.Widget(""))
|
2020-03-07 13:48:54 +01:00
|
|
|
self._paused = False
|
|
|
|
# Make sure that dunst is currently not paused
|
2020-05-03 11:15:52 +02:00
|
|
|
util.cli.execute("killall -s SIGUSR2 dunst", ignore_errors=True)
|
|
|
|
core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.toggle_status)
|
2020-03-07 13:48:54 +01:00
|
|
|
|
|
|
|
def toggle_status(self, event):
|
|
|
|
self._paused = not self._paused
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-03-07 13:48:54 +01:00
|
|
|
try:
|
|
|
|
if self._paused:
|
2020-05-03 11:15:52 +02:00
|
|
|
util.cli.execute("killall -s SIGUSR1 dunst")
|
2020-03-07 13:48:54 +01:00
|
|
|
else:
|
2020-05-03 11:15:52 +02:00
|
|
|
util.cli.execute("killall -s SIGUSR2 dunst")
|
2020-03-07 13:48:54 +01:00
|
|
|
except:
|
2020-05-03 11:15:52 +02:00
|
|
|
self._paused = not self._paused # toggling failed
|
2020-03-07 13:48:54 +01:00
|
|
|
|
|
|
|
def state(self, widget):
|
|
|
|
if self._paused:
|
2020-05-03 11:15:52 +02:00
|
|
|
return ["muted", "warning"]
|
|
|
|
return ["unmuted"]
|