From a31e938c2b0ab4dc4183f5e1ab86e1f6b359878c Mon Sep 17 00:00:00 2001
From: BtbN <btbn@btbn.de>
Date: Thu, 3 Apr 2014 23:41:22 +0200
Subject: [PATCH] Fix getting the X11 display with the Qt ui

---
 libobs-opengl/gl-x11.c | 7 +------
 obs/CMakeLists.txt     | 7 ++++++-
 obs/qt-wrappers.cpp    | 5 +++++
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/libobs-opengl/gl-x11.c b/libobs-opengl/gl-x11.c
index 042f87d5f..f82adf619 100644
--- a/libobs-opengl/gl-x11.c
+++ b/libobs-opengl/gl-x11.c
@@ -59,12 +59,7 @@ extern struct gl_windowinfo *gl_windowinfo_create(struct gs_init_data *info)
 {
 	struct gl_windowinfo *wi = bzalloc(sizeof(struct gl_windowinfo));
 	wi->id = info->window.id;
-	/* wi->display = info->window.display; */
-
-	/*
-		The above no longer works with Qt.
-		Let's hope it continues to work.
-	*/
+	wi->display = info->window.display;
 
 	return wi;
 }
diff --git a/obs/CMakeLists.txt b/obs/CMakeLists.txt
index 00a25a7c1..1b71cb0ca 100644
--- a/obs/CMakeLists.txt
+++ b/obs/CMakeLists.txt
@@ -31,6 +31,8 @@ elseif(APPLE)
 
 	add_definitions(-fobjc-arc)
 elseif(UNIX)
+        find_package(Qt5X11Extras REQUIRED)
+
 	set(obs_PLATFORM_SOURCES
 		platform-x11.cpp)
 
@@ -44,6 +46,9 @@ elseif(UNIX)
 	set(obs_PLATFORM_LIBRARIES
 		${X11_LIBRARIES}
 		${X11_Xinerama_LIB})
+
+        set(obs_PLATFORM_QT_MODULES
+                X11Extras)
 endif()
 
 set(obs_SOURCES
@@ -87,7 +92,7 @@ add_executable(obs WIN32
 	${obs_UI_HEADERS}
 	${obs_QRC_SOURCES})
 
-qt5_use_modules(obs Widgets)
+qt5_use_modules(obs Widgets ${obs_PLATFORM_QT_MODULES})
 
 if(WIN32)
 	if(CMAKE_SIZEOF_VOID_P EQUAL 8)
diff --git a/obs/qt-wrappers.cpp b/obs/qt-wrappers.cpp
index 525c9b16b..bd20bfe93 100644
--- a/obs/qt-wrappers.cpp
+++ b/obs/qt-wrappers.cpp
@@ -20,6 +20,10 @@
 #include <QWidget>
 #include <QMessageBox>
 
+#if !defined(_WIN32) && !defined(__APPLE__)
+#include <QX11Info>
+#endif
+
 static inline void OBSErrorBoxva(QWidget *parent, const char *msg, va_list args)
 {
 	char full_message[4096];
@@ -44,5 +48,6 @@ void QTToGSWindow(WId windowId, gs_window &gswindow)
 	gswindow.view = (id)windowId;
 #else
 	gswindow.id = windowId;
+	gswindow.display = QX11Info::display();
 #endif
 }
-- 
GitLab