summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xbin/centercon45
-rwxr-xr-xbin/swx9
2 files changed, 39 insertions, 15 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"
diff --git a/bin/swx b/bin/swx
index e902751..1536ad0 100755
--- a/bin/swx
+++ b/bin/swx
@@ -3,7 +3,7 @@ set -e
 [ -n "$DEBUG" ] && set -x
 
 # check requirements
-for app in swaymsg jq swq; do
+for app in swaymsg jq swq centercon; do
 	if ! command -v "$app" >/dev/null; then
 		printf "%s: %s not install but required" "$0" "$app" >&2
 		exit 1
@@ -19,7 +19,7 @@ rotate=
 sticky=
 floating=
 autotile=
-while getopts b:w:o:g:I:r:stfah name; do
+while getopts b:w:o:g:I:r:stfF:ah name; do
 	case "$name" in
 	b)	# border
 		border="${OPTARG}" ;;
@@ -41,6 +41,8 @@ while getopts b:w:o:g:I:r:stfah name; do
 		sticky=1 ;;
 	f)      # set container to float
 		floating=1 ;;
+	F)
+		floating="${OPTARG}" ;;
 	a)	# auto-tiling enabled
 		autotile=1 ;;
 	h|?)	printf "usage: %s [-bwogIrsfo] COMMAND\n" "$(basename "$0")"
@@ -52,7 +54,7 @@ while getopts b:w:o:g:I:r:stfah 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"
+		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 "\n"
 		printf "See sway(5) for possible options for BORDER, WORKSPACE, OUTPUT and GEOMETRY.\n"
@@ -134,6 +136,7 @@ while [ -z "${sway_props_done}" ]; do
 	fi
 	if [ -n "${floating}" ]; then
 		swaymsg [con_id="${con_id}"] floating enable
+		[ "${floating}" = "1" ] || centercon ${floating}
 	fi
 	sway_props_done=1
 done >/dev/null