summary refs log tree commit diff
path: root/bin/centercon
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2020-07-21 13:15:21 +0200
committerRobert Günzler <r@gnzler.io>2020-07-21 13:15:21 +0200
commite7cfd58af25de9fe7e2a991baf57dfad4d1a0c10 (patch)
tree361fa19bcbe32cb02fd06299a01512f0556e828d /bin/centercon
parentc66b664c987efd14ef256ed1a9b87f888f2defd2 (diff)
bin/centercon: Remove special case for centering
Diffstat (limited to 'bin/centercon')
-rwxr-xr-xbin/centercon71
1 files changed, 39 insertions, 32 deletions
diff --git a/bin/centercon b/bin/centercon
index fc65d13..db48f94 100755
--- a/bin/centercon
+++ b/bin/centercon
@@ -1,4 +1,5 @@
 #!/bin/sh
+set -e
 
 if [ "$1" = "-h" ]; then
 	printf "usage: %s [RESIZE_PERC] [MODE]\n" "$(basename "$0")"
@@ -8,16 +9,11 @@ if [ "$1" = "-h" ]; then
 fi
 
 con=$(swq current con)
-if [ "$(echo "$con" | jq -r '.type')" = "con" ]; then
-	printf "not a floating container\n"
-	exit 1
-fi
-
 ws=$(swq current workspace)
 ws_width=$(echo "$ws" | jq -r '.rect.width')
 ws_height=$(echo "$ws" | jq -r '.rect.height')
 
-if [ -n "$1" ]; then
+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)}")
@@ -26,32 +22,43 @@ else
 	con_height=$(echo "$con" | jq -r '.window_rect.height')
 fi
 
-if [ -n "$2" ]; then
-	case "$2" in
-	tl)     # top-left
-		tar_x=0
-		tar_y=0
-		;;
-	tr)     # top-right
-		tar_x=$(awk "BEGIN{print int($ws_width - $con_width)}")
-		tar_y=0
-		;;
-	bl)     # bottom-left
-		tar_x=0
-		tar_y=$(awk "BEGIN{print int($ws_height - $con_height)}")
-		;;
-	br)     # bottom-right
-		tar_x=$(awk "BEGIN{print int($ws_width - $con_width)}")
-		tar_y=$(awk "BEGIN{print int($ws_height - $con_height)}")
-		;;
-	esac
-else 		# center
-	center_x=$(awk "BEGIN{print int($ws_width/2)}")
-	center_y=$(awk "BEGIN{print int($ws_height/2)}")
-	echo "center: $center_x x $center_y"
-	tar_x=$(awk "BEGIN{print int($center_x - ($con_width / 2))}")
-	tar_y=$(awk "BEGIN{print int($center_y - ($con_height / 2))}")
-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"