#!/bin/sh

device=znt0001:00-14e5:650e-touchpad
toggle_variable="device[${device}]:enabled"

hyprctl keyword "${toggle_variable}" true

status_file="$XDG_RUNTIME_DIR/touchpad.status"

enable_touchpad() {
  printf "true" > "${status_file}"

  hyprctl notify 1 2000 0 "Enabled touchpad"

  hyprctl keyword "${toggle_variable}" true
}

disable_touchpad() {
  printf "false" > "${status_file}"

  hyprctl notify 0 2000 0 "Disabled Touchpad"

  hyprctl keyword "${toggle_variable}" false
}

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
fi
