diff options
Diffstat (limited to 'config/hypr/scripts/TouchPad.sh')
| -rwxr-xr-x | config/hypr/scripts/TouchPad.sh | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/config/hypr/scripts/TouchPad.sh b/config/hypr/scripts/TouchPad.sh index 030c36de..f14165a0 100755 --- a/config/hypr/scripts/TouchPad.sh +++ b/config/hypr/scripts/TouchPad.sh @@ -5,28 +5,50 @@ # use hyprctl devices to get your system touchpad device name # source https://github.com/hyprwm/Hyprland/discussions/4283?sort=new#discussioncomment-8648109 +set -euo pipefail + notif="$HOME/.config/swaync/images/ja.png" +laptops_conf="$HOME/.config/hypr/UserConfigs/Laptops.conf" + +touchpad_device="${TOUCHPAD_DEVICE:-}" +if [[ -z "$touchpad_device" && -f "$laptops_conf" ]]; then + touchpad_device="$( + awk -F= '/^\$Touchpad_Device/ { + gsub(/[[:space:]]*/, "", $1); + gsub(/^[[:space:]]+|[[:space:]]+$/, "", $2); + print $2; + exit + }' "$laptops_conf" + )" +fi + +if [[ -z "$touchpad_device" ]]; then + notify-send -u low -i "$notif" " Touchpad" " Device name not set (check Laptops.conf)" + exit 1 +fi -export STATUS_FILE="$XDG_RUNTIME_DIR/touchpad.status" +touchpad_keyword="${TOUCHPAD_KEYWORD:-device:${touchpad_device}:enabled}" +status_file="${XDG_RUNTIME_DIR:-/tmp}/touchpad.status" enable_touchpad() { - printf "true" >"$STATUS_FILE" - notify-send -u low -i $notif " Enabling" " touchpad" - hyprctl keyword '$TOUCHPAD_ENABLED' "true" -r + printf "true" >"$status_file" + notify-send -u low -i "$notif" " Enabling" " touchpad" + hyprctl keyword "$touchpad_keyword" true -r } disable_touchpad() { - printf "false" >"$STATUS_FILE" - notify-send -u low -i $notif " Disabling" " touchpad" - hyprctl keyword '$TOUCHPAD_ENABLED' "false" -r + printf "false" >"$status_file" + notify-send -u low -i "$notif" " Disabling" " touchpad" + hyprctl keyword "$touchpad_keyword" false -r } -if ! [ -f "$STATUS_FILE" ]; then - enable_touchpad -else - if [ $(cat "$STATUS_FILE") = "true" ]; then +current_state="false" +if [[ -f "$status_file" ]]; then + current_state="$(<"$status_file")" +fi + +if [[ "$current_state" == "true" ]]; then disable_touchpad - elif [ $(cat "$STATUS_FILE") = "false" ]; then +else enable_touchpad - fi fi |
