summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2020-07-03 12:32:51 +0200
committerRobert Günzler <r@gnzler.io>2020-07-03 12:32:51 +0200
commitfef12f92c8548f9a7c424ca3b21e3d8a5e5a1400 (patch)
tree41c29a8aca2c62e73a271d200b380ea7cdeb45d2 /bin
parentcec04184748f8dc082d9da1cd9828c8b29e693b1 (diff)
bin/swx: Add auto-tiling feature
Diffstat (limited to 'bin')
-rwxr-xr-xbin/swx15
1 files changed, 13 insertions, 2 deletions
diff --git a/bin/swx b/bin/swx
index f4bedd4..77daf1c 100755
--- a/bin/swx
+++ b/bin/swx
@@ -3,7 +3,7 @@ set -e
 [ -n "$DEBUG" ] && set -x
 
 # check requirements
-for app in swaymsg jq; do
+for app in swaymsg jq swq; do
 	if ! command -v "$app" >/dev/null; then
 		printf "%s: %s not install but required" "$0" "$app" >&2
 		exit 1
@@ -19,7 +19,8 @@ rotate=
 force_sleep=
 sticky=
 floating=
-while getopts b:w:o:g:I:r:S:stfh name; do
+autotile=
+while getopts b:w:o:g:I:r:S:stfAh name; do
 	case "$name" in
 	b)	# border
 		border="${OPTARG}" ;;
@@ -43,6 +44,8 @@ while getopts b:w:o:g:I:r:S:stfh name; do
 		sticky=1 ;;
 	f)      # set container to float
 		floating=1 ;;
+	A)	# auto-tiling enabled
+		autotile=1 ;;
 	h|?)	printf "usage: %s [-bwogIrSs] COMMAND\n" "$(basename "$0")"
 		printf "\n"
 		printf "  -t \t\t(run COMMAND in \$TERM)\n"
@@ -96,6 +99,14 @@ if [ -n "${rotate}" ]; then
 	command="cage -d ${rotate_args} -- \"${command}\""
 fi
 
+if [ -n "${autotile}" ]; then
+	if [ "$(swq current con | jq '.rect | .width > .height')" = "true" ]; then
+		swaymsg splith
+	else
+		swaymsg splitv
+	fi
+fi
+
 swaymsg exec "${command}" >/dev/null
 con_id="$(swaymsg -t subscribe '["window"]' | jq -s -r '.[]|select(.change=="new")|.container.id')"