-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecutable_resizetopresel.sh
83 lines (76 loc) · 3.59 KB
/
executable_resizetopresel.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/zsh
# Check if the brother node is a receptacle
if [[ $(bspc query -T -n @brother/ | jshon -e client) = null ]]; then
# Yep, it's a receptacle. Get the real dimensions
eval $(grep "gap=" .config/bspwm/bspwmrc)
# Get orientation
wattr xywh $(pfw) | read focused_x focused_y focused_width focused_height
receptacle_y=$(bspc query -T -n @brother/ | jshon -e rectangle -e y)
if [[ "$focused_y" -eq "$receptacle_y" ]]; then
receptacle_width=$(bspc query -T -n @brother/ | jshon -e rectangle -e width)
receptacle_x=$(bspc query -T -n @brother/ | jshon -e rectangle -e x)
# receptacle and window have the same height, so they are side by side
if [[ receptacle_x -gt focused_x ]]; then
echo "receptacle is right of the window"
# get the true window dimension
true_dim=$(( receptacle_width + gap ))
# kill the repectacle
for i in $(bspc query -N -n .leaf.!window.local); do bspc node $i -k; done
# resize the window
bspc node @east -r -$true_dim || bspc node @west -r +$true_dim
else
echo "receptacle is left of the window"
# get the true window dimension
true_dim=$(( receptacle_width + gap ))
# kill the repectacle
for i in $(bspc query -N -n .leaf.!window.local); do bspc node $i -k; done
# resize the window
bspc node @west -r +$true_dim || bspc node @east -r -$true_dim
fi
else
receptacle_height=$(bspc query -T -n @brother/ | jshon -e rectangle -e height)
# widht is necessarily equal if height is not, because the nodes are brothers
# Window are on the top of each other
if [[ receptacle_y -gt focused_y ]]; then
echo "receptacle is below the window"
# get the true window dimension
true_dim=$(( receptacle_height + gap))
# kill the repectacle
for i in $(bspc query -N -n .leaf.!window.local); do bspc node $i -k; done
# resize the window
bspc node @south -r -$true_dim || bspc node @north -r +$true_dim
else
echo "receptacle is above the window"
# get the true window dimension
true_dim=$(( receptacle_height + gap))
# kill the repectacle
for i in $(bspc query -N -n .leaf.!window.local); do bspc node $i -k; done
# resize the window
bspc node @north -r +$true_dim || bspc node @south -r -$true_dim
fi
fi
echo $true_dim
exit 0
fi
# If the focused window is not preselected, exit
[[ "$(bspc query -T -n focused | jshon -e presel)" == null ]] && exit 0
dir=$(bspc query -T -n focused | jshon -e presel -e splitDir | tr -d \")
ratio=$(bspc query -T -n focused | jshon -e presel -e splitRatio)
case "$dir" in
west)
cur=$(bspc query -T -n focused | jshon -e rectangle -e width)
bspc node @west -r +$((${cur}*${ratio})) || bspc node @east -r -$((${cur}*${ratio}))
;;
east)
cur=$(bspc query -T -n focused | jshon -e rectangle -e width)
bspc node @east -r -$((${cur}*${ratio})) || bspc node @west -r +$((${cur}*${ratio}))
;;
north)
cur=$(bspc query -T -n focused | jshon -e rectangle -e height)
bspc node @north -r +$((${cur}*${ratio})) || bspc node @south -r -$((${cur}*${ratio}))
;;
south)
cur=$(bspc query -T -n focused | jshon -e rectangle -e height)
bspc node @south -r -$((${cur}*${ratio})) || bspc node @north -r +$((${cur}*${ratio}))
esac
cancel_presels