summarylogtreecommitdiffstats
path: root/0020-UI-Check-for-Expose-and-PlatformSurface-events-to-cr.patch
blob: c9cb4391674535ec402998a64c9a309d73784869 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
From 8a8757b4b6ce1e74d68c9fe6a3f31fad906c0fe7 Mon Sep 17 00:00:00 2001
From: Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
Date: Thu, 20 Aug 2020 11:58:45 -0300
Subject: [PATCH 20/25] UI: Check for Expose and PlatformSurface events to
 create display

This is a workaround for QWaylandWindow never becoming exposed, or
receiving the QEvent::Expose [1].

[1] https://bugreports.qt.io/browse/QTBUG-86176
---
 UI/qt-display.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/UI/qt-display.cpp b/UI/qt-display.cpp
index b230ab4e..5d81c463 100644
--- a/UI/qt-display.cpp
+++ b/UI/qt-display.cpp
@@ -10,6 +10,56 @@
 
 #ifdef ENABLE_WAYLAND
 #include <obs-nix-platform.h>
+
+class SurfaceEventFilter : public QObject {
+	OBSQTDisplay *display;
+	int mTimerId;
+
+public:
+	SurfaceEventFilter(OBSQTDisplay *src) : display(src), mTimerId(0) {}
+
+protected:
+	bool eventFilter(QObject *obj, QEvent *event) override
+	{
+		bool result = QObject::eventFilter(obj, event);
+		QPlatformSurfaceEvent *surfaceEvent;
+
+		switch (event->type()) {
+		case QEvent::PlatformSurface:
+			surfaceEvent =
+				static_cast<QPlatformSurfaceEvent *>(event);
+			if (surfaceEvent->surfaceEventType() !=
+			    QPlatformSurfaceEvent::SurfaceCreated)
+				return result;
+
+			if (display->windowHandle()->isExposed())
+				createOBSDisplay();
+			else
+				mTimerId = startTimer(67); // Arbitrary
+			break;
+		case QEvent::Expose:
+			createOBSDisplay();
+			break;
+		default:
+			break;
+		}
+
+		return result;
+	}
+
+	void timerEvent(QTimerEvent *) { createOBSDisplay(true); }
+
+private:
+	void createOBSDisplay(bool force = false)
+	{
+		display->CreateDisplay(force);
+		if (mTimerId > 0) {
+			killTimer(mTimerId);
+			mTimerId = 0;
+		}
+	}
+};
+
 #endif
 
 static inline long long color_to_int(const QColor &color)
@@ -65,6 +115,12 @@ OBSQTDisplay::OBSQTDisplay(QWidget *parent, Qt::WindowFlags flags)
 
 	connect(windowHandle(), &QWindow::visibleChanged, windowVisible);
 	connect(windowHandle(), &QWindow::screenChanged, screenChanged);
+
+#ifdef ENABLE_WAYLAND
+	if (obs_get_nix_platform() == OBS_NIX_PLATFORM_WAYLAND)
+		windowHandle()->installEventFilter(
+			new SurfaceEventFilter(this));
+#endif
 }
 
 QColor OBSQTDisplay::GetDisplayBackgroundColor() const
-- 
2.28.0