fix(hyprlua): fix the touchpad toggle keybind

Two independent bugs, both silent no-ops:

1. hyprlua's hyprland.lua config is Lua-generated, not the classic hyprlang
   parser, so `hyprctl keyword device[...]:enabled ...` fails outright
   ("keyword can't work with non-legacy parsers. Use eval."). Switched to
   `hyprctl eval "hl.device({name=..., enabled=...})"`, the Lua API's
   live-reachable equivalent — same hl.* eval bridge eww's workspace
   switching already uses, and the same hl.device() block hyprland.lua
   itself uses at config-load time for per-device overrides.

2. The device name was hardcoded to a previous machine's touchpad
   ("synaptics-tm3053-009"), so even a working keyword/eval call would
   silently match nothing on this Framework 12's
   "pixa3854:...-touchpad". Resolve it dynamically from `hyprctl devices -j`
   instead.

Also renamed the copy-pasted enable_keyboard/disable_keyboard functions and
keyboard.status state file to match what this script actually toggles.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
main
Amir Alexander Abdelbaki 2026-07-30 20:15:37 +02:00
parent fc929d4747
commit d5da519c9b
1 changed files with 29 additions and 12 deletions

View File

@ -2,30 +2,47 @@
# State file lives in the user's runtime dir (tmpfs, cleared on logout). # State file lives in the user's runtime dir (tmpfs, cleared on logout).
# Using XDG_RUNTIME_DIR avoids /tmp collisions on multi-user systems. # Using XDG_RUNTIME_DIR avoids /tmp collisions on multi-user systems.
export STATUS_FILE="$XDG_RUNTIME_DIR/keyboard.status" export STATUS_FILE="$XDG_RUNTIME_DIR/touchpad.status"
enable_keyboard() { # Resolve the touchpad's libinput device name dynamically. A previous version
# of this script hardcoded one machine's name ("synaptics-tm3053-009") —
# `hyprctl keyword device[...]:enabled` silently no-ops when the selector
# matches no device, so on any other touchpad (e.g. this Framework 12's
# "pixa3854:...-touchpad") the toggle just did nothing. `mice` entries carry
# no explicit "type: touchpad" field, but libinput's generated name reliably
# includes "touchpad" as a substring.
TOUCHPAD_NAME="$(hyprctl devices -j | jq -r '.mice[] | select(.name | test("touchpad"; "i")) | .name' | head -n1)"
if [[ -z "$TOUCHPAD_NAME" ]]; then
notify-send -u critical "Touchpad toggle" "No touchpad device found"
exit 1
fi
enable_touchpad() {
printf "true" >"$STATUS_FILE" printf "true" >"$STATUS_FILE"
notify-send -u normal "Enabling Touchpad" notify-send -u normal "Enabling Touchpad"
# `hyprctl keyword` changes a live config value over IPC without reloading. # hyprlua's config is Lua-generated, not the classic hyprlang parser, so
# The device name in square brackets scopes the change to that input device only. # `hyprctl keyword device[...]:enabled ...` fails outright ("keyword can't
hyprctl keyword 'device[synaptics-tm3053-009]:enabled' "true" # work with non-legacy parsers. Use eval."). hl.device({...}) is the Lua
# API's live-reachable equivalent (same hl.* eval bridge eww's workspace
# switching uses) — see hypr/hyprland.lua's own hl.device() block.
hyprctl eval "hl.device({name='$TOUCHPAD_NAME', enabled=true})"
} }
disable_keyboard() { disable_touchpad() {
printf "false" >"$STATUS_FILE" printf "false" >"$STATUS_FILE"
notify-send -u normal "Disabling Touchpad" notify-send -u normal "Disabling Touchpad"
hyprctl keyword 'device[synaptics-tm3053-009]:enabled' "false" hyprctl eval "hl.device({name='$TOUCHPAD_NAME', enabled=false})"
} }
# If no status file exists yet, treat as "enabled" (first run after login). # If no status file exists yet, treat as "enabled" (first run after login).
if ! [ -f "$STATUS_FILE" ]; then if ! [ -f "$STATUS_FILE" ]; then
enable_keyboard enable_touchpad
else else
# Toggle based on the persisted state: true → disable, false → enable. # Toggle based on the persisted state: true → disable, false → enable.
if [ $(cat "$STATUS_FILE") = "true" ]; then if [ "$(cat "$STATUS_FILE")" = "true" ]; then
disable_keyboard disable_touchpad
elif [ $(cat "$STATUS_FILE") = "false" ]; then elif [ "$(cat "$STATUS_FILE")" = "false" ]; then
enable_keyboard enable_touchpad
fi fi
fi fi