summary refs log tree commit diff stats
path: root/bin/toggle_monitor_focus
blob: 790ebe2124d81dcde1bf94f0e14c2d7459518f84 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash

# Get the currently focused output
current_output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')

# Get the list of outputs
outputs=($(swaymsg -t get_outputs | jq -r '.[].name'))

# Find the index of the currently focused output
for i in "${!outputs[@]}"; do
    if [[ "${outputs[$i]}" == "$current_output" ]]; then
        current_index=$i
        break
    fi
done

# Calculate the index of the next output
next_index=$(( (current_index + 1) % ${#outputs[@]} ))

# Focus the next output
swaymsg focus output "${outputs[$next_index]}"