add home to repo

This commit is contained in:
valere
2025-11-15 09:59:44 +01:00
parent 170ede89f8
commit 463540770a
85 changed files with 1051 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
#!/usr/bin/env python3
import evdev
import subprocess
import time
DEVICE_NAMES = ["8BitDo NGC Modkit"]
BUTTON_MAP = {
"304": "Return", # A
"305": None, # B (non utilisé)
"311": "Alt_L", # R
"307": "Right", # X
"308": "Left", # Y
# 318 (BTN_THUMBR) sera géré à part
}
def find_device():
for path in evdev.list_devices():
try:
dev = evdev.InputDevice(path)
if any(dn in dev.name for dn in DEVICE_NAMES):
return path
except Exception:
continue
return None
def is_dolphin_running():
try:
output = subprocess.check_output(["flatpak", "ps"]).decode()
return "org.DolphinEmu.dolphin-emu" in output
except Exception:
return False
def press_key(key, press):
# press=True -> key down, press=False -> key up
action = "keydown" if press else "keyup"
subprocess.run(["xdotool", action, key])
def handle_device(dev_path):
dev = evdev.InputDevice(dev_path)
try:
for event in dev.read_loop():
if event.type != evdev.ecodes.EV_KEY:
continue
key_code = str(event.code)
# cas spécial : joystick jaune (BTN_THUMBR, code 318)
if key_code == "318" and event.value == 1: # pression
press_key("Alt_L", True)
time.sleep(0.02)
press_key("Escape", True)
time.sleep(0.05)
press_key("Escape", False)
press_key("Alt_L", False)
continue
if key_code in BUTTON_MAP:
mapped_key = BUTTON_MAP[key_code]
if mapped_key is not None:
press_key(mapped_key, event.value == 1)
except OSError:
dev.close()
raise
def main():
connected = False
time.sleep(5) # délai pour que le serveur graphique soit prêt
while True:
dev_path = find_device()
if dev_path and not connected:
print(f"[+] Manette connectée: {dev_path}")
connected = True
if not is_dolphin_running():
try:
subprocess.Popen(["flatpak", "run", "org.DolphinEmu.dolphin-emu"])
except Exception as e:
print(f"[!] Impossible de lancer Dolphin: {e}")
try:
handle_device(dev_path)
except OSError:
print("[-] Manette déconnectée")
connected = False
try:
subprocess.Popen(["flatpak", "kill", "org.DolphinEmu.dolphin-emu"])
except Exception as e:
print(f"[!] Impossible de tuer Dolphin: {e}")
elif not dev_path and connected:
print("[-] Manette déconnectée")
connected = False
time.sleep(1)
if __name__ == "__main__":
main()

77
home/gamecube-pad/install.sh Executable file
View File

@@ -0,0 +1,77 @@
#!/bin/bash
set -e
PYTHON_SCRIPT="$HOME/.local/bin/gamecube-pad.py"
AUTOSTART_DIR="$HOME/.config/autostart"
AUTOSTART_FILE="$AUTOSTART_DIR/gamecube-pad.desktop"
SILENT=false
if [[ "$1" == "silent" ]]; then
SILENT=true
fi
log() {
if [ "$SILENT" = false ]; then
echo "$@"
fi
}
check_and_install_deps() {
for pkg in evdev uinput; do
if ! python3 -c "import $pkg" &>/dev/null; then
log "[!] Dépendance manquante : $pkg. Installation avec pip..."
python3 -m pip install --user "$pkg" &>/dev/null
fi
done
for cmd in xdotool wmctrl; do
if ! command -v "$cmd" &>/dev/null; then
log "[!] Commande manquante : $cmd. Merci de linstaller via votre gestionnaire de paquets."
fi
done
}
install_script() {
check_and_install_deps
log "[+] Copie du script Python..."
mkdir -p "$(dirname "$PYTHON_SCRIPT")"
cp "$HOME/.linux-env/gamecube-pad/gamecube-pad.py" "$PYTHON_SCRIPT"
chmod +x "$PYTHON_SCRIPT"
log "[+] Création du fichier autostart..."
mkdir -p "$AUTOSTART_DIR"
cat > "$AUTOSTART_FILE" <<EOF
[Desktop Entry]
Type=Application
Exec=$PYTHON_SCRIPT
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=GameCube Pad
Comment=Lance le script GameCube Pad au démarrage
EOF
log "[✓] Installation terminée. Le script se lancera automatiquement à l'ouverture de session."
}
uninstall_script() {
log "[+] Suppression du script Python et autostart..."
rm -f "$PYTHON_SCRIPT"
rm -f "$AUTOSTART_FILE"
log "[✓] Désinstallation terminée."
}
case "$1" in
uninstall)
uninstall_script
;;
silent)
SILENT=true
uninstall_script &>/dev/null
install_script &>/dev/null
;;
*)
install_script
;;
esac