hyprland-void-dots/hypr-configs/hyprland/eww/scripts/workspaces
2024-06-28 09:56:54 +03:30

54 lines
1.4 KiB
Bash
Executable file

#!/bin/bash
SOCKET="/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock"
spaces() {
local workspace_windows=$(hyprctl workspaces -j | jq 'map({key: .id | tostring, value: .windows}) | from_entries')
seq 1 5 | jq --argjson windows "$workspace_windows" --slurp -Mc 'map(tostring) | map({id: ., windows: ($windows[.]//0)})'
}
clamp() {
python -c "print(max($1, min($3, $2)))"
}
get_workspaces() {
spaces
socat -u UNIX-CONNECT:"$SOCKET" - | while read -r; do
spaces
done
}
get_active_workspace() {
hyprctl monitors -j | jq '.[] | select(.focused) | .activeWorkspace.id'
socat -u UNIX-CONNECT:"$SOCKET" - | stdbuf -o0 awk -F '>>|,' '/^workspace>>/ {print $2} /^focusedmon>>/ {print $3}'
}
change_workspace() {
local direction=$1 current=$2 target
if [[ "$direction" == "down" ]]; then
target=$(clamp 1 9 $((current + 1)))
elif [[ "$direction" == "up" ]]; then
target=$(clamp 1 9 $((current - 1)))
else
echo "Invalid direction" >&2
return 1
fi
echo "Jumping to $target"
hyprctl dispatch workspace "$target"
}
main() {
case $1 in
get-all-workspaces) get_workspaces ;;
get-active-workspace) get_active_workspace ;;
change) change_workspace "$2" "$3" ;;
*)
echo "Usage: $0 {gw|ga|c <direction> <current>}" >&2
exit 1
;;
esac
}
main "$@"