blob: 6dd7d4605c027dfa5c2d6b91614917944c73c27a (
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
32
33
|
#!/bin/bash
# toggle reading/focus mode on the current workspace
WIDTH=1000 # desired window width in pixels
ws=$(i3-msg -t get_tree | jq -c 'first(.. | objects
| select(.type=="workspace" and any(.. | objects; .focused == true)))')
# Gap per side = (workspace width - desired width) / 2, minus any inner gap
ws_width=$(echo "$ws" | jq '.rect.width')
inner_gap=$(echo "$ws" | jq '.gaps.inner // 0')
gap=$(( (ws_width - WIDTH) / 2 - inner_gap ))
[ "$gap" -lt 0 ] && gap=0
on="layout tabbed; gaps horizontal current set $gap; bar mode hide"
off="layout splith; gaps horizontal current set 0; bar mode dock"
count=$(echo "$ws" | jq '.nodes | length')
inner=$(echo "$ws" | jq '.nodes[0].nodes | length')
if [ "$count" -eq 1 ] && [ "$inner" -gt 0 ]; then
layout=$(echo "$ws" | jq -r '.nodes[0].layout')
child=$(echo "$ws" | jq '.nodes[0].nodes[0].id')
if [ "$layout" = "tabbed" ]; then
i3-msg "[con_id=$child] $off"
else
i3-msg "[con_id=$child] $on"
fi
else
child=$(echo "$ws" | jq '.nodes[0].id')
i3-msg "[con_id=$child] $on"
fi
|