diff --git a/bin/omarchy-toggle-input-device b/bin/omarchy-toggle-input-device new file mode 100755 index 00000000..aea0ca11 --- /dev/null +++ b/bin/omarchy-toggle-input-device @@ -0,0 +1,50 @@ +#!/bin/bash + +# omarchy:summary=Enable, disable, or toggle a Hyprland input device +# omarchy:args= [on|off|toggle] +# omarchy:hidden=true + +KIND="${1:-}" +ACTION="${2:-toggle}" + +case "$KIND" in + touchpad) LABEL="Touchpad" ICON="touchpad" ;; + touchscreen) LABEL="Touchscreen" ICON="touch" ;; + *) + echo "Usage: omarchy-toggle-input-device [on|off|toggle]" >&2 + exit 1 + ;; +esac + +# Hyprland sources this directory on reload, so the disabled state survives restarts +STATE_FILE="$HOME/.local/state/omarchy/toggles/hypr/$KIND-disabled.lua" + +device="$("omarchy-hw-$KIND")" + +if [[ -z $device ]]; then + echo "No $KIND device found" >&2 + exit 1 +fi + +enable() { + hyprctl eval "hl.device({ name = \"$device\", enabled = true })" >/dev/null + rm -f "$STATE_FILE" + omarchy-osd -i "$ICON" -m "$LABEL enabled" +} + +disable() { + hyprctl eval "hl.device({ name = \"$device\", enabled = false })" >/dev/null + mkdir -p "$(dirname "$STATE_FILE")" + printf 'hl.device({ name = "%s", enabled = false })\n' "$device" >"$STATE_FILE" + omarchy-osd -i "$ICON" -m "$LABEL disabled" +} + +case "$ACTION" in + on) enable ;; + off) disable ;; + toggle) if [[ -f $STATE_FILE ]]; then enable; else disable; fi ;; + *) + echo "Usage: omarchy-toggle-input-device [on|off|toggle]" >&2 + exit 1 + ;; +esac diff --git a/bin/omarchy-toggle-touchpad b/bin/omarchy-toggle-touchpad index 3ab72616..f218efb8 100755 --- a/bin/omarchy-toggle-touchpad +++ b/bin/omarchy-toggle-touchpad @@ -3,30 +3,4 @@ # omarchy:summary=Enable, disable, or toggle the touchpad # omarchy:args=[on|off|toggle] -STATE_FILE="$HOME/.local/state/omarchy/toggles/hypr/touchpad-disabled.lua" - -device="$(omarchy-hw-touchpad)" - -if [[ -z $device ]]; then - echo "No touchpad device found" >&2 - exit 1 -fi - -enable() { - hyprctl eval "hl.device({ name = \"$device\", enabled = true })" >/dev/null - rm -f "$STATE_FILE" - omarchy-osd -i touchpad -m "Touchpad enabled" -} - -disable() { - hyprctl eval "hl.device({ name = \"$device\", enabled = false })" >/dev/null - mkdir -p "$(dirname "$STATE_FILE")" - printf 'hl.device({ name = "%s", enabled = false })\n' "$device" >"$STATE_FILE" - omarchy-osd -i touchpad -m "Touchpad disabled" -} - -case "${1:-toggle}" in - on) enable ;; - off) disable ;; - toggle) if [[ -f $STATE_FILE ]]; then enable; else disable; fi ;; -esac +exec omarchy-toggle-input-device touchpad "${1:-toggle}" diff --git a/bin/omarchy-toggle-touchscreen b/bin/omarchy-toggle-touchscreen index 45b1284f..320c9a3d 100755 --- a/bin/omarchy-toggle-touchscreen +++ b/bin/omarchy-toggle-touchscreen @@ -3,30 +3,4 @@ # omarchy:summary=Enable, disable, or toggle the touch functionality of the screen # omarchy:args=[on|off|toggle] -STATE_FILE="$HOME/.local/state/omarchy/toggles/hypr/touchscreen-disabled.lua" - -device="$(omarchy-hw-touchscreen)" - -if [[ -z $device ]]; then - echo "No touchscreen device found" >&2 - exit 1 -fi - -enable() { - hyprctl eval "hl.device({ name = \"$device\", enabled = true })" >/dev/null - rm -f "$STATE_FILE" - omarchy-osd -i touch -m "Touchscreen enabled" -} - -disable() { - hyprctl eval "hl.device({ name = \"$device\", enabled = false })" >/dev/null - mkdir -p "$(dirname "$STATE_FILE")" - printf 'hl.device({ name = "%s", enabled = false })\n' "$device" >"$STATE_FILE" - omarchy-osd -i touch -m "Touchscreen disabled" -} - -case "${1:-toggle}" in - on) enable ;; - off) disable ;; - toggle) if [[ -f $STATE_FILE ]]; then enable; else disable; fi ;; -esac +exec omarchy-toggle-input-device touchscreen "${1:-toggle}"