fix(settings): fix virtual keyboard

Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
This commit is contained in:
2025-11-23 15:28:30 +05:00
parent b7804fdd01
commit bbfbc00c11

View File

@@ -724,7 +724,7 @@ class InputManager(QObject):
logger.error(f"Error restoring gamepad handlers from Settings: {e}") logger.error(f"Error restoring gamepad handlers from Settings: {e}")
def handle_settings_button(self, button_code, value): def handle_settings_button(self, button_code, value):
if self.settings_dialog is None or value == 0: if self.settings_dialog is None:
return return
try: try:
@@ -732,111 +732,123 @@ class InputManager(QObject):
kb = getattr(self.settings_dialog, 'keyboard', None) kb = getattr(self.settings_dialog, 'keyboard', None)
if kb and kb.isVisible(): if kb and kb.isVisible():
if button_code in BUTTONS['back']: if button_code in BUTTONS['back']:
kb.hide() if value != 0: # Only handle press, not release
if kb.current_input_widget: kb.hide()
kb.current_input_widget.setFocus() if kb.current_input_widget:
kb.current_input_widget.setFocus()
return # Return early to avoid dialog closing logic
elif button_code in (BUTTONS['confirm'] | BUTTONS['context_menu']): elif button_code in (BUTTONS['confirm'] | BUTTONS['context_menu']):
kb.activateFocusedKey() if value != 0: # Only handle press, not release
kb.activateFocusedKey()
return
elif button_code in BUTTONS['prev_tab']: elif button_code in BUTTONS['prev_tab']:
kb.on_lang_click() if value != 0: # Only handle press, not release
kb.on_lang_click()
return
elif button_code in BUTTONS['next_tab']: elif button_code in BUTTONS['next_tab']:
kb.on_shift_click(not kb.shift_pressed) if value != 0: # Only handle press, not release
kb.on_shift_click(not kb.shift_pressed)
return
elif button_code in BUTTONS['add_game']: elif button_code in BUTTONS['add_game']:
kb.on_backspace_pressed() if value != 0: # Press event
return kb.on_backspace_pressed()
else: # Release event
kb.stop_backspace_repeat()
return
# Handle common UI elements like QMessageBox, QMenu, etc. # Handle common UI elements like QMessageBox, QMenu, etc.
if self._handle_common_ui_elements(button_code): if self._handle_common_ui_elements(button_code):
return return
# Handle other QDialogs # Handle other QDialogs
popup = QApplication.activePopupWidget() if value != 0: # Only handle press events, not releases
if isinstance(popup, QDialog): popup = QApplication.activePopupWidget()
if button_code in BUTTONS['confirm']: if isinstance(popup, QDialog):
popup.accept() if button_code in BUTTONS['confirm']:
elif button_code in BUTTONS['back']: popup.accept()
popup.reject() elif button_code in BUTTONS['back']:
return popup.reject()
# 3. Advanced Tab Combo Box Logic
table = self._get_current_settings_table()
open_combo = None
if table and table == self.settings_dialog.advanced_table:
for r in range(table.rowCount()):
w = table.cellWidget(r, 1)
if isinstance(w, QComboBox) and w.view().isVisible():
open_combo = w
break
# B Button - Close combo or dialog
if button_code in BUTTONS['back']:
if open_combo:
open_combo.hidePopup()
if table:
table.setFocus()
else:
self.settings_dialog.reject()
return
# A Button - Confirm
if button_code in BUTTONS['confirm']:
if open_combo:
view = open_combo.view()
if view.currentIndex().isValid():
open_combo.setCurrentIndex(view.currentIndex().row())
open_combo.hidePopup()
if table:
table.setFocus()
return return
# Standard interaction # 3. Advanced Tab Combo Box Logic
focused = QApplication.focusWidget() table = self._get_current_settings_table()
if isinstance(focused, QTableWidget) and table and focused.currentRow() >= 0: open_combo = None
row = focused.currentRow() if table and table == self.settings_dialog.advanced_table:
cell = focused.cellWidget(row, 1) for r in range(table.rowCount()):
w = table.cellWidget(r, 1)
if isinstance(w, QComboBox) and w.view().isVisible():
open_combo = w
break
# Main settings (checkboxes) # B Button - Close combo or dialog
if self.settings_dialog and table == self.settings_dialog.settings_table: if button_code in BUTTONS['back']:
item = focused.item(row, 1) if open_combo:
if item and (item.flags() & Qt.ItemFlag.ItemIsUserCheckable): open_combo.hidePopup()
new_state = Qt.CheckState.Checked if item.checkState() == Qt.CheckState.Unchecked else Qt.CheckState.Unchecked if table:
item.setCheckState(new_state) table.setFocus()
else:
self.settings_dialog.reject()
return
# A Button - Confirm
if button_code in BUTTONS['confirm']:
if open_combo:
view = open_combo.view()
if view.currentIndex().isValid():
open_combo.setCurrentIndex(view.currentIndex().row())
open_combo.hidePopup()
if table:
table.setFocus()
return return
# Advanced settings # Standard interaction
if isinstance(cell, QComboBox) and cell.isEnabled(): focused = QApplication.focusWidget()
cell.showPopup() if isinstance(focused, QTableWidget) and table and focused.currentRow() >= 0:
cell.setFocus() row = focused.currentRow()
return cell = focused.cellWidget(row, 1)
if isinstance(cell, QLineEdit):
cell.setFocus()
self.settings_dialog.show_virtual_keyboard(cell)
return
if isinstance(focused, QLineEdit): # Main settings (checkboxes)
self.settings_dialog.show_virtual_keyboard(focused) if self.settings_dialog and table == self.settings_dialog.settings_table:
return item = focused.item(row, 1)
if item and (item.flags() & Qt.ItemFlag.ItemIsUserCheckable):
new_state = Qt.CheckState.Checked if item.checkState() == Qt.CheckState.Unchecked else Qt.CheckState.Unchecked
item.setCheckState(new_state)
return
# 4. Global Shortcuts # Advanced settings
if button_code in BUTTONS['add_game']: # X: Apply if isinstance(cell, QComboBox) and cell.isEnabled():
self.settings_dialog.apply_changes() cell.showPopup()
cell.setFocus()
return
if isinstance(cell, QLineEdit):
cell.setFocus()
self.settings_dialog.show_virtual_keyboard(cell)
return
elif button_code in BUTTONS['prev_dir']: # Y: Search + Keyboard if isinstance(focused, QLineEdit):
self.settings_dialog.search_edit.setFocus() self.settings_dialog.show_virtual_keyboard(focused)
self.settings_dialog.show_virtual_keyboard(self.settings_dialog.search_edit) return
elif button_code in BUTTONS['prev_tab']: # LB # 4. Global Shortcuts
idx = max(0, self.settings_dialog.tab_widget.currentIndex() - 1) if button_code in BUTTONS['add_game']: # X: Apply
self.settings_dialog.tab_widget.setCurrentIndex(idx) self.settings_dialog.apply_changes()
self._focus_first_row_in_current_settings_table()
elif button_code in BUTTONS['next_tab']: # RB elif button_code in BUTTONS['prev_dir']: # Y: Search + Keyboard
idx = min(self.settings_dialog.tab_widget.count() - 1, self.settings_dialog.tab_widget.currentIndex() + 1) self.settings_dialog.search_edit.setFocus()
self.settings_dialog.tab_widget.setCurrentIndex(idx) self.settings_dialog.show_virtual_keyboard(self.settings_dialog.search_edit)
self._focus_first_row_in_current_settings_table()
else: elif button_code in BUTTONS['prev_tab']: # LB
self._parent.activateFocusedWidget() idx = max(0, self.settings_dialog.tab_widget.currentIndex() - 1)
self.settings_dialog.tab_widget.setCurrentIndex(idx)
self._focus_first_row_in_current_settings_table()
elif button_code in BUTTONS['next_tab']: # RB
idx = min(self.settings_dialog.tab_widget.count() - 1, self.settings_dialog.tab_widget.currentIndex() + 1)
self.settings_dialog.tab_widget.setCurrentIndex(idx)
self._focus_first_row_in_current_settings_table()
else:
self._parent.activateFocusedWidget()
except Exception as e: except Exception as e:
logger.error(f"Error in handle_settings_button: {e}") logger.error(f"Error in handle_settings_button: {e}")