[dwm] re-add dwmswallow
it was a shell script not an executable
This commit is contained in:
parent
7546b13d58
commit
7267a268d8
1
suckless/dwm/.gitignore
vendored
1
suckless/dwm/.gitignore
vendored
@ -4,5 +4,4 @@
|
||||
*.tar.gz
|
||||
*.diff
|
||||
dwm
|
||||
dwmswallow
|
||||
config.h
|
||||
|
120
suckless/dwm/dwmswallow
Executable file
120
suckless/dwm/dwmswallow
Executable file
@ -0,0 +1,120 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# 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.
|
||||
is_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 arguments
|
||||
arg1="$1" # save for later
|
||||
arg2="$2" # save for later
|
||||
num_pargs=0
|
||||
while :; do
|
||||
case "$1" in
|
||||
-*|"") break ;;
|
||||
*) num_pargs=$((num_pargs + 1)); shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
case "$num_pargs" in
|
||||
1)
|
||||
! 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
|
||||
fi
|
||||
esac
|
Loading…
Reference in New Issue
Block a user