From fa1fab994e76c19a08903e9b641732ce388a30bd Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 2 Apr 2025 21:38:54 +0300 Subject: [PATCH] dbusmenu: Skip registration with the registrar on Wayland The RegisterWindow request expects a window id. The QDBusMenuBar uses the QWindow::winId() property for that. On X11, the winId() returns the XID of the window. On Wayland, the winId() returns an integer that has meaning only to the application, there are no global window ids on Wayland. The menubar should be registered using other means, for example using the kde-appmenu protocol, which QtWayland already does. The QDBusMenuBar can skip synchronously calling the RegisterWindow request on Wayland because the menu will be registered using a different api. Pick-to: 6.9 Change-Id: I6b2968624c5c9ddbdc93807f65eac369dc7a993a Reviewed-by: David Edmundson Reviewed-by: Liang Qi --- .../platform/unix/dbusmenu/qdbusmenubar.cpp | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/gui/platform/unix/dbusmenu/qdbusmenubar.cpp b/src/gui/platform/unix/dbusmenu/qdbusmenubar.cpp index 6fa0e8b36af..153dedf54ac 100644 --- a/src/gui/platform/unix/dbusmenu/qdbusmenubar.cpp +++ b/src/gui/platform/unix/dbusmenu/qdbusmenubar.cpp @@ -118,15 +118,18 @@ void QDBusMenuBar::registerMenuBar() if (!connection.registerObject(m_objectPath, m_menu)) return; - QDBusMenuRegistrarInterface registrar(REGISTRAR_SERVICE, REGISTRAR_PATH, connection, this); - QDBusPendingReply<> r = registrar.RegisterWindow(m_window->winId(), QDBusObjectPath(m_objectPath)); - r.waitForFinished(); - if (r.isError()) { - qWarning("Failed to register window menu, reason: %s (\"%s\")", - qUtf8Printable(r.error().name()), qUtf8Printable(r.error().message())); - connection.unregisterObject(m_objectPath); - return; + if (QGuiApplication::platformName() == "xcb"_L1) { + QDBusMenuRegistrarInterface registrar(REGISTRAR_SERVICE, REGISTRAR_PATH, connection, this); + QDBusPendingReply<> r = registrar.RegisterWindow(m_window->winId(), QDBusObjectPath(m_objectPath)); + r.waitForFinished(); + if (r.isError()) { + qWarning("Failed to register window menu, reason: %s (\"%s\")", + qUtf8Printable(r.error().name()), qUtf8Printable(r.error().message())); + connection.unregisterObject(m_objectPath); + return; + } } + const auto unixServices = dynamic_cast( QGuiApplicationPrivate::platformIntegration()->services()); unixServices->registerDBusMenuForWindow(m_window, connection.baseService(), m_objectPath); @@ -137,12 +140,14 @@ void QDBusMenuBar::unregisterMenuBar() QDBusConnection connection = QDBusConnection::sessionBus(); if (m_window) { - QDBusMenuRegistrarInterface registrar(REGISTRAR_SERVICE, REGISTRAR_PATH, connection, this); - QDBusPendingReply<> r = registrar.UnregisterWindow(m_window->winId()); - r.waitForFinished(); - if (r.isError()) - qWarning("Failed to unregister window menu, reason: %s (\"%s\")", - qUtf8Printable(r.error().name()), qUtf8Printable(r.error().message())); + if (QGuiApplication::platformName() == "xcb"_L1) { + QDBusMenuRegistrarInterface registrar(REGISTRAR_SERVICE, REGISTRAR_PATH, connection, this); + QDBusPendingReply<> r = registrar.UnregisterWindow(m_window->winId()); + r.waitForFinished(); + if (r.isError()) + qWarning("Failed to unregister window menu, reason: %s (\"%s\")", + qUtf8Printable(r.error().name()), qUtf8Printable(r.error().message())); + } const auto unixServices = dynamic_cast( QGuiApplicationPrivate::platformIntegration()->services());