summary refs log tree commit diff
path: root/bin/centercon
blob: db48f94eaf5a2c7dd5bcb67df0fef0b83397af95 (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
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
#!/bin/sh
set -e

if [ "$1" = "-h" ]; then
	printf "usage: %s [RESIZE_PERC] [MODE]\n" "$(basename "$0")"
	printf "\n"
	printf "MODE can be tr (for top-right) or empty (for center)\n"
	exit 2
fi

con=$(swq current con)
ws=$(swq current workspace)
ws_width=$(echo "$ws" | jq -r '.rect.width')
ws_height=$(echo "$ws" | jq -r '.rect.height')

if [ -n "$1" ] && [ ! "$1" = "-" ]; then
	perc="$1"
	con_width=$(awk "BEGIN{print int($ws_width * $perc)}")
	con_height=$(awk "BEGIN{print int($ws_height * $perc)}")
else
	con_width=$(echo "$con" | jq -r '.window_rect.width')
	con_height=$(echo "$con" | jq -r '.window_rect.height')
fi

case "$2" in
tl)     # top-left
	tar_x=0
	tar_y=0
	;;
tm)	# top-middle
	tar_x=$(awk "BEGIN{print int(($ws_width - $con_width)/2)}")
	tar_y=0
	;;
tr)     # top-right
	tar_x=$(awk "BEGIN{print int($ws_width - $con_width)}")
	tar_y=0
	;;
rm)	# right-middle
	tar_x=$(awk "BEGIN{print int($ws_width - $con_width)}")
	tar_y=$(awk "BEGIN{print int(($ws_height - $con_height)/2)}")
	;;
br)     # bottom-right
	tar_x=$(awk "BEGIN{print int($ws_width - $con_width)}")
	tar_y=$(awk "BEGIN{print int($ws_height - $con_height)}")
	;;
bm)	# bottom-middle
	tar_x=$(awk "BEGIN{print int(($ws_width - $con_width)/2)}")
	tar_y=$(awk "BEGIN{print int($ws_height - $con_height)}")
	;;
bl)     # bottom-left
	tar_x=0
	tar_y=$(awk "BEGIN{print int($ws_height - $con_height)}")
	;;
lm)	# left-middle
	tar_x=0
	tar_y=$(awk "BEGIN{print int(($ws_height - $con_height)/2)}")
	;;
*)	# center
	tar_x=$(awk "BEGIN{print int(($ws_width - $con_width)/2)}")
	tar_y=$(awk "BEGIN{print int(($ws_height - $con_height)/2)}")
esac

echo "ws: $ws_width x $ws_height"
echo "con: $con_width x $con_height"
echo "moveto: $tar_x x $tar_y"

swaymsg resize set "$con_width" "$con_height"
swaymsg move position "$tar_x" "$tar_y"