forked from Boria138/PortProtonQt
fix: disable input manager if window is not focused
Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
This commit is contained in:
@@ -32,6 +32,8 @@ class MainWindowProtocol(Protocol):
|
|||||||
...
|
...
|
||||||
def on_slider_released(self) -> None:
|
def on_slider_released(self) -> None:
|
||||||
...
|
...
|
||||||
|
def isActiveWindow(self) -> bool:
|
||||||
|
...
|
||||||
stackedWidget: QStackedWidget
|
stackedWidget: QStackedWidget
|
||||||
tabButtons: dict[int, QWidget]
|
tabButtons: dict[int, QWidget]
|
||||||
gamesListWidget: QWidget
|
gamesListWidget: QWidget
|
||||||
@@ -444,12 +446,9 @@ class InputManager(QObject):
|
|||||||
if not self._gamepad_handling_enabled:
|
if not self._gamepad_handling_enabled:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
# Ignore gamepad events if a game is launched
|
|
||||||
if getattr(self._parent, '_gameLaunched', False):
|
|
||||||
return
|
|
||||||
|
|
||||||
app = QApplication.instance()
|
app = QApplication.instance()
|
||||||
if not app:
|
if not app or not self._parent.isActiveWindow():
|
||||||
return
|
return
|
||||||
active = QApplication.activeWindow()
|
active = QApplication.activeWindow()
|
||||||
focused = QApplication.focusWidget()
|
focused = QApplication.focusWidget()
|
||||||
@@ -599,12 +598,9 @@ class InputManager(QObject):
|
|||||||
if not self._gamepad_handling_enabled:
|
if not self._gamepad_handling_enabled:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
# Ignore gamepad events if a game is launched
|
|
||||||
if getattr(self._parent, '_gameLaunched', False):
|
|
||||||
return
|
|
||||||
|
|
||||||
app = QApplication.instance()
|
app = QApplication.instance()
|
||||||
if not app:
|
if not app or not self._parent.isActiveWindow():
|
||||||
return
|
return
|
||||||
active = QApplication.activeWindow()
|
active = QApplication.activeWindow()
|
||||||
focused = QApplication.focusWidget()
|
focused = QApplication.focusWidget()
|
||||||
@@ -1125,10 +1121,14 @@ class InputManager(QObject):
|
|||||||
if event.type not in (ecodes.EV_KEY, ecodes.EV_ABS):
|
if event.type not in (ecodes.EV_KEY, ecodes.EV_ABS):
|
||||||
continue
|
continue
|
||||||
now = time.time()
|
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.type == ecodes.EV_KEY and event.value == 1:
|
||||||
if event.code in BUTTONS['menu'] and not self._is_gamescope_session:
|
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:
|
else:
|
||||||
self.button_pressed.emit(event.code)
|
self.button_pressed.emit(event.code)
|
||||||
|
@@ -2238,8 +2238,6 @@ 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:
|
||||||
@@ -2295,9 +2293,6 @@ class MainWindow(QMainWindow):
|
|||||||
# Проверяем, запущена ли игра
|
# Проверяем, запущена ли игра
|
||||||
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)
|
||||||
@@ -2357,10 +2352,6 @@ class MainWindow(QMainWindow):
|
|||||||
icon = QIcon()
|
icon = QIcon()
|
||||||
update_button.setIcon(icon)
|
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 = QTimer(self)
|
||||||
self.checkProcessTimer.timeout.connect(self.checkTargetExe)
|
self.checkProcessTimer.timeout.connect(self.checkTargetExe)
|
||||||
self.checkProcessTimer.start(500)
|
self.checkProcessTimer.start(500)
|
||||||
@@ -2398,9 +2389,6 @@ 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)
|
||||||
@@ -2448,10 +2436,6 @@ class MainWindow(QMainWindow):
|
|||||||
env_vars['START_FROM_STEAM'] = '1'
|
env_vars['START_FROM_STEAM'] = '1'
|
||||||
env_vars['PROCESS_LOG'] = '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:
|
try:
|
||||||
process = subprocess.Popen(entry_exec_split, env=env_vars, shell=False, preexec_fn=os.setsid)
|
process = subprocess.Popen(entry_exec_split, env=env_vars, shell=False, preexec_fn=os.setsid)
|
||||||
|
Reference in New Issue
Block a user