2023-05-23 18:09:54 +02:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
# Get two outputs, visible workspaces and focused workspace
|
|
|
|
output1=$(swaymsg -t get_outputs --raw | jq '.[0].name' -r)
|
|
|
|
output2=$(swaymsg -t get_outputs --raw | jq '.[1].name' -r)
|
|
|
|
workspace1=$(swaymsg -t get_outputs --raw | jq '.[0].current_workspace' -r)
|
|
|
|
workspace2=$(swaymsg -t get_outputs --raw | jq '.[1].current_workspace' -r)
|
|
|
|
workspace_active=$(swaymsg -t get_workspaces | jq -r '.[] | select(.focused==true).name')
|
|
|
|
|
|
|
|
# If any of the outputs doesn't have a workspace, do nothing
|
|
|
|
if [ "$workspace1" = null ] || [ "$workspace2" = null ]; then
|
2024-11-15 10:17:56 +01:00
|
|
|
exit 0
|
2023-05-23 18:09:54 +02:00
|
|
|
else
|
2024-11-15 10:17:56 +01:00
|
|
|
# If script is provided with `follow` argument, then follow focused workspace
|
|
|
|
if [ "$1" = "follow" ]; then
|
|
|
|
if [ "$workspace1" = "$workspace_active" ]; then
|
|
|
|
swaymsg move workspace to output "$output2"
|
|
|
|
swaymsg workspace "$workspace2"
|
|
|
|
swaymsg move workspace to output "$output1"
|
|
|
|
swaymsg workspace "$workspace2"
|
2023-05-23 18:09:54 +02:00
|
|
|
else
|
2024-11-15 10:17:56 +01:00
|
|
|
swaymsg workspace "$workspace1"
|
|
|
|
swaymsg move workspace to output "$output2"
|
|
|
|
swaymsg workspace "$workspace2"
|
|
|
|
swaymsg move workspace to output "$output1"
|
2023-05-23 18:09:54 +02:00
|
|
|
fi
|
2024-11-15 10:17:56 +01:00
|
|
|
# Else focus stays with focused output
|
|
|
|
else
|
|
|
|
if [ "$workspace1" = "$workspace_active" ]; then
|
|
|
|
swaymsg move workspace to output "$output2"
|
|
|
|
swaymsg workspace "$workspace2"
|
|
|
|
swaymsg move workspace to output "$output1"
|
|
|
|
else
|
|
|
|
swaymsg workspace "$workspace1"
|
|
|
|
swaymsg move workspace to output "$output2"
|
|
|
|
swaymsg workspace "$workspace2"
|
|
|
|
swaymsg move workspace to output "$output1"
|
|
|
|
swaymsg workspace "$workspace1"
|
|
|
|
fi
|
|
|
|
fi
|
2023-05-23 18:09:54 +02:00
|
|
|
fi
|