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:
commit
922c1ee7bc
2 changed files with 52 additions and 13 deletions
11
README.md
11
README.md
|
@ -1,7 +1,6 @@
|
||||||
# hyprfreeze
|
# hyprfreeze
|
||||||
[![basher install](https://www.basher.it/assets/logo/basher_install.svg)](https://www.basher.it/package/)
|
[![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
|
Hyprfreeze is a utility to suspend a game process (and other programs) in Hyprland and Sway.
|
||||||
Hyprland.
|
|
||||||
|
|
||||||
https://github.com/Zerodya/hyprfreeze/assets/73220426/541318e2-441a-485a-91c5-f58d4f65926a
|
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).
|
Hyprfreeze is available in [AUR](https://aur.archlinux.org/packages/hyprfreeze-git).
|
||||||
|
|
||||||
### Dependencies
|
### 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
|
- `jq` to parse json
|
||||||
- `psmisc` contains 'pstree' which is required to list child processes
|
- `psmisc` contains 'pstree' which is required to list child processes
|
||||||
### Optional
|
### 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
|
### 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.
|
- [`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
|
## 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
|
```bash
|
||||||
# ~/.config/hypr/hyprland.conf
|
# ~/.config/hypr/hyprland.conf
|
||||||
...
|
...
|
||||||
|
@ -53,7 +52,7 @@ bind = , PAUSE, exec, hyprfreeze -a
|
||||||
-a, --active toggle suspend by active window
|
-a, --active toggle suspend by active window
|
||||||
-p, --pid toggle suspend by process id
|
-p, --pid toggle suspend by process id
|
||||||
-n, --name toggle suspend by process name/command
|
-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
|
-s, --silent don't send notification
|
||||||
-t, --notif-timeout notification timeout in milliseconds (default 5000)
|
-t, --notif-timeout notification timeout in milliseconds (default 5000)
|
||||||
|
|
54
hyprfreeze
54
hyprfreeze
|
@ -12,7 +12,7 @@ Options:
|
||||||
-a, --active toggle suspend by active window
|
-a, --active toggle suspend by active window
|
||||||
-p, --pid toggle suspend by process id
|
-p, --pid toggle suspend by process id
|
||||||
-n, --name toggle suspend by process name/command
|
-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
|
-s, --silent don't send notification
|
||||||
-t, --notif-timeout notification timeout in milliseconds (default 5000)
|
-t, --notif-timeout notification timeout in milliseconds (default 5000)
|
||||||
|
@ -56,7 +56,14 @@ function toggleFreeze() {
|
||||||
|
|
||||||
function getPidByActive() {
|
function getPidByActive() {
|
||||||
debugPrint "Getting PID by active window..."
|
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"
|
debugPrint "PID by active window: $PID"
|
||||||
|
|
||||||
# Die if PID is not numeric (e.g. "null" if there is no active window)
|
# Die if PID is not numeric (e.g. "null" if there is no active window)
|
||||||
|
@ -92,17 +99,48 @@ function getPidByName() {
|
||||||
|
|
||||||
function getPidByProp() {
|
function getPidByProp() {
|
||||||
debugPrint "Getting PID by prop..."
|
debugPrint "Getting PID by prop..."
|
||||||
if ! command -v hyprprop; then
|
if [[ "hyprland" == "$DESKTOP" ]]; then
|
||||||
echo "You need to install 'hyprprop' to use this feature. (https://github.com/vilari-mickopf/hyprprop)"
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PID=$(hyprprop | jq '.pid')
|
|
||||||
debugPrint "PID by prop: $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() {
|
function printInfo() {
|
||||||
debugPrint "Printing process info...\n"
|
debugPrint "Printing process info..."
|
||||||
echo -e "$(tput bold)Process tree:$(tput sgr0)"
|
echo -e "$(tput bold)Process tree:$(tput sgr0)"
|
||||||
ps -p "$PID" 2>/dev/null && pstree -p "$PID"
|
ps -p "$PID" 2>/dev/null && pstree -p "$PID"
|
||||||
|
|
||||||
|
@ -226,4 +264,6 @@ DEBUG=0
|
||||||
|
|
||||||
args "$@"
|
args "$@"
|
||||||
|
|
||||||
|
detectEnvironment
|
||||||
|
|
||||||
main
|
main
|
||||||
|
|
Loading…
Reference in a new issue