Mirror of obs-studio-wayland which has been taken down from the AUR for whatever reason
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.9 KiB

  1. From ee7de65649ce502b68cd0b2a1da8cf15f016cc0d Mon Sep 17 00:00:00 2001
  2. From: Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
  3. Date: Mon, 9 Mar 2020 21:23:37 -0300
  4. Subject: [PATCH 14/25] UI: Retrieve Wayland surface from QWindow
  5. On Wayland, we want to query the window's underlying
  6. platform for the Wayland surface, instead of foolishly
  7. retrieving the X11 display.
  8. Pass QWindow instead of WId directly, and set the surface
  9. as the platform data on Wayland systems.
  10. ---
  11. UI/qt-display.cpp | 2 +-
  12. UI/qt-wrappers.cpp | 28 +++++++++++++++++++++++-----
  13. UI/qt-wrappers.hpp | 3 ++-
  14. 3 files changed, 26 insertions(+), 7 deletions(-)
  15. diff --git a/UI/qt-display.cpp b/UI/qt-display.cpp
  16. index 1bb97c7b..685ee6f9 100644
  17. --- a/UI/qt-display.cpp
  18. +++ b/UI/qt-display.cpp
  19. @@ -89,7 +89,7 @@ void OBSQTDisplay::CreateDisplay()
  20. info.format = GS_BGRA;
  21. info.zsformat = GS_ZS_NONE;
  22. - QTToGSWindow(winId(), info.window);
  23. + QTToGSWindow(windowHandle(), info.window);
  24. display = obs_display_create(&info, backgroundColor);
  25. diff --git a/UI/qt-wrappers.cpp b/UI/qt-wrappers.cpp
  26. index b9d00a78..040d1bb6 100644
  27. --- a/UI/qt-wrappers.cpp
  28. +++ b/UI/qt-wrappers.cpp
  29. @@ -28,9 +28,14 @@
  30. #include <QFileDialog>
  31. #if !defined(_WIN32) && !defined(__APPLE__)
  32. +#include <obs-nix-platform.h>
  33. #include <QX11Info>
  34. #endif
  35. +#ifdef ENABLE_WAYLAND
  36. +#include <qpa/qplatformnativeinterface.h>
  37. +#endif
  38. +
  39. static inline void OBSErrorBoxva(QWidget *parent, const char *msg, va_list args)
  40. {
  41. char full_message[4096];
  42. @@ -106,15 +111,28 @@ void OBSMessageBox::critical(QWidget *parent, const QString &title,
  43. mb.exec();
  44. }
  45. -void QTToGSWindow(WId windowId, gs_window &gswindow)
  46. +void QTToGSWindow(QWindow *window, gs_window &gswindow)
  47. {
  48. #ifdef _WIN32
  49. - gswindow.hwnd = (HWND)windowId;
  50. + gswindow.hwnd = (HWND)window->winId();
  51. #elif __APPLE__
  52. - gswindow.view = (id)windowId;
  53. + gswindow.view = (id)window->winId();
  54. #else
  55. - gswindow.id = windowId;
  56. - gswindow.display = QX11Info::display();
  57. + switch (obs_get_nix_platform()) {
  58. + case OBS_NIX_PLATFORM_X11_GLX:
  59. + case OBS_NIX_PLATFORM_X11_EGL:
  60. + gswindow.id = window->winId();
  61. + gswindow.display = obs_get_nix_platform_display();
  62. + break;
  63. +#ifdef ENABLE_WAYLAND
  64. + case OBS_NIX_PLATFORM_WAYLAND:
  65. + QPlatformNativeInterface *native =
  66. + QGuiApplication::platformNativeInterface();
  67. + gswindow.display =
  68. + native->nativeResourceForWindow("surface", window);
  69. + break;
  70. +#endif
  71. + }
  72. #endif
  73. }
  74. diff --git a/UI/qt-wrappers.hpp b/UI/qt-wrappers.hpp
  75. index 71b11354..51c4f937 100644
  76. --- a/UI/qt-wrappers.hpp
  77. +++ b/UI/qt-wrappers.hpp
  78. @@ -20,6 +20,7 @@
  79. #include <QApplication>
  80. #include <QMessageBox>
  81. #include <QWidget>
  82. +#include <QWindow>
  83. #include <QThread>
  84. #include <obs.hpp>
  85. @@ -55,7 +56,7 @@ public:
  86. void OBSErrorBox(QWidget *parent, const char *msg, ...);
  87. -void QTToGSWindow(WId windowId, gs_window &gswindow);
  88. +void QTToGSWindow(QWindow *window, gs_window &gswindow);
  89. uint32_t TranslateQtKeyboardEventModifiers(Qt::KeyboardModifiers mods);
  90. --
  91. 2.28.0