From 6855d3f0b58c3af35a90398d1e14c5e79d832270 Mon Sep 17 00:00:00 2001 From: humocs-man Date: Sun, 25 Oct 2026 07:32:15 +0100 Subject: [PATCH] fix: Bing-Wallpaper auch ungedockt anwenden + auf allen Monitoren spiegeln --- scripts/bing-wallpaper.sh | 37 ++++++++++++---- scripts/kanshi-autoconfig | 93 ++++++++++++++++++++++++++++----------- 2 files changed, 96 insertions(+), 34 deletions(-) diff --git a/scripts/bing-wallpaper.sh b/scripts/bing-wallpaper.sh index 09aa6d2..840befb 100644 --- a/scripts/bing-wallpaper.sh +++ b/scripts/bing-wallpaper.sh @@ -46,15 +46,34 @@ if [[ "${#KEEP[@]}" -gt 0 ]]; then fi echo "Bereinigt, behalten: ${#KEEP[@]}" -# Direkt setzen. Laeuft die Shell noch nicht (Timer feuert beim Login via -# Persistent oft vor Noctalia), bis zu ~2 Min warten statt aufzugeben. -command -v noctalia >/dev/null 2>&1 || { echo "FEHLER: noctalia fehlt im Image"; exit 1; } -TRIES=24 -until noctalia msg wallpaper-set "${TARGET}" && echo "Gesetzt: ${TARGET}"; do - TRIES=$((TRIES - 1)) - if [[ ${TRIES} -le 0 ]]; then - echo "Noctalia laeuft nicht - Datei liegt bereit" - exit 0 +# Direkt setzen. Timer feuert beim Login (Persistent) oft vor Noctalia, daher +# erst auf Bereitschaft warten, dann einmal (mit wenigen Wiederholungen fuer +# die asynchrone Output-Registrierung) feuern statt blind zu pollen. +command -v /usr/bin/noctalia >/dev/null 2>&1 || command -v noctalia >/dev/null 2>&1 || { echo "FEHLER: noctalia fehlt im Image"; exit 1; } +NOCTALIA="$(command -v /usr/bin/noctalia 2>/dev/null || command -v noctalia)" + +# 1) Auf Noctalia warten (IPC antwortet), bis zu ~2 Min. +READY=0 +for ((i=0; i<24; i++)); do + if "${NOCTALIA}" msg wallpaper-get >/dev/null 2>&1; then + READY=1 + break fi sleep 5 done +if [[ ${READY} -eq 0 ]]; then + echo "Noctalia laeuft nicht - Datei liegt bereit" + exit 0 +fi + +# 2) Kurz warten, bis Outputs registriert sind, dann setzen (wenige Retries). +sleep 2 +TRIES=6 +until "${NOCTALIA}" msg wallpaper-set "${TARGET}" && echo "Gesetzt: ${TARGET}"; do + TRIES=$((TRIES - 1)) + if [[ ${TRIES} -le 0 ]]; then + echo "Wallpaper konnte nicht gesetzt werden - Datei liegt bereit" + exit 0 + fi + sleep 3 +done diff --git a/scripts/kanshi-autoconfig b/scripts/kanshi-autoconfig index 66abb20..4fa51da 100755 --- a/scripts/kanshi-autoconfig +++ b/scripts/kanshi-autoconfig @@ -444,33 +444,68 @@ def bing_opted_in(): / "timers.target.wants" / "bing-wallpaper.timer").exists() -def maybe_refresh_bing_wallpaper(): - """Bing-Wallpaper nach Output-Wechsel neu auf alle Monitore setzen. - Hintergrund: Neu erscheinende Outputs bekommen sonst Noctalias - Verzeichnis-Default (z.B. curvy-d.jxl) statt Bing. Nur bei aktivem - Opt-in (Timer enabled) - sonst bleibt eine per Picker gewaehlte - Tapete unangetastet. Best-effort: Fehler nur loggen.""" +def maybe_refresh_wallpaper(): + """Aktuelles Wallpaper nach Output-Wechsel (und beim Login) auf ALLE + Monitore spiegeln. Hintergrund: Neu angeschlossene Outputs bekommen + sonst Noctalias Verzeichnis-Default (z.B. curvy-d.jxl) statt des + laufenden Wallpapers; ausserdem lag die vom 06:00-Timer geladene + Bing-Datei bisher unangewendet, wenn Noctalia beim Timer-Lauf noch + nicht lief (dann schien das Bing-Skript nur gedockt zu wirken). + + Zielpfad: + - Bing Opt-in + heutige Datei vorhanden -> heutiges Bing-Bild + (taegliche Aktualisierung, egal ob gedockt oder nicht). + - sonst das aktuell gesetzte Default-Wallpaper + (noctalia msg wallpaper-get), damit beim Andocken dasselbe + Wallpaper auf allen Monitoren erscheint. + Nur bei gesetztem Ziel; Best-effort: Fehler nur loggen.""" from datetime import date - if not bing_opted_in(): + noctalia_bin = "/usr/bin/noctalia" if Path("/usr/bin/noctalia").is_file() else "noctalia" + + target = None + if bing_opted_in(): + pics = Path.home() / "Bilder" + if not pics.is_dir(): + pics = Path.home() / "Pictures" + bing = pics / "Bing" / f"bing-{date.today().isoformat()}.jpg" + if bing.is_file(): + target = bing + if target is None: + # Aktuelles Default-Wallpaper ermitteln (Fallback fuer Nicht-Bing + # und fuer den Fall, dass die Bing-Datei noch fehlt). + try: + r = subprocess.run( + [noctalia_bin, "msg", "wallpaper-get"], + timeout=15, check=False, capture_output=True, text=True, + ) + if r.returncode == 0: + pth = r.stdout.strip() + if pth and Path(pth).is_file(): + target = Path(pth) + except Exception: # noqa: BLE001 - optionaler Schritt + pass + if target is None: return - pics = Path.home() / "Bilder" - if not pics.is_dir(): - pics = Path.home() / "Pictures" - target = pics / "Bing" / f"bing-{date.today().isoformat()}.jpg" - if not target.is_file(): - return - try: - r = subprocess.run( - ["noctalia", "msg", "wallpaper-set", str(target)], - timeout=30, check=False, capture_output=True, text=True, - ) - if r.returncode == 0: - print(f"Bing-Wallpaper erneuert: {target}", flush=True) - else: - print(f"WARN: wallpaper-set fehlgeschlagen: {r.stderr.strip()[:200]}", + + # Noctalia registriert frisch erschienene Outputs asynchron; ein + # sofortiger wallpaper-set wuerde sie sonst verpassen. Daher kurz + # warten und bei Bedarf wiederholen. + for attempt in range(5): + if attempt: + time.sleep(2) + try: + r = subprocess.run( + [noctalia_bin, "msg", "wallpaper-set", str(target)], + timeout=30, check=False, capture_output=True, text=True, + ) + if r.returncode == 0: + print(f"Wallpaper gespiegelt: {target}", flush=True) + return + print(f"WARN: wallpaper-set fehlgeschlagen (Versuch {attempt + 1}): " + f"{r.stderr.strip()[:200]}", file=sys.stderr, flush=True) + except Exception as e: # noqa: BLE001 - optionaler Schritt + print(f"WARN: wallpaper-set nicht moeglich (Versuch {attempt + 1}): {e}", file=sys.stderr, flush=True) - except Exception as e: # noqa: BLE001 - optionaler Schritt - print(f"WARN: wallpaper-set nicht moeglich: {e}", file=sys.stderr, flush=True) def is_internal_name(name): @@ -568,6 +603,14 @@ def run_watch(): # Erstlauf: wie --apply-if-managed sicherstellen, kanshi starten. if is_managed(CONFIG_PATH) and names != config_output_names(CONFIG_PATH): apply(merge_configs(safe_read(CONFIG_PATH), render(outputs))) + # Beim Login (insb. ungedockt) anstehendes Wallpaper + # anwenden: der 06:00-Timer feuert oft vor dem Login, dann + # liegt die Bing-Datei zwar bereit, wird aber nie gesetzt - + # bisher griff das erst beim Docking-Wechsel (daher schien + # das Bing-Skript nur gedockt zu wirken). Zudem wird das + # aktuelle Wallpaper auf alle Monitore gespiegelt, sobald + # welche erscheinen. + maybe_refresh_wallpaper() elif names != last_set: # Abdock-Sequenz: Waren Externe da und ist jetzt (auch) ein # internes Panel da, erst das interne anzünden und kurz @@ -585,7 +628,7 @@ def run_watch(): apply(merge_configs(safe_read(CONFIG_PATH), render(outputs))) child = restart_kanshi(child) profile = matching_profile_name(names) - maybe_refresh_bing_wallpaper() + maybe_refresh_wallpaper() notify_send("Monitorprofil gewechselt", f"{profile or 'unbekannt'}: {', '.join(sorted(names))}") last_set = names