forked from Boria138/PortProtonQt
feat(input_manager): close AddGameDialog with B or Esc
Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
This commit is contained in:
parent
bc91b03843
commit
57d499fab2
@ -3,7 +3,7 @@ import threading
|
|||||||
from typing import Protocol, cast
|
from typing import Protocol, cast
|
||||||
from evdev import InputDevice, ecodes, list_devices
|
from evdev import InputDevice, ecodes, list_devices
|
||||||
import pyudev
|
import pyudev
|
||||||
from PySide6.QtWidgets import QWidget, QStackedWidget, QApplication, QScrollArea, QLineEdit
|
from PySide6.QtWidgets import QWidget, QStackedWidget, QApplication, QScrollArea, QLineEdit, QDialog
|
||||||
from PySide6.QtCore import Qt, QObject, QEvent, QPoint, Signal, Slot
|
from PySide6.QtCore import Qt, QObject, QEvent, QPoint, Signal, Slot
|
||||||
from PySide6.QtGui import QKeyEvent
|
from PySide6.QtGui import QKeyEvent
|
||||||
from portprotonqt.logger import get_logger
|
from portprotonqt.logger import get_logger
|
||||||
@ -30,6 +30,7 @@ class MainWindowProtocol(Protocol):
|
|||||||
gamesListWidget: QWidget
|
gamesListWidget: QWidget
|
||||||
currentDetailPage: QWidget | None
|
currentDetailPage: QWidget | None
|
||||||
current_exec_line: str | None
|
current_exec_line: str | None
|
||||||
|
current_add_game_dialog: QDialog | None # Добавляем для отслеживания диалога
|
||||||
|
|
||||||
# Mapping of actions to evdev button codes, includes PlayStation, Xbox, and Switch controllers
|
# Mapping of actions to evdev button codes, includes PlayStation, Xbox, and Switch controllers
|
||||||
BUTTONS = {
|
BUTTONS = {
|
||||||
@ -67,6 +68,7 @@ class InputManager(QObject):
|
|||||||
# 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)
|
||||||
|
self._parent.current_add_game_dialog = getattr(self._parent, 'current_add_game_dialog', None)
|
||||||
|
|
||||||
self.axis_deadzone = axis_deadzone
|
self.axis_deadzone = axis_deadzone
|
||||||
self.initial_axis_move_delay = initial_axis_move_delay
|
self.initial_axis_move_delay = initial_axis_move_delay
|
||||||
@ -134,6 +136,11 @@ class InputManager(QObject):
|
|||||||
app.quit()
|
app.quit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# Закрытие AddGameDialog на Esc
|
||||||
|
if key == Qt.Key.Key_Escape and isinstance(popup, QDialog):
|
||||||
|
popup.reject() # Закрываем диалог
|
||||||
|
return True
|
||||||
|
|
||||||
# Skip navigation keys if a popup is open
|
# Skip navigation keys if a popup is open
|
||||||
if popup:
|
if popup:
|
||||||
return False
|
return False
|
||||||
@ -357,14 +364,21 @@ 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:
|
||||||
try:
|
try:
|
||||||
|
# Игнорировать события геймпада, если игра запущена
|
||||||
if getattr(self._parent, '_gameLaunched', False):
|
if getattr(self._parent, '_gameLaunched', False):
|
||||||
return
|
return
|
||||||
|
|
||||||
app = QApplication.instance()
|
app = QApplication.instance()
|
||||||
if not app:
|
if not app:
|
||||||
return
|
return
|
||||||
active = QApplication.activeWindow()
|
active = QApplication.activeWindow()
|
||||||
focused = QApplication.focusWidget()
|
focused = QApplication.focusWidget()
|
||||||
|
|
||||||
|
# Закрытие AddGameDialog на кнопку B
|
||||||
|
if button_code in BUTTONS['back'] and isinstance(active, QDialog):
|
||||||
|
active.reject() # Закрываем диалог
|
||||||
|
return
|
||||||
|
|
||||||
# FullscreenDialog
|
# FullscreenDialog
|
||||||
if isinstance(active, FullscreenDialog):
|
if isinstance(active, FullscreenDialog):
|
||||||
if button_code in BUTTONS['prev_tab']:
|
if button_code in BUTTONS['prev_tab']:
|
||||||
@ -409,8 +423,10 @@ 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:
|
||||||
try:
|
try:
|
||||||
|
# Игнорировать события геймпада, если игра запущена
|
||||||
if getattr(self._parent, '_gameLaunched', False):
|
if getattr(self._parent, '_gameLaunched', False):
|
||||||
return
|
return
|
||||||
|
|
||||||
app = QApplication.instance()
|
app = QApplication.instance()
|
||||||
if not app:
|
if not app:
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user