From e734dfcb06fa1bc87917167f01faab99855a7217 Mon Sep 17 00:00:00 2001 From: reionwong Date: Thu, 10 Jun 2021 02:07:25 +0800 Subject: [PATCH] Support global menu --- platformtheme/platformtheme.cpp | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/platformtheme/platformtheme.cpp b/platformtheme/platformtheme.cpp index 59fb828..efaabe1 100644 --- a/platformtheme/platformtheme.cpp +++ b/platformtheme/platformtheme.cpp @@ -128,38 +128,38 @@ const QFont* PlatformTheme::font(Font type) const QPlatformMenuBar *PlatformTheme::createPlatformMenuBar() const { -// if (isDBusGlobalMenuAvailable()) { -// auto *menu = new QDBusMenuBar(); - -// QObject::connect(menu, &QDBusMenuBar::windowChanged, menu, [this, menu](QWindow *newWindow, QWindow *oldWindow) { -// const QString &serviceName = QDBusConnection::sessionBus().baseService(); -// const QString &objectPath = menu->objectPath(); - -// if (m_x11Integration) { + if (isDBusGlobalMenuAvailable()) { + auto *menu = new QDBusMenuBar(); + + QObject::connect(menu, &QDBusMenuBar::windowChanged, menu, [this, menu](QWindow *newWindow, QWindow *oldWindow) { + const QString &serviceName = QDBusConnection::sessionBus().baseService(); + const QString &objectPath = menu->objectPath(); + + if (m_x11Integration) { + if (oldWindow) { + m_x11Integration->setWindowProperty(oldWindow, s_x11AppMenuServiceNamePropertyName, {}); + m_x11Integration->setWindowProperty(oldWindow, s_x11AppMenuObjectPathPropertyName, {}); + } + + if (newWindow) { + m_x11Integration->setWindowProperty(newWindow, s_x11AppMenuServiceNamePropertyName, serviceName.toUtf8()); + m_x11Integration->setWindowProperty(newWindow, s_x11AppMenuObjectPathPropertyName, objectPath.toUtf8()); + } + } + +// if (m_kwaylandIntegration) { // if (oldWindow) { -// m_x11Integration->setWindowProperty(oldWindow, s_x11AppMenuServiceNamePropertyName, {}); -// m_x11Integration->setWindowProperty(oldWindow, s_x11AppMenuObjectPathPropertyName, {}); +// m_kwaylandIntegration->setAppMenu(oldWindow, QString(), QString()); // } - +// // if (newWindow) { -// m_x11Integration->setWindowProperty(newWindow, s_x11AppMenuServiceNamePropertyName, serviceName.toUtf8()); -// m_x11Integration->setWindowProperty(newWindow, s_x11AppMenuObjectPathPropertyName, objectPath.toUtf8()); +// m_kwaylandIntegration->setAppMenu(newWindow, serviceName, objectPath); // } // } + }); -// // if (m_kwaylandIntegration) { -// // if (oldWindow) { -// // m_kwaylandIntegration->setAppMenu(oldWindow, QString(), QString()); -// // } -// // -// // if (newWindow) { -// // m_kwaylandIntegration->setAppMenu(newWindow, serviceName, objectPath); -// // } -// // } -// }); - -// return menu; -// } + return menu; + } return nullptr; }