aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/hyprland/.local
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-20 21:55:13 -0400
committerCraig Jennings <c@cjennings.net>2026-05-20 21:55:13 -0400
commit8bb842ca37c348b3fb885c6d0f83d7e284800955 (patch)
tree1e19795b9adced6f1fb962b86ef99722a9e44b2a /dotfiles/hyprland/.local
parent8eede6d7f9decc27bf77ab51a4f24f479b2434ee (diff)
downloadarchsetup-8bb842ca37c348b3fb885c6d0f83d7e284800955.tar.gz
archsetup-8bb842ca37c348b3fb885c6d0f83d7e284800955.zip
feat(hyprland): add touchpad state indicator to waybar
The $mod+F9 toggle and the toggle-touchpad / touchpad-auto scripts already worked, but the scripts lived only in ~/.local/bin and were never committed, and there was no way to see the touchpad's state at a glance. I committed both scripts into the repo so stow installs them, and added a waybar indicator: a waybar-touchpad status script and a custom/touchpad module that shows a mouse glyph when the touchpad is on and a mouse-off glyph (in the dupre orange) when it's off. The scripts signal the module with pkill -RTMIN+9 waybar after each state change, so the icon updates the moment the touchpad toggles. touchpad-auto now runs at login via exec-once. The waybar-touchpad script has unit tests under tests/waybar-touchpad/ covering the enabled, disabled, and missing-state-file cases.
Diffstat (limited to 'dotfiles/hyprland/.local')
-rwxr-xr-xdotfiles/hyprland/.local/bin/toggle-touchpad25
-rwxr-xr-xdotfiles/hyprland/.local/bin/touchpad-auto53
-rwxr-xr-xdotfiles/hyprland/.local/bin/waybar-touchpad15
3 files changed, 93 insertions, 0 deletions
diff --git a/dotfiles/hyprland/.local/bin/toggle-touchpad b/dotfiles/hyprland/.local/bin/toggle-touchpad
new file mode 100755
index 0000000..cab605b
--- /dev/null
+++ b/dotfiles/hyprland/.local/bin/toggle-touchpad
@@ -0,0 +1,25 @@
+#!/bin/bash
+# Toggle the laptop touchpad on/off
+
+TOUCHPAD="pixa3854:00-093a:0274-touchpad"
+STATE_FILE="${XDG_RUNTIME_DIR:-/tmp}/touchpad-state"
+
+# Default to enabled if no state file
+if [ ! -f "$STATE_FILE" ]; then
+ echo "enabled" > "$STATE_FILE"
+fi
+
+state=$(cat "$STATE_FILE")
+
+if [ "$state" = "enabled" ]; then
+ hyprctl keyword "device[$TOUCHPAD]:enabled" false >/dev/null
+ echo "disabled" > "$STATE_FILE"
+ notify info "Touchpad" "Disabled"
+else
+ hyprctl keyword "device[$TOUCHPAD]:enabled" true >/dev/null
+ echo "enabled" > "$STATE_FILE"
+ notify info "Touchpad" "Enabled"
+fi
+
+# Refresh the waybar indicator immediately (custom/touchpad listens on signal 9).
+pkill -RTMIN+9 waybar 2>/dev/null
diff --git a/dotfiles/hyprland/.local/bin/touchpad-auto b/dotfiles/hyprland/.local/bin/touchpad-auto
new file mode 100755
index 0000000..830a8f2
--- /dev/null
+++ b/dotfiles/hyprland/.local/bin/touchpad-auto
@@ -0,0 +1,53 @@
+#!/bin/bash
+# Auto-disable touchpad when an external mouse is connected, re-enable when removed.
+# Watches Hyprland socket for device add/remove events.
+
+TOUCHPAD="pixa3854:00-093a:0274-touchpad"
+STATE_FILE="${XDG_RUNTIME_DIR:-/tmp}/touchpad-state"
+
+has_external_mouse() {
+ hyprctl devices -j | jq -e '[.mice[] | select(.name != "'"$TOUCHPAD"'" and .name != "pixa3854:00-093a:0274-mouse" and (.name | test("frmw") | not))] | length > 0' >/dev/null 2>&1
+}
+
+set_touchpad() {
+ hyprctl keyword "device[$TOUCHPAD]:enabled" "$1" >/dev/null
+ if [ "$1" = "true" ]; then
+ echo "enabled" > "$STATE_FILE"
+ else
+ echo "disabled" > "$STATE_FILE"
+ fi
+ # Refresh the waybar indicator (custom/touchpad listens on signal 9).
+ pkill -RTMIN+9 waybar 2>/dev/null
+}
+
+# Set initial state
+if has_external_mouse; then
+ set_touchpad false
+else
+ set_touchpad true
+fi
+
+# BT mice may auto-reconnect after boot — recheck after delay
+(sleep 10 && if has_external_mouse; then set_touchpad false; fi) &
+
+# Watch for device events
+socat -u "UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" - | while read -r line; do
+ case "$line" in
+ mouseadded\>\>*|mouseremoved\>\>*)
+ sleep 0.5
+ if has_external_mouse; then
+ set_touchpad false
+ else
+ set_touchpad true
+ fi
+ ;;
+ configreloaded\>\>*)
+ sleep 0.5
+ if has_external_mouse; then
+ set_touchpad false
+ else
+ set_touchpad true
+ fi
+ ;;
+ esac
+done
diff --git a/dotfiles/hyprland/.local/bin/waybar-touchpad b/dotfiles/hyprland/.local/bin/waybar-touchpad
new file mode 100755
index 0000000..d3adddd
--- /dev/null
+++ b/dotfiles/hyprland/.local/bin/waybar-touchpad
@@ -0,0 +1,15 @@
+#!/bin/sh
+# Touchpad on/off indicator for waybar.
+# Reads the state file that toggle-touchpad and touchpad-auto maintain; emits
+# one JSON line (text + tooltip + class) for the custom/touchpad module.
+# Anything other than "disabled" reads as enabled, so a missing or garbled
+# state file fails safe (pointer shown rather than hidden).
+
+STATE_FILE="${XDG_RUNTIME_DIR:-/tmp}/touchpad-state"
+state=$(cat "$STATE_FILE" 2>/dev/null || echo enabled)
+
+if [ "$state" = "disabled" ]; then
+ echo "{\"text\": \"<span size='large'>󰍾</span>\", \"tooltip\": \"Touchpad disabled\", \"class\": \"disabled\"}"
+else
+ echo "{\"text\": \"<span size='large'>󰍽</span>\", \"tooltip\": \"Touchpad enabled\", \"class\": \"enabled\"}"
+fi