| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 | #!/usr/bin/dash# Separator and command prefix, as defined in dwm.c:fakesignal()SEP='###'PREFIX='#!'# Asserts that all arguments are valid X11 window IDs, i.e. positive integers.# For the purpose of this script 0 is declared invalid asweis_winid() {	while :; do		# Given input incompatible to %d, some implementations of printf return		# an error while others silently evaluate the expression to 0.		if ! wid=$(printf '%d' "$1" 2>/dev/null) || [ "$wid" -le 0 ]; then			return 1		fi		[ -n "$2" ] && shift || break	done}# Prints usage help. If "$1" is provided, function exits script after# execution.usage() {	[ -t 1 ] && myprintf=printf || myprintf=true	msg="$(cat <<-EOF	dwm window swallowing command-line interface. Usage:	  $($myprintf "\033[1m")dwmswallow $($myprintf "\033[3m")SWALLOWER [-c CLASS] [-i INSTANCE] [-t TITLE]$($myprintf "\033[0m")	    Register window $($myprintf "\033[3m")SWALLOWER$($myprintf "\033[0m") to swallow the next future window whose attributes	    match the $($myprintf "\033[3m")CLASS$($myprintf "\033[0m") name, $($myprintf "\033[3m")INSTANCE$($myprintf "\033[0m") name and window $($myprintf "\033[3m")TITLE$($myprintf "\033[0m") filters using basic	    string-matching. An omitted filter will match anything.	  $($myprintf "\033[1m")dwmswallow $($myprintf "\033[3m")SWALLOWER -d$($myprintf "\033[0m")	    Deregister queued swallow for window $($myprintf "\033[3m")SWALLOWER$($myprintf "\033[0m"). Inverse of above signature.	  $($myprintf "\033[1m")dwmswallow $($myprintf "\033[3m")SWALLOWER SWALLOWEE$($myprintf "\033[0m")	    Perform immediate swallow of window $($myprintf "\033[3m")SWALLOWEE$($myprintf "\033[0m") by window $($myprintf "\033[3m")SWALLOWER$($myprintf "\033[0m").	  $($myprintf "\033[1m")dwmswallow $($myprintf "\033[3m")SWALLOWEE -s$($myprintf "\033[0m")	    Stop swallow of window $($myprintf "\033[3m")SWALLOWEE$($myprintf "\033[0m"). Inverse of the above signature. Visible	    windows only.	  $($myprintf "\033[1m")dwmswallow -h$($myprintf "\033[0m")	    Show this usage information.	EOF	)"	if [ -n "$1" ]; then		echo "$msg" >&2		exit "$1"	else		echo "$msg"	fi}# Determine number of leading positional argumentsarg1="$1" # save for laterarg2="$2" # save for laternum_pargs=0while :; do	case "$1" in	-*|"") break ;;	*) num_pargs=$((num_pargs + 1)); shift ;;	esacdonecase "$num_pargs" in1)	! is_winid "$arg1" && usage 1	widswer="$arg1"	if [ "$1" = "-d" ] && [ "$#" -eq 1 ]; then		if name="$(printf "${PREFIX}swalunreg${SEP}%u" "$widswer" 2>/dev/null)"; then			xsetroot -name "$name"		else			usage 1		fi	elif [ "$1" = "-s" ] && [ "$#" -eq 1 ]; then		widswee="$arg1"		if name="$(printf "${PREFIX}swalstop${SEP}%u" "$widswee" 2>/dev/null)"; then			xsetroot -name "$name"		else			usage 1		fi	else		while :; do			case "$1" in			-c) [ -n "$2" ] && { class="$2"; shift 2; } || usage 1 ;;			-i) [ -n "$2" ] && { instance="$2"; shift 2; } || usage 1 ;;			-t) [ -n "$2" ] && { title="$2"; shift 2; } || usage 1 ;;			"") break ;;			*)	usage 1 ;;			esac		done		widswer="$arg1"		if name="$(printf "${PREFIX}swalreg${SEP}%u${SEP}%s${SEP}%s${SEP}%s" "$widswer" "$class" "$instance" "$title" 2>/dev/null)"; then			xsetroot -name "$name"		else			usage 1		fi	fi	;;2)	! is_winid "$arg1" "$arg2" || [ -n "$1" ] && usage 1	widswer="$arg1"	widswee="$arg2"	if name="$(printf "${PREFIX}swal${SEP}%u${SEP}%u" "$widswer" "$widswee" 2>/dev/null)"; then		xsetroot -name "$name"	else		usage 1	fi	;;*)	if [ "$arg1" = "-h" ] && [ $# -eq 1 ]; then		usage	else		usage 1	fiesac
 |