From ddaed2cf0e5af7f05f17a588a8409d8f42fb6668 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Mon, 9 Mar 2020 21:23:37 -0300 Subject: [PATCH] UI: Retrieve Wayland surface from QWindow On Wayland, we want to query the window's underlying platform for the Wayland surface, instead of foolishly retrieving the X11 display. --- UI/qt-display.cpp | 2 +- UI/qt-wrappers.cpp | 23 ++++++++++++++++++++--- UI/qt-wrappers.hpp | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/UI/qt-display.cpp b/UI/qt-display.cpp index 1bb97c7baef6b6..21a3137e2f69fb 100644 --- a/UI/qt-display.cpp +++ b/UI/qt-display.cpp @@ -89,7 +89,7 @@ void OBSQTDisplay::CreateDisplay() info.format = GS_BGRA; info.zsformat = GS_ZS_NONE; - QTToGSWindow(winId(), info.window); + QTToGSWindow(windowHandle(), winId(), info.window); display = obs_display_create(&info, backgroundColor); diff --git a/UI/qt-wrappers.cpp b/UI/qt-wrappers.cpp index 5e285ac47d56d2..2280cd9f08fa44 100644 --- a/UI/qt-wrappers.cpp +++ b/UI/qt-wrappers.cpp @@ -28,6 +28,11 @@ #if !defined(_WIN32) && !defined(__APPLE__) #include + +#ifdef ENABLE_WAYLAND +#include +#endif + #endif static inline void OBSErrorBoxva(QWidget *parent, const char *msg, va_list args) @@ -105,15 +110,27 @@ void OBSMessageBox::critical(QWidget *parent, const QString &title, mb.exec(); } -void QTToGSWindow(WId windowId, gs_window &gswindow) +void QTToGSWindow(QWindow *window, WId windowId, gs_window &gswindow) { #ifdef _WIN32 gswindow.hwnd = (HWND)windowId; #elif __APPLE__ gswindow.view = (id)windowId; #else - gswindow.id = windowId; - gswindow.surface = QX11Info::display(); + switch (obs_get_platform()) { + case OBS_PLATFORM_DEFAULT: + gswindow.id = windowId; + gswindow.surface = QX11Info::display(); + break; +#ifdef ENABLE_WAYLAND + case OBS_PLATFORM_WAYLAND: + QPlatformNativeInterface *native = + QGuiApplication::platformNativeInterface(); + gswindow.surface = + native->nativeResourceForWindow("surface", window); + break; +#endif + } #endif } diff --git a/UI/qt-wrappers.hpp b/UI/qt-wrappers.hpp index 69996deb200442..f01b0251454cfe 100644 --- a/UI/qt-wrappers.hpp +++ b/UI/qt-wrappers.hpp @@ -55,7 +55,7 @@ class OBSMessageBox { void OBSErrorBox(QWidget *parent, const char *msg, ...); -void QTToGSWindow(WId windowId, gs_window &gswindow); +void QTToGSWindow(QWindow *window, WId windowId, gs_window &gswindow); uint32_t TranslateQtKeyboardEventModifiers(Qt::KeyboardModifiers mods);