76 lines
2.6 KiB
Python
Executable File
76 lines
2.6 KiB
Python
Executable File
import pyudev
|
|
import subprocess
|
|
|
|
def procesar_dispositivo_conectado(device, inicial=False):
|
|
vendor_id = device.get('ID_VENDOR_ID', '')
|
|
model_id = device.get('ID_MODEL_ID', '')
|
|
name = device.get('NAME', '')
|
|
device_str = f"{vendor_id}:{model_id} - {name}"
|
|
|
|
|
|
if "Xbox" in name:
|
|
print(f"{'🔍' if inicial else '🎮'} Xbox detectado: {device_str}")
|
|
if not inicial:
|
|
subprocess.run(["hyprctl", "dispatch", "dpms", "off", "HDMI-A-1"])
|
|
subprocess.run(["hyprctl", "dispatch", "dpms", "on", "DP-1"])
|
|
subprocess.run(["hyprctl", "dispatch", "dpms", "on", "DP-2"])
|
|
|
|
elif vendor_id.lower() == '2dc8':
|
|
print(f"{'🔍' if inicial else '🎮'} 8BitDo detectado: {device_str}")
|
|
if not inicial:
|
|
subprocess.run(["hyprctl", "dispatch", "dpms", "on", "HDMI-A-1"])
|
|
subprocess.run(["hyprctl", "dispatch", "dpms", "off", "DP-1"])
|
|
subprocess.run(["hyprctl", "dispatch", "dpms", "off", "DP-2"])
|
|
if not vendor_id:
|
|
return # Ignorar dispositivos sin vendor_id
|
|
|
|
def evento_callback(device):
|
|
if device.subsystem != 'input':
|
|
return
|
|
if device.action == 'add':
|
|
procesar_dispositivo_conectado(device)
|
|
elif device.action == 'remove':
|
|
print(f"❌ Dispositivo desconectado: {device.device_path}")
|
|
|
|
# --------------------------
|
|
# 🔍 Detectar dispositivos ya conectados
|
|
# --------------------------
|
|
context = pyudev.Context()
|
|
print(context.list_devices)
|
|
print("🔍 Buscando controles ya conectados...")
|
|
|
|
subprocess.run(["hyprctl", "dispatch", "dpms", "off", "HDMI-A-1"])
|
|
subprocess.run(["hyprctl", "dispatch", "dpms", "on", "DP-1"])
|
|
subprocess.run(["hyprctl", "dispatch", "dpms", "on", "DP-2"])
|
|
for device in context.list_devices(subsystem='input'):
|
|
|
|
vendor_id = device.get('ID_VENDOR_ID', '')
|
|
model_id = device.get('ID_MODEL_ID', '')
|
|
name = device.get('NAME', '')
|
|
device_str = f"{vendor_id}:{model_id} - {name}"
|
|
print(device_str)
|
|
if "8Bit" in name:
|
|
print("LOGRE DETECTAR EL CONTROL DE 8BIT")
|
|
positivo_conectado(device, inicial = False)
|
|
|
|
|
|
if "Xbox" in name:
|
|
print("LOGRE DETECTAR EL CONTROL DE XBOX")
|
|
procesar_dispositivo_conectado(device, inicial=True)
|
|
|
|
|
|
|
|
|
|
# --------------------------
|
|
# 👂 Escuchar nuevos eventos
|
|
# --------------------------
|
|
monitor = pyudev.Monitor.from_netlink(context)
|
|
monitor.filter_by(subsystem='input')
|
|
observer = pyudev.MonitorObserver(monitor, callback=evento_callback)
|
|
observer.start()
|
|
|
|
print("👀 Escuchando eventos de controles...")
|
|
import signal
|
|
signal.pause()
|
|
|