refactor: Review-Funde umgesetzt (Notify-Parsing, Flatpak-Schritte, Asserts, Kanshi-Polling, Appmenu-Quoting, Layer-5-Cache)
This commit is contained in:
1 parent
c5a0fcd35c
commit
8def9724d6
10 files changed
+70
-17
No files matched your search
@@ -51,7 +51,7 @@ from pathlib import Path
|
||||
|
||||
MARKER = "# kanshi-autoconfig: managed"
|
||||
CONFIG_PATH = Path.home() / ".config" / "kanshi" / "config"
|
||||
POLL_INTERVAL = 5
|
||||
POLL_INTERVAL = 10
|
||||
|
||||
|
||||
_VM_CACHE = None
|
||||
@@ -79,12 +79,24 @@ def norm_rate(value):
|
||||
|
||||
|
||||
def choose_mode(modes, current, in_vm):
|
||||
"""Modus waehlen: VM-Heuristik, sonst preferred, sonst current/erster."""
|
||||
"""Modus waehlen: VM-Heuristik (hoechste Aufloesung, bevorzugt ~60 Hz),
|
||||
sonst preferred, sonst current/erster."""
|
||||
if in_vm:
|
||||
# In VMs meldet die Firmware oft einen Kleinstmodus als preferred.
|
||||
# Daher die Aufloesung mit den meisten Pixeln waehlen; bei Gleichstand
|
||||
# die Bildwiederholrate nahe 60 Hz.
|
||||
best = None
|
||||
best_key = None
|
||||
for m in modes:
|
||||
w = m.get("width") or 0
|
||||
h = m.get("height") or 0
|
||||
rate = norm_rate(m.get("refresh") or m.get("rate")) or 0
|
||||
if m.get("width") == 1920 and m.get("height") == 1080 and round(rate) == 60:
|
||||
return m
|
||||
key = (w * h, -abs(rate - 60) if rate else 0)
|
||||
if best_key is None or key > best_key:
|
||||
best_key = key
|
||||
best = m
|
||||
if best is not None:
|
||||
return best
|
||||
for m in modes:
|
||||
if m.get("preferred"):
|
||||
return m
|
||||
|
||||
+14
-8
@@ -20,6 +20,12 @@ import shutil
|
||||
import sys
|
||||
import xml.sax.saxutils as sax
|
||||
|
||||
def esc(value):
|
||||
# sax.escape maskiert standardmaessig nur <, >, &. Fuer Attributwerte
|
||||
# (doppelte Anfuehrungszeichen) zusaetzlich " maskieren, damit Namen/
|
||||
# Icons mit Anfuehrungszeichen das Pipe-Menue nicht ungueltig machen.
|
||||
return sax.escape(str(value), {'"': '"', "'": '''})
|
||||
|
||||
APP_DIRS = [
|
||||
os.path.expanduser("~/.local/share/flatpak/exports/share/applications"),
|
||||
"/var/lib/flatpak/exports/share/applications",
|
||||
@@ -137,23 +143,23 @@ def main():
|
||||
items = sections[label]
|
||||
if not items:
|
||||
continue
|
||||
out.append(' <separator label="%s" />' % sax.escape(label))
|
||||
out.append(' <separator label="%s" />' % esc(label))
|
||||
for _, name, command, icon in sorted(items):
|
||||
if icon:
|
||||
out.append(' <item label="%s" icon="%s">' % (sax.escape(name), sax.escape(icon)))
|
||||
out.append(' <item label="%s" icon="%s">' % (esc(name), esc(icon)))
|
||||
else:
|
||||
out.append(' <item label="%s">' % sax.escape(name))
|
||||
out.append(' <action name="Execute" command="%s" />' % sax.escape(command))
|
||||
out.append(' <item label="%s">' % esc(name))
|
||||
out.append(' <action name="Execute" command="%s" />' % esc(command))
|
||||
out.append(" </item>")
|
||||
rest = sections[FALLBACK_SECTION]
|
||||
if rest:
|
||||
out.append(' <separator label="%s" />' % sax.escape(FALLBACK_SECTION))
|
||||
out.append(' <separator label="%s" />' % esc(FALLBACK_SECTION))
|
||||
for _, name, command, icon in sorted(rest):
|
||||
if icon:
|
||||
out.append(' <item label="%s" icon="%s">' % (sax.escape(name), sax.escape(icon)))
|
||||
out.append(' <item label="%s" icon="%s">' % (esc(name), esc(icon)))
|
||||
else:
|
||||
out.append(' <item label="%s">' % sax.escape(name))
|
||||
out.append(' <action name="Execute" command="%s" />' % sax.escape(command))
|
||||
out.append(' <item label="%s">' % esc(name))
|
||||
out.append(' <action name="Execute" command="%s" />' % esc(command))
|
||||
out.append(" </item>")
|
||||
out.append("</openbox_pipe_menu>")
|
||||
sys.stdout.write("\n".join(out) + "\n")
|
||||
|
||||
@@ -72,8 +72,15 @@ $LOGGER -t "$TAG" "Update gestaged. Suche aktive Desktop-User..."
|
||||
# echter Desktop-Nutzer (eigene greetd-Session) und wird ausgeschlossen.
|
||||
USER_IDS=""
|
||||
if have "${LOGINCTL}"; then
|
||||
# Spaltenlayout von `loginctl list-sessions` ist versionsabhaengig
|
||||
# (CLASS/SEAT/STATE wandern). Daher token-basiert statt fester Indizes:
|
||||
# Zeile muss "seat0" und "user" als eigenstaendige Tokens enthalten und
|
||||
# der Nutzername (3. Spalte) darf nicht "greeter" sein. UIDs deduplizieren.
|
||||
USER_IDS="$(${LOGINCTL} list-sessions --no-legend 2>/dev/null \
|
||||
| awk 'NF >= 6 && $4 == "seat0" && $6 == "user" && $3 != "greeter" {print $2}' || true)"
|
||||
| awk '$0 ~ /(^|[[:space:]])seat0([[:space:]]|$)/ \
|
||||
&& $0 ~ /(^|[[:space:]])user([[:space:]]|$)/ \
|
||||
&& $3 != "greeter" {print $2}' \
|
||||
| sort -u || true)"
|
||||
fi
|
||||
|
||||
if [[ -z "${USER_IDS}" ]]; then
|
||||
@@ -112,6 +119,7 @@ for USER_ID in ${USER_IDS}; do
|
||||
--action="reboot=Jetzt neu starten" \
|
||||
--wait \
|
||||
2>/dev/null || echo "closed")"
|
||||
ACTION="${ACTION:-closed}"
|
||||
if [[ "${ACTION}" == "reboot" ]]; then
|
||||
REBOOT_REQUESTED=1
|
||||
break
|
||||
|
||||
Reference in new issue
Block a user