1
0
Fork 1
mirror of https://github.com/Zerodya/hyprfreeze.git synced 2024-11-10 01:18:49 +01:00

Merge pull request #8 from alterNERDtive/feat/sway

feat: add Sway support
This commit is contained in:
Nicola 2024-02-17 15:57:02 +01:00 committed by GitHub
commit 922c1ee7bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 52 additions and 13 deletions

View file

@ -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) in Hyprland and Sway.
https://github.com/Zerodya/hyprfreeze/assets/73220426/541318e2-441a-485a-91c5-f58d4f65926a
@ -17,11 +16,11 @@ 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
- [`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.
@ -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
...
@ -53,7 +52,7 @@ bind = , PAUSE, exec, hyprfreeze -a
-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 (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)

View file

@ -12,7 +12,7 @@ Options:
-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 (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)
@ -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)
@ -92,17 +99,48 @@ 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')
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
fi
PID=$(hyprprop | jq '.pid')
debugPrint "PID by prop: $PID"
}
function detectEnvironment() {
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
debugPrint "Desktop: $DESKTOP"
}
function printInfo() {
debugPrint "Printing process info...\n"
debugPrint "Printing process info..."
echo -e "$(tput bold)Process tree:$(tput sgr0)"
ps -p "$PID" 2>/dev/null && pstree -p "$PID"
@ -226,4 +264,6 @@ DEBUG=0
args "$@"
detectEnvironment
main