2024-09-09 00:22:14 +00:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
2024-09-24 23:24:27 +00:00
|
|
|
# @describe Toggle device pawdedness
|
|
|
|
#
|
|
|
|
# https://github.com/sigoden/argc
|
2024-09-09 00:22:14 +00:00
|
|
|
|
2024-09-15 22:42:24 +00:00
|
|
|
# BUG: New hyprctl syntax does not support per-device getoption
|
|
|
|
# https://github.com/hyprwm/hyprlang/issues/43
|
2024-09-17 15:37:53 +00:00
|
|
|
# HACK: Condition based on file presence, requires execution at reload to set state
|
2024-09-24 23:24:27 +00:00
|
|
|
#?? exec = left --init <DEVICE>
|
2024-09-09 00:22:14 +00:00
|
|
|
|
2024-09-24 23:24:27 +00:00
|
|
|
# @arg device! Device name, obtained via hyprctl devices
|
|
|
|
# @option -f --file=`_default_file` Specify file for state
|
|
|
|
# @flag -i --init Enforce file-based state without switching
|
|
|
|
# @flag -s --scroll Also invert scroll direction
|
|
|
|
|
|
|
|
_default_file() {
|
|
|
|
echo "$HOME/.left"
|
|
|
|
}
|
|
|
|
|
|
|
|
eval "$(argc --argc-eval "$0" "$@")"
|
|
|
|
|
|
|
|
# Get initial state
|
|
|
|
if [[ -f "${argc_file:-}" ]]; then
|
2024-09-17 15:37:53 +00:00
|
|
|
left=1
|
2024-09-09 00:22:14 +00:00
|
|
|
else
|
2024-09-17 15:37:53 +00:00
|
|
|
left=0
|
|
|
|
fi
|
|
|
|
|
2024-09-24 23:24:27 +00:00
|
|
|
# If not initializing
|
|
|
|
if [[ ! "${argc_init:-}" ]]; then
|
|
|
|
left=$((1 - "$left")) # Toggle 0/1
|
2024-09-17 15:37:53 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Enforce state
|
|
|
|
if (("$left")); then
|
2024-09-24 23:24:27 +00:00
|
|
|
hyprctl keyword "device[${argc_device:-}]:left_handed" true
|
|
|
|
|
|
|
|
if [[ "${argc_scroll:-}" ]]; then
|
|
|
|
hyprctl keyword "device[${argc_device:-}]:natural_scroll" true
|
|
|
|
fi
|
|
|
|
|
|
|
|
touch "${argc_file:-}"
|
2024-09-25 00:54:15 +00:00
|
|
|
|
|
|
|
if [[ ! "${argc_init:-}" ]]; then
|
|
|
|
notify-send "> left" "Left-pawed" --urgency low
|
|
|
|
fi
|
2024-09-17 15:37:53 +00:00
|
|
|
else
|
2024-09-24 23:24:27 +00:00
|
|
|
hyprctl keyword "device[${argc_device:-}]:left_handed" false
|
|
|
|
|
|
|
|
if [[ "${argc_scroll:-}" ]]; then
|
|
|
|
hyprctl keyword "device[${argc_device:-}]:natural_scroll" false
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm --force "${argc_file:-}"
|
2024-09-25 00:54:15 +00:00
|
|
|
|
|
|
|
if [[ ! "${argc_init:-}" ]]; then
|
|
|
|
notify-send "> left" "Right-pawed" --urgency low
|
|
|
|
fi
|
2024-09-09 00:22:14 +00:00
|
|
|
fi
|