summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2022-08-17 15:43:46 +0200
committerRobert Günzler <r@gnzler.io>2022-08-17 15:43:46 +0200
commit1142e0630399a27b8f6d2c61034f515d2968203f (patch)
tree94698d5d49644acdec36d4b0e3e1aebfc1630814
parent22de37b2827266fe5e871d6a1e1943f4c27eff85 (diff)
bin/swx: refactor
Diffstat (limited to '')
-rwxr-xr-xbin/swx140
1 files changed, 71 insertions, 69 deletions
diff --git a/bin/swx b/bin/swx
index 1ba942b..11efac0 100755
--- a/bin/swx
+++ b/bin/swx
@@ -30,66 +30,68 @@ mark=
 term_title=
 while getopts b:w:o:g:I:r:stfF:aSM:T:h name; do
 	case "$name" in
-		b) # border
-			border="${OPTARG}" ;;
-		w) # move to workspace
-			wspace="${OPTARG}" ;;
-		o) # move to output
-			output="${OPTARG}" ;;
-		g) # geometry
-			geometry="${OPTARG}" ;;
-		t) # termify
-			termify=1 ;;
-		r) # rotate
-			if ! command -v cage >/dev/null; then
-				printf "%s: cage not installed but required to rotate containers" "$0" >&2
-				exit 1
-			fi
-			rotate="${OPTARG}"
-			;;
-		s) # set container to sticky
-			sticky=1 ;;
-		f) # set container to float
-			floating=1 ;;
-		F)
-			floating="${OPTARG}"
-			;;
-		a) # auto-tiling enabled
-			autotile=1 ;;
-		S) # launch into scratchpad
-			into_scratchpad=1 ;;
-		M) # mark
-			mark="${OPTARG}" ;;
-		T) # set terminal title
-			term_title="${OPTARG}" ;;
+	b) # border
+		border="${OPTARG}" ;;
+	w) # move to workspace
+		wspace="${OPTARG}" ;;
+	o) # move to output
+		output="${OPTARG}" ;;
+	g) # geometry
+		geometry="${OPTARG}"
+		floating=1
+		;;
+	t) # termify
+		termify=1 ;;
+	r) # rotate
+		if ! command -v cage >/dev/null; then
+			printf "%s: cage not installed but required to rotate containers" "$0" >&2
+			exit 1
+		fi
+		rotate="${OPTARG}"
+		;;
+	s) # set container to sticky
+		sticky=1 ;;
+	f) # set container to float
+		floating=1 ;;
+	F)
+		floating="${OPTARG}"
+		;;
+	a) # auto-tiling enabled
+		autotile=1 ;;
+	S) # launch into scratchpad
+		into_scratchpad=1 ;;
+	M) # mark
+		mark="${OPTARG}" ;;
+	T) # set terminal title
+		term_title="${OPTARG}" ;;
 
-		h | ?)
-			printf "usage: %s [-bwogIrsfoSMT] COMMAND\n" "$(basename "$0")"
-			printf "\n"
-			printf "  -t \t\trun COMMAND in \$TERM\n"
-			printf "  -b BORDER \tset border property\n"
-			printf "  -w WORKSPACE \tmove to workspace\n"
-			printf "  -o OUTPUT \tmove to output\n"
-			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 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 "  -M MARK\t\set MARK on the container\n"
-			printf "  -T TERM_TITLE\t\set a title on the terminal (only makes sense with -t)\n"
-			printf "\n"
-			printf "See sway(5) for possible options for BORDER, WORKSPACE, OUTPUT and GEOMETRY.\n"
-			exit 2
-			;;
+	h | ?)
+		printf "usage: %s [-bwogIrsfoSMT] COMMAND\n" "$(basename "$0")"
+		printf "\n"
+		printf "  -t \t\trun COMMAND in \$TERM\n"
+		printf "  -b BORDER \tset border property\n"
+		printf "  -w WORKSPACE \tmove to workspace\n"
+		printf "  -o OUTPUT \tmove to output\n"
+		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 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 "  -M MARK\t\set MARK on the container\n"
+		printf "  -T TERM_TITLE\t\set a title on the terminal (only makes sense with -t)\n"
+		printf "\n"
+		printf "See sway(5) for possible options for BORDER, WORKSPACE, OUTPUT and GEOMETRY.\n"
+		exit 2
+		;;
 	esac
 	# block until we have a con_id matching on pid of the spawned process
 	patience=1
 done
 shift $((OPTIND - 1))
 
-arg0=$(basename "$1")
+arg0=$1
 if [ -z "${arg0}" ]; then
 	exec "$0" -h
 fi
@@ -105,7 +107,7 @@ if [ -n "${termify}" ]; then
 	else
 		term_args="foot"
 	fi
-	term_args="${term_args} --title=${term_title:-${arg0}} --app-id=${term_title:-${arg0}}"
+	term_args="${term_args} --title=${term_title:-$(basename "${arg0}")} --app-id=${term_title:-$(basename "${arg0}")}"
 	if [ -n "${SWX_TERM_ARGS}" ]; then
 		term_args="${term_args} ${SWX_TERM_ARGS}"
 	fi
@@ -135,13 +137,13 @@ if [ -n "${autotile}" ]; then
 	# layout=$(swq current workspace | jq -r '.. | select(.type?=="con" and .name?==null) | .layout')
 	# notify-send swx "${layout}"
 	case "${layout}" in
-		split*)
-			if [ "$(swq current con | jq '.rect | .width > .height')" = "true" ]; then
-				swaymsg splith
-			else
-				swaymsg splitv
-			fi
-			;;
+	split*)
+		if [ "$(swq current con | jq '.rect | .width > .height')" = "true" ]; then
+			swaymsg splith
+		else
+			swaymsg splitv
+		fi
+		;;
 	esac
 fi
 
@@ -157,8 +159,15 @@ con_id="$(swaymsg -t subscribe '["window"]' | jq -s '.[]|select(.change=="new")|
 sway_props_done=
 while [ -z "${sway_props_done}" ]; do
 	if [ -n "${floating}" ]; then
+		swaymsg -- [con_id="${con_id}"] fullscreen disable
 		swaymsg -- [con_id="${con_id}"] floating enable
-		[ "${floating}" = "1" ] || centercon -w ${floating}
+		[ "${floating}" != "1" ] && centercon -w "${floating}"
+	fi
+	if [ -n "${output}" ]; then
+		swaymsg -- [con_id="${con_id}"] move output "${output}"
+	fi
+	if [ -n "${wspace}" ]; then
+		swaymsg -- [con_id="${con_id}"] move workspace "${wspace}"
 	fi
 	if [ -n "${into_scratchpad}" ]; then
 		swaymsg -- [con_id="${con_id}"] move to scratchpad
@@ -167,7 +176,6 @@ while [ -z "${sway_props_done}" ]; do
 		swaymsg -- [con_id="${con_id}"] mark --add "${mark}"
 	fi
 	if [ -n "${geometry}" ]; then
-		swaymsg -- [con_id="${con_id}"] floating enable
 		wh=$(printf "%s" "${geometry}" | cut -d' ' -f2)
 		swaymsg -- [con_id="${con_id}"] resize set \
 			width "$(printf "%s" "${wh}" | cut -d'x' -f1)" px \
@@ -177,12 +185,6 @@ while [ -z "${sway_props_done}" ]; do
 			"$(printf "%s" "${xy}" | cut -d',' -f1)" px \
 			"$(printf "%s" "${xy}" | cut -d',' -f2)" px
 	fi
-	if [ -n "${output}" ]; then
-		swaymsg -- [con_id="${con_id}"] move output "${output}"
-	fi
-	if [ -n "${wspace}" ]; then
-		swaymsg -- [con_id="${con_id}"] move workspace "${wspace}"
-	fi
 	if [ -n "${sticky}" ]; then
 		swaymsg -- [con_id="${con_id}"] sticky enable
 	fi