From fef12f92c8548f9a7c424ca3b21e3d8a5e5a1400 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Fri, 3 Jul 2020 12:32:51 +0200 Subject: bin/swx: Add auto-tiling feature --- bin/swx | 15 +++++++++++++-- 1 file 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')" -- cgit 1.4.1