From d5da519c9be2594de3c781f80441bdb26d85805c Mon Sep 17 00:00:00 2001 From: The_miro Date: Thu, 30 Jul 2026 20:15:37 +0200 Subject: [PATCH] fix(hyprlua): fix the touchpad toggle keybind MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../scripts/hyprland-toggle-touchpad.sh | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/desktopenvs/hyprlua/scripts/hyprland-toggle-touchpad.sh b/desktopenvs/hyprlua/scripts/hyprland-toggle-touchpad.sh index cb673bd..b01a6eb 100755 --- a/desktopenvs/hyprlua/scripts/hyprland-toggle-touchpad.sh +++ b/desktopenvs/hyprlua/scripts/hyprland-toggle-touchpad.sh @@ -2,30 +2,47 @@ # State file lives in the user's runtime dir (tmpfs, cleared on logout). # 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" notify-send -u normal "Enabling Touchpad" - # `hyprctl keyword` changes a live config value over IPC without reloading. - # The device name in square brackets scopes the change to that input device only. - hyprctl keyword 'device[synaptics-tm3053-009]:enabled' "true" + # hyprlua's 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."). 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" 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 ! [ -f "$STATUS_FILE" ]; then - enable_keyboard + enable_touchpad else # Toggle based on the persisted state: true → disable, false → enable. - if [ $(cat "$STATUS_FILE") = "true" ]; then - disable_keyboard - elif [ $(cat "$STATUS_FILE") = "false" ]; then - enable_keyboard + if [ "$(cat "$STATUS_FILE")" = "true" ]; then + disable_touchpad + elif [ "$(cat "$STATUS_FILE")" = "false" ]; then + enable_touchpad fi fi