aboutsummaryrefslogtreecommitdiffstats
path: root/bin/udt-accent
diff options
context:
space:
mode:
Diffstat (limited to 'bin/udt-accent')
-rwxr-xr-xbin/udt-accent34
1 files changed, 34 insertions, 0 deletions
diff --git a/bin/udt-accent b/bin/udt-accent
index fbd6a65..978f340 100755
--- a/bin/udt-accent
+++ b/bin/udt-accent
@@ -39,6 +39,7 @@ MIN_CHROMA = 10.0
OUTPUT = Path.home() / ".cache" / "wal" / "udt-accent.rasi"
BORDER_OUTPUT = Path.home() / ".cache" / "wal" / "udt-border.lua"
+DUNSTRC = Path.home() / ".cache" / "wal" / "dunstrc"
def _to_lab(hexval):
@@ -162,6 +163,38 @@ def write_border(name):
raise
+def write_dunst(name):
+ """Substitute the accent into the dunst config pywal just rendered.
+
+ pywal owns that file, so this runs after it and rewrites in place. A
+ missing file is not an error: dunst simply may not be configured here.
+ """
+ try:
+ text = DUNSTRC.read_text()
+ except FileNotFoundError:
+ return
+
+ if "@ACCENT@" not in text:
+ return
+
+ fd, tmp = tempfile.mkstemp(dir=str(DUNSTRC.parent), suffix=".tmp")
+ try:
+ with os.fdopen(fd, "w") as handle:
+ handle.write(text.replace("@ACCENT@", ACCENTS[name]))
+ os.replace(tmp, DUNSTRC)
+ except BaseException:
+ if os.path.exists(tmp):
+ os.unlink(tmp)
+ raise
+
+ # Restart dunst so it rereads the file. It must be started again, not just
+ # killed: nothing else respawns it, and a dead dunst means no notifications
+ # at all.
+ if subprocess.run(["pkill", "-x", "dunst"], capture_output=True).returncode == 0:
+ subprocess.Popen(["dunst"], start_new_session=True,
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+
+
def main(image):
try:
name = snap(signature_color(image))
@@ -172,6 +205,7 @@ def main(image):
write_accent(name)
write_border(name)
+ write_dunst(name)
# Hyprland only rereads its config on request, and may not be running.
subprocess.run(["hyprctl", "reload"], capture_output=True, check=False)