summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xbin/swx51
1 files changed, 39 insertions, 12 deletions
diff --git a/bin/swx b/bin/swx
index 4d86d06..ea2d8f0 100755
--- a/bin/swx
+++ b/bin/swx
@@ -1,6 +1,16 @@
 #!/bin/sh
 set -e
 
+[ -n "$DEBUG" ] && set -x
+
+# check requirements
+for app in swaymsg swq jq; do
+	if ! command -v "$app" >/dev/null; then
+		printf "%s: %s not install but required" "$0" "$app" >&2
+		exit 1
+	fi
+done
+
 border=
 wspace=
 output=
@@ -8,7 +18,9 @@ geometry=
 termify=
 appid_override=
 rotate=
-while getopts b:w:o:g:I:r:th name; do
+force_sleep=
+sticky=
+while getopts b:w:o:g:I:r:S:sth name; do
 	case "$name" in
 	b)	# border
 		border="${OPTARG}" ;;
@@ -28,7 +40,11 @@ while getopts b:w:o:g:I:r:th name; do
 			exit 1
 		fi
 		rotate="${OPTARG}" ;;
-	h|?)	printf "usage: %s [-bwog] COMMAND\n" "$(basename "$0")"
+	S)	# force sleep
+		force_sleep="${OPTARG}" ;;
+	s)	# set contianer to sticky
+		sticky=1 ;;
+	h|?)	printf "usage: %s [-bwogIrSs] COMMAND\n" "$(basename "$0")"
 		printf "\n"
 		printf "  -t \t\t(run COMMAND in \$TERM)\n"
 		printf "  -b BORDER \t(set border property)\n"
@@ -36,8 +52,10 @@ while getopts b:w:o:g:I:r:th name; do
 		printf "  -o OUTPUT \t(move to output)\n"
 		printf "  -g GEOMETRY \t(resize/position window)\n"
 		printf "  -I APP_ID \t(override app_id used to detect window, only makes sense with -t)\n"
+		printf "  -r ROTATION \t(rotate the container, requires cage(1))\n"
+		printf "  -S SLEEP \t(force a delay between spawning and property setting, see sleep(1))\n"
+		printf "  -s \t\t(make COMMAND a sticky window, appearing on all workspaces)\n"
 		printf "\n"
-		printf "For this to work swq(1) is required.\n"
 		printf "See sway(5) for possible options for BORDER, WORKSPACE, OUTPUT and GEOMETRY.\n"
 		exit 2 ;;
 	esac
@@ -58,10 +76,10 @@ if [ -n "${termify}" ]; then
 	alacritty)	args="--title=${arg0} --class=${arg0} --command" ;;
 	*) 		args="" ;;
 	esac
-	command="${TERM} ${args} ${arg0} $*"
+	command="${TERM} ${args} ${arg0} ${*}"
 else
 	[ -n "${appid_override}" ] && appid=${appid_override}
-	command="${arg0} $*"
+	command="${arg0} ${*}"
 fi
 
 # needs to be rotated
@@ -78,16 +96,22 @@ if [ -n "${rotate}" ]; then
 	if echo "$command" | grep -E 'firefox'; then
 		command="firejail --overlay-tmpfs --profile=firefox ${command} --no-remote --kiosk"
 	fi
-	command="cage -d ${rotate_args} -- ${command}"
+	command="cage -d ${rotate_args} -- \"${command}\""
 	appid="wlroots"
 fi
 
 sway exec "${command}" >/dev/null
 
+if [ -n "${force_sleep}" ]; then
+	sleep "${force_sleep}"
+fi
+
 sway_props_done=
 waiting=0
 while [ -z "${sway_props_done}" ]; do
-	if ! swq has appid "${appid}" | jq -e 'length>0'; then
+	if ! swq has appid "${appid}" | jq -e 'length>0' \
+		&& [ -z "${force_sleep}" ]
+	then
 		waiting=$((waiting+1))
 		if [ "${waiting}" -gt 20 ]; then
 			printf "%s: failed to run %s.\n" "$0" "${arg0}" >&2
@@ -103,24 +127,27 @@ while [ -z "${sway_props_done}" ]; do
 		continue
 	fi
 	if [ -n "${border}" ]; then
-		sway border "${border}"
+		swaymsg border "${border}"
 	fi
 	if [ -n "${wspace}" ]; then
-		sway move workspace "${wspace}"
+		swaymsg move workspace "${wspace}"
 	fi
 	if [ -n "${output}" ]; then
-		sway move output "${wspace}"
+		swaymsg move output "${wspace}"
 	fi
 	if [ -n "${geometry}" ]; then
-		sway floating enable
+		swaymsg floating enable
 		wh=$(printf "%s" "${geometry}" | cut -d' ' -f2)
 		sway resize set \
 			width "$(printf "%s" "${wh}" | cut -d'x' -f1)" px \
 			height "$(printf "%s" "${wh}" | cut -d'x' -f2)" px
 		xy=$(printf "%s" "${geometry}" | cut -d' ' -f1)
-		sway move absolute position \
+		swaymsg move absolute position \
 			"$(printf "%s" "${xy}" | cut -d',' -f1)" px \
 			"$(printf "%s" "${xy}" | cut -d',' -f2)" px
 	fi
+	if [ -n "${sticky}" ]; then
+		swaymsg sticky enable
+	fi
 	sway_props_done=1
 done >/dev/null