mirror of
https://github.com/outbackdingo/hyprcosmic-session.git
synced 2026-08-25 14:53:23 +00:00
Pressing PrtScr said "COSMIC screenshot crashed". cosmic-screenshot was aborting on an unwrap, because org.freedesktop.portal.Screenshot had no implementation behind it. start-hyprcosmic exported XDG_CURRENT_DESKTOP=COSMIC, and the compositor had it. But an export only reaches processes started by this script, and the portal is not one of them: xdg-desktop-portal is launched by `systemd --user`, which is older than the session and carries its own environment block. Its copy had XDG_SESSION_TYPE and nothing else. xdg-desktop-portal chooses a backend by matching the `UseIn=` line of /usr/share/xdg-desktop-portal/portals/*.portal against XDG_CURRENT_DESKTOP. Unset, `UseIn=COSMIC` never matched, no backend loaded, and the Screenshot interface was never exported. Nothing anywhere logged a missing portal. The crash was the only symptom, and it pointed at the screenshot tool. `systemctl --user import-environment` fixes it, which is what start-cosmic has always done and this script had not. Ordering works out: the portal unit is `After=` and `Requisite=graphical-session.target`, which cosmic-session brings up later, so it cannot start ahead of the import. dbus-update-activation-environment as well, for any backend whose .service file has no `SystemdService=` line -- but only when a bus already exists, since in the dbus-run-session branch the bus is created after this point. Everything is `||:`. Losing a portal is bad; refusing to log in is worse. Verified by clearing all three variables out of the user manager, running the script's environment block, restarting xdg-desktop-portal, and watching the Screenshot interface come back and cosmic-screenshot exit 0 with a real PNG.