aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/scripts/PortalHyprland.sh
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2026-07-10 11:21:24 -0700
committerPinapelz <yukais@pinapelz.com>2026-07-10 11:21:24 -0700
commit24de2a31a52d17b6f7214197bdbfeab7428742dd (patch)
treef7736c4712d5a394525a3da2f2b4294e81ba9540 /config/hypr/scripts/PortalHyprland.sh
parent861bf5be200bfcf2440fec4cda911d29ec18493f (diff)
parentbca86bbec4757cec1f6f5bdea2ed210542f10fae (diff)
Merge remote-tracking branch 'upstream'
Diffstat (limited to 'config/hypr/scripts/PortalHyprland.sh')
-rwxr-xr-xconfig/hypr/scripts/PortalHyprland.sh149
1 files changed, 123 insertions, 26 deletions
diff --git a/config/hypr/scripts/PortalHyprland.sh b/config/hypr/scripts/PortalHyprland.sh
index 3d3dc410..54ea71bb 100755
--- a/config/hypr/scripts/PortalHyprland.sh
+++ b/config/hypr/scripts/PortalHyprland.sh
@@ -10,21 +10,73 @@
set -euo pipefail
is_ubuntu_family() {
if [[ ! -r /etc/os-release ]]; then
- return 1
+ #return 1
+ # It's been reported this also addresses
+ # The xdg-desktop-portal failure when not using
+ # UWSM on Arch
+ exit 0
fi
# shellcheck disable=SC1091
. /etc/os-release
- [[ "${ID:-}" == "ubuntu" \
- || "${ID:-}" == "linuxmint" \
- || "${ID:-}" == "zorin" \
- || "${ID:-}" == "rhino" \
- || "${ID_LIKE:-}" == *ubuntu* ]]
+ [[ "${ID:-}" == "ubuntu" ||
+ "${ID:-}" == "linuxmint" ||
+ "${ID:-}" == "zorin" ||
+ "${ID:-}" == "rhino" ||
+ "${ID_LIKE:-}" == *ubuntu* ]]
}
kill_quietly() {
killall -q "$1" 2>/dev/null || true
}
+wait_for_wayland() {
+ local runtime_dir="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
+ export XDG_RUNTIME_DIR="$runtime_dir"
+
+ if [[ -n "${WAYLAND_DISPLAY:-}" && -S "$runtime_dir/$WAYLAND_DISPLAY" ]]; then
+ return 0
+ fi
+
+ for _ in $(seq 1 120); do
+ if [[ -n "${WAYLAND_DISPLAY:-}" && -S "$runtime_dir/$WAYLAND_DISPLAY" ]]; then
+ return 0
+ fi
+
+ for socket in "$runtime_dir"/wayland-[0-9]*; do
+ [[ -S "$socket" ]] || continue
+ case "$(basename "$socket")" in
+ *awww*) continue ;;
+ esac
+ export WAYLAND_DISPLAY="$(basename "$socket")"
+ return 0
+ done
+ sleep 0.1
+ done
+
+ return 1
+}
+
+ensure_portal_env() {
+ export XDG_CURRENT_DESKTOP="${XDG_CURRENT_DESKTOP:-Hyprland}"
+ export XDG_SESSION_DESKTOP="${XDG_SESSION_DESKTOP:-Hyprland}"
+ export XDG_SESSION_TYPE="${XDG_SESSION_TYPE:-wayland}"
+ if [[ -f "/usr/share/glib-2.0/schemas/gschemas.compiled" ]]; then
+ export GSETTINGS_SCHEMA_DIR="/usr/share/glib-2.0/schemas"
+ fi
+
+ local data_dirs="${XDG_DATA_DIRS:-}"
+ if [[ -z "$data_dirs" ]]; then
+ data_dirs="/usr/local/share:/usr/share"
+ else
+ if [[ ":$data_dirs:" != *":/usr/local/share:"* ]]; then
+ data_dirs="/usr/local/share:$data_dirs"
+ fi
+ if [[ ":$data_dirs:" != *":/usr/share:"* ]]; then
+ data_dirs="$data_dirs:/usr/share"
+ fi
+ fi
+ export XDG_DATA_DIRS="$data_dirs"
+}
start_portal_binary() {
local description="$1"
@@ -38,29 +90,74 @@ start_portal_binary() {
echo "Warning: no $description binary found (checked: $*)" >&2
return 1
}
-if ! is_ubuntu_family; then
- exit 0
-fi
+stop_portal_processes() {
+ kill_quietly xdg-desktop-portal-hyprland
+ kill_quietly xdg-desktop-portal-wlr
+ kill_quietly xdg-desktop-portal-gnome
+ kill_quietly xdg-desktop-portal-gtk
+ kill_quietly xdg-desktop-portal
+}
+
+restart_portal_via_systemd() {
+ command -v systemctl >/dev/null 2>&1 || return 1
+ ensure_portal_env
+ if command -v dbus-update-activation-environment >/dev/null 2>&1; then
+ dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_TYPE XDG_DATA_DIRS GSETTINGS_SCHEMA_DIR >/dev/null 2>&1 || true
+ fi
+
+ systemctl --user import-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_TYPE XDG_DATA_DIRS GSETTINGS_SCHEMA_DIR >/dev/null 2>&1 || true
+ systemctl --user stop xdg-desktop-portal.service xdg-desktop-portal-hyprland.service xdg-desktop-portal-gtk.service >/dev/null 2>&1 || true
+ stop_portal_processes
+ sleep 0.5
+ systemctl --user reset-failed xdg-desktop-portal-hyprland.service xdg-desktop-portal.service xdg-desktop-portal-gtk.service >/dev/null 2>&1 || true
+ systemctl --user start graphical-session.target >/dev/null 2>&1 || true
+
+ for _ in $(seq 1 30); do
+ if systemctl --user is-active --quiet graphical-session.target; then
+ break
+ fi
+ sleep 0.1
+ done
+
+ systemctl --user start xdg-desktop-portal-hyprland.service >/dev/null 2>&1 || true
+ if is_ubuntu_family; then
+ systemctl --user start xdg-desktop-portal-gtk.service >/dev/null 2>&1 || true
+ fi
-sleep 1
-kill_quietly xdg-desktop-portal-hyprland
-kill_quietly xdg-desktop-portal-wlr
-kill_quietly xdg-desktop-portal-gnome
-kill_quietly xdg-desktop-portal-gtk
-kill_quietly xdg-desktop-portal
-sleep 1
+ for _ in $(seq 1 60); do
+ if systemctl --user is-active --quiet xdg-desktop-portal-hyprland.service; then
+ return 0
+ fi
+ sleep 0.1
+ done
+ return 1
+}
-start_portal_binary "xdg-desktop-portal-hyprland" \
- /usr/lib/xdg-desktop-portal-hyprland \
- /usr/libexec/xdg-desktop-portal-hyprland
+restart_portal_manually() {
+ sleep 1
+ stop_portal_processes
+ sleep 1
-sleep 2
+ start_portal_binary "xdg-desktop-portal-hyprland" \
+ /usr/lib/xdg-desktop-portal-hyprland \
+ /usr/libexec/xdg-desktop-portal-hyprland
-start_portal_binary "xdg-desktop-portal-gtk" \
- /usr/lib/xdg-desktop-portal-gtk \
- /usr/libexec/xdg-desktop-portal-gtk
+ sleep 2
-start_portal_binary "xdg-desktop-portal" \
- /usr/lib/xdg-desktop-portal \
- /usr/libexec/xdg-desktop-portal
+ if is_ubuntu_family; then
+ start_portal_binary "xdg-desktop-portal-gtk" \
+ /usr/lib/xdg-desktop-portal-gtk \
+ /usr/libexec/xdg-desktop-portal-gtk || true
+ fi
+
+ start_portal_binary "xdg-desktop-portal" \
+ /usr/lib/xdg-desktop-portal \
+ /usr/libexec/xdg-desktop-portal
+}
+wait_for_wayland || true
+if command -v systemctl >/dev/null 2>&1; then
+ restart_portal_via_systemd || true
+else
+ restart_portal_manually
+fi
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage