Bash · 1578 bytes Raw Blame History
1 #!/bin/bash
2 # HyprKVM Move Handler
3 #
4 # This script intercepts workspace movement keybindings and routes them
5 # through HyprKVM to enable cross-machine navigation.
6 #
7 # Usage: hyprkvm-move.sh <direction>
8 # Directions: left, right, up, down
9 #
10 # Install in hyprland.conf:
11 # bind = SUPER, Left, exec, ~/.config/hypr/scripts/hyprkvm-move.sh left
12 # bind = SUPER, Right, exec, ~/.config/hypr/scripts/hyprkvm-move.sh right
13 # bind = SUPER, Up, exec, ~/.config/hypr/scripts/hyprkvm-move.sh up
14 # bind = SUPER, Down, exec, ~/.config/hypr/scripts/hyprkvm-move.sh down
15
16 set -e
17
18 DIRECTION="${1:-}"
19 SOCKET_PATH="${XDG_RUNTIME_DIR:-/tmp}/hyprkvm.sock"
20
21 if [[ -z "$DIRECTION" ]]; then
22 echo "Usage: $0 <left|right|up|down>" >&2
23 exit 1
24 fi
25
26 # Validate direction
27 case "$DIRECTION" in
28 left|right|up|down|l|r|u|d)
29 ;;
30 *)
31 echo "Invalid direction: $DIRECTION" >&2
32 echo "Valid: left, right, up, down" >&2
33 exit 1
34 ;;
35 esac
36
37 # Check if HyprKVM daemon is running
38 if [[ -S "$SOCKET_PATH" ]]; then
39 # Daemon is running - send move request
40 # The daemon will decide whether to do a local move or network switch
41 if command -v hyprkvm &>/dev/null; then
42 hyprkvm move "$DIRECTION"
43 else
44 # Fallback: try to send via socket directly
45 echo "{\"command\":\"move\",\"direction\":\"$DIRECTION\"}" | \
46 nc -U -N "$SOCKET_PATH" 2>/dev/null || \
47 hyprctl dispatch movefocus "$DIRECTION"
48 fi
49 else
50 # Daemon not running - fall back to native hyprctl
51 hyprctl dispatch movefocus "$DIRECTION"
52 fi