summary refs log tree commit diff
path: root/bin/centercon
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2020-07-07 18:07:23 +0200
committerRobert Günzler <r@gnzler.io>2020-07-07 18:07:23 +0200
commit2f2c0ab361fb31edd2fe5c39281c5150411c1d9a (patch)
treeafdac02d1ed8d874864c31d0039a361be5cf2c28 /bin/centercon
parent6791776f428307c6aa500287a7e03c1ed1d1de89 (diff)
bin/centercon,swx: support placing windows in corners
Diffstat (limited to 'bin/centercon')
-rwxr-xr-xbin/centercon45
1 files changed, 33 insertions, 12 deletions
diff --git a/bin/centercon b/bin/centercon
index e9cd189..fc65d13 100755
--- a/bin/centercon
+++ b/bin/centercon
@@ -1,7 +1,9 @@
 #!/bin/sh
 
 if [ "$1" = "-h" ]; then
-	printf "usage: %s [RESIZE_PERC]\n" "$(basename "$0")"
+	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
 
@@ -14,27 +16,46 @@ fi
 ws=$(swq current workspace)
 ws_width=$(echo "$ws" | jq -r '.rect.width')
 ws_height=$(echo "$ws" | jq -r '.rect.height')
-ws_x=$(echo "$ws" | jq -r '.rect.x')
-ws_y=$(echo "$ws" | jq -r '.rect.y')
-
-center_x=$(awk "BEGIN{print int($ws_width - $ws_x)/2}")
-center_y=$(awk "BEGIN{print int($ws_height - $ws_y)/2}")
 
 if [ -n "$1" ]; then
 	perc="$1"
 	con_width=$(awk "BEGIN{print int($ws_width * $perc)}")
 	con_height=$(awk "BEGIN{print int($ws_height * $perc)}")
-	swaymsg resize set "$con_width" "$con_height"
 else
 	con_width=$(echo "$con" | jq -r '.window_rect.width')
 	con_height=$(echo "$con" | jq -r '.window_rect.height')
 fi
 
-echo "center: $center_x x $center_y"
-echo "con: $con_width x $con_height"
-
-tar_x=$(awk "BEGIN{print int($center_x - ($con_width / 2))}")
-tar_y=$(awk "BEGIN{print int($center_y - ($con_height / 2))}")
+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
 
+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"