Skip to content

Commit

Permalink
fullscreen: rebuild & reconnect menu only on desktops with global menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Mar 12, 2023
1 parent 572cee8 commit 84264c6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/mixxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@
#endif

#if defined(Q_OS_LINUX)
#include <QtX11Extras/QX11Info>
#include <X11/Xlib.h>
#include <X11/Xlibint.h>

#include <QtDBus>
#include <QtX11Extras/QX11Info>
// Xlibint.h predates C++ and defines macros which conflict
// with references to std::max and std::min
#undef max
Expand Down Expand Up @@ -135,6 +137,13 @@ inline QLocale inputLocale() {
QLocale(QLocale::English);
}

#ifdef __LINUX__
inline bool supportsGlobalMenu() {
QDBusConnection conn = QDBusConnection::sessionBus();
return conn.interface()->isServiceRegistered("com.canonical.AppMenu.Registrar");
}
#endif

} // anonymous namespace

// static
Expand All @@ -161,6 +170,9 @@ MixxxMainWindow::MixxxMainWindow(QApplication* pApp, const CmdlineArgs& args)
#endif
m_pKeyboard(nullptr),
m_pLibrary(nullptr),
#ifdef __LINUX__
m_supportsNativeMenuBar(supportsGlobalMenu()),
#endif
m_pDeveloperToolsDlg(nullptr),
m_pPrefDlg(nullptr),
m_pKbdConfig(nullptr),
Expand Down Expand Up @@ -224,11 +236,13 @@ MixxxMainWindow::MixxxMainWindow(QApplication* pApp, const CmdlineArgs& args)
// 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);
if (m_supportsNativeMenuBar) {
bool fullscreenPref = m_pSettingsManager->settings()->getValue<bool>(
ConfigKey("[Config]", "StartInFullscreen"));
QApplication::setAttribute(
Qt::AA_DontUseNativeMenuBar,
args.getStartInFullscreen() || fullscreenPref);
}
#endif // __LINUX__
createMenuBar();
m_pMenuBar->hide();
Expand Down Expand Up @@ -1446,15 +1460,19 @@ void MixxxMainWindow::slotViewFullScreen(bool toggle) {
// those bugs.
// Set this attribute instead of calling setNativeMenuBar(false), see
// https://github.com/mixxxdj/mixxx/issues/11320
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
createMenuBar();
connectMenuBar();
if (m_supportsNativeMenuBar) {
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
createMenuBar();
connectMenuBar();
}
#endif
} else {
#ifdef __LINUX__
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, false);
createMenuBar();
connectMenuBar();
if (m_supportsNativeMenuBar) {
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, false);
createMenuBar();
connectMenuBar();
}
#endif
showNormal();
}
Expand Down
3 changes: 3 additions & 0 deletions src/mixxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ class MixxxMainWindow : public QMainWindow {
Library* m_pLibrary;

parented_ptr<WMainMenuBar> m_pMenuBar;
#ifdef __LINUX__
const bool m_supportsNativeMenuBar;
#endif

DlgDeveloperTools* m_pDeveloperToolsDlg;

Expand Down

0 comments on commit 84264c6

Please sign in to comment.