#!/usr/bin/env bash # Detect GPU vendor, session type, hostname, compositor. detect_gpu_vendor() { local vga vga="$(lspci -nn 2>/dev/null | grep -iE 'vga|3d|display' || true)" # Prefer the first discrete/dedicated entry — VM hosts often expose a # placeholder BOCHS/QEMU VGA device before the real GPU. local nvidia_line amd_line intel_line nvidia_line="$(grep -i 'nvidia' <<<"$vga" | head -n1)" amd_line="$(grep -iE 'amd|advanced micro devices|ati' <<<"$vga" | head -n1)" intel_line="$(grep -i 'intel' <<<"$vga" | head -n1)" if [[ -n "$nvidia_line" ]]; then echo "nvidia" elif [[ -n "$amd_line" ]]; then echo "amd" elif [[ -n "$intel_line" ]]; then echo "intel" else echo "unknown" fi } # Decide which wlroots-based compositor to drive for headless capture. # Returns one of: # hyprland - hyprctl available (preferred when present, matches existing hooks) # sway - sway/swaymsg available # none - neither installed yet (install_headless_compositor will fix this) detect_compositor() { if command -v hyprctl >/dev/null 2>&1; then echo "hyprland" elif command -v swaymsg >/dev/null 2>&1 || command -v sway >/dev/null 2>&1; then echo "sway" else echo "none" fi } detect_all() { HOSTNAME_SHORT="$(hostname -s 2>/dev/null || hostname)" GPU_VENDOR="$(detect_gpu_vendor)" SESSION_TYPE="${XDG_SESSION_TYPE:-unknown}" COMPOSITOR="$(detect_compositor)" export HOSTNAME_SHORT GPU_VENDOR SESSION_TYPE COMPOSITOR if [[ "$SESSION_TYPE" != "wayland" ]]; then warn "Session type is '$SESSION_TYPE' (not wayland). KMS capture still works at the TTY/DRM level, but Hyprland-specific paths assume Wayland." fi if [[ "$GPU_VENDOR" == "unknown" ]]; then warn "Could not detect GPU vendor. Encoder packages will be skipped; HW encode may not work." fi }