Skip to content

Commit

Permalink
Merge pull request #426 from jolange/pr_dunst
Browse files Browse the repository at this point in the history
dunst: simplifications and cleaning
  • Loading branch information
jolange authored Oct 3, 2021
2 parents 8acf36d + 1abdecb commit cb89074
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
1 change: 0 additions & 1 deletion dunst/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ format=json
markup=pango
#min_width=50
#align=center
#DUNST_MUTE=off
```

37 changes: 9 additions & 28 deletions dunst/dunst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"""
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.
Mute is handled using the `dunstctl` command.
"""

__author__ = "Jessey White-Cinis <[email protected]>"
Expand All @@ -16,25 +14,13 @@ import os
import subprocess
import json

def mute_on():
'''Turns off dunst notifications'''
subprocess.run(["dunstctl", "set-paused", "true"], 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(["dunstctl", "set-paused", "false"], check=True)
return {
"full_text":"<span font='Font Awesome 5 Free Solid' color='#A4B98E'>\uf0f3</span>",
"DUNST_MUTE":"off"
}
def mute_toggle():
'''Toggle dunst notifications'''
subprocess.run(["dunstctl", "set-paused", "toggle"], check=True)

def clicked():
'''Returns True if the button was clicked'''
button = "BLOCK_BUTTON" in os.environ and os.environ["BLOCK_BUTTON"]
button = os.environ.get("BLOCK_BUTTON", None)
return bool(button)

def muted():
Expand All @@ -46,16 +32,11 @@ def muted():

if clicked():
# toggle button click to turn mute on and off
if muted():
RTN = mute_off()
else:
RTN = mute_on()
mute_toggle()

if muted():
RTN = {"full_text":"<span font='Font Awesome 5 Free Solid' color='#BE616E'>\uf1f6</span>"}
else:
# Set default state using 'DUNST_MUTE' environment variable
if muted():
RTN = mute_on()
else:
RTN = mute_off()
RTN = {"full_text":"<span font='Font Awesome 5 Free Solid' color='#A4B98E'>\uf0f3</span>"}

print(json.dumps(RTN))

0 comments on commit cb89074

Please sign in to comment.