#!/usr/bin/bash
# Toggle the InputPlumber active profile between the default
# (gamepad) and mouse_keyboard_wasd (joystick→mouse + WASD).
# Reads current ProfilePath from D-Bus so it's stateless across
# reboots and sessions — same effect as a GPD-style mode key.
set -eu
DEV=/org/shadowblip/InputPlumber/CompositeDevice0
SVC=org.shadowblip.InputPlumber
IFACE=org.shadowblip.Input.CompositeDevice

GAMEPAD=/usr/share/inputplumber/profiles/default.yaml
JOYMOUSE=/usr/share/inputplumber/profiles/mouse_keyboard_wasd.yaml

cur=$(busctl get-property "$SVC" "$DEV" "$IFACE" ProfilePath 2>/dev/null \
      | sed -E 's/^s "(.*)"$/\1/')

case "$cur" in
    "$JOYMOUSE")
        next="$GAMEPAD"
        label="Gamepad mode"
        ;;
    *)
        next="$JOYMOUSE"
        label="Joystick → mouse + WASD"
        ;;
esac

busctl call "$SVC" "$DEV" "$IFACE" LoadProfilePath s "$next"
notify-send -u low "Pocket DS" "$label" 2>/dev/null || true
