#!/bin/bash

# omarchy:summary=Remove the xpadneo Xbox controller driver and its module config.
# omarchy:group=remove
# omarchy:name=gaming xbox-controllers
# omarchy:requires-sudo=true

set -e

echo "Removing Xbox controller Bluetooth support..."
# Only the Xbox installer's own blacklist: hid-tmff2 suggests the same file for Thrustmaster wheels.
installer_ran=false
[[ -e /etc/modules-load.d/xpadneo.conf ]] || omarchy-pkg-present xpadneo-dkms && installer_ran=true

omarchy-pkg-drop xpadneo linux-omarchy-xpadneo linux-omarchy-eevdf-xpadneo linux-omarchy-muqss-xpadneo xpadneo-dkms

legacy_blacklist=/etc/modprobe.d/blacklist-xpad.conf
if $installer_ran && [[ -f $legacy_blacklist ]]; then
  contents=$(sudo cat -- "$legacy_blacklist")
  if [[ $contents == "blacklist xpad" ]]; then
    sudo rm -f -- "$legacy_blacklist"
  fi
fi

sudo rm -f -- /etc/modules-load.d/xpadneo.conf

echo ""
echo "Xbox controller Bluetooth support removed. Reboot to fully unload xpadneo."
