From 6199866e4c983affa815bd59aaf71b3b1089d149 Mon Sep 17 00:00:00 2001 From: Jeena Date: Sat, 13 Jun 2026 16:47:44 +0900 Subject: [PATCH] fix: make portal startup uwsm-aware to stop light-mode race Logging in via a bare Hyprland session never activates graphical-session.target, so the systemd xdg-desktop-portal units can't start. The old script worked around this by killing and relaunching the portals manually, but that delayed the portal past waybar/chromium startup, so they intermittently came up in light mode. Switch to the "Hyprland (uwsm-managed)" session: uwsm activates graphical-session.target and systemd starts the portals in the right order. The startup script now detects that target and bows out, falling back to the manual launch only on a bare session (e.g. another machine without uwsm). Document uwsm in the README. Co-Authored-By: Claude Opus 4.8 (1M context) --- README.md | 4 ++++ hypr/scripts/xdg-desktop-portal-hyprland.sh | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e23e4dd..a19fddf 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,10 @@ You also need to install all the dependencies: - ttf-jetbrains-mono-nerd (required for waybar icons) - xdg-desktop-portal-hyprland - xdg-desktop-portal-gtk +- uwsm (recommended; log in via the "Hyprland (uwsm-managed)" session so + systemd starts the portals before the autostart apps — otherwise apps like + waybar and chromium intermittently come up in light mode. Without uwsm the + portal startup script falls back to launching the portals manually.) - fcitx5 - fcitx5-hangul diff --git a/hypr/scripts/xdg-desktop-portal-hyprland.sh b/hypr/scripts/xdg-desktop-portal-hyprland.sh index a1ea640..80bc362 100755 --- a/hypr/scripts/xdg-desktop-portal-hyprland.sh +++ b/hypr/scripts/xdg-desktop-portal-hyprland.sh @@ -1,8 +1,23 @@ #!/bin/sh -sleep 1 -killall -e xdg-desktop-portal-hyprland -killall xdg-desktop-portal +# Under a uwsm-managed session, systemd brings up graphical-session.target and +# starts the xdg-desktop-portal units natively, in the right order. In that case +# we must NOT manually kill/relaunch them — doing so fights systemd and causes +# the portal to crash (broken pipe), which left apps stuck in light mode. +# +# So: wait briefly for graphical-session.target. If it comes up (uwsm), bow out. +# If it never does (a bare "Hyprland" session, e.g. launched directly from GDM), +# fall through and start the portals manually as before. +for _ in $(seq 1 10); do + if systemctl --user -q is-active graphical-session.target; then + exit 0 + fi + sleep 0.5 +done + +# Bare session fallback: start the portals by hand. +killall -e xdg-desktop-portal-hyprland 2>/dev/null +killall xdg-desktop-portal 2>/dev/null /usr/lib/xdg-desktop-portal-hyprland & sleep 2 /usr/lib/xdg-desktop-portal &