dotfiles/eggs/hypr/scripts/workspace_manager.sh
2025-05-19 16:47:38 +02:00

55 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Args:
# $1: destination
# $2: mode
WORKSPACES=4
function confirm_valid_destination() {
destination=$1
if [ "${str:0:1}" == "+" ]; then
destination=$(( ${destination:1} + 1 ))
elif [ "${str:0:1}" == "-" ]; then
destination=$(( ${destination:1} - 1 ))
fi
if [ $destination -lt 1 ]; then
destination=$WORKSPACES
elif [ $destination -gt $WORKSPACES ]; then
destination=1
fi
echo $destination
}
active_ws_id=$(hyprctl activeworkspace -j | jq -r '.id')
active_window_monitor_id=$(hyprctl activeworkspace -j | jq -r '.monitorID')
monitors=$(hyprctl monitors -j | jq -r '.[].id')
dp_iterator=0
destination=$(confirm_valid_destination $1)
# Adjust destination for monitor
destination_with_monitor=$((($active_window_monitor_id * 4) + $destination))
mode=$2
echo "Destination: $destination"
echo "Destination with monitor: $destination_with_monitor"
for dp in $monitors
do
echo "Display: $dp"
hyprctl dispatch focusmonitor $dp
real_destination=$((($dp_iterator * 4) + $destination))
echo "Real Destination $real_destination"
if [[ $real_destination -eq $destination_with_monitor && $mode == "carry" ]]; then
echo "Moving window"
hyprctl dispatch movetoworkspace $real_destination
else
echo "Changing workspace"
hyprctl dispatch workspace $real_destination
fi
dp_iterator=$((dp_iterator+1))
done