feat(input_manager): rework gamepad buttons maping
Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
This commit is contained in:
@ -34,19 +34,18 @@ class MainWindowProtocol(Protocol):
|
|||||||
current_exec_line: str | None
|
current_exec_line: str | None
|
||||||
current_add_game_dialog: QDialog | None
|
current_add_game_dialog: QDialog | None
|
||||||
|
|
||||||
# Mapping of actions to evdev button codes, includes PlayStation, Xbox controllers
|
# Mapping of actions to evdev button codes, includes Xbox and Playstation controllers
|
||||||
# https://github.com/torvalds/linux/blob/master/drivers/hid/hid-playstation.c
|
# https://github.com/torvalds/linux/blob/master/drivers/hid/hid-playstation.c
|
||||||
# https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c
|
# https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c
|
||||||
BUTTONS = {
|
BUTTONS = {
|
||||||
'confirm': {ecodes.BTN_A, ecodes.BTN_SOUTH},
|
'confirm': {ecodes.BTN_A, ecodes.BTN_SOUTH}, # A / Cross
|
||||||
'back': {ecodes.BTN_B, ecodes.BTN_EAST},
|
'back': {ecodes.BTN_B, ecodes.BTN_EAST}, # B / Circle
|
||||||
'add_game': {ecodes.BTN_Y, ecodes.BTN_NORTH},
|
'add_game': {ecodes.BTN_Y, ecodes.BTN_NORTH}, # Y / Triangle
|
||||||
'prev_tab': {ecodes.BTN_TL},
|
'prev_tab': {ecodes.BTN_TL}, # LB / L1
|
||||||
'next_tab': {ecodes.BTN_TR},
|
'next_tab': {ecodes.BTN_TR}, # RB / R1
|
||||||
'confirm_stick': {ecodes.BTN_THUMBL, ecodes.BTN_THUMBR},
|
'context_menu': {ecodes.BTN_START}, # Start / Options
|
||||||
'context_menu': {ecodes.BTN_START},
|
'menu': {ecodes.BTN_SELECT}, # Select / Share
|
||||||
'menu': {ecodes.BTN_SELECT},
|
'guide': {ecodes.BTN_MODE}, # Xbox / PS Home
|
||||||
'guide': {ecodes.BTN_MODE, ecodes.KEY_HOMEPAGE},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class InputManager(QObject):
|
class InputManager(QObject):
|
||||||
@ -149,19 +148,19 @@ class InputManager(QObject):
|
|||||||
|
|
||||||
# Handle QMenu (context menu)
|
# Handle QMenu (context menu)
|
||||||
if isinstance(popup, QMenu):
|
if isinstance(popup, QMenu):
|
||||||
if button_code in BUTTONS['confirm'] or button_code in BUTTONS['confirm_stick']:
|
if button_code in BUTTONS['confirm']:
|
||||||
if popup.activeAction():
|
if popup.activeAction():
|
||||||
popup.activeAction().trigger()
|
popup.activeAction().trigger()
|
||||||
popup.close()
|
popup.close()
|
||||||
return
|
return
|
||||||
elif button_code in BUTTONS['back'] or button_code in BUTTONS['menu']:
|
elif button_code in BUTTONS['back']:
|
||||||
popup.close()
|
popup.close()
|
||||||
return
|
return
|
||||||
return
|
return
|
||||||
|
|
||||||
# Handle QComboBox
|
# Handle QComboBox
|
||||||
if isinstance(focused, QComboBox):
|
if isinstance(focused, QComboBox):
|
||||||
if button_code in BUTTONS['confirm'] or button_code in BUTTONS['confirm_stick']:
|
if button_code in BUTTONS['confirm']:
|
||||||
focused.showPopup()
|
focused.showPopup()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -175,7 +174,7 @@ class InputManager(QObject):
|
|||||||
break
|
break
|
||||||
parent = parent.parentWidget()
|
parent = parent.parentWidget()
|
||||||
|
|
||||||
if button_code in BUTTONS['confirm'] or button_code in BUTTONS['confirm_stick']:
|
if button_code in BUTTONS['confirm']:
|
||||||
idx = focused.currentIndex()
|
idx = focused.currentIndex()
|
||||||
if idx.isValid():
|
if idx.isValid():
|
||||||
if combo:
|
if combo:
|
||||||
@ -221,18 +220,17 @@ class InputManager(QObject):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Game launch on detail page
|
# Game launch on detail page
|
||||||
if (button_code in BUTTONS['confirm'] or button_code in BUTTONS['confirm_stick']) and self._parent.currentDetailPage is not None and self._parent.current_add_game_dialog is None:
|
if (button_code in BUTTONS['confirm']) and self._parent.currentDetailPage is not None and self._parent.current_add_game_dialog is None:
|
||||||
if self._parent.current_exec_line:
|
if self._parent.current_exec_line:
|
||||||
self._parent.toggleGame(self._parent.current_exec_line, None)
|
self._parent.toggleGame(self._parent.current_exec_line, None)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Standard navigation
|
# Standard navigation
|
||||||
if button_code in BUTTONS['confirm'] or button_code in BUTTONS['confirm_stick']:
|
if button_code in BUTTONS['confirm']:
|
||||||
self._parent.activateFocusedWidget()
|
self._parent.activateFocusedWidget()
|
||||||
elif button_code in BUTTONS['back'] or button_code in BUTTONS['menu']:
|
elif button_code in BUTTONS['back']:
|
||||||
self._parent.goBackDetailPage(getattr(self._parent, 'currentDetailPage', None))
|
self._parent.goBackDetailPage(getattr(self._parent, 'currentDetailPage', None))
|
||||||
elif button_code in BUTTONS['add_game']:
|
elif button_code in BUTTONS['add_game']:
|
||||||
# Only open AddGameDialog if in library tab (index 0)
|
|
||||||
if self._parent.stackedWidget.currentIndex() == 0:
|
if self._parent.stackedWidget.currentIndex() == 0:
|
||||||
self._parent.openAddGameDialog()
|
self._parent.openAddGameDialog()
|
||||||
elif button_code in BUTTONS['prev_tab']:
|
elif button_code in BUTTONS['prev_tab']:
|
||||||
@ -791,9 +789,7 @@ class InputManager(QObject):
|
|||||||
continue
|
continue
|
||||||
now = time.time()
|
now = time.time()
|
||||||
if event.type == ecodes.EV_KEY and event.value == 1:
|
if event.type == ecodes.EV_KEY and event.value == 1:
|
||||||
# Обработка кнопки Select для переключения полноэкранного режима
|
|
||||||
if event.code in BUTTONS['menu']:
|
if event.code in BUTTONS['menu']:
|
||||||
# Переключаем полноэкранный режим
|
|
||||||
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)
|
||||||
|
Reference in New Issue
Block a user