#!/usr/bin/bash
# Toggle InterceptMode (right-stick → mouse) on the composite
# device. Reads current state straight from D-Bus so it's
# stateless across reboots / sessions.
set -eu
DEV=/org/shadowblip/InputPlumber/CompositeDevice0
SVC=org.shadowblip.InputPlumber
IFACE=org.shadowblip.Input.CompositeDevice

cur=$(busctl get-property "$SVC" "$DEV" "$IFACE" InterceptMode 2>/dev/null \
      | awk '{print $2}')
case "$cur" in
    0|"") new=1; label=on ;;
    *)   new=0; label=off ;;
esac
busctl set-property "$SVC" "$DEV" "$IFACE" InterceptMode u "$new"
notify-send -u low "Pocket DS" "Joystick-as-mouse: ${label}" 2>/dev/null || true
