From 0f59c46d362baa81f79490231fc2f4ac23b7035a Mon Sep 17 00:00:00 2001 From: Boris Yumankulov Date: Sat, 7 Jun 2025 15:26:37 +0500 Subject: [PATCH] fix(input_manager): handle AddGameDialog navigation with D-pad Signed-off-by: Boris Yumankulov --- portprotonqt/input_manager.py | 29 +++++++++++++++++++++++++---- portprotonqt/main_window.py | 1 + 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/portprotonqt/input_manager.py b/portprotonqt/input_manager.py index e030ad3..2f0caff 100644 --- a/portprotonqt/input_manager.py +++ b/portprotonqt/input_manager.py @@ -216,7 +216,9 @@ class InputManager(QObject): elif button_code in BUTTONS['back'] or button_code in BUTTONS['menu']: self._parent.goBackDetailPage(getattr(self._parent, 'currentDetailPage', None)) elif button_code in BUTTONS['add_game']: - self._parent.openAddGameDialog() + # Only open AddGameDialog if in library tab (index 0) + if self._parent.stackedWidget.currentIndex() == 0: + self._parent.openAddGameDialog() elif button_code in BUTTONS['prev_tab']: idx = (self._parent.stackedWidget.currentIndex() - 1) % len(self._parent.tabButtons) self._parent.switchTab(idx) @@ -242,6 +244,21 @@ class InputManager(QObject): focused = QApplication.focusWidget() popup = QApplication.activePopupWidget() + # Handle AddGameDialog navigation with D-pad + if isinstance(active, QDialog) and code == ecodes.ABS_HAT0Y and value != 0: + if not focused or not active.focusWidget(): + # If no widget is focused, focus the first focusable widget + focusables = active.findChildren(QWidget, options=Qt.FindChildOption.FindChildrenRecursively) + focusables = [w for w in focusables if w.focusPolicy() & Qt.FocusPolicy.StrongFocus] + if focusables: + focusables[0].setFocus(Qt.FocusReason.OtherFocusReason) + return + if value > 0: # Down + active.focusNextChild() + elif value < 0: # Up + active.focusPreviousChild() + return + # Handle QMenu navigation with D-pad if isinstance(popup, QMenu): if code == ecodes.ABS_HAT0Y and value != 0: @@ -364,7 +381,6 @@ class InputManager(QObject): next_card.setFocus() if scroll_area: scroll_area.ensureWidgetVisible(next_card, 50, 50) - elif code == ecodes.ABS_HAT0Y and value != 0: # Up/Down if value > 0: # Down next_row_idx = current_row_idx + 1 @@ -621,6 +637,9 @@ class InputManager(QObject): if focusables: focusables[0].setFocus() return True + elif focused: + focused.focusNextChild() + return True # Navigate up through tab content if key == Qt.Key.Key_Up: if isinstance(focused, NavLabel): @@ -641,8 +660,10 @@ class InputManager(QObject): elif key == Qt.Key.Key_E: if isinstance(focused, QLineEdit): return False - self._parent.openAddGameDialog() - return True + # Only open AddGameDialog if in library tab (index 0) + if self._parent.stackedWidget.currentIndex() == 0: + self._parent.openAddGameDialog() + return True # Toggle fullscreen with F11 if key == Qt.Key.Key_F11: diff --git a/portprotonqt/main_window.py b/portprotonqt/main_window.py index b31f398..77cb547 100644 --- a/portprotonqt/main_window.py +++ b/portprotonqt/main_window.py @@ -742,6 +742,7 @@ class MainWindow(QMainWindow): return dialog = AddGameDialog(self, self.theme) + dialog.setFocus(Qt.FocusReason.OtherFocusReason) self.current_add_game_dialog = dialog # Сохраняем ссылку на диалог # Предзаполняем путь к .exe при drag-and-drop