aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dot_config/sway/executable_tb-toggle.sh
blob: 52884847c73599158dff73f84e4322abb79fa9d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh
# Toggle the Thunderbird main window between the current workspace (tiled)
# and a hidden stash workspace. If Thunderbird isn't running yet, launch it —
# the for_window rule in sway config will mark and park it on the stash.

set -eu

STASH=_tb
MARK=tb-main

current_ws=$(swaymsg -t get_workspaces \
    | jq -r '.[] | select(.focused) | .name')

tb_ws=$(swaymsg -t get_tree \
    | jq -r --arg m "$MARK" '
        first(
          .. | objects
          | select(.type=="workspace")
          | select([.. | objects | select(.marks? // [] | index($m))] | length > 0)
          | .name
        ) // empty')

if [ -z "$tb_ws" ]; then
    exec thunderbird
fi

if [ "$tb_ws" = "$current_ws" ]; then
    swaymsg "[con_mark=\"$MARK\"] move container to workspace $STASH" >/dev/null
else
    swaymsg "[con_mark=\"$MARK\"] move container to workspace $current_ws, focus" >/dev/null
fi