fix: Bing-Wallpaper auch ungedockt anwenden + auf allen Monitoren spiegeln
This commit is contained in:
1 parent
bf6bfee7f9
commit
6855d3f0b5
2 files changed
+89
-27
No files matched your search
@@ -46,15 +46,34 @@ if [[ "${#KEEP[@]}" -gt 0 ]]; then
|
|||||||
fi
|
fi
|
||||||
echo "Bereinigt, behalten: ${#KEEP[@]}"
|
echo "Bereinigt, behalten: ${#KEEP[@]}"
|
||||||
|
|
||||||
# Direkt setzen. Laeuft die Shell noch nicht (Timer feuert beim Login via
|
# Direkt setzen. Timer feuert beim Login (Persistent) oft vor Noctalia, daher
|
||||||
# Persistent oft vor Noctalia), bis zu ~2 Min warten statt aufzugeben.
|
# erst auf Bereitschaft warten, dann einmal (mit wenigen Wiederholungen fuer
|
||||||
command -v noctalia >/dev/null 2>&1 || { echo "FEHLER: noctalia fehlt im Image"; exit 1; }
|
# die asynchrone Output-Registrierung) feuern statt blind zu pollen.
|
||||||
TRIES=24
|
command -v /usr/bin/noctalia >/dev/null 2>&1 || command -v noctalia >/dev/null 2>&1 || { echo "FEHLER: noctalia fehlt im Image"; exit 1; }
|
||||||
until noctalia msg wallpaper-set "${TARGET}" && echo "Gesetzt: ${TARGET}"; do
|
NOCTALIA="$(command -v /usr/bin/noctalia 2>/dev/null || command -v noctalia)"
|
||||||
TRIES=$((TRIES - 1))
|
|
||||||
if [[ ${TRIES} -le 0 ]]; then
|
# 1) Auf Noctalia warten (IPC antwortet), bis zu ~2 Min.
|
||||||
echo "Noctalia laeuft nicht - Datei liegt bereit"
|
READY=0
|
||||||
exit 0
|
for ((i=0; i<24; i++)); do
|
||||||
|
if "${NOCTALIA}" msg wallpaper-get >/dev/null 2>&1; then
|
||||||
|
READY=1
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
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
|
||||||
+61
-18
@@ -444,33 +444,68 @@ def bing_opted_in():
|
|||||||
/ "timers.target.wants" / "bing-wallpaper.timer").exists()
|
/ "timers.target.wants" / "bing-wallpaper.timer").exists()
|
||||||
|
|
||||||
|
|
||||||
def maybe_refresh_bing_wallpaper():
|
def maybe_refresh_wallpaper():
|
||||||
"""Bing-Wallpaper nach Output-Wechsel neu auf alle Monitore setzen.
|
"""Aktuelles Wallpaper nach Output-Wechsel (und beim Login) auf ALLE
|
||||||
Hintergrund: Neu erscheinende Outputs bekommen sonst Noctalias
|
Monitore spiegeln. Hintergrund: Neu angeschlossene Outputs bekommen
|
||||||
Verzeichnis-Default (z.B. curvy-d.jxl) statt Bing. Nur bei aktivem
|
sonst Noctalias Verzeichnis-Default (z.B. curvy-d.jxl) statt des
|
||||||
Opt-in (Timer enabled) - sonst bleibt eine per Picker gewaehlte
|
laufenden Wallpapers; ausserdem lag die vom 06:00-Timer geladene
|
||||||
Tapete unangetastet. Best-effort: Fehler nur loggen."""
|
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
|
from datetime import date
|
||||||
if not bing_opted_in():
|
noctalia_bin = "/usr/bin/noctalia" if Path("/usr/bin/noctalia").is_file() else "noctalia"
|
||||||
return
|
|
||||||
|
target = None
|
||||||
|
if bing_opted_in():
|
||||||
pics = Path.home() / "Bilder"
|
pics = Path.home() / "Bilder"
|
||||||
if not pics.is_dir():
|
if not pics.is_dir():
|
||||||
pics = Path.home() / "Pictures"
|
pics = Path.home() / "Pictures"
|
||||||
target = pics / "Bing" / f"bing-{date.today().isoformat()}.jpg"
|
bing = pics / "Bing" / f"bing-{date.today().isoformat()}.jpg"
|
||||||
if not target.is_file():
|
if bing.is_file():
|
||||||
return
|
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:
|
try:
|
||||||
r = subprocess.run(
|
r = subprocess.run(
|
||||||
["noctalia", "msg", "wallpaper-set", str(target)],
|
[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
|
||||||
|
|
||||||
|
# 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,
|
timeout=30, check=False, capture_output=True, text=True,
|
||||||
)
|
)
|
||||||
if r.returncode == 0:
|
if r.returncode == 0:
|
||||||
print(f"Bing-Wallpaper erneuert: {target}", flush=True)
|
print(f"Wallpaper gespiegelt: {target}", flush=True)
|
||||||
else:
|
return
|
||||||
print(f"WARN: wallpaper-set fehlgeschlagen: {r.stderr.strip()[:200]}",
|
print(f"WARN: wallpaper-set fehlgeschlagen (Versuch {attempt + 1}): "
|
||||||
file=sys.stderr, flush=True)
|
f"{r.stderr.strip()[:200]}", file=sys.stderr, flush=True)
|
||||||
except Exception as e: # noqa: BLE001 - optionaler Schritt
|
except Exception as e: # noqa: BLE001 - optionaler Schritt
|
||||||
print(f"WARN: wallpaper-set nicht moeglich: {e}", file=sys.stderr, flush=True)
|
print(f"WARN: wallpaper-set nicht moeglich (Versuch {attempt + 1}): {e}",
|
||||||
|
file=sys.stderr, flush=True)
|
||||||
|
|
||||||
|
|
||||||
def is_internal_name(name):
|
def is_internal_name(name):
|
||||||
@@ -568,6 +603,14 @@ def run_watch():
|
|||||||
# Erstlauf: wie --apply-if-managed sicherstellen, kanshi starten.
|
# Erstlauf: wie --apply-if-managed sicherstellen, kanshi starten.
|
||||||
if is_managed(CONFIG_PATH) and names != config_output_names(CONFIG_PATH):
|
if is_managed(CONFIG_PATH) and names != config_output_names(CONFIG_PATH):
|
||||||
apply(merge_configs(safe_read(CONFIG_PATH), render(outputs)))
|
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:
|
elif names != last_set:
|
||||||
# Abdock-Sequenz: Waren Externe da und ist jetzt (auch) ein
|
# Abdock-Sequenz: Waren Externe da und ist jetzt (auch) ein
|
||||||
# internes Panel da, erst das interne anzünden und kurz
|
# 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)))
|
apply(merge_configs(safe_read(CONFIG_PATH), render(outputs)))
|
||||||
child = restart_kanshi(child)
|
child = restart_kanshi(child)
|
||||||
profile = matching_profile_name(names)
|
profile = matching_profile_name(names)
|
||||||
maybe_refresh_bing_wallpaper()
|
maybe_refresh_wallpaper()
|
||||||
notify_send("Monitorprofil gewechselt",
|
notify_send("Monitorprofil gewechselt",
|
||||||
f"{profile or 'unbekannt'}: {', '.join(sorted(names))}")
|
f"{profile or 'unbekannt'}: {', '.join(sorted(names))}")
|
||||||
last_set = names
|
last_set = names
|
||||||
|
|||||||
Reference in new issue
Block a user