User avatar
菱来coffeegoat @hiira@sudo.mkdir.uk
3mo
スクリプト書く羽目になった
#!/bin/env sh

DIRECTION=$1 # next/prev
MODE=$2 # all/active
OUTPUT=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused).name')

if [ "$OUTPUT" == "eDP-1" ]; then
    START=1; END=10
elif [ "$OUTPUT" == "HDMI-A-1" ]; then
    START=11; END=20
else
    START=21; END=30
fi

CURRENT=$(swaymsg -t get_workspaces | jq -r '.[] | select(.focused).num')

if [ "$MODE" == "active" ]; then
    WS_LIST=$(swaymsg -t get_workspaces | jq -r ".[] | select(.output == \"$OUTPUT\") | .num" | sort -n)
    
    if [ "$DIRECTION" == "next" ]; then
        TARGET=$(echo "$WS_LIST" | awk -v curr="$CURRENT" '$1 > curr {print $1; exit} END {print ""}')
        [ -z "$TARGET" ] && TARGET=$(echo "$WS_LIST" | head -n 1)
    else
        TARGET=$(echo "$WS_LIST" | awk -v curr="$CURRENT" '$1 < curr {prev=$1} END {print prev}')
        [ -z "$TARGET" ] && TARGET=$(echo "$WS_LIST" | tail -n 1)
    fi
else
    if [ "$DIRECTION" == "next" ]; then
        TARGET=$((CURRENT + 1))
        [ $TARGET -gt $END ] && TARGET=$START
    else
        TARGET=$((CURRENT - 1))
        [ $TARGET -lt $START ] && TARGET=$END
    fi
fi

swaymsg workspace number $TARGET