Fix menubar toggle to react only on Alt

This commit is contained in:
xboxones1 2026-02-12 14:48:38 +00:00
parent 5bd42c4725
commit 330e78a3fc
2 changed files with 15 additions and 1 deletions

View file

@ -2270,8 +2270,21 @@ bool MainWindowEventFilter::eventFilter(QObject* watched, QEvent* event)
}
}
#endif
} else if (eventType == QEvent::KeyPress) {
auto keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Alt) {
m_altKeyAlone = (keyEvent->modifiers() == Qt::AltModifier);
} else {
m_altKeyAlone = false;
}
return QObject::eventFilter(watched, event);
} else if (eventType == QEvent::KeyRelease && watched == mainWindow) {
auto keyEvent = dynamic_cast<QKeyEvent*>(event);
if (keyEvent->key() != Qt::Key_Alt) {
m_altKeyAlone = false;
return QObject::eventFilter(watched, event);
}
#ifdef Q_OS_WIN
// Windows translates AltGr into CTRL + ALT, this breaks using AltGr when the menubar is hidden
// Prevent this by activating the ALT cooldown to ignore the next key event which will be an ALT key
@ -2281,7 +2294,7 @@ bool MainWindowEventFilter::eventFilter(QObject* watched, QEvent* event)
return false;
}
#endif
if (keyEvent->key() == Qt::Key_Alt && !keyEvent->modifiers() && config()->get(Config::GUI_HideMenubar).toBool()
if (keyEvent->key() == Qt::Key_Alt && m_altKeyAlone && config()->get(Config::GUI_HideMenubar).toBool()
&& !m_altCoolDown.isActive()) {
auto menubar = mainWindow->m_ui->menubar;
menubar->setMaximumHeight(menubar->maximumHeight() > 0 ? 0 : QWIDGETSIZE_MAX);

View file

@ -220,6 +220,7 @@ public:
private:
QTimer m_menubarTimer;
QTimer m_altCoolDown;
bool m_altKeyAlone = false;
};
/**