Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/mixxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ MixxxMainWindow::MixxxMainWindow(QApplication* pApp, const CmdlineArgs& args)
mixxx::Translations::initializeTranslations(
m_pSettingsManager->settings(), pApp, args.getLocale());

#ifdef __LINUX__
// If the desktop features a global menubar and we'll go fullscreen during
// startup, set Qt::AA_DontUseNativeMenuBar so the menubar is placed in the
// window like it's done in slotViewFullScreen(). On other desktops this
// attribute has no effect. This is a safe alternative to setNativeMenuBar()
// which can cause a crash when using menu shortcuts like Alt+F after resetting
// the menubar. See https://github.com/mixxxdj/mixxx/issues/11320
bool fullscreenPref = m_pSettingsManager->settings()->getValue<bool>(
ConfigKey("[Config]", "StartInFullscreen"));
QApplication::setAttribute(
Qt::AA_DontUseNativeMenuBar,
args.getStartInFullscreen() || fullscreenPref);
#endif // __LINUX__
Copy link
Copy Markdown
Member

@ronso0 ronso0 Mar 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for future improvements:
it looks like this attribute is the only way to figure whether a platform uses native menus, so let's note the initial state before setting it. That way we could restrict recreating and reconnecting the menu to platforms that actually require/support it.

createMenuBar();
m_pMenuBar->hide();

Expand Down Expand Up @@ -265,13 +278,6 @@ void MixxxMainWindow::initialize(QApplication* pApp, const CmdlineArgs& args) {
ConfigKey("[Config]", "StartInFullscreen"));
if (args.getStartInFullscreen() || fullscreenPref) {
showFullScreen();
#ifdef __LINUX__
// If the desktop features a global menubar and we go fullscreen during
// startup, move the menubar to the window like in slotViewFullScreen()
if (m_pMenuBar->isNativeMenuBar()) {
m_pMenuBar->setNativeMenuBar(false);
}
#endif
}

QString resourcePath = pConfig->getResourcePath();
Expand Down Expand Up @@ -1435,17 +1441,18 @@ void MixxxMainWindow::slotViewFullScreen(bool toggle) {
if (toggle) {
showFullScreen();
#ifdef __LINUX__
// Fix for "No menu bar with ubuntu unity in full screen mode" Bug
// #885890 and Bug #1076789. Before touching anything here, please read
// Fix for "No menu bar with ubuntu unity in full screen mode" (issues
// #885890 and #1076789. Before touching anything here, please read
// those bugs.
// Set this attribute instead of calling setNativeMenuBar(false), see
// https://github.com/mixxxdj/mixxx/issues/11320
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
Copy link
Copy Markdown
Member

@ronso0 ronso0 Mar 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my tests I did exactly that (just at the beginning of createMenuBar() depending on isFullScreen(), not directly before the call) and I did set it in main.cpp, not in mixxx.cpp.

So I wonder how that makes the difference...
Anyway, crash fixed!

createMenuBar();
connectMenuBar();
if (m_pMenuBar->isNativeMenuBar()) {
m_pMenuBar->setNativeMenuBar(false);
}
#endif
} else {
#ifdef __LINUX__
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, false);
createMenuBar();
connectMenuBar();
#endif
Expand Down