Auto-select VAAPI device if only one is available
Some checks failed
Bump build.func Revision / bump-revision (push) Has been cancelled

Improves the vaapi_select_and_apply function to automatically select the VAAPI device when only one is detected, bypassing the whiptail selection dialog. This streamlines the user experience by reducing unnecessary prompts.
This commit is contained in:
CanbiZ 2025-09-22 14:48:40 +02:00
parent dc45da17fe
commit 176f86de5d

View File

@ -166,26 +166,34 @@ vaapi_select_and_apply() {
return return
} }
local items=() maxlen=0 # only one device -> auto-select
for p in "${pairs[@]}"; do
local devs="${p%%$'\t'*}" label="${p#*$'\t'}"
items+=("$devs" "$label" "OFF")
((${#label} > maxlen)) && maxlen=${#label}
done
read -r h w < <(_whiptail_dims $((${#items[@]} / 3)) "$maxlen")
local SELECTED local SELECTED
SELECTED="$(whiptail --title "VAAPI Device Selection" \ if [[ ${#pairs[@]} -eq 1 ]]; then
--checklist "Select VAAPI devices for CT $CTID:" "$h" "$w" 6 \ SELECTED="${pairs[0]%%$'\t'*}"
"${items[@]}" 3>&1 1>&2 2>&3)" || { msg_info "Auto-selecting VAAPI device: ${pairs[0]#*$'\t'}"
msg_warn "VAAPI selection cancelled." else
return # more than one device -> show whiptail
} local items=() maxlen=0
[[ -z "$SELECTED" ]] && { for p in "${pairs[@]}"; do
msg_warn "No VAAPI devices selected." local devs="${p%%$'\t'*}" label="${p#*$'\t'}"
return items+=("$devs" "$label" "OFF")
} ((${#label} > maxlen)) && maxlen=${#label}
done
read -r h w < <(_whiptail_dims $((${#items[@]} / 3)) "$maxlen")
SELECTED="$(whiptail --title "VAAPI Device Selection" \
--checklist "Select VAAPI devices for CT $CTID:" "$h" "$w" 6 \
"${items[@]}" 3>&1 1>&2 2>&3)" || {
msg_warn "VAAPI selection cancelled."
return
}
[[ -z "$SELECTED" ]] && {
msg_warn "No VAAPI devices selected."
return
}
fi
# Apply selection to LXC config
local DID_MOUNT_DRI=0 idx=0 local DID_MOUNT_DRI=0 idx=0
for dev in $SELECTED; do for dev in $SELECTED; do
dev="${dev%\"}" dev="${dev%\"}"
@ -209,6 +217,8 @@ vaapi_select_and_apply() {
fi fi
done done
done done
# Fallback only for privileged CTs
[[ "$CTTYPE" == "0" ]] && cat <<'EOF' >>"$LXC_CONFIG" [[ "$CTTYPE" == "0" ]] && cat <<'EOF' >>"$LXC_CONFIG"
# VAAPI fallback # VAAPI fallback
lxc.mount.entry: /dev/dri /dev/dri none bind,optional,create=dir lxc.mount.entry: /dev/dri /dev/dri none bind,optional,create=dir