diff --git a/dotfiles/.config/hypr/input/keybinds.lua b/dotfiles/.config/hypr/input/keybinds.lua index 8a9db38..bb5f0dc 100644 --- a/dotfiles/.config/hypr/input/keybinds.lua +++ b/dotfiles/.config/hypr/input/keybinds.lua @@ -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, -}) diff --git a/dotfiles/.config/hypr/scripts/TouchPad.sh b/dotfiles/.config/hypr/scripts/TouchPad.sh index 3c9415c..609a75a 100755 --- a/dotfiles/.config/hypr/scripts/TouchPad.sh +++ b/dotfiles/.config/hypr/scripts/TouchPad.sh @@ -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" - -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 -else - if [ $(cat "$STATUS_FILE") = "true" ]; then - disable_touchpad - elif [ $(cat "$STATUS_FILE") = "false" ]; then - enable_touchpad - fi +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 + +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 + 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