Qt: Re-enable menu keyboard navigation and mnemonics

when "Keyboard requries capture" is enabled and mouse isn't captured
on Windows and Linux
This commit is contained in:
Alexander Babikov
2025-08-01 02:31:29 +05:00
parent 9b8a2b8361
commit 5e8064c969
4 changed files with 28 additions and 3 deletions

View File

@@ -585,7 +585,11 @@ main(int argc, char *argv[])
} }
if (!vmm_enabled) if (!vmm_enabled)
#ifdef Q_OS_MACOS
qt_set_sequence_auto_mnemonic(false); qt_set_sequence_auto_mnemonic(false);
#else
qt_set_sequence_auto_mnemonic(!!kbd_req_capture);
#endif
app.setStyle(new StyleOverride()); app.setStyle(new StyleOverride());
bool startMaximized = window_remember && monitor_settings[0].mon_window_maximized; bool startMaximized = window_remember && monitor_settings[0].mon_window_maximized;

View File

@@ -92,6 +92,8 @@ extern bool cpu_thread_running;
# include <QVulkanFunctions> # include <QVulkanFunctions>
#endif #endif
void qt_set_sequence_auto_mnemonic(bool b);
#include <array> #include <array>
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
@@ -335,6 +337,16 @@ MainWindow::MainWindow(QWidget *parent)
} }
ui->stackedWidget->unsetCursor(); ui->stackedWidget->unsetCursor();
} }
#ifndef Q_OS_MACOS
if (kbd_req_capture) {
qt_set_sequence_auto_mnemonic(!mouse_capture);
/* Hack to get the menubar to update the internal Alt+shortcut table */
if (!video_fullscreen) {
ui->menubar->hide();
ui->menubar->show();
}
}
#endif
}); });
connect(qApp, &QGuiApplication::applicationStateChanged, [this](Qt::ApplicationState state) { connect(qApp, &QGuiApplication::applicationStateChanged, [this](Qt::ApplicationState state) {
@@ -1034,6 +1046,14 @@ void
MainWindow::on_actionKeyboard_requires_capture_triggered() MainWindow::on_actionKeyboard_requires_capture_triggered()
{ {
kbd_req_capture ^= 1; kbd_req_capture ^= 1;
#ifndef Q_OS_MACOS
qt_set_sequence_auto_mnemonic(!!kbd_req_capture);
/* Hack to get the menubar to update the internal Alt+shortcut table */
if (!video_fullscreen) {
ui->menubar->hide();
ui->menubar->show();
}
#endif
} }
void void
@@ -1432,7 +1452,7 @@ MainWindow::eventFilter(QObject *receiver, QEvent *event)
} }
if (!dopause) { if (!dopause && (!kbd_req_capture || mouse_capture)) {
if (event->type() == QEvent::Shortcut) { if (event->type() == QEvent::Shortcut) {
auto shortcutEvent = (QShortcutEvent *) event; auto shortcutEvent = (QShortcutEvent *) event;
if (shortcutEvent->key() == ui->actionExit->shortcut()) { if (shortcutEvent->key() == ui->actionExit->shortcut()) {

View File

@@ -85,7 +85,7 @@ private slots:
void on_actionCtrl_Alt_Esc_triggered(); void on_actionCtrl_Alt_Esc_triggered();
void on_actionHard_Reset_triggered(); void on_actionHard_Reset_triggered();
void on_actionRight_CTRL_is_left_ALT_triggered(); void on_actionRight_CTRL_is_left_ALT_triggered();
static void on_actionKeyboard_requires_capture_triggered(); void on_actionKeyboard_requires_capture_triggered();
void on_actionResizable_window_triggered(bool checked); void on_actionResizable_window_triggered(bool checked);
void on_actionInverted_VGA_monitor_triggered(); void on_actionInverted_VGA_monitor_triggered();
void on_action0_5x_triggered(); void on_action0_5x_triggered();

View File

@@ -24,6 +24,7 @@
extern "C" { extern "C" {
#include <86box/86box.h> #include <86box/86box.h>
#include <86box/plat.h>
} }
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
@@ -41,7 +42,7 @@ StyleOverride::styleHint(
QStyleHintReturn *returnData) const QStyleHintReturn *returnData) const
{ {
/* Disable using menu with alt key */ /* Disable using menu with alt key */
if (!vmm_enabled && (hint == QStyle::SH_MenuBar_AltKeyNavigation)) if (!vmm_enabled && (!kbd_req_capture || mouse_capture) && (hint == QStyle::SH_MenuBar_AltKeyNavigation))
return 0; return 0;
return QProxyStyle::styleHint(hint, option, widget, returnData); return QProxyStyle::styleHint(hint, option, widget, returnData);