Skip to content

Instantly share code, notes, and snippets.

@sleeyax
Created March 9, 2026 00:10
Show Gist options
  • Select an option

  • Save sleeyax/1fb2368df75eae0e6240f0dbb1e997a0 to your computer and use it in GitHub Desktop.

Select an option

Save sleeyax/1fb2368df75eae0e6240f0dbb1e997a0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Create/destroy a temporary 1920x1200 (landscape mode) virtual monitor with VNC for tablet use
ACTION="${1:-start}"
PORT="${2:-5900}"
case "$ACTION" in
start)
hyprctl output create headless
MONITOR=$(hyprctl monitors -j | jq -r '.[] | select(.name | startswith("HEADLESS-")) | .name' | tail -1)
if [[ -z "$MONITOR" ]]; then
echo "Failed to create virtual monitor"
exit 1
fi
hyprctl keyword monitor "$MONITOR,1920x1200@60,auto,1.5"
echo "Created virtual monitor: $MONITOR"
# sleep 1
wayvnc -o "$MONITOR" 0.0.0.0 "$PORT" &
WAYVNC_PID=$!
echo "$WAYVNC_PID" > /tmp/tablet-wayvnc.pid
echo "wayvnc running on port $PORT (pid $WAYVNC_PID)"
echo "Connect from tablet with a VNC client to $(ip -4 -o addr show | awk '!/127.0.0.1/ {print $4}' | cut -d/ -f1 | head -1):$PORT"
echo "Run '$0 stop' to tear down"
;;
stop)
if [[ -f /tmp/tablet-wayvnc.pid ]]; then
kill "$(cat /tmp/tablet-wayvnc.pid)" 2>/dev/null
rm /tmp/tablet-wayvnc.pid
echo "Stopped wayvnc"
fi
MONITOR=$(hyprctl monitors -j | jq -r '.[] | select(.name | startswith("HEADLESS-")) | .name' | tail -1)
if [[ -z "$MONITOR" ]]; then
echo "No virtual monitor found"
exit 0
fi
hyprctl output remove "$MONITOR"
echo "Removed virtual monitor: $MONITOR"
;;
*)
echo "Usage: $0 {start|stop} [port]"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment