Change output numbers to output names

Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
Skylar "The Cobra" Widulski 2023-05-23 03:05:13 -04:00
parent a85754ea38
commit b2bb46c061
Signed by: cobra
GPG Key ID: 4FD8F812083FF6F9
5 changed files with 37 additions and 19 deletions

View File

@ -33,8 +33,9 @@ For a more in-depth guide, see wf-shadow(1)
# Dependencies
This script depends on `wf-recorder`, `wofi`, and, obviously, `bash`.
`wf-shadow` depends on `wf-recorder`, `wofi` (optional), `wlr-randr`, and, obviously, `bash`.
`wf-shadow-tui` depends on `dialog` alongside all of these programs.
# Installation

View File

@ -5,7 +5,7 @@
.nh
.ad l
.\" Begin generated content:
.TH "wf-shadow" "1" "2023-05-17" "wf-shadow" "General Commands Manual"
.TH "wf-shadow" "1" "2023-05-23" "wf-shadow" "General Commands Manual"
.P
.SH NAME
.P
@ -153,6 +153,12 @@ variables.\&
The output number to use to start, end, or record on.\& Default is 1.\&
.P
.RE
\fBOUTPUT_NAME\fR
.RS 4
The name of the output to use to start, end, or record on.\& Unset by
default.\& Overrides \fBOUTPUT\fR.\&
.P
.RE
\fBAUDIO_DEV\fR
.RS 4
This variable is the same as what is passed to \fI-a\fR.\& See \fBOPTIONS\fR for

View File

@ -102,6 +102,10 @@ variables.
*OUTPUT*
The output number to use to start, end, or record on. Default is 1.
*OUTPUT_NAME*
The name of the output to use to start, end, or record on. Unset by
default. Overrides *OUTPUT*.
*AUDIO_DEV*
This variable is the same as what is passed to _-a_. See *OPTIONS* for
more information.

View File

@ -28,7 +28,7 @@ if [ ! -f "$CONFIG" ]; then
printf '' >> "$CONFIG"
fi
OUTPUT=1
OUTPUT=""
AUDIO_DEV=""
AUDIO_CODEC=""
NO_AUDIO=""
@ -76,6 +76,11 @@ if ! command -v wf-recorder &>/dev/null; then
exit 1
fi
if ! command -v wlr-randr &>/dev/null; then
printf "Need wlr-randr\n"
exit 1
fi
print_help() {
cat << EOF
wf-shadow: A Wayland shadow recorder using wf-recorder and wofi
@ -124,9 +129,9 @@ start() {
printf '' >> "$i"
printf '%s' "$i" > "$RUNTIME"/"$OUTPUT"_current
if [ -n "$VERBOSE" ]; then
wf-recorder ${VIDEO_DEV:+-d "$VIDEO_DEV"} -a $AUDIO_DEV -f "$i" <<< y$'\n'$OUTPUT &
wf-recorder ${OUTPUT:+-o "$OUTPUT"} ${VIDEO_DEV:+-d "$VIDEO_DEV"} -a $AUDIO_DEV -f "$i" <<< y$'\n'1 &
else
wf-recorder ${VIDEO_DEV:+-d "$VIDEO_DEV"} -a $AUDIO_DEV -f "$i" <<< y$'\n'$OUTPUT &>/dev/null &
wf-recorder ${OUTPUT:+-o "$OUTPUT"} ${VIDEO_DEV:+-d "$VIDEO_DEV"} -a $AUDIO_DEV -f "$i" <<< y$'\n'1 &>/dev/null &
fi
printf "%s" "$!" > "$RUNTIME"/"$OUTPUT".pid
fg || exit
@ -134,13 +139,21 @@ start() {
done
}
check_output() {
if ! wlr-randr | grep "$1" &>/dev/null; then
printf "Output %s does not exist\n" "$1"
exit 1
fi
}
until [ -z "$1" ]; do
re="^[0-9]+$"
re="^[A-Z]+-[1-9][0-9]*$"
case "$1" in
'-h' | '--help') print_help ;;
'-e' | '--end')
END=1
if [[ "$2" =~ $re ]]; then
check_output "$2"
OUTPUT="$2"
shift 2
else
@ -149,6 +162,7 @@ until [ -z "$1" ]; do
'-r' | '--record')
RECORD=1
if [[ "$2" =~ $re ]]; then
check_output "$2"
OUTPUT="$2"
shift 2
else
@ -157,6 +171,7 @@ until [ -z "$1" ]; do
'-s' | '--start')
START=1
if [[ "$2" =~ $re ]]; then
check_output "$2"
OUTPUT="$2"
shift 2
else
@ -232,7 +247,7 @@ if [ "$START" == 1 ]; then
printf "%s" "$$" > "$RUNTIME"/"$OUTPUT"_host.pid
start
else
printf "A wf-shadow instance is already running on output %d (%s/%d_host.pid)\n" "$OUTPUT" "$RUNTIME" "$OUTPUT"
printf "A wf-shadow instance is already running on output %s (%s/%s_host.pid)\n" "$OUTPUT" "$RUNTIME" "$OUTPUT"
fi
fi
@ -263,7 +278,7 @@ if [ "$RECORD" == 1 ]; then
+([0-9])) record "$FILE" "$TIME" ;;
esac
else
printf "No such session on output %d\n" "$OUTPUT"
printf "No such session on output %s\n" "$OUTPUT"
fi
fi
@ -272,6 +287,6 @@ if [ "$END" == 1 ]; then
kill "$(<"$RUNTIME"/"$OUTPUT"_host.pid)"
rm -f "$RUNTIME"/"$OUTPUT"_host.pid
else
printf "No such session on output %d\n" "$OUTPUT"
printf "No such session on output %s\n" "$OUTPUT"
fi
fi

View File

@ -54,23 +54,15 @@ trap 'if command -v tput &>/dev/null; then tput rmcup; fi' EXIT
get_output() {
RANDR="$(wlr-randr)"
i=0
while read -r line; do
if [[ "$line" =~ - ]]; then
((i++))
fi
done <<< "$RANDR"
OUTPUT="$(eval "dialog $TITLE --menu 'Output:' 24 64 24 $(while read -r line; do
if [[ "$line" =~ - ]]; then
tmp="${line#*(}"
tmp="${tmp%)*}"
printf "$i '(%s) \t" "$tmp"
printf "'%s' \t" "$tmp"
tmp=${line#*\"}
tmp="${tmp% (*}"
printf "%s' " "$tmp"
((i--))
printf "'%s' " "$tmp"
fi
done <<< "$RANDR") 3>&1 1>&2 2>&3")"
}