From 5464089948d71a0f343fc8cc500d66232a5fccb1 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 24 Sep 2024 18:24:27 -0500 Subject: [PATCH] left: refactor with argc Signed-off-by: Myned --- options/custom/desktops/hyprland/binds.nix | 2 +- options/custom/desktops/hyprland/settings.nix | 2 +- options/custom/scripts/default.nix | 1 + options/custom/scripts/left.sh | 49 +++++++++++++------ 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/options/custom/desktops/hyprland/binds.nix b/options/custom/desktops/hyprland/binds.nix index 81ca73e..f47ca46 100644 --- a/options/custom/desktops/hyprland/binds.nix +++ b/options/custom/desktops/hyprland/binds.nix @@ -132,7 +132,7 @@ in { (key "Bracketright" "Super" "layoutmsg" "orientationnext") (key "Bracketright" "Super+Shift" "splitratio" "+0.1") (key "Delete" "Super" "exec" "${swayosd-client} --output-volume mute") - (key "Delete" "Super+Shift" "exec" "${left} kensington-orbit-wireless-tb-mouse") + (key "Delete" "Super+Shift" "exec" "${left} --scroll kensington-orbit-wireless-tb-mouse") (key "Down" "Super" "movewindow" "d") (key "Down" "Super+Shift" "movewindoworgroup" "d") (key "Equal" "Super" "exec" "${swayosd-client} --output-volume raise") diff --git a/options/custom/desktops/hyprland/settings.nix b/options/custom/desktops/hyprland/settings.nix index 712d4fc..e30ee1a 100644 --- a/options/custom/desktops/hyprland/settings.nix +++ b/options/custom/desktops/hyprland/settings.nix @@ -61,7 +61,7 @@ in { # https://wiki.hyprland.org/Configuring/Keywords/#executing exec = [ - left # Set left-pawed state + "${left} --init --scroll kensington-orbit-wireless-tb-mouse" # Enforce left-pawed state "${sleep} 5 && ${systemctl} --user restart walker" "${sleep} 5 && ${systemctl} --user restart waybar" ]; diff --git a/options/custom/scripts/default.nix b/options/custom/scripts/default.nix index 75ad8ef..675a715 100644 --- a/options/custom/scripts/default.nix +++ b/options/custom/scripts/default.nix @@ -92,6 +92,7 @@ in { systemd ]) (bash "left" [ + argc hyprland jq libnotify diff --git a/options/custom/scripts/left.sh b/options/custom/scripts/left.sh index 741a87f..6fe098a 100644 --- a/options/custom/scripts/left.sh +++ b/options/custom/scripts/left.sh @@ -1,35 +1,54 @@ #! /usr/bin/env bash -# Toggle left-pawed mouse -#?? left DEVICE +# @describe Toggle device pawdedness +# +# https://github.com/sigoden/argc # BUG: New hyprctl syntax does not support per-device getoption # https://github.com/hyprwm/hyprlang/issues/43 # HACK: Condition based on file presence, requires execution at reload to set state -#?? exec = left -FILE="$HOME/.left" +#?? exec = left --init -# Set initial state -if [[ -f "$FILE" ]]; then +# @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 left=1 else left=0 fi -# If device argument, then toggle -if (("$#" > 0)); then - left=$((1 - "$left")) +# If not initializing +if [[ ! "${argc_init:-}" ]]; then + left=$((1 - "$left")) # Toggle 0/1 fi # Enforce state if (("$left")); then - hyprctl keyword "device[$1]:left_handed" true - hyprctl keyword "device[$1]:natural_scroll" true - touch "$FILE" + hyprctl keyword "device[${argc_device:-}]:left_handed" true + + if [[ "${argc_scroll:-}" ]]; then + hyprctl keyword "device[${argc_device:-}]:natural_scroll" true + fi + + touch "${argc_file:-}" notify-send "> left" "Left-pawed" --urgency low else - hyprctl keyword "device[$1]:left_handed" false - hyprctl keyword "device[$1]:natural_scroll" false - rm --force "$FILE" + 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:-}" notify-send "> left" "Right-pawed" --urgency low fi