#!/bin/sh
# Manually force the Razer Naga V2 HyperSpeed into OpenRazer "driver mode" and
# re-apply the saved DPI stage — a one-tap "fix my mouse" after a wireless wake
# resets it. No sudo needed (user must be in the `openrazer` group).
ok=0
for dm in /sys/bus/hid/devices/*1532*00B4*/device_mode; do
    [ -e "$dm" ] || continue
    printf '\003\000' > "$dm" 2>/dev/null && ok=1
done

# Re-apply the saved DPI stage too (wakes can reset DPI as well).
dpi="$HOME/.config/hypr/scripts/naga-dpi-cycle.sh"
[ -x "$dpi" ] && "$dpi" apply >/dev/null 2>&1

if command -v notify-send >/dev/null 2>&1; then
    if [ "$ok" = 1 ]; then
        notify-send -t 1200 -h string:x-canonical-private-synchronous:naga "Naga" "driver mode set"
    else
        notify-send -t 1500 -h string:x-canonical-private-synchronous:naga "Naga" "device not found"
    fi
fi
