Skip to content

Instantly share code, notes, and snippets.

@izelnakri
Last active November 16, 2024 22:48
Show Gist options
  • Save izelnakri/50c4b746ba47623ed6e88f0eda1c62b0 to your computer and use it in GitHub Desktop.
Save izelnakri/50c4b746ba47623ed6e88f0eda1c62b0 to your computer and use it in GitHub Desktop.
How to share laptop keyboard and trackpad with the VR headset
#!/bin/bash
DEVICE_IDENTIFIER="adb-RFCW7028MXJ-JZpS3e" # Phone
# DEVICE_IDENTIFIER="adb-2G0YC5ZG2001JS" # VR headset
FALLBACK_HOSTNAME="Android.local"
FOUND_DEVICE=$(avahi-browse --all --resolve --terminate -p | grep 'IPv4' | grep "$DEVICE_IDENTIFIER" | grep '=;')
echo "DEVICE IS:"
echo $FOUND_DEVICE
if [[ -n "$FOUND_DEVICE" ]]; then
FOUND_IP=$(echo "$FOUND_DEVICE" | awk -F ';' '{print $8}')
FOUND_PORT=$(echo "$FOUND_DEVICE" | awk -F ';' '{print $9}')
echo "Device found: $DEVICE_IDENTIFIER at IP $FOUND_IP and Port $FOUND_PORT."
else
echo "Warning: Device identifier '$DEVICE_IDENTIFIER' not found. Trying fallback hostname $FALLBACK_HOSTNAME."
FOUND_DEVICE=$(avahi-browse --all --ignore-local --resolve --terminate -p | grep 'IPv4' | grep "$FALLBACK_HOSTNAME" | grep '=;')
FOUND_IP=$(echo "$FOUND_DEVICE" | awk -F ';' '{print $8}')
FOUND_PORT=5555
if [[ -z "$FOUND_IP" ]]; then
echo "Error: Could not resolve IP for fallback hostname '$FALLBACK_HOSTNAME'. Exiting."
exit 1
else
echo "Using fallback IP $FOUND_IP and port $FOUND_PORT."
fi
fi
echo "Connecting to $FOUND_IP:$FOUND_PORT via adb..."
adb connect "$FOUND_IP:$FOUND_PORT"
if [[ $? -ne 0 ]]; then
echo "Error: adb connection to $FOUND_IP:$FOUND_PORT failed. Exiting."
exit 1
fi
echo "Starting scrcpy..."
pkill -f scrcpy
NEW_WORKSPACE=99
hyprctl dispatch exec \[workspace $NEW_WORKSPACE\] -- scrcpy -KM --fullscreen --no-video --tcpip="$FOUND_IP:$FOUND_PORT"
echo "Moved scrcpy to workspace $NEW_WORKSPACE and set to fullscreen."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment