Skip to content

Truly independent web browser

UI/Qt: Resolve the Wayland interface revision for the Qt runtime

Timothy Flynn0d6681be5a0f
diff --git a/UI/Qt/ExternalURLActivationToken.cpp b/UI/Qt/ExternalURLActivationToken.cpp
index d918843e553..43f4b69478f 100644
--- a/UI/Qt/ExternalURLActivationToken.cpp
+++ b/UI/Qt/ExternalURLActivationToken.cpp
@@ -95,7 +95,7 @@ void request_external_url_activation_token([[maybe_unused]] StringView desktop_i
auto* surface = window ? wayland_surface_for_window(*window) : nullptr;
if (surface) {
- auto* wayland = application->nativeInterface<QNativeInterface::QWaylandApplication>();
+ auto* wayland = wayland_application();
if (auto* activation = wayland_activation()) {
auto* token = xdg_activation_v1_get_activation_token(activation);
diff --git a/UI/Qt/WaylandPageSurface.cpp b/UI/Qt/WaylandPageSurface.cpp
index 4fa17f7f5df..4c401dfeadf 100644
--- a/UI/Qt/WaylandPageSurface.cpp
+++ b/UI/Qt/WaylandPageSurface.cpp
@@ -45,13 +45,17 @@ static u32 opaque_drm_format(u32 drm_format)
OwnPtr<WaylandPageSurface> WaylandPageSurface::create()
{
static Optional<Globals> const globals = []() -> Optional<Globals> {
- auto* wayland_application = qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>();
+ auto* application = wayland_application();
+ auto* compositor = application ? application->compositor() : nullptr;
+ if (!compositor)
+ return {};
+
auto registry = WaylandRegistry::create();
- if (!registry || !wayland_application->compositor())
+ if (!registry)
return {};
Globals globals {
- .compositor = wayland_application->compositor(),
+ .compositor = compositor,
.subcompositor = registry->bind<wl_subcompositor>(wl_subcompositor_interface, 1),
.viewporter = registry->bind<wp_viewporter>(wp_viewporter_interface, 1),
.dmabuf = registry->bind<zwp_linux_dmabuf_v1>(zwp_linux_dmabuf_v1_interface, 3),
diff --git a/UI/Qt/WaylandRegistry.cpp b/UI/Qt/WaylandRegistry.cpp
index 99f33b6fdef..cb0def75adb 100644
--- a/UI/Qt/WaylandRegistry.cpp
+++ b/UI/Qt/WaylandRegistry.cpp
@@ -5,6 +5,7 @@
*/
#include <UI/Qt/WaylandRegistry.h>
+#include <UI/Qt/WaylandWindow.h>
#include <QGuiApplication>
@@ -14,10 +15,11 @@ namespace Ladybird {
OwnPtr<WaylandRegistry> WaylandRegistry::create()
{
- auto* wayland_application = qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>();
- if (!wayland_application || !wayland_application->display())
+ auto* application = wayland_application();
+ auto* display = application ? application->display() : nullptr;
+ if (!display)
return nullptr;
- return adopt_own(*new WaylandRegistry(wayland_application->display()));
+ return adopt_own(*new WaylandRegistry(display));
}
WaylandRegistry::WaylandRegistry(wl_display* display)
diff --git a/UI/Qt/WaylandWindow.cpp b/UI/Qt/WaylandWindow.cpp
index 5a6e905ebc6..9954711367b 100644
--- a/UI/Qt/WaylandWindow.cpp
+++ b/UI/Qt/WaylandWindow.cpp
@@ -7,6 +7,7 @@
#include <UI/Qt/WaylandWindow.h>
#include <QGuiApplication>
+#include <QLibraryInfo>
#include <QWindow>
#include <string.h>
@@ -14,9 +15,27 @@
namespace Ladybird {
+#if QT_VERSION < QT_VERSION_CHECK(6, 11, 0)
+struct WaylandApplicationRevision2 : QNativeInterface::Private::TypeInfo<QNativeInterface::QWaylandApplication> {
+ static constexpr int revision() { return 2; }
+};
+#endif
+
+QNativeInterface::QWaylandApplication* wayland_application()
+{
+#if QT_VERSION < QT_VERSION_CHECK(6, 11, 0)
+ // Qt 6.11 appended xkbContext() to the interface and bumped the revision. The virtual methods used here retain
+ // their layout, so a build against Qt 6.10 can request revision 2 when it runs with the newer library.
+ static bool const use_revision_2 = QLibraryInfo::version() >= QVersionNumber(6, 11);
+ if (use_revision_2)
+ return qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication, WaylandApplicationRevision2>();
+#endif
+ return qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>();
+}
+
wl_surface* wayland_surface_for_window(QWindow const& window)
{
- if (!window.handle() || !qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>())
+ if (!window.handle() || !wayland_application())
return nullptr;
// Since Qt 6.10, the Wayland backend returns its wl_surface as the window ID.
@@ -26,12 +45,12 @@ wl_surface* wayland_surface_for_window(QWindow const& window)
bool wayland_compositor_moves_dragged_windows()
{
static bool const moves_dragged_windows = [] {
- auto* wayland_application = qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>();
- if (!wayland_application || !wayland_application->display())
+ auto* application = wayland_application();
+ auto* display = application ? application->display() : nullptr;
+ if (!display)
return false;
// NB: The globals are listed on a queue of our own, so that Qt's queue never sees our registry's events.
- auto* display = wayland_application->display();
auto* queue = wl_display_create_queue(display);
auto* display_on_queue = static_cast<wl_display*>(wl_proxy_create_wrapper(display));
wl_proxy_set_queue(reinterpret_cast<wl_proxy*>(display_on_queue), queue);
diff --git a/UI/Qt/WaylandWindow.h b/UI/Qt/WaylandWindow.h
index 4677c96c10e..0130d1789b5 100644
--- a/UI/Qt/WaylandWindow.h
+++ b/UI/Qt/WaylandWindow.h
@@ -9,8 +9,16 @@
class QWindow;
struct wl_surface;
+namespace QNativeInterface {
+
+struct QWaylandApplication;
+
+}
+
namespace Ladybird {
+QNativeInterface::QWaylandApplication* wayland_application();
+
// The surface of an existing native Wayland window. This does not create a platform window.
wl_surface* wayland_surface_for_window(QWindow const&);