fix(input_manager): handle AddGameDialog navigation with D-pad

Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
This commit is contained in:
Boris Yumankulov 2025-06-07 15:26:37 +05:00
parent 364e1dd02a
commit 0f59c46d36
Signed by: Boria138
GPG Key ID: 14B4A5673FD39C76
2 changed files with 26 additions and 4 deletions

View File

@ -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:

View File

@ -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