Workspace locator should now support more than 2 monitors

This commit is contained in:
Ezri Brimhall 2024-04-08 15:48:22 -06:00
parent 9b211faf8c
commit 4a0c72174b
Signed by: ezri
GPG Key ID: 058A78E5680C6F24

View File

@ -7,18 +7,53 @@ for output in $(swaymsg -t get_outputs | jq '[ (.[] | select(.active) | pick(.na
output_sets+=$output
done
workspace_counts=()
total_workspaces=0
for output in {1..${#output_sets[@]}}; do
workspace_counts+=$(jq <~/.config/sway/workspaces.json "[.[] | values[]][$((output - 1))] | length" -r)
((total_workspaces += workspace_counts[output]))
done
workspaces=$(swaymsg -t get_workspaces)
current_output=$(echo $workspaces | jq '.[] | select(.focused).output' -r)
current_workspace=$(echo $workspaces | jq '.[] | select(.focused).name' -r)
function get_previous_output_workspaces {
output=$1
previous_outputs=0
if ((output == 0)); then
echo 0
return
fi
for cur_output in {1..$output}; do
((previous_outputs += workspace_counts[cur_output]))
done
echo $previous_outputs
}
function get_ws {
ws_set=$1
ws_target=$2
workspace=$((ws_set * 10 + ws_target))
if (( workspace == current_workspace )); then
workspace=$(( (workspace + 9) % 20 + 1 ))
echo "Searching for workspace $ws_target on output $ws_set" >&2
workspace=$(($(get_previous_output_workspaces $ws_set) + ws_target))
echo "Staying on this output would be workspace $workspace" >&2
if ((workspace == current_workspace)); then
echo "We're already on the target workspace, so we should look to change outputs" >&2
initial_ws_set=$ws_set
while :; do
ws_set=$(((ws_set + 1) % ${#output_sets[@]}))
echo "Checking output $ws_set" >&2
if ((ws_target < workspace_counts[ws_set + 1])); then
workspace=$(($(get_previous_output_workspaces $ws_set) + ws_target))
break
elif ((ws_set == initial_ws_set)); then
# If we've looped around to the initial output, just stay on the current workspace
break
else
echo "Output $ws_set doesn't have enough workspaces (only ${workspace_counts[$((ws_set + 1))]}), moving to the next one" >&2
fi
done
fi
echo $workspace