fix: disable input manager if window is not focused

Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
This commit is contained in:
2025-09-13 12:15:12 +05:00
parent 850bc57a16
commit 0f37a8fc6f
2 changed files with 11 additions and 27 deletions

View File

@@ -32,6 +32,8 @@ class MainWindowProtocol(Protocol):
...
def on_slider_released(self) -> None:
...
def isActiveWindow(self) -> bool:
...
stackedWidget: QStackedWidget
tabButtons: dict[int, QWidget]
gamesListWidget: QWidget
@@ -444,12 +446,9 @@ class InputManager(QObject):
if not self._gamepad_handling_enabled:
return
try:
# Ignore gamepad events if a game is launched
if getattr(self._parent, '_gameLaunched', False):
return
app = QApplication.instance()
if not app:
if not app or not self._parent.isActiveWindow():
return
active = QApplication.activeWindow()
focused = QApplication.focusWidget()
@@ -599,12 +598,9 @@ class InputManager(QObject):
if not self._gamepad_handling_enabled:
return
try:
# Ignore gamepad events if a game is launched
if getattr(self._parent, '_gameLaunched', False):
return
app = QApplication.instance()
if not app:
if not app or not self._parent.isActiveWindow():
return
active = QApplication.activeWindow()
focused = QApplication.focusWidget()
@@ -1125,11 +1121,15 @@ class InputManager(QObject):
if event.type not in (ecodes.EV_KEY, ecodes.EV_ABS):
continue
now = time.time()
# Проверка фокуса: игнорируем события, если окно не в фокусе
app = QApplication.instance()
if not app or not self._parent.isActiveWindow():
continue
if event.type == ecodes.EV_KEY and event.value == 1:
if event.code in BUTTONS['menu'] and not self._is_gamescope_session:
# Проверяем, не запущена ли игра
if not getattr(self._parent, '_gameLaunched', False):
self.toggle_fullscreen.emit(not self._is_fullscreen)
self.toggle_fullscreen.emit(not self._is_fullscreen)
else:
self.button_pressed.emit(event.code)
elif event.type == ecodes.EV_ABS:

View File

@@ -2238,8 +2238,6 @@ class MainWindow(QMainWindow):
elif not child_running:
# Игра завершилась сбрасываем флаг, сбрасываем кнопку и останавливаем таймер
self._gameLaunched = False
if hasattr(self, 'input_manager'):
self.input_manager.enable_gamepad_handling()
self.resetPlayButton()
#self._uninhibit_screensaver()
if hasattr(self, 'checkProcessTimer') and self.checkProcessTimer is not None:
@@ -2295,9 +2293,6 @@ class MainWindow(QMainWindow):
# Проверяем, запущена ли игра
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:
try:
parent = psutil.Process(proc.pid)
@@ -2357,10 +2352,6 @@ class MainWindow(QMainWindow):
icon = QIcon()
update_button.setIcon(icon)
# Delay disabling gamepad handling
if hasattr(self, 'input_manager'):
QTimer.singleShot(200, self.input_manager.disable_gamepad_handling)
self.checkProcessTimer = QTimer(self)
self.checkProcessTimer.timeout.connect(self.checkTargetExe)
self.checkProcessTimer.start(500)
@@ -2398,9 +2389,6 @@ class MainWindow(QMainWindow):
# Если игра уже запущена для этого 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:
try:
parent = psutil.Process(proc.pid)
@@ -2448,10 +2436,6 @@ class MainWindow(QMainWindow):
env_vars['START_FROM_STEAM'] = '1'
env_vars['PROCESS_LOG'] = '1'
# Delay disabling gamepad handling to allow rumble to complete
if hasattr(self, 'input_manager'):
QTimer.singleShot(200, self.input_manager.disable_gamepad_handling)
# Запускаем игру
try:
process = subprocess.Popen(entry_exec_split, env=env_vars, shell=False, preexec_fn=os.setsid)