Skip to content

Commit 32fee17

Browse files
committed
dunst: add dunst, a do-not-disturb button for muting notifications
1 parent 21708ed commit 32fee17

File tree

5 files changed

+122
-0
lines changed

5 files changed

+122
-0
lines changed

dunst/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Jessey White-Cinis
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

dunst/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# dunst
2+
3+
Creates a do-not-disturb button for muting [dunst](https://dunst-project.org/) notifications.
4+
5+
![](dunst.gif)
6+
7+
8+
# Dependencies
9+
10+
- [dunst](https://dunst-project.org/)
11+
- [Font Awesome](https://fontawesome.com) for the [bell](https://fontawesome.com/icons/bell?style=solid) and [bell-slash](https://fontawesome.com/icons/bell-slash?style=solid) icons
12+
13+
14+
# Usage
15+
16+
Clicking the bell icon will toggle dunst notifications from being displayed.
17+
18+
This is accomplished by sending ```notify-send``` the special ```DUNST_COMMAND_PAUSE``` or ```DUNST_COMMAND_RESUME``` message.
19+
20+
21+
# Config
22+
23+
```INI
24+
[dunst]
25+
command=$SCRIPT_DIR/dunst
26+
interval=once
27+
format=json
28+
markup=pango
29+
#min_width=50
30+
#align=center
31+
#DUNST_MUTE=off
32+
```
33+

dunst/dunst

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python3
2+
"""
3+
A do-not-disturb button for muting Dunst notifications in i3 using i3blocks
4+
5+
Mute is handled by passing 'DUNST_COMMAND_PAUSE' and 'DUNST_COMMAND_RESUME' to
6+
the notify-send script and the 'DUNST_MUTE' environment variable is set to keep
7+
track of the toggle.
8+
"""
9+
10+
__author__ = "Jessey White-Cinis <[email protected]>"
11+
__copyright__ = "Copyright (c) 2019 Jessey White-Cinis"
12+
__license__ = "MIT"
13+
__version__ = "1.0.0"
14+
15+
import os
16+
import subprocess
17+
import json
18+
19+
def mute_on():
20+
'''Turns off dunst notifications'''
21+
subprocess.run(["notify-send","DUNST_COMMAND_PAUSE"])
22+
return {
23+
"full_text":"<span font='Font Awesome 5 Free Solid' color='#BE616E'>\uf1f6</span>",
24+
"DUNST_MUTE":"on"
25+
}
26+
27+
def mute_off():
28+
'''Turns back on dunst notifications'''
29+
subprocess.run(["notify-send","DUNST_COMMAND_RESUME"])
30+
return {
31+
"full_text":"<span font='Font Awesome 5 Free Solid' color='#A4B98E'>\uf0f3</span>",
32+
"DUNST_MUTE":"off"
33+
}
34+
35+
def clicked():
36+
'''Returns True if the button was clicked'''
37+
button = "BLOCK_BUTTON" in os.environ and os.environ["BLOCK_BUTTON"]
38+
return bool(button)
39+
40+
def muted():
41+
'''Returns True if Dunst is muted'''
42+
mute = "DUNST_MUTE" in os.environ and os.environ["DUNST_MUTE"]
43+
return mute == 'on'
44+
45+
if clicked():
46+
# toggle button click to turn mute on and off
47+
if muted():
48+
RTN = mute_off()
49+
else:
50+
RTN = mute_on()
51+
52+
else:
53+
# Set default state using 'DUNST_MUTE' environment variable
54+
if muted():
55+
RTN = mute_on()
56+
else:
57+
RTN = mute_off()
58+
59+
print(json.dumps(RTN))

dunst/dunst.gif

1.3 KB
Loading

dunst/i3blocks.conf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[dunst]
2+
command=$SCRIPT_DIR/dunst
3+
markup=pango
4+
interval=once
5+
format=json
6+
#min_width=50
7+
#align=center
8+
#DUNST_MUTE=off
9+

0 commit comments

Comments
 (0)