Skip to content

Commit

Permalink
UI: Retrieve Wayland surface from QWindow
Browse files Browse the repository at this point in the history
On Wayland, we want to query the window's underlying
platform for the Wayland surface, instead of foolishly
retrieving the X11 display.
  • Loading branch information
GeorgesStavracas committed Mar 13, 2020
1 parent e99dec3 commit ddaed2c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion UI/qt-display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
23 changes: 20 additions & 3 deletions UI/qt-wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@

#if !defined(_WIN32) && !defined(__APPLE__)
#include <QX11Info>

#ifdef ENABLE_WAYLAND
#include <qpa/qplatformnativeinterface.h>
#endif

#endif

static inline void OBSErrorBoxva(QWidget *parent, const char *msg, va_list args)
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion UI/qt-wrappers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit ddaed2c

Please sign in to comment.