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

feat: session/desktop detection

This commit is contained in:
alterNERDtive 2024-02-12 11:58:21 +01:00
parent 93a2017713
commit 6607c0c568
Signed by: alterNERDtive
GPG key ID: 547787A4FE6533F1
2 changed files with 19 additions and 1 deletions

View file

@ -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

View file

@ -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