From 93a2017713ac0662f488eb8fee382583c9a75938 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Sun, 11 Feb 2024 17:56:12 +0100 Subject: [PATCH 01/11] docs: mention hyprland + sway --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e681f83..60c248b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # hyprfreeze [![basher install](https://www.basher.it/assets/logo/basher_install.svg)](https://www.basher.it/package/) -Hyprfreeze is a utility to suspend a game process (and other programs) in -Hyprland. +Hyprfreeze is a utility to suspend a game process (and other programs) on Wayland https://github.com/Zerodya/hyprfreeze/assets/73220426/541318e2-441a-485a-91c5-f58d4f65926a @@ -17,7 +16,7 @@ https://github.com/Zerodya/hyprfreeze/assets/73220426/541318e2-441a-485a-91c5-f5 Hyprfreeze is available in [AUR](https://aur.archlinux.org/packages/hyprfreeze-git). ### Dependencies -- `hyprland` to get the pid of the active window with hyprctl +- 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 ### Optional @@ -39,7 +38,7 @@ ln -s $(pwd)/Hyprfreeze/hyprfreeze $HOME/.local/bin ``` ## Usage -Add a bind in your Hyprland config to pause the current active window: +Add a bind in your Hyprland or Sway config to pause the current active window: ```bash # ~/.config/hypr/hyprland.conf ... From 6607c0c568db759aecc679d5678d0615d19abc3b Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Mon, 12 Feb 2024 11:58:21 +0100 Subject: [PATCH 02/11] feat: session/desktop detection --- README.md | 1 + hyprfreeze | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 60c248b..8aec8f3 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ 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) to get the pid of a window by selecting it with your mouse ### Highly Recommended diff --git a/hyprfreeze b/hyprfreeze index 3858dc9..7d05a3e 100755 --- a/hyprfreeze +++ b/hyprfreeze @@ -101,8 +101,23 @@ function getPidByProp() { debugPrint "PID by prop: $PID" } +function detectEnvironment() { + local Type + local Desktop + eval "$(loginctl show-session $(loginctl | grep $(whoami) | awk '{print $1}') -p Type -p Desktop)" + [ -z "$Type" ] && echo "Could not determine session type via \`loginctl\`." && exit 1 + [ -z "$Desktop" ] && echo "Could not determine desktop environment via \`loginctl\`." && exit 1 + SESSION=$Type + DESKTOP=$Desktop +} + function printInfo() { - debugPrint "Printing process info...\n" + debugPrint "Printing environment info..." + echo -e "$(tput bold)Session type:$(tput sgr0) $SESSION" + echo -e "$(tput bold)Desktop:$(tput sgr0) $DESKTOP" + echo "" + + debugPrint "Printing process info..." echo -e "$(tput bold)Process tree:$(tput sgr0)" ps -p "$PID" 2>/dev/null && pstree -p "$PID" @@ -226,4 +241,6 @@ DEBUG=0 args "$@" +detectEnvironment + main From 38da7492badf60fc5e42ffcee6f15ee775e39615 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Mon, 12 Feb 2024 12:19:58 +0100 Subject: [PATCH 03/11] feat: sway support for -a --- hyprfreeze | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hyprfreeze b/hyprfreeze index 7d05a3e..f9febfe 100755 --- a/hyprfreeze +++ b/hyprfreeze @@ -56,7 +56,14 @@ function toggleFreeze() { function getPidByActive() { debugPrint "Getting PID by active window..." - PID=$(hyprctl activewindow -j | jq '.pid') + if [[ "hyprland" == "$DESKTOP" ]]; then + PID=$(hyprctl activewindow -j | jq '.pid') + elif [[ "sway" == "$DESKTOP" ]]; then + PID=$(swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true) | .pid') + else + echo "Detecting the active window is currently not supported on $DESKTOP." + exit 1 + fi debugPrint "PID by active window: $PID" # Die if PID is not numeric (e.g. "null" if there is no active window) From dc6636de41f2bf3379d8e3f96086b70e1c25ff71 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Mon, 12 Feb 2024 12:20:27 +0100 Subject: [PATCH 04/11] docs: window manager clarification for -a and -r --- README.md | 4 ++-- hyprfreeze | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8aec8f3..e894088 100644 --- a/README.md +++ b/README.md @@ -50,10 +50,10 @@ bind = , PAUSE, exec, hyprfreeze -a ``` -h, --help show help message --a, --active toggle suspend by active window +-a, --active toggle suspend by active window (supported on hyprland and sway) -p, --pid toggle suspend by process id -n, --name toggle suspend by process name/command --r, --prop toggle suspend by clicking on window (hyprprop must be installed) +-r, --prop toggle suspend by clicking on window (supported on hyperland, hyprprop must be installed) -s, --silent don't send notification -t, --notif-timeout notification timeout in milliseconds (default 5000) diff --git a/hyprfreeze b/hyprfreeze index f9febfe..278db09 100755 --- a/hyprfreeze +++ b/hyprfreeze @@ -9,10 +9,10 @@ Utility to suspend a game process (and other programs) in Hyprland. Options: -h, --help show help message - -a, --active toggle suspend by active window + -a, --active toggle suspend by active window (supported on hyprland and sway) -p, --pid toggle suspend by process id -n, --name toggle suspend by process name/command - -r, --prop toggle suspend by clicking on window (hyprprop must be installed) + -r, --prop toggle suspend by clicking on window (supported on hyprland, hyprprop must be installed) -s, --silent don't send notification -t, --notif-timeout notification timeout in milliseconds (default 5000) From d2656ce853d4c1c6c4ec800bde4d5cabe40ae30a Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Mon, 12 Feb 2024 12:20:51 +0100 Subject: [PATCH 05/11] feat: desktop-aware -r --- hyprfreeze | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hyprfreeze b/hyprfreeze index 278db09..27fb249 100755 --- a/hyprfreeze +++ b/hyprfreeze @@ -99,12 +99,17 @@ function getPidByName() { function getPidByProp() { debugPrint "Getting PID by prop..." - if ! command -v hyprprop; then - echo "You need to install 'hyprprop' to use this feature. (https://github.com/vilari-mickopf/hyprprop)" + if [[ "hyprland" == "$DESKTOP" ]]; then + if ! command -v hyprprop; then + echo "You need to install 'hyprprop' to use this feature. (https://github.com/vilari-mickopf/hyprprop)" + exit 1 + fi + + PID=$(hyprprop | jq '.pid') + else + echo "Selecting the target window by mouse is currently not supported on $DESKTOP." exit 1 fi - - PID=$(hyprprop | jq '.pid') debugPrint "PID by prop: $PID" } From 16346343dd09ea4312bb782b4d5abf1e4168f78d Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Tue, 13 Feb 2024 02:07:02 +0100 Subject: [PATCH 06/11] feat: implement swayprop --- README.md | 2 +- hyprfreeze | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e894088..3ca99cc 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Hyprfreeze is available in [AUR](https://aur.archlinux.org/packages/hyprfreeze-g - `psmisc` contains 'pstree' which is required to list child processes - Systemd for the `loginctl` utility ### Optional -- [`hyprprop`](https://github.com/vilari-mickopf/hyprprop) to get the pid of a window by selecting it with your mouse +- [`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 - [`gamescope`](https://github.com/ValveSoftware/gamescope) fixes mouse input not working in other XWayland windows after pausing a Wine game. It's also the superior way to game in Wayland anyway. diff --git a/hyprfreeze b/hyprfreeze index 27fb249..0344f45 100755 --- a/hyprfreeze +++ b/hyprfreeze @@ -12,7 +12,8 @@ Options: -a, --active toggle suspend by active window (supported on hyprland and sway) -p, --pid toggle suspend by process id -n, --name toggle suspend by process name/command - -r, --prop toggle suspend by clicking on window (supported on hyprland, hyprprop must be installed) + -r, --prop toggle suspend by clicking on window (supported on hyprland and sway, + hyprprop/swayprop must be installed) -s, --silent don't send notification -t, --notif-timeout notification timeout in milliseconds (default 5000) @@ -100,12 +101,19 @@ function getPidByName() { function getPidByProp() { debugPrint "Getting PID by prop..." if [[ "hyprland" == "$DESKTOP" ]]; then - if ! command -v hyprprop; then + if ! [ $(command -v hyprprop) ]; then echo "You need to install 'hyprprop' to use this feature. (https://github.com/vilari-mickopf/hyprprop)" exit 1 fi PID=$(hyprprop | jq '.pid') + elif [[ "sway" == "$DESKTOP" ]]; then + if ! [ $(command -v swayprop) ]; then + echo "You need to install 'swayprop' to use this feature. (https://git.alternerd.tv/alterNERDtive/swayprop)" + exit 1 + fi + + PID=$(swayprop | jq '.pid') else echo "Selecting the target window by mouse is currently not supported on $DESKTOP." exit 1 From 73b4073b61ee71024ba0eb80514c622ff0a0c3f4 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Tue, 13 Feb 2024 16:38:07 +0100 Subject: [PATCH 07/11] =?UTF-8?q?docs:=20=E2=80=9CWayland=E2=80=9D=20?= =?UTF-8?q?=E2=86=92=20=E2=80=9CHyprland=20and=20Sway=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ca99cc..e599ac7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # hyprfreeze [![basher install](https://www.basher.it/assets/logo/basher_install.svg)](https://www.basher.it/package/) -Hyprfreeze is a utility to suspend a game process (and other programs) on Wayland +Hyprfreeze is a utility to suspend a game process (and other programs) in Hyprland and Sway. https://github.com/Zerodya/hyprfreeze/assets/73220426/541318e2-441a-485a-91c5-f58d4f65926a From 32e32bc6e5f5455c3f5665978247994f3daa51f0 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Tue, 13 Feb 2024 16:43:11 +0100 Subject: [PATCH 08/11] feat: if desktop cannot be auto detected, assume Hyprland --- hyprfreeze | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/hyprfreeze b/hyprfreeze index 0344f45..7e6e8c4 100755 --- a/hyprfreeze +++ b/hyprfreeze @@ -122,12 +122,9 @@ function getPidByProp() { } function detectEnvironment() { - local Type local Desktop - eval "$(loginctl show-session $(loginctl | grep $(whoami) | awk '{print $1}') -p Type -p Desktop)" - [ -z "$Type" ] && echo "Could not determine session type via \`loginctl\`." && exit 1 - [ -z "$Desktop" ] && echo "Could not determine desktop environment via \`loginctl\`." && exit 1 - SESSION=$Type + 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 } From a119f872fe4b5dce1b61f66d1a63eec9894b6df4 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Tue, 13 Feb 2024 19:29:49 +0100 Subject: [PATCH 09/11] docs: cleaned up --help, hyprland/sway have feature parity now --- README.md | 4 ++-- hyprfreeze | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e599ac7..56113fe 100644 --- a/README.md +++ b/README.md @@ -50,10 +50,10 @@ bind = , PAUSE, exec, hyprfreeze -a ``` -h, --help show help message --a, --active toggle suspend by active window (supported on hyprland and sway) +-a, --active toggle suspend by active window -p, --pid toggle suspend by process id -n, --name toggle suspend by process name/command --r, --prop toggle suspend by clicking on window (supported on hyperland, hyprprop must be installed) +-r, --prop toggle suspend by clicking on window (hyprprop/swayprop must be installed) -s, --silent don't send notification -t, --notif-timeout notification timeout in milliseconds (default 5000) diff --git a/hyprfreeze b/hyprfreeze index 7e6e8c4..3e31d51 100755 --- a/hyprfreeze +++ b/hyprfreeze @@ -9,11 +9,10 @@ Utility to suspend a game process (and other programs) in Hyprland. Options: -h, --help show help message - -a, --active toggle suspend by active window (supported on hyprland and sway) + -a, --active toggle suspend by active window -p, --pid toggle suspend by process id -n, --name toggle suspend by process name/command - -r, --prop toggle suspend by clicking on window (supported on hyprland and sway, - hyprprop/swayprop must be installed) + -r, --prop toggle suspend by clicking on window (hyprprop/swayprop must be installed) -s, --silent don't send notification -t, --notif-timeout notification timeout in milliseconds (default 5000) From c894c7630526da947aa6820dbf7fae8285d57e81 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Tue, 13 Feb 2024 19:54:49 +0100 Subject: [PATCH 10/11] 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() { From f0328d81b26237007252307ffca7054183176f76 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Sat, 17 Feb 2024 14:45:14 +0100 Subject: [PATCH 11/11] fix: move session info debug output to `detectEnvironment()` --- hyprfreeze | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/hyprfreeze b/hyprfreeze index a19467c..b9ac956 100755 --- a/hyprfreeze +++ b/hyprfreeze @@ -135,14 +135,11 @@ function detectEnvironment() { debugPrint "Could not determine desktop environment via \`loginctl\`, and `$XDG_DESKTOP_SESSION` is not set. Assuming Hyprland." DESKTOP="hyprland" fi + + debugPrint "Desktop: $DESKTOP" } function printInfo() { - debugPrint "Printing environment info..." - echo -e "$(tput bold)Session type:$(tput sgr0) $SESSION" - echo -e "$(tput bold)Desktop:$(tput sgr0) $DESKTOP" - echo "" - debugPrint "Printing process info..." echo -e "$(tput bold)Process tree:$(tput sgr0)" ps -p "$PID" 2>/dev/null && pstree -p "$PID"