AutoYADM commit: 2025-01-22 13:45:06
This commit is contained in:
parent
e0a4daea1f
commit
5e452a1408
1 changed files with 151 additions and 128 deletions
|
@ -1,181 +1,197 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
WL_PRESENT_DMENU="tofi"
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: wl-present [options] <command> [argument]"
|
echo "usage: wl-present [options] <command> [argument]"
|
||||||
echo
|
echo
|
||||||
echo "start wl-mirror and control the mirrored output and region in a convenient way"
|
echo "start wl-mirror and control the mirrored output and region in a convenient way"
|
||||||
echo
|
echo
|
||||||
echo "commands:"
|
echo "commands:"
|
||||||
echo " help show this help"
|
echo " help show this help"
|
||||||
echo " mirror [output] [options] start wl-mirror on output [output] (default asks via slurp)"
|
echo " mirror [output] [options] start wl-mirror on output [output] (default asks via slurp)"
|
||||||
echo " set-output [output] set the recorded output (default asks via slurp)"
|
echo " set-output [output] set the recorded output (default asks via slurp)"
|
||||||
echo " set-region [region] set the recorded region (default asks via slurp)"
|
echo " set-region [region] set the recorded region (default asks via slurp)"
|
||||||
echo " unset-region unset the recorded region"
|
echo " unset-region unset the recorded region"
|
||||||
echo " set-scaling [scale] set the scaling mode (default asks via rofi)"
|
echo " set-scaling [scale] set the scaling mode (default asks via rofi)"
|
||||||
echo " freeze freeze the screen"
|
echo " freeze freeze the screen"
|
||||||
echo " unfreeze resume the screen capture after freeze"
|
echo " unfreeze resume the screen capture after freeze"
|
||||||
echo " toggle-freeze toggle freeze state of screen capture"
|
echo " toggle-freeze toggle freeze state of screen capture"
|
||||||
echo " fullscreen fullscreen the wl-mirror window"
|
echo " fullscreen fullscreen the wl-mirror window"
|
||||||
echo " unfullscreen unfullscreen the wl-mirror window"
|
echo " unfullscreen unfullscreen the wl-mirror window"
|
||||||
echo " fullscreen-output [output] set fullscreen target output, implies fullscreen (default asks via slurp)"
|
echo " fullscreen-output [output] set fullscreen target output, implies fullscreen (default asks via slurp)"
|
||||||
echo " no-fullscreen-output unset fullscreen target output, implies unfullscreen"
|
echo " no-fullscreen-output unset fullscreen target output, implies unfullscreen"
|
||||||
echo " custom [options] send custom options to wl-mirror (default asks via rofi)"
|
echo " custom [options] send custom options to wl-mirror (default asks via rofi)"
|
||||||
echo
|
echo
|
||||||
echo "options:"
|
echo "options:"
|
||||||
echo " -n, --name use an alternative pipe name (default is wl-present)"
|
echo " -n, --name use an alternative pipe name (default is wl-present)"
|
||||||
echo " this allows multiple instances of wl-present to run"
|
echo " this allows multiple instances of wl-present to run"
|
||||||
echo " at the same time."
|
echo " at the same time."
|
||||||
echo "dependencies:"
|
echo "dependencies:"
|
||||||
echo " wl-mirror, bash, slurp, pipectl (optional), and either wofi, wmenu, rofi, fuzzel, or dmenu"
|
echo " wl-mirror, bash, slurp, pipectl (optional), and either wofi, wmenu, rofi, fuzzel, or dmenu"
|
||||||
echo
|
echo
|
||||||
echo "environment variables":
|
echo "environment variables":
|
||||||
echo " WL_PRESENT_DMENU overrides the used dmenu implementation"
|
echo " WL_PRESENT_DMENU overrides the used dmenu implementation"
|
||||||
echo " WL_PRESENT_PIPECTL overrides the used pipectl implementation"
|
echo " WL_PRESENT_PIPECTL overrides the used pipectl implementation"
|
||||||
echo " WL_PRESENT_SLURP overrides the used slurp implementation"
|
echo " WL_PRESENT_SLURP overrides the used slurp implementation"
|
||||||
echo " WL_PRESENT_PIPE_NAME overrides the default pipe name (default is wl-present)"
|
echo " WL_PRESENT_PIPE_NAME overrides the default pipe name (default is wl-present)"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ -n "$WL_PRESENT_DMENU" ]]; then
|
if [[ -n "$WL_PRESENT_DMENU" ]]; then
|
||||||
DMENU="$WL_PRESENT_DMENU"
|
DMENU="$WL_PRESENT_DMENU"
|
||||||
elif type -p wofi >/dev/null; then
|
elif type -p wofi >/dev/null; then
|
||||||
DMENU="wofi -d"
|
DMENU="wofi -d"
|
||||||
elif type -p wmenu >/dev/null; then
|
elif type -p wmenu >/dev/null; then
|
||||||
DMENU=wmenu
|
DMENU=wmenu
|
||||||
elif type -p fuzzel >/dev/null; then
|
elif type -p fuzzel >/dev/null; then
|
||||||
DMENU="fuzzel -d"
|
DMENU="fuzzel -d"
|
||||||
elif type -p rofi >/dev/null; then
|
elif type -p rofi >/dev/null; then
|
||||||
DMENU="rofi -dmenu"
|
DMENU="rofi -dmenu"
|
||||||
else
|
else
|
||||||
DMENU=dmenu
|
DMENU=dmenu
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$WL_PRESENT_PIPECTL" ]]; then
|
if [[ -n "$WL_PRESENT_PIPECTL" ]]; then
|
||||||
PIPECTL="$WL_PRESENT_PIPECTL"
|
PIPECTL="$WL_PRESENT_PIPECTL"
|
||||||
elif type -p pipectl >/dev/null; then
|
elif type -p pipectl >/dev/null; then
|
||||||
PIPECTL=pipectl
|
PIPECTL=pipectl
|
||||||
else
|
else
|
||||||
PIPECTL=pipectl-shim
|
PIPECTL=pipectl-shim
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$WL_PRESENT_SLURP" ]]; then
|
if [[ -n "$WL_PRESENT_SLURP" ]]; then
|
||||||
SLURP="$WL_PRESENT_SLURP"
|
SLURP="$WL_PRESENT_SLURP"
|
||||||
else
|
else
|
||||||
SLURP=slurp
|
SLURP=slurp
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$WL_PRESENT_PIPE_NAME" ]]; then
|
if [[ -n "$WL_PRESENT_PIPE_NAME" ]]; then
|
||||||
PRESENT_PIPE_NAME="$WL_PRESENT_PIPE_NAME"
|
PRESENT_PIPE_NAME="$WL_PRESENT_PIPE_NAME"
|
||||||
else
|
else
|
||||||
PRESENT_PIPE_NAME=wl-present
|
PRESENT_PIPE_NAME=wl-present
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pipectl-shim() {
|
pipectl-shim() {
|
||||||
PIPEPATH="${XDG_RUNTIME_DIR:-"${TMPDIR:-/tmp}"}"
|
PIPEPATH="${XDG_RUNTIME_DIR:-"${TMPDIR:-/tmp}"}"
|
||||||
PIPENAME="pipectl.$(id -u).pipe"
|
PIPENAME="pipectl.$(id -u).pipe"
|
||||||
MODE=
|
MODE=
|
||||||
FORCE=0
|
FORCE=0
|
||||||
|
|
||||||
while [[ $# -gt 0 && "${1:0:1}" == "-" ]]; do
|
while [[ $# -gt 0 && "${1:0:1}" == "-" ]]; do
|
||||||
opt="$1"
|
opt="$1"
|
||||||
shift
|
shift
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
-n|--name) arg="$1"; shift; PIPENAME="pipectl.$(id -u).$arg.pipe";;
|
-n | --name)
|
||||||
-i|--in) MODE=in;;
|
arg="$1"
|
||||||
-o|--out) MODE=out;;
|
shift
|
||||||
-f|--force) FORCE=1;;
|
PIPENAME="pipectl.$(id -u).$arg.pipe"
|
||||||
--) break;;
|
;;
|
||||||
esac
|
-i | --in) MODE=in ;;
|
||||||
done
|
-o | --out) MODE=out ;;
|
||||||
|
-f | --force) FORCE=1 ;;
|
||||||
PIPE="$PIPEPATH/$PIPENAME"
|
--) break ;;
|
||||||
|
|
||||||
case "$MODE" in
|
|
||||||
"in") if [[ ! -p "$PIPE" ]]; then
|
|
||||||
echo "error: could not open pipe at '$PIPE': No such file or directory" >&2
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
cat > "$PIPE"
|
|
||||||
fi;;
|
|
||||||
"out") if [[ "$FORCE" -eq 0 && -p "$PIPE" ]]; then
|
|
||||||
echo "error: cannot create pipe at '$PIPE': File exists" >&2
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
[[ "$FORCE" -eq 1 ]] && rm -f "$PIPE"
|
|
||||||
mkfifo "$PIPE"; (tail -f "$PIPE" & echo > "$PIPE"; wait); rm -f "$PIPE"
|
|
||||||
fi;;
|
|
||||||
esac
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
PIPE="$PIPEPATH/$PIPENAME"
|
||||||
|
|
||||||
|
case "$MODE" in
|
||||||
|
"in") if [[ ! -p "$PIPE" ]]; then
|
||||||
|
echo "error: could not open pipe at '$PIPE': No such file or directory" >&2
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
cat >"$PIPE"
|
||||||
|
fi ;;
|
||||||
|
"out") if [[ "$FORCE" -eq 0 && -p "$PIPE" ]]; then
|
||||||
|
echo "error: cannot create pipe at '$PIPE': File exists" >&2
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
[[ "$FORCE" -eq 1 ]] && rm -f "$PIPE"
|
||||||
|
mkfifo "$PIPE"
|
||||||
|
(
|
||||||
|
tail -f "$PIPE" &
|
||||||
|
echo >"$PIPE"
|
||||||
|
wait
|
||||||
|
)
|
||||||
|
rm -f "$PIPE"
|
||||||
|
fi ;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
slurp-output() {
|
slurp-output() {
|
||||||
$SLURP -or -f '%o' 2>/dev/null
|
$SLURP -or -f '%o' 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
slurp-region() {
|
slurp-region() {
|
||||||
$SLURP 2>/dev/null
|
$SLURP 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
slurp-output-or-region() {
|
slurp-output-or-region() {
|
||||||
$SLURP -o -f '%o|%x,%y %wx%h' 2>/dev/null
|
$SLURP -o -f '%o|%x,%y %wx%h' 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
mirror() {
|
mirror() {
|
||||||
if [[ "$#" -eq 0 || "$1" =~ ^- ]]; then
|
if [[ "$#" -eq 0 || "$1" =~ ^- ]]; then
|
||||||
OUTPUT_REGION=$(ask-output-or-region)
|
OUTPUT_REGION=$(ask-output-or-region)
|
||||||
IFS='|' read -r OUTPUT REGION <<< "$OUTPUT_REGION"
|
IFS='|' read -r OUTPUT REGION <<<"$OUTPUT_REGION"
|
||||||
|
|
||||||
mirror "$OUTPUT" -r "$REGION" "$@"
|
mirror "$OUTPUT" -r "$REGION" "$@"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OUTPUT="$1"
|
OUTPUT="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
$PIPECTL -n "$PRESENT_PIPE_NAME" -o | wl-mirror -S "$@" "$OUTPUT"
|
$PIPECTL -n "$PRESENT_PIPE_NAME" -o | wl-mirror -S "$@" "$OUTPUT"
|
||||||
}
|
}
|
||||||
|
|
||||||
mirror-cmd() {
|
mirror-cmd() {
|
||||||
$PIPECTL -n "$PRESENT_PIPE_NAME" -i <<< "$1"
|
$PIPECTL -n "$PRESENT_PIPE_NAME" -i <<<"$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
set-output() {
|
set-output() {
|
||||||
mirror-cmd "$1"
|
mirror-cmd "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
set-region() {
|
set-region() {
|
||||||
mirror-cmd "-r '$1'"
|
mirror-cmd "-r '$1'"
|
||||||
}
|
}
|
||||||
|
|
||||||
set-scaling() {
|
set-scaling() {
|
||||||
mirror-cmd "-s $1"
|
mirror-cmd "-s $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
set-fullscreen-output() {
|
set-fullscreen-output() {
|
||||||
mirror-cmd "--fullscreen-output $1"
|
mirror-cmd "--fullscreen-output $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
ask-output() {
|
ask-output() {
|
||||||
slurp-output
|
slurp-output
|
||||||
[[ $? -ne 0 ]] && exit 1
|
[[ $? -ne 0 ]] && exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
ask-region() {
|
ask-region() {
|
||||||
slurp-region
|
slurp-region
|
||||||
[[ $? -ne 0 ]] && exit 1
|
[[ $? -ne 0 ]] && exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
ask-output-or-region() {
|
ask-output-or-region() {
|
||||||
slurp-output-or-region
|
slurp-output-or-region
|
||||||
[[ $? -ne 0 ]] && exit 1
|
[[ $? -ne 0 ]] && exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
ask-scaling() {
|
ask-scaling() {
|
||||||
(echo fit; echo cover; echo exact; echo linear; echo nearest) | $DMENU -p "wl-present scaling"
|
(
|
||||||
[[ $? -ne 0 ]] && exit 1
|
echo fit
|
||||||
|
echo cover
|
||||||
|
echo exact
|
||||||
|
echo linear
|
||||||
|
echo nearest
|
||||||
|
) | $DMENU -p "wl-present scaling"
|
||||||
|
[[ $? -ne 0 ]] && exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
ask-custom() {
|
ask-custom() {
|
||||||
cat <<EOF | $DMENU -p "wl-present custom"
|
cat <<EOF | $DMENU -p "wl-present custom"
|
||||||
--verbose
|
--verbose
|
||||||
--no-verbose
|
--no-verbose
|
||||||
--show-cursor
|
--show-cursor
|
||||||
|
@ -199,37 +215,44 @@ ask-custom() {
|
||||||
--region
|
--region
|
||||||
--no-region
|
--no-region
|
||||||
EOF
|
EOF
|
||||||
[[ $? -ne 0 ]] && exit 1
|
[[ $? -ne 0 ]] && exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
while [[ $# -gt 0 && "${1:0:1}" == "-" ]]; do
|
while [[ $# -gt 0 && "${1:0:1}" == "-" ]]; do
|
||||||
opt="$1"
|
opt="$1"
|
||||||
|
shift
|
||||||
|
case "$opt" in
|
||||||
|
-n | --name)
|
||||||
|
arg="$1"
|
||||||
shift
|
shift
|
||||||
case "$opt" in
|
PRESENT_PIPE_NAME="$arg"
|
||||||
-n|--name) arg="$1"; shift; PRESENT_PIPE_NAME="$arg";;
|
;;
|
||||||
-h|--help) usage;;
|
-h | --help) usage ;;
|
||||||
--) break;;
|
--) break ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
help) usage;;
|
help) usage ;;
|
||||||
mirror) shift; mirror "$@";;
|
mirror)
|
||||||
set-output) set-output "${2:-$(ask-output)}";;
|
shift
|
||||||
set-region) set-region "${2:-$(ask-region)}";;
|
mirror "$@"
|
||||||
unset-region|no-region) mirror-cmd --no-region;;
|
;;
|
||||||
set-scaling) set-scaling "${2:-$(ask-scaling)}";;
|
set-output) set-output "${2:-$(ask-output)}" ;;
|
||||||
freeze) mirror-cmd --freeze;;
|
set-region) set-region "${2:-$(ask-region)}" ;;
|
||||||
unfreeze) mirror-cmd --unfreeze;;
|
unset-region | no-region) mirror-cmd --no-region ;;
|
||||||
toggle-freeze) mirror-cmd --toggle-freeze;;
|
set-scaling) set-scaling "${2:-$(ask-scaling)}" ;;
|
||||||
fullscreen) mirror-cmd --fullscreen;;
|
freeze) mirror-cmd --freeze ;;
|
||||||
unfullscreen|no-fullscreen) mirror-cmd --no-fullscreen;;
|
unfreeze) mirror-cmd --unfreeze ;;
|
||||||
fullscreen-output) set-fullscreen-output "${2:-$(ask-output)}";;
|
toggle-freeze) mirror-cmd --toggle-freeze ;;
|
||||||
no-fullscreen-output) mirror-cmd --no-fullscreen-output;;
|
fullscreen) mirror-cmd --fullscreen ;;
|
||||||
custom) mirror-cmd "${2:-$(ask-custom)}";;
|
unfullscreen | no-fullscreen) mirror-cmd --no-fullscreen ;;
|
||||||
*) usage;;
|
fullscreen-output) set-fullscreen-output "${2:-$(ask-output)}" ;;
|
||||||
|
no-fullscreen-output) mirror-cmd --no-fullscreen-output ;;
|
||||||
|
custom) mirror-cmd "${2:-$(ask-custom)}" ;;
|
||||||
|
*) usage ;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue