user service works
This commit is contained in:
@@ -1,25 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
import evdev
|
||||
import uinput
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
DEVICE_NAMES = ["8BitDo NGC Modkit"]
|
||||
BUTTON_MAP = {
|
||||
"304": "KEY_ENTER", # A
|
||||
"305": None, # B (non utilisé)
|
||||
"311": "KEY_LEFTALT", # R
|
||||
"307": "KEY_RIGHT", # Stick droit → Droite
|
||||
"308": "KEY_LEFT", # Stick droit → Gauche
|
||||
"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
|
||||
}
|
||||
|
||||
events = [
|
||||
uinput.KEY_LEFT, uinput.KEY_RIGHT,
|
||||
uinput.KEY_ENTER, uinput.KEY_ESC, uinput.KEY_LEFTALT
|
||||
]
|
||||
keyboard = uinput.Device(events)
|
||||
|
||||
def find_device():
|
||||
for path in evdev.list_devices():
|
||||
try:
|
||||
@@ -32,13 +25,16 @@ def find_device():
|
||||
|
||||
def is_dolphin_running():
|
||||
try:
|
||||
output = subprocess.check_output(
|
||||
["flatpak", "ps"]
|
||||
).decode()
|
||||
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:
|
||||
@@ -50,19 +46,18 @@ def handle_device(dev_path):
|
||||
|
||||
# cas spécial : joystick jaune (BTN_THUMBR, code 318)
|
||||
if key_code == "318" and event.value == 1: # pression
|
||||
keyboard.emit(uinput.KEY_LEFTALT, 1)
|
||||
press_key("Alt_L", True)
|
||||
time.sleep(0.02)
|
||||
keyboard.emit(uinput.KEY_ESC, 1)
|
||||
press_key("Escape", True)
|
||||
time.sleep(0.05)
|
||||
keyboard.emit(uinput.KEY_ESC, 0)
|
||||
keyboard.emit(uinput.KEY_LEFTALT, 0)
|
||||
press_key("Escape", False)
|
||||
press_key("Alt_L", False)
|
||||
continue
|
||||
|
||||
# touches normales selon le mapping
|
||||
if key_code in BUTTON_MAP:
|
||||
mapped_key = BUTTON_MAP[key_code]
|
||||
if mapped_key is not None:
|
||||
keyboard.emit(getattr(uinput, mapped_key), event.value)
|
||||
press_key(mapped_key, event.value == 1)
|
||||
|
||||
except OSError:
|
||||
dev.close()
|
||||
@@ -70,7 +65,7 @@ def handle_device(dev_path):
|
||||
|
||||
def main():
|
||||
connected = False
|
||||
time.sleep(5) # délai pour que uinput et le serveur graphique soient prêts
|
||||
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:
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
[Unit]
|
||||
Description=Pad Dolphin Watcher Service (User)
|
||||
After=graphical.target dev-uinput.device
|
||||
After=graphical.target
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/bin/sleep 10
|
||||
ExecStart=/home/$USER/.local/bin/gamecube-pad.py
|
||||
WorkingDirectory=/home/$USER
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/python3 /home/%u/.local/bin/gamecube-pad.py
|
||||
Restart=always
|
||||
RestartSec=3
|
||||
StandardOutput=journal+console
|
||||
StandardError=journal+console
|
||||
WorkingDirectory=/home/%u
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
set -e
|
||||
|
||||
SERVICE_NAME="gamecube-pad.service"
|
||||
SERVICE_PATH="/etc/systemd/system/$SERVICE_NAME"
|
||||
SERVICE_PATH="$HOME/.config/systemd/user/gamecube-pad.service"
|
||||
PYTHON_SCRIPT="/home/$USER/.local/bin/gamecube-pad.py"
|
||||
|
||||
install_service() {
|
||||
@@ -14,25 +14,25 @@ install_service() {
|
||||
cp gamecube-pad.py "$PYTHON_SCRIPT"
|
||||
chmod +x "$PYTHON_SCRIPT"
|
||||
|
||||
echo "[+] Copie du fichier systemd..."
|
||||
sudo cp gamecube-pad.service "$SERVICE_PATH"
|
||||
sudo sed -i "s|\$USER|$USER|g" "$SERVICE_PATH"
|
||||
echo "[+] Copie du fichier systemd utilisateur..."
|
||||
mkdir -p "$HOME/.config/systemd/user"
|
||||
cp gamecube-pad.service "$SERVICE_PATH"
|
||||
|
||||
echo "[+] Activation du service..."
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable "$SERVICE_NAME"
|
||||
sudo systemctl restart "$SERVICE_NAME"
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable gamecube-pad.service
|
||||
systemctl --user restart gamecube-pad.service
|
||||
|
||||
echo "[✓] Installation terminée. Consultez les logs avec : journalctl -u $SERVICE_NAME -f"
|
||||
echo "[✓] Installation terminée. Consultez les logs avec : journalctl --user -u gamecube-pad.service -f"
|
||||
}
|
||||
|
||||
uninstall_service() {
|
||||
echo "[+] Arrêt et suppression du service..."
|
||||
sudo systemctl stop "$SERVICE_NAME" || true
|
||||
sudo systemctl disable "$SERVICE_NAME" || true
|
||||
sudo rm -f "$SERVICE_PATH"
|
||||
sudo systemctl daemon-reload
|
||||
systemctl --user stop gamecube-pad.service || true
|
||||
systemctl --user disable gamecube-pad.service || true
|
||||
rm -f "$SERVICE_PATH"
|
||||
rm -f "$PYTHON_SCRIPT"
|
||||
systemctl --user daemon-reload
|
||||
echo "[✓] Désinstallation terminée."
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user