hyprland-alt-toggle.nix (1808B)
1 { pkgs, ... }: 2 3 let 4 hyprland-alt-toggle = pkgs.writeShellScriptBin "hyprland-alt-toggle" '' 5 set -euo pipefail 6 7 STATE_FILE="''${XDG_RUNTIME_DIR:-/tmp}/hyprland-alt-toggle.state" 8 9 DRAG_KEYS="ALT + mouse:272" 10 RESIZE_KEYS="ALT + mouse:273" 11 12 hl_eval() { 13 # Runs a Lua expression via hyprctl eval and surfaces errors. 14 local expr="$1" 15 local out 16 if ! out="$(hyprctl eval "$expr" 2>&1)"; then 17 echo "Error running: $expr" >&2 18 echo "$out" >&2 19 exit 1 20 fi 21 if [[ "$out" != "ok" ]]; then 22 echo "Warning: unexpected response for: $expr" >&2 23 echo "$out" >&2 24 fi 25 } 26 27 do_unbind() { 28 echo "Unbinding $DRAG_KEYS (drag) and $RESIZE_KEYS (resize)..." 29 hl_eval "hl.unbind('$DRAG_KEYS')" 30 hl_eval "hl.unbind('$RESIZE_KEYS')" 31 touch "$STATE_FILE" 32 echo "Done. Alt+Click is now free for other apps." 33 } 34 35 do_rebind() { 36 echo "Rebinding $DRAG_KEYS to window.drag and $RESIZE_KEYS to window.resize..." 37 hl_eval "hl.bind('$DRAG_KEYS', hl.dsp.window.drag(), { mouse = true })" 38 hl_eval "hl.bind('$RESIZE_KEYS', hl.dsp.window.resize(), { mouse = true })" 39 rm -f "$STATE_FILE" 40 echo "Done. Hyprland's Alt+Click window drag/resize is restored." 41 } 42 43 case "''${1:-toggle}" in 44 unbind) 45 do_unbind 46 ;; 47 rebind) 48 do_rebind 49 ;; 50 toggle) 51 if [[ -f "$STATE_FILE" ]]; then 52 do_rebind 53 else 54 do_unbind 55 fi 56 ;; 57 *) 58 echo "Usage: $0 [unbind|rebind|toggle]" >&2 59 exit 1 60 ;; 61 esac 62 ''; 63 in 64 { 65 environment.systemPackages = [ hyprland-alt-toggle ]; 66 }