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.

Change-Id: I6b2968624c5c9ddbdc93807f65eac369dc7a993a
Reviewed-by: David Edmundson <davidedmundson@kde.org>
Reviewed-by: Liang Qi <liang.qi@qt.io>
(cherry picked from commit fa1fab994e76c19a08903e9b641732ce388a30bd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Vlad Zahorodnii 2025-04-02 21:38:54 +03:00 committed by Qt Cherry-pick Bot
parent 6276f26bda
commit a47b7c285d

View File

@ -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<QDesktopUnixServices *>(
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<QDesktopUnixServices *>(
QGuiApplicationPrivate::platformIntegration()->services());