summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2020-12-03 12:44:38 +0100
committerRobert Günzler <r@gnzler.io>2020-12-03 12:44:38 +0100
commit7013fa78b840b5754dda685ea081994a167e12c6 (patch)
treee6cdcc09fb197f9f21818573982316dbfe807fb1
parent832ca7ead2e11727c8064e39ec5c5435591f6312 (diff)
bin/swx: implement marking
* support foot as terminal
* exit early if we don't need con_id
-rwxr-xr-xbin/swx51
1 files changed, 35 insertions, 16 deletions
diff --git a/bin/swx b/bin/swx
index 693c1da..5b25d35 100755
--- a/bin/swx
+++ b/bin/swx
@@ -1,4 +1,9 @@
 #!/bin/sh
+#
+# DESCRIPTION:
+#  wrapper for `swaymsg exec` with many useful additions
+#
+
 set -e
 [ -n "$DEBUG" ] && set -x
 
@@ -10,6 +15,7 @@ for app in swaymsg jq swq centercon; do
 	fi
 done
 
+patience=
 border=
 wspace=
 output=
@@ -20,7 +26,8 @@ sticky=
 floating=
 autotile=
 into_scratchpad=
-while getopts b:w:o:g:I:r:stfF:aSh name; do
+mark=
+while getopts b:w:o:g:I:r:stfF:aSM:h name; do
 	case "$name" in
 	b)	# border
 		border="${OPTARG}" ;;
@@ -48,7 +55,9 @@ while getopts b:w:o:g:I:r:stfF:aSh name; do
 		autotile=1 ;;
 	S)	# launch into scratchpad
 		into_scratchpad=1 ;;
-	h|?)	printf "usage: %s [-bwogIrsfoS] COMMAND\n" "$(basename "$0")"
+	M)	# mark
+		mark="${OPTARG}" ;;
+	h|?)	printf "usage: %s [-bwogIrsfoSM] COMMAND\n" "$(basename "$0")"
 		printf "\n"
 		printf "  -t \t\trun COMMAND in \$TERM\n"
 		printf "  -b BORDER \tset border property\n"
@@ -61,10 +70,13 @@ while getopts b:w:o:g:I:r:stfF:aSh name; do
 		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 "\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))
 
@@ -79,6 +91,7 @@ shift
 if [ -n "${termify}" ]; then
 	case ${TERM} in
 	alacritty)	term_args="--title=${arg0} --class=${arg0} --command" ;;
+	foot) 		term_args="--title=${arg0} --app-id=${arg0} --" ;;
 	*) 		term_args="" ;;
 	esac
 	command="${TERM} ${term_args} ${arg0} ${*}"
@@ -98,7 +111,8 @@ if [ -n "${rotate}" ]; then
 	# allow for the firefox workaround that spawns a kiosk window
 	# under firejail (to avoid profile folder issues)
 	if echo "$command" | grep -E 'firefox'; then
-		command="firejail --overlay-tmpfs --profile=firefox ${command} --no-remote --kiosk"
+		# command="firejail --overlay-tmpfs --profile=firefox ${command} --no-remote --kiosk"
+		command="firefox-kiosk ${command}"
 	fi
 	command="cage -d ${rotate_args} -- \"${command}\""
 fi
@@ -116,40 +130,45 @@ if [ -n "${autotile}" ]; then
 fi
 
 swaymsg exec -- "${command}" >/dev/null
-[ $? ] || exit 1
-con_id="$(swaymsg -t subscribe '["window"]' | jq -s -r '.[]|select(.change=="new")|.container.id')"
+[ $? ] || { printf "error: failed to spawn \"${command}\"\n"; exit 1; }
+[ -z "$patience" ] && exit 0
+# waiting for container to appear
+con_id="$(swaymsg -t subscribe '["window"]' | jq -s '.[]|select(.change=="new")|.container.id')"
 
 sway_props_done=
 while [ -z "${sway_props_done}" ]; do
 	if [ -n "${floating}" ]; then
-		swaymsg [con_id="${con_id}"] floating enable
+		swaymsg -- [con_id="${con_id}"] floating enable
 		[ "${floating}" = "1" ] || centercon ${floating}
 	fi
 	if [ -n "${into_scratchpad}" ]; then
-		swaymsg [con_id="${con_id}"] move to scratchpad
+		swaymsg -- [con_id="${con_id}"] move to scratchpad
+	fi
+	if [ -n "${mark}" ]; then
+		swaymsg -- [con_id="${con_id}"] mark --add "${mark}"
 	fi
 	if [ -n "${geometry}" ]; then
-		swaymsg [con_id="${con_id}"] floating enable
+		swaymsg -- [con_id="${con_id}"] floating enable
 		wh=$(printf "%s" "${geometry}" | cut -d' ' -f2)
-		swaymsg [con_id="${con_id}"] resize set \
+		swaymsg -- [con_id="${con_id}"] 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)
-		swaymsg [con_id="${con_id}"] move absolute position \
+		swaymsg -- [con_id="${con_id}"] move absolute position \
 			"$(printf "%s" "${xy}" | cut -d',' -f1)" px \
 			"$(printf "%s" "${xy}" | cut -d',' -f2)" px
 	fi
-	if [ -n "${wspace}" ]; then
-		swaymsg [con_id="${con_id}"] move workspace "${wspace}"
-	fi
 	if [ -n "${output}" ]; then
-		swaymsg [con_id="${con_id}"] move output "${wspace}"
+		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
+		swaymsg -- [con_id="${con_id}"] sticky enable
 	fi
 	if [ -n "${border}" ]; then
-		swaymsg [con_id="${con_id}"] border "${border}"
+		swaymsg -- [con_id="${con_id}"] border "${border}"
 	fi
 	sway_props_done=1
 done >/dev/null