Commit 0f3fd179 authored by David Edmundson's avatar David Edmundson

Port plasma-integration to explicit wayland AppMenu protocol

Summary:
Also fixed to handle the case of surfaces not having the lifespan of the
window, which the old code didn't handle.

I don't think it's worth trying to handle the case of different versions
of kwin and plasma-integration.

Test Plan: Made relevant kwin change and it gets communicated fine

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D9248
parent 9211b2b7
......@@ -60,9 +60,6 @@
static const QByteArray s_x11AppMenuServiceNamePropertyName = QByteArrayLiteral("_KDE_NET_WM_APPMENU_SERVICE_NAME");
static const QByteArray s_x11AppMenuObjectPathPropertyName = QByteArrayLiteral("_KDE_NET_WM_APPMENU_OBJECT_PATH");
static const QByteArray s_waylandAppMenuServiceNamePropertyName = QByteArrayLiteral("KDE_APPMENU_SERVICE_NAME");
static const QByteArray s_waylandAppMenuObjectPathPropertyName = QByteArrayLiteral("KDE_APPMENU_OBJECT_PATH");
static bool checkDBusGlobalMenuAvailable()
{
if (qEnvironmentVariableIsSet("KDE_NO_GLOBAL_MENU")) {
......@@ -374,13 +371,11 @@ QPlatformMenuBar *KdePlatformTheme::createPlatformMenuBar() const
if (m_kwaylandIntegration) {
if (oldWindow) {
m_kwaylandIntegration->setWindowProperty(oldWindow, s_waylandAppMenuServiceNamePropertyName, {});
m_kwaylandIntegration->setWindowProperty(oldWindow, s_waylandAppMenuObjectPathPropertyName, {});
m_kwaylandIntegration->setAppMenu(QString(), QString());
}
if (newWindow) {
m_kwaylandIntegration->setWindowProperty(newWindow, s_waylandAppMenuServiceNamePropertyName, serviceName.toUtf8());
m_kwaylandIntegration->setWindowProperty(newWindow, s_waylandAppMenuObjectPathPropertyName, objectPath.toUtf8());
m_kwaylandIntegration->setAppMenu(serviceName, objectPath);
}
}
});
......
......@@ -29,6 +29,7 @@
#include <KWayland/Client/registry.h>
#include <KWayland/Client/surface.h>
#include <KWayland/Client/server_decoration.h>
#include <KWayland/Client/appmenu.h>
#include <KWindowEffects>
using namespace KWayland::Client;
......@@ -59,6 +60,11 @@ void KWaylandIntegration::init()
m_decoration = registry->createServerSideDecorationManager(interface.name, interface.version, this);
qputenv("QT_WAYLAND_DISABLE_WINDOWDECORATION", "1");
QCoreApplication::instance()->installEventFilter(this);
}
const auto menuInterface = registry->interface(Registry::Interface::AppMenu);
if (menuInterface.name != 0) {
m_appMenuManager = registry->createAppMenuManager(menuInterface.name, menuInterface.version, this);
}
}
);
......@@ -130,12 +136,21 @@ void KWaylandIntegration::shellSurfaceCreated(QWindow *w)
deco->requestMode(ourMode);
}
w->setProperty("org.kde.plasma.integration.waylandserverdecoration", QVariant::fromValue(deco));
if (m_appMenuManager) {
auto menu = m_appMenuManager->create(s, w);
w->setProperty("org.kde.plasma.integration.appmenu", QVariant::fromValue(menu));
menu->setAddress(m_appMenuServiceName, m_appMenuObjectPath);
}
}
void KWaylandIntegration::shellSurfaceDestroyed(QWindow *w)
{
delete w->property("org.kde.plasma.integration.waylandserverdecoration").value<ServerSideDecoration*>();
w->setProperty("org.kde.plasma.integration.waylandserverdecoration", QVariant());
delete w->property("org.kde.plasma.integration.appmenu").value<AppMenu*>();
w->setProperty("org.kde.plasma.integration.appmenu", QVariant());
}
void KWaylandIntegration::installColorScheme(QWindow *w)
......@@ -156,4 +171,14 @@ void KWaylandIntegration::setWindowProperty(QWindow *window, const QByteArray &n
}
}
void KWaylandIntegration::setAppMenu(const QString &serviceName, const QString &objectPath)
{
m_appMenuServiceName = serviceName;
m_appMenuObjectPath = objectPath;
auto menu = property("org.kde.plasma.integration.appmenu").value<AppMenu*>();
if (menu) {
menu->setAddress(serviceName, objectPath);
}
}
#include "kwaylandintegration.moc"
......@@ -29,6 +29,7 @@ namespace KWayland
namespace Client
{
class ServerSideDecorationManager;
class AppMenuManager;
}
}
......@@ -41,6 +42,7 @@ public:
void init();
void setWindowProperty(QWindow *window, const QByteArray &name, const QByteArray &value);
void setAppMenu(const QString &serviceName, const QString &objectPath);
bool eventFilter(QObject *watched, QEvent *event) override;
......@@ -49,7 +51,11 @@ private:
void shellSurfaceDestroyed(QWindow *w);
void installColorScheme(QWindow *w);
KWayland::Client::ServerSideDecorationManager *m_decoration;
KWayland::Client::ServerSideDecorationManager *m_decoration = nullptr;
KWayland::Client::AppMenuManager *m_appMenuManager = nullptr;
QString m_appMenuServiceName;
QString m_appMenuObjectPath;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment