summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xbin/centercon71
-rwxr-xr-xbin/swx17
2 files changed, 48 insertions, 40 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"
diff --git a/bin/swx b/bin/swx
index c9ca172..693c1da 100755
--- a/bin/swx
+++ b/bin/swx
@@ -57,9 +57,9 @@ while getopts b:w:o:g:I:r:stfF:aSh name; do
 		printf "  -g GEOMETRY \tresize/position window\n"
 		printf "  -r ROTATION \trotate the container, requires cage(1)\n"
 		printf "  -s \t\tmake COMMAND a sticky window, appearing on all workspaces\n"
-		printf "  -f \t\tmake COMMAND a floating window\n\tsee centercon(1) for possible values\n"
-		printf "  -F [PERC [MODE]]\tmake COMMAND a floating window\n\tsee centercon(1) for possible values\n"
-		printf "  -a \t\tauto-tiling; always open COMMAND on the shorter edge\n\t\tof the current container\n"
+		printf "  -f \t\tmake COMMAND a floating window\n"
+		printf "  -F OPTIONS\tmake COMMAND a floating window\n\t\tsee centercon(1) for possible options\n"
+		printf "  -a \t\tauto-tiling; always open COMMAND on the shorter edge of\n\t\tthe current container\n"
 		printf "  -S \t\tmove the container into the scratchpad\n"
 		printf "\n"
 		printf "See sway(5) for possible options for BORDER, WORKSPACE, OUTPUT and GEOMETRY.\n"
@@ -78,10 +78,10 @@ shift
 # spawn a $TERM instance and exec that
 if [ -n "${termify}" ]; then
 	case ${TERM} in
-	alacritty)	args="--title=${arg0} --class=${arg0} --command" ;;
-	*) 		args="" ;;
+	alacritty)	term_args="--title=${arg0} --class=${arg0} --command" ;;
+	*) 		term_args="" ;;
 	esac
-	command="${TERM} ${args} ${arg0} ${*}"
+	command="${TERM} ${term_args} ${arg0} ${*}"
 else
 	command="${arg0} ${*}"
 fi
@@ -115,14 +115,15 @@ if [ -n "${autotile}" ]; then
 	esac
 fi
 
-swaymsg exec "${command}" >/dev/null
+swaymsg exec -- "${command}" >/dev/null
+[ $? ] || exit 1
 con_id="$(swaymsg -t subscribe '["window"]' | jq -s -r '.[]|select(.change=="new")|.container.id')"
 
 sway_props_done=
 while [ -z "${sway_props_done}" ]; do
 	if [ -n "${floating}" ]; then
 		swaymsg [con_id="${con_id}"] floating enable
-		[ ! "${floating}" = "1" ] && centercon "${floating}"
+		[ "${floating}" = "1" ] || centercon ${floating}
 	fi
 	if [ -n "${into_scratchpad}" ]; then
 		swaymsg [con_id="${con_id}"] move to scratchpad