55 lines
1.7 KiB
Bash
Executable File
55 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
instances=$(($(pgrep -f $0 | wc -l) -1))
|
|
if [ "$instances" -gt 1 ]; then
|
|
echo "Another instance of this script is already running."
|
|
exit 1
|
|
fi
|
|
|
|
monitors=$(hyprctl -j monitors | jq "length")
|
|
desired_workspaces=4
|
|
|
|
|
|
handle_workspace_change(){
|
|
params=("$@")
|
|
workspace_id=$(( ${params[0]} - 1 )) # -1 for we start at 1
|
|
#echo "Workspace ID: $workspace_id"
|
|
|
|
|
|
curent_state=$(hyprctl -j monitors)
|
|
relative_ws_id=$((($workspace_id % $desired_workspaces) + 1)) # +1 for we start at 1
|
|
ws_group=$(( ($workspace_id - 1) / $desired_workspaces))
|
|
transaction_occured=false
|
|
#echo "Following monitor $ws_group to (rel.) WS $relative_ws_id"
|
|
for ((dp=0; dp<monitors; dp++));
|
|
do
|
|
absolute_ws_id=$((($dp * $desired_workspaces) + $relative_ws_id))
|
|
if [ $(echo $curent_state | jq ".[$dp].activeWorkspace.id") = $absolute_ws_id ]; then
|
|
# This is the monitor we already changed the displat on
|
|
continue
|
|
fi
|
|
#echo "Switching to (abs.) WS $absolute_ws_id on monitor $dp"
|
|
hyprctl dispatch focusmonitor $dp
|
|
hyprctl dispatch workspace $absolute_ws_id
|
|
transaction_occured=true
|
|
done
|
|
if [ $transaction_occured = "true" ]; then
|
|
#echo "Focusing monitor $ws_group"
|
|
hyprctl dispatch focusmonitor $ws_group
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
nc -U $XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock | while read -r line; do
|
|
cmd="${line%%>>*}"
|
|
# Extract everything after ">>" and split at commas
|
|
|
|
IFS=',' read -ra params <<< "${line#*>>}"
|
|
case $cmd in
|
|
"workspacev2")
|
|
handle_workspace_change ${params[@]}
|
|
;;
|
|
esac
|
|
|
|
done; |