Fix: Toggle touchpad via hyprctl eval and detect the device automatically
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -151,9 +151,6 @@ hl.bind(mainMod .. " + mouse:273", hl.dsp.window.resize(), { mouse = true }) --
|
||||
-- Laptop specific keybinds
|
||||
--------------------------------------------------------------------------------------
|
||||
|
||||
-- for disabling Touchpad. hyprctl devices to get device name.
|
||||
local touchpadDevice = "asue1209:00-04f3:319f-touchpad"
|
||||
|
||||
hl.bind("XF86KbdBrightnessDown", hl.dsp.exec_cmd(scriptsDir .. "/BrightnessKbd.sh --dec"), { repeating = true }) -- decrease keyboard brightness
|
||||
hl.bind("XF86KbdBrightnessUp", hl.dsp.exec_cmd(scriptsDir .. "/BrightnessKbd.sh --inc"), { repeating = true }) -- increase keyboard brightness
|
||||
hl.bind("XF86Launch1", hl.dsp.exec_cmd("rog-control-center")) -- ASUS Armory crate button
|
||||
@@ -161,7 +158,7 @@ hl.bind("XF86Launch3", hl.dsp.exec_cmd("asusctl led-mode -n")) -- FN+F4 Switch k
|
||||
hl.bind("XF86Launch4", hl.dsp.exec_cmd("asusctl profile -n")) -- FN+F5 change of fan profiles (Quiet, Balance, Performance)
|
||||
hl.bind("XF86MonBrightnessDown", hl.dsp.exec_cmd(scriptsDir .. "/Brightness.sh --dec"), { repeating = true }) -- decrease monitor brightness
|
||||
hl.bind("XF86MonBrightnessUp", hl.dsp.exec_cmd(scriptsDir .. "/Brightness.sh --inc"), { repeating = true }) -- increase monitor brightness
|
||||
hl.bind("XF86TouchpadToggle", hl.dsp.exec_cmd(scriptsDir .. "/TouchPad.sh")) -- disable touchpad
|
||||
hl.bind("XF86TouchpadToggle", hl.dsp.exec_cmd(scriptsDir .. "/TouchPad.sh")) -- toggle touchpad (finds the device itself)
|
||||
|
||||
-- Screenshot keybindings using F6 (no PrintSrc button)
|
||||
-- hl.bind(mainMod .. " + F6", hl.dsp.exec_cmd(scriptsDir .. "/ScreenShot.sh --now")) -- screenshot
|
||||
@@ -169,8 +166,3 @@ hl.bind("XF86TouchpadToggle", hl.dsp.exec_cmd(scriptsDir .. "/TouchPad.sh")) --
|
||||
-- hl.bind(mainMod .. " + CTRL + F6", hl.dsp.exec_cmd(scriptsDir .. "/ScreenShot.sh --in5")) -- screenshot (5 secs delay)
|
||||
-- hl.bind(mainMod .. " + ALT + F6", hl.dsp.exec_cmd(scriptsDir .. "/ScreenShot.sh --in10")) -- screenshot (10 secs delay)
|
||||
-- hl.bind("ALT + F6", hl.dsp.exec_cmd(scriptsDir .. "/ScreenShot.sh --active")) -- screenshot (active window only)
|
||||
|
||||
hl.device({
|
||||
name = touchpadDevice,
|
||||
enabled = true,
|
||||
})
|
||||
|
||||
@@ -1,32 +1,30 @@
|
||||
#!/bin/bash
|
||||
# HyprFlux — https://github.com/ahmad9059/HyprFlux
|
||||
# For disabling touchpad.
|
||||
# Edit the Touchpad_Device on ~/.config/hypr/UserConfigs/Laptops.conf according to your system
|
||||
# use hyprctl devices to get your system touchpad device name
|
||||
# source https://github.com/hyprwm/Hyprland/discussions/4283?sort=new#discussioncomment-8648109
|
||||
# Toggles the laptop touchpad (XF86TouchpadToggle).
|
||||
# Finds the touchpad by name in `hyprctl devices`, so it works on any laptop
|
||||
# without hard-coding the device. The Lua config rejects `hyprctl keyword`,
|
||||
# so the device is switched with hl.device() through `hyprctl eval`.
|
||||
|
||||
notif="$HOME/.config/swaync/images/ja.png"
|
||||
notif="$HOME/.config/swaync/images/note.png"
|
||||
STATUS_FILE="$XDG_RUNTIME_DIR/touchpad.status"
|
||||
|
||||
export STATUS_FILE="$XDG_RUNTIME_DIR/touchpad.status"
|
||||
device=$(hyprctl devices -j | jq -r '[.mice[].name | select(test("touchpad"; "i"))][0] // empty')
|
||||
if [ -z "$device" ]; then
|
||||
notify-send -u low -i "$notif" "Touchpad" "No touchpad found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
enable_touchpad() {
|
||||
printf "true" >"$STATUS_FILE"
|
||||
notify-send -u low -i $notif " Enabling" " touchpad"
|
||||
hyprctl keyword '$TOUCHPAD_ENABLED' "true" -r
|
||||
}
|
||||
|
||||
disable_touchpad() {
|
||||
printf "false" >"$STATUS_FILE"
|
||||
notify-send -u low -i $notif " Disabling" " touchpad"
|
||||
hyprctl keyword '$TOUCHPAD_ENABLED' "false" -r
|
||||
}
|
||||
|
||||
if ! [ -f "$STATUS_FILE" ]; then
|
||||
enable_touchpad
|
||||
set_touchpad() {
|
||||
printf '%s' "$1" >"$STATUS_FILE"
|
||||
hyprctl eval "hl.device({ name = \"$device\", enabled = $1 })" >/dev/null
|
||||
if [ "$1" = true ]; then
|
||||
notify-send -u low -i "$notif" " Enabling" " touchpad"
|
||||
else
|
||||
if [ $(cat "$STATUS_FILE") = "true" ]; then
|
||||
disable_touchpad
|
||||
elif [ $(cat "$STATUS_FILE") = "false" ]; then
|
||||
enable_touchpad
|
||||
notify-send -u low -i "$notif" " Disabling" " touchpad"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$(cat "$STATUS_FILE" 2>/dev/null)" = "false" ]; then
|
||||
set_touchpad true
|
||||
else
|
||||
set_touchpad false
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user