From c894c7630526da947aa6820dbf7fae8285d57e81 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Tue, 13 Feb 2024 19:54:49 +0100 Subject: [PATCH] feat: fall back to `$XDG_SESSION_DESKTOP` for detection --- README.md | 1 - hyprfreeze | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 56113fe..f07af63 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,6 @@ Hyprfreeze is available in [AUR](https://aur.archlinux.org/packages/hyprfreeze-g - a compatible window manager (`hyprland` or `sway`) to get the PID of the active window - `jq` to parse json - `psmisc` contains 'pstree' which is required to list child processes -- Systemd for the `loginctl` utility ### Optional - [`hyprprop`](https://github.com/vilari-mickopf/hyprprop) or [`swayprop`](https://git.alternerd.tv/alterNERDtive/swayprop) to get the pid of a window by selecting it with your mouse ### Highly Recommended diff --git a/hyprfreeze b/hyprfreeze index 3e31d51..a19467c 100755 --- a/hyprfreeze +++ b/hyprfreeze @@ -121,10 +121,20 @@ function getPidByProp() { } function detectEnvironment() { - local Desktop - eval "$(loginctl show-session $(loginctl | grep $(whoami) | awk '{print $1}') -p Desktop)" - [ -z "$Desktop" ] && echo "Could not determine desktop environment via \`loginctl\`. Assuming Hyprland." && Desktop="hyprland" - DESKTOP=$Desktop + if [ $(command -v loginctl) ]; then + local Desktop + eval "$(loginctl show-session $(loginctl | grep $(whoami) | awk '{print $1}') -p Desktop)" + DESKTOP=$Desktop + fi + + if [ -z "$DESKTOP" ]; then + DESKTOP=$XDG_SESSION_DESKTOP + fi + + if [ -z "$DESKTOP" ]; then + debugPrint "Could not determine desktop environment via \`loginctl\`, and `$XDG_DESKTOP_SESSION` is not set. Assuming Hyprland." + DESKTOP="hyprland" + fi } function printInfo() {