-
Notifications
You must be signed in to change notification settings - Fork 0
/
aspectscale
executable file
·39 lines (33 loc) · 958 Bytes
/
aspectscale
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
#!/usr/bin/env bash
# resize focused window to aspect ratio
# arguments: aspectX aspectY (default 16 9)
# dependencies: bc, jq
x=16
y=9
if [ $# -eq 2 ]; then
x=$1
y=$2
fi
node=($(bspc query -T -n | jq -r .client.tiledRectangle.width,.client.tiledRectangle.height,.id))
parent=($(bspc query -T -n @parent | jq -r .splitType,.firstChild.id))
# vertical split: adjust width
if [ "${parent[0]}" = "vertical" ]; then
width=$(printf "%.0f" $(echo "scale=4;${node[1]}*$x/$y" | bc))
# left window
if [ "${node[2]}" = "${parent[1]}" ]; then
bspc node -z right $((width-node[0])) 0
# right window
else
bspc node -z left $((node[0]-width)) 0
fi
# horizontal split: adjust height
else
height=$(printf "%.0f\n" $(echo "scale=4;${node[0]}*$y/$x" | bc))
# top window
if [ "${node[2]}" = "${parent[1]}" ]; then
bspc node -z bottom 0 $((height-node[1]))
# bottom window
else
bspc node -z top 0 $((node[1]-height))
fi
fi