summaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <55825613+luevano@users.noreply.github.com>2020-12-13 19:55:46 -0700
committerDavid Luevano Alvarado <55825613+luevano@users.noreply.github.com>2020-12-13 19:55:46 -0700
commitadecf122c7df49cf81b884e72c4011240ea5660d (patch)
tree2eb425150fe97c23230277ea2efc6c5ad7331feb /.local
parent9d5adc46d08567a298192b6be95fcec42cf78006 (diff)
Redo config and add dunst do-not-disturb
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/blocks/dunst59
1 files changed, 59 insertions, 0 deletions
diff --git a/.local/bin/blocks/dunst b/.local/bin/blocks/dunst
new file mode 100755
index 0000000..6f7ab0c
--- /dev/null
+++ b/.local/bin/blocks/dunst
@@ -0,0 +1,59 @@
+#!/usr/bin/python
+"""
+A do-not-disturb button for muting Dunst notifications in i3 using i3blocks
+Mute is handled by passing 'DUNST_COMMAND_PAUSE' and 'DUNST_COMMAND_RESUME' to
+the notify-send script and the 'DUNST_MUTE' environment variable is set to keep
+track of the toggle.
+"""
+import os
+import subprocess
+import json
+
+
+def mute_on():
+ '''Turns off dunst notifications'''
+ subprocess.run(["notify-send", "DUNST_COMMAND_PAUSE"], check=True)
+ return {
+ "full_text":"<span font='Font Awesome 5 Free Solid' color='#BE616E'>\uf1f6</span>",
+ "DUNST_MUTE":"on"
+ }
+
+
+def mute_off():
+ '''Turns back on dunst notifications'''
+ subprocess.run(["notify-send", "DUNST_COMMAND_RESUME"], check=True)
+ return {
+ "full_text":"<span font='Font Awesome 5 Free Solid' color='#A4B98E'>\uf0f3</span>",
+ "DUNST_MUTE":"off"
+ }
+
+
+def clicked():
+ '''Returns True if the button was clicked'''
+ button = "BLOCK_BUTTON" in os.environ and os.environ["BLOCK_BUTTON"]
+ return bool(button)
+
+
+def muted():
+ '''Returns True if Dunst is muted'''
+ mute = "DUNST_MUTE" in os.environ and os.environ["DUNST_MUTE"]
+ return mute == 'on'
+
+
+if clicked():
+ # toggle button click to turn mute on and off
+ if muted():
+ RTN = mute_off()
+ else:
+ RTN = mute_on()
+
+
+else:
+ # Set default state using 'DUNST_MUTE' environment variable
+ if muted():
+ RTN = mute_on()
+ else:
+ RTN = mute_off()
+
+
+print(json.dumps(RTN))