#!/usr/bin/env bash # Write a tuned ~/.config/sunshine/sunshine.conf for low-latency LAN streaming. # Only overwrites if (a) no config exists, or (b) our managed marker is present. SUNSHINE_CONF_DIR="$HOME/.config/sunshine" SUNSHINE_CONF="$SUNSHINE_CONF_DIR/sunshine.conf" MANAGED_MARKER="# managed-by: omarchy-moonlight" write_sunshine_config() { local mode="${1:-mirror}" mkdir -p "$SUNSHINE_CONF_DIR" if [[ -f "$SUNSHINE_CONF" ]] && ! grep -qF "$MANAGED_MARKER" "$SUNSHINE_CONF"; then ok "Existing sunshine.conf is user-managed — leaving it alone" info " To re-apply tuned defaults, delete $SUNSHINE_CONF and re-run install.sh" return 0 fi local encoder_block case "$GPU_VENDOR" in nvidia) encoder_block=$'encoder = nvenc\nnvenc_preset = p1\nnvenc_tune = ll\nnvenc_rc = cbr\nnvenc_coder = auto' ;; amd) encoder_block=$'encoder = vaapi\namd_quality = speed\namd_rc = cbr\namd_usage = ultralowlatency' ;; intel) encoder_block=$'encoder = quicksync\nqsv_preset = veryfast\nqsv_coder = auto' ;; *) encoder_block=$'# encoder auto-detected by Sunshine' ;; esac local capture_block case "$mode" in headless) # wlr capture of the Hyprland headless output that prep-cmd hooks create. # global_prep_cmd is parsed as a JSON array by Sunshine, so keep it on one line. capture_block="# Capture: wlr — captures a Hyprland headless output created on stream start. capture = wlr output_name = HEADLESS-1 # Hooks that create/resize HEADLESS-1 on stream start and remove it on stop. global_prep_cmd = [{\"do\":\"${DO_SCRIPT}\",\"undo\":\"${UNDO_SCRIPT}\"}]" ;; mirror|*) capture_block="# Capture: KMS (DRM) — the right choice on Wayland. capture = kms" ;; esac info "Writing tuned $SUNSHINE_CONF (GPU: $GPU_VENDOR, mode: $mode)" cat >"$SUNSHINE_CONF" <