Files
omarchycn/bin/omarchy-toggle-touchpad
T
DrunkLeenandGitHub d00b3ea24b feat: Add Touchpad toggle/on/off support (#5353)
* feat: add touchpad toggle keybinding and script

Binds XF86TouchpadToggle/On/Off to a new leenium-toggle-touchpad script
that enables/disables the touchpad via hyprctl and shows OSD feedback.

* fix: make XF86TouchpadOn/Off enforce state instead of toggling

Add on/off/toggle argument support to omarchy-toggle-touchpad.
XF86TouchpadOn now always enables and XF86TouchpadOff always disables,
so firmware that emits separate On/Off keysyms behaves correctly regardless
of current state. XF86TouchpadToggle retains the invert behavior.

* feat: add touchpad toggle to menu and persist state as hyprland config

- Show touchpad option in toggle menu only when a touchpad/trackpad device is detected
- Replace /tmp state file with a persistent hyprland device config at
~/.local/state/omarchy/toggles/hypr/touchpad-disabled.conf

* fix: avoid unsafe && || toggle logic for Touchpad state

Replace `[[ -f $STATE_CONF ]] && enable || disable` with an explicit if/else.
The previous logic was not a true ternary: if `enable` failed (e.g. OSD command error),
`disable` would run unintentionally, causing unreliable toggle behavior.
2026-04-22 12:59:43 +02:00

43 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
STATE_CONF="$HOME/.local/state/omarchy/toggles/hypr/touchpad-disabled.conf"
osdclient="swayosd-client --monitor $(omarchy-hyprland-monitor-focused)"
device="$(hyprctl devices -j | jq -r '[.mice[] | .name | select(test("touchpad|trackpad"; "i"))] | first // empty')"
if [[ -z $device ]]; then
echo "No touchpad device found" >&2
exit 1
fi
enable() {
hyprctl keyword "device[$device]:enabled" true >/dev/null
rm -f "$STATE_CONF"
$osdclient --custom-icon input-touchpad-symbolic --custom-message "Enabled"
}
disable() {
hyprctl keyword "device[$device]:enabled" false >/dev/null
mkdir -p "$(dirname "$STATE_CONF")"
printf 'device {\n name = %s\n enabled = false\n}\n' "$device" > "$STATE_CONF"
$osdclient --custom-icon touchpad-disabled-symbolic --custom-message "Disabled"
}
case "${1:-toggle}" in
on) enable ;;
off) disable ;;
toggle)
if [[ -f $STATE_CONF ]]; then
enable || {
echo "enable failed" >&2
exit 1
}
else
disable || {
echo "disable failed" >&2
exit 1
}
fi
;;
esac