fix: disable gamepad handling on game start thanks to @Vector_null
Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
This commit is contained in:
@ -72,6 +72,7 @@ class InputManager(QObject):
|
|||||||
):
|
):
|
||||||
super().__init__(cast(QObject, main_window))
|
super().__init__(cast(QObject, main_window))
|
||||||
self._parent = main_window
|
self._parent = main_window
|
||||||
|
self._gamepad_handling_enabled = True
|
||||||
# Ensure attributes exist on main_window
|
# Ensure attributes exist on main_window
|
||||||
self._parent.currentDetailPage = getattr(self._parent, 'currentDetailPage', None)
|
self._parent.currentDetailPage = getattr(self._parent, 'currentDetailPage', None)
|
||||||
self._parent.current_exec_line = getattr(self._parent, 'current_exec_line', None)
|
self._parent.current_exec_line = getattr(self._parent, 'current_exec_line', None)
|
||||||
@ -132,6 +133,16 @@ class InputManager(QObject):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in handle_fullscreen_slot: {e}", exc_info=True)
|
logger.error(f"Error in handle_fullscreen_slot: {e}", exc_info=True)
|
||||||
|
|
||||||
|
def disable_gamepad_handling(self) -> None:
|
||||||
|
"""Отключает обработку событий геймпада."""
|
||||||
|
self._gamepad_handling_enabled = False
|
||||||
|
self.stop_rumble()
|
||||||
|
self.dpad_timer.stop()
|
||||||
|
|
||||||
|
def enable_gamepad_handling(self) -> None:
|
||||||
|
"""Включает обработку событий геймпада."""
|
||||||
|
self._gamepad_handling_enabled = True
|
||||||
|
|
||||||
def trigger_rumble(self, duration_ms: int = 200, strong_magnitude: int = 0x8000, weak_magnitude: int = 0x8000) -> None:
|
def trigger_rumble(self, duration_ms: int = 200, strong_magnitude: int = 0x8000, weak_magnitude: int = 0x8000) -> None:
|
||||||
"""Trigger a rumble effect on the gamepad if supported."""
|
"""Trigger a rumble effect on the gamepad if supported."""
|
||||||
if not read_rumble_config():
|
if not read_rumble_config():
|
||||||
@ -176,6 +187,8 @@ class InputManager(QObject):
|
|||||||
|
|
||||||
@Slot(int)
|
@Slot(int)
|
||||||
def handle_button_slot(self, button_code: int) -> None:
|
def handle_button_slot(self, button_code: int) -> None:
|
||||||
|
if not self._gamepad_handling_enabled:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
# Ignore gamepad events if a game is launched
|
# Ignore gamepad events if a game is launched
|
||||||
if getattr(self._parent, '_gameLaunched', False):
|
if getattr(self._parent, '_gameLaunched', False):
|
||||||
@ -318,6 +331,8 @@ class InputManager(QObject):
|
|||||||
|
|
||||||
@Slot(int, int, float)
|
@Slot(int, int, float)
|
||||||
def handle_dpad_slot(self, code: int, value: int, current_time: float) -> None:
|
def handle_dpad_slot(self, code: int, value: int, current_time: float) -> None:
|
||||||
|
if not self._gamepad_handling_enabled:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
# Ignore gamepad events if a game is launched
|
# Ignore gamepad events if a game is launched
|
||||||
if getattr(self._parent, '_gameLaunched', False):
|
if getattr(self._parent, '_gameLaunched', False):
|
||||||
|
@ -1726,6 +1726,8 @@ class MainWindow(QMainWindow):
|
|||||||
elif not child_running:
|
elif not child_running:
|
||||||
# Игра завершилась – сбрасываем флаг, сбрасываем кнопку и останавливаем таймер
|
# Игра завершилась – сбрасываем флаг, сбрасываем кнопку и останавливаем таймер
|
||||||
self._gameLaunched = False
|
self._gameLaunched = False
|
||||||
|
if hasattr(self, 'input_manager'):
|
||||||
|
self.input_manager.enable_gamepad_handling()
|
||||||
self.resetPlayButton()
|
self.resetPlayButton()
|
||||||
#self._uninhibit_screensaver()
|
#self._uninhibit_screensaver()
|
||||||
if hasattr(self, 'checkProcessTimer') and self.checkProcessTimer is not None:
|
if hasattr(self, 'checkProcessTimer') and self.checkProcessTimer is not None:
|
||||||
@ -1782,6 +1784,9 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
# Если игра уже запущена для этого exe – останавливаем её по нажатию кнопки
|
# Если игра уже запущена для этого exe – останавливаем её по нажатию кнопки
|
||||||
if self.game_processes and self.target_exe == current_exe:
|
if self.game_processes and self.target_exe == current_exe:
|
||||||
|
if hasattr(self, 'input_manager'):
|
||||||
|
self.input_manager.enable_gamepad_handling()
|
||||||
|
|
||||||
for proc in self.game_processes:
|
for proc in self.game_processes:
|
||||||
try:
|
try:
|
||||||
parent = psutil.Process(proc.pid)
|
parent = psutil.Process(proc.pid)
|
||||||
@ -1821,6 +1826,10 @@ class MainWindow(QMainWindow):
|
|||||||
self.target_exe = current_exe
|
self.target_exe = current_exe
|
||||||
exe_name = os.path.splitext(current_exe)[0]
|
exe_name = os.path.splitext(current_exe)[0]
|
||||||
env_vars = os.environ.copy()
|
env_vars = os.environ.copy()
|
||||||
|
|
||||||
|
if hasattr(self, 'input_manager'):
|
||||||
|
self.input_manager.disable_gamepad_handling()
|
||||||
|
|
||||||
if entry_exec_split[0] == "env" and len(entry_exec_split) > 1 and 'data/scripts/start.sh' in entry_exec_split[1]:
|
if entry_exec_split[0] == "env" and len(entry_exec_split) > 1 and 'data/scripts/start.sh' in entry_exec_split[1]:
|
||||||
env_vars['START_FROM_STEAM'] = '1'
|
env_vars['START_FROM_STEAM'] = '1'
|
||||||
elif entry_exec_split[0] == "flatpak":
|
elif entry_exec_split[0] == "flatpak":
|
||||||
|
Reference in New Issue
Block a user