From 864a89ba4ebe7d807ce771d2791dbac39dc55d84 Mon Sep 17 00:00:00 2001 From: Uyanide Date: Thu, 8 Jan 2026 19:22:09 +0100 Subject: [PATCH] wallpaper-daemon: I hate threading --- .../scripts/.local/scripts/wallpaper-daemon | 34 +++++++++++++------ config/shell/.config/posh_theme.omp.json | 7 +++- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/config/scripts/.local/scripts/wallpaper-daemon b/config/scripts/.local/scripts/wallpaper-daemon index 6d20fc1..c2f67e6 100755 --- a/config/scripts/.local/scripts/wallpaper-daemon +++ b/config/scripts/.local/scripts/wallpaper-daemon @@ -25,20 +25,20 @@ BLURRED_WALLPAPER_DIR = Path("~/.local/share/wallpaper/blurred").expanduser() def getFirstFile(dir: Path, pattern: str = "*") -> Path | None: - '''`find $dir -type f | head -n 1`''' + """`find $dir -type f | head -n 1`""" return next(dir.glob(pattern), None) def getNiriSocket(): - return environ['NIRI_SOCKET'] + return environ["NIRI_SOCKET"] def _log(msg: str): # print(msg) - # logFIle = Path("/tmp/niri-autoblur.log") + # logFile = Path("/tmp/niri-autoblur.log") # try: - # with logFIle.open("a") as f: + # with logFile.open("a") as f: # f.write(msg + "\n") # except Exception: # pass @@ -58,7 +58,7 @@ def swwwLoadImg(namespace: str, wallpaper: Path): "--transition-duration", "0.5", ] - _log(f"[SWWW] {" ".join(cmd)}") + _log(f"[SWWW] {' '.join(cmd)}") ret = 0 try: ret = subprocess.run(cmd, check=True).returncode @@ -90,7 +90,11 @@ def swwwStartDaemon(namespace: str): pass try: - subprocess.Popen(["swww-daemon", "-n", namespace], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + subprocess.Popen( + ["swww-daemon", "-n", namespace], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) _log(f"[SWWW] daemon started for namespace: {namespace}") return True except Exception as e: @@ -163,7 +167,7 @@ class AutoBlur: @staticmethod def initIsBlurred() -> bool: - '''[ $(niri msg focused-window | wc -l) -gt 1 ]''' + """[ $(niri msg focused-window | wc -l) -gt 1 ]""" cmd = ["niri", "msg", "focused-window"] try: output = subprocess.check_output(cmd, text=True) @@ -192,15 +196,21 @@ class AutoBlur: self._thread.start() def _run(self) -> None: - '''Wait until wallpapers are ready & apply the correct one according to the current state''' + """Wait until wallpapers are ready & apply the correct one according to the current state""" while True: - if self._isBlurred.is_set(): + setBlurred = self._isBlurred.is_set() + if setBlurred: wallpaper = getFirstFile(self._blurredDir) else: wallpaper = getFirstFile(self._normalDir) if wallpaper is not None and wallpaper.exists(): - if self._apply(wallpaper): + success = self._apply(wallpaper) + if setBlurred != self._isBlurred.is_set(): + # State changed during apply, loop again immediately + continue + if success: + # Applied successfully break sleep(self._interval) @@ -254,7 +264,9 @@ def handleEvent(event_name, payload): def printEvent(eventName, payload): - _log(f"[EventHandler] event: {eventName}, payload:\n{json.dumps(payload, indent=2, ensure_ascii=False)}") + _log( + f"[EventHandler] event: {eventName}, payload:\n{json.dumps(payload, indent=2, ensure_ascii=False)}" + ) def connectNiri(niriSocket: str, handler) -> bool: diff --git a/config/shell/.config/posh_theme.omp.json b/config/shell/.config/posh_theme.omp.json index a4d2194..2b6d149 100755 --- a/config/shell/.config/posh_theme.omp.json +++ b/config/shell/.config/posh_theme.omp.json @@ -41,7 +41,12 @@ "options": { "branch_icon": "\ue725 ", "fetch_status": true, - "fetch_upstream_icon": true + "fetch_upstream_icon": true, + "mapped_branches": { + "feat/*": "🚀 ", + "bug/*": "🐛 ", + "dev/*": "🚧 " + } }, "style": "powerline", "template": " {{ .UpstreamIcon }} {{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} \ueb4b {{ .StashCount }}{{ end }} ",