bumblebee-status/modules/contrib/dunst.py

40 lines
1.1 KiB
Python
Raw Normal View History

2020-03-07 13:48:54 +01:00
#pylint: disable=C0111,R0903
2020-03-07 13:49:09 +01:00
'''Toggle dunst notifications.'''
2020-03-07 13:48:54 +01:00
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,
2020-03-07 13:49:09 +01:00
bumblebee.output.Widget(full_text='')
2020-03-07 13:48:54 +01:00
)
self._paused = False
# Make sure that dunst is currently not paused
try:
2020-03-07 13:49:09 +01:00
bumblebee.util.execute('killall -SIGUSR2 dunst')
2020-03-07 13:48:54 +01:00
except:
pass
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
cmd=self.toggle_status
)
def toggle_status(self, event):
self._paused = not self._paused
try:
if self._paused:
2020-03-07 13:49:09 +01:00
bumblebee.util.execute('killall -SIGUSR1 dunst')
2020-03-07 13:48:54 +01:00
else:
2020-03-07 13:49:09 +01:00
bumblebee.util.execute('killall -SIGUSR2 dunst')
2020-03-07 13:48:54 +01:00
except:
self._paused = not self._paused # toggling failed
def state(self, widget):
if self._paused:
2020-03-07 13:49:09 +01:00
return ['muted', 'warning']
return ['unmuted']