summarylogtreecommitdiffstats
path: root/0011-libobs-Add-a-Wayland-platform.patch
blob: 3a9d60da20bb8169ff30634bfce470840be82181 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
From eb2b38d24454b1fdd21cb8184a224cb9fa0579d3 Mon Sep 17 00:00:00 2001
From: Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
Date: Fri, 6 Mar 2020 18:53:42 -0300
Subject: [PATCH 11/25] libobs: Add a Wayland platform

Introduce the OBS_NIX_PLATFORM_WAYLAND enum value, and try to detect
it when OBS Studio runs by looking into the platform name.
---
 CMakeLists.txt                  |  2 +
 UI/CMakeLists.txt               |  5 ++
 UI/obs-app.cpp                  | 17 +++++++
 cmake/Modules/FindWayland.cmake | 78 +++++++++++++++++++++++++++++
 libobs-opengl/CMakeLists.txt    |  2 +-
 libobs-opengl/gl-nix.c          |  5 ++
 libobs/CMakeLists.txt           | 15 ++++++
 libobs/obs-nix-platform.h       |  4 ++
 libobs/obs-nix-wayland.c        | 88 +++++++++++++++++++++++++++++++++
 libobs/obs-nix-wayland.h        | 24 +++++++++
 libobs/obs-nix.c                | 14 ++++++
 libobs/obsconfig.h.in           |  2 +
 12 files changed, 255 insertions(+), 1 deletion(-)
 create mode 100644 cmake/Modules/FindWayland.cmake
 create mode 100644 libobs/obs-nix-wayland.c
 create mode 100644 libobs/obs-nix-wayland.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5bdfe21f..7828c65a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -205,6 +205,8 @@ if(APPLE)
 	list(APPEND CMAKE_INSTALL_RPATH "@loader_path/" "@executable_path/")
 elseif(UNIX)
 	option(USE_XDG "Utilize XDG Base Directory Specification" ON)
+	option(ENABLE_WAYLAND "Build support for Wayland" ON)
+
 	if(USE_XDG)
 		add_definitions(-DUSE_XDG)
 	endif()
diff --git a/UI/CMakeLists.txt b/UI/CMakeLists.txt
index df4d2645..ae689c95 100644
--- a/UI/CMakeLists.txt
+++ b/UI/CMakeLists.txt
@@ -408,6 +408,11 @@ if (APPLE)
 endif()
 set_target_properties(obs PROPERTIES FOLDER "frontend")
 
+if (ENABLE_WAYLAND)
+	find_package(Qt5Gui REQUIRED)
+	include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
+endif()
+
 define_graphic_modules(obs)
 
 install_obs_core(obs)
diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp
index 2a8de8d9..ce350f06 100644
--- a/UI/obs-app.cpp
+++ b/UI/obs-app.cpp
@@ -59,6 +59,11 @@
 #if !defined(_WIN32) && !defined(__APPLE__)
 #include <obs-nix-platform.h>
 #include <QX11Info>
+
+#ifdef ENABLE_WAYLAND
+#include <qpa/qplatformnativeinterface.h>
+#endif
+
 #endif
 
 #include <iostream>
@@ -1383,6 +1388,18 @@ bool OBSApp::OBSInit()
 		}
 		obs_set_nix_platform_display(QX11Info::display());
 	}
+
+#ifdef ENABLE_WAYLAND
+	if (QApplication::platformName().contains("wayland")) {
+		obs_set_nix_platform(OBS_NIX_PLATFORM_WAYLAND);
+		QPlatformNativeInterface *native =
+			QGuiApplication::platformNativeInterface();
+		obs_set_nix_platform_display(
+			native->nativeResourceForIntegration("display"));
+
+		blog(LOG_INFO, "Platform: Wayland");
+	}
+#endif
 #endif
 
 	if (!StartupOBS(locale.c_str(), GetProfilerNameStore()))
diff --git a/cmake/Modules/FindWayland.cmake b/cmake/Modules/FindWayland.cmake
new file mode 100644
index 00000000..377f0545
--- /dev/null
+++ b/cmake/Modules/FindWayland.cmake
@@ -0,0 +1,78 @@
+# Try to find Wayland on a Unix system
+#
+# This will define:
+#
+#   WAYLAND_FOUND        - True if Wayland is found
+#   WAYLAND_LIBRARIES    - Link these to use Wayland
+#   WAYLAND_INCLUDE_DIRS - Include directory for Wayland
+#   WAYLAND_DEFINITIONS  - Compiler flags for using Wayland
+#
+# In addition the following more fine grained variables will be defined:
+#
+#   Wayland_Client_FOUND  WAYLAND_CLIENT_INCLUDE_DIRS  WAYLAND_CLIENT_LIBRARIES
+#   Wayland_Server_FOUND  WAYLAND_SERVER_INCLUDE_DIRS  WAYLAND_SERVER_LIBRARIES
+#   Wayland_EGL_FOUND     WAYLAND_EGL_INCLUDE_DIRS     WAYLAND_EGL_LIBRARIES
+#   Wayland_Cursor_FOUND  WAYLAND_CURSOR_INCLUDE_DIRS  WAYLAND_CURSOR_LIBRARIES
+#
+# Copyright (c) 2013 Martin Gräßlin <mgraesslin@kde.org>
+#               2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+IF (NOT WIN32)
+
+  # Use pkg-config to get the directories and then use these values
+  # in the find_path() and find_library() calls
+  find_package(PkgConfig)
+  PKG_CHECK_MODULES(PKG_WAYLAND QUIET wayland-client wayland-server wayland-egl wayland-cursor)
+
+  set(WAYLAND_DEFINITIONS ${PKG_WAYLAND_CFLAGS})
+
+  find_path(WAYLAND_CLIENT_INCLUDE_DIRS NAMES wayland-client.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
+  find_library(WAYLAND_CLIENT_LIBRARIES NAMES wayland-client   HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
+  if(WAYLAND_CLIENT_INCLUDE_DIRS AND WAYLAND_CLIENT_LIBRARIES)
+    set(Wayland_Client_FOUND TRUE)
+  else()
+    set(Wayland_Client_FOUND FALSE)
+  endif()
+  mark_as_advanced(WAYLAND_CLIENT_INCLUDE_DIRS WAYLAND_CLIENT_LIBRARIES)
+
+  find_path(WAYLAND_CURSOR_INCLUDE_DIRS NAMES wayland-cursor.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
+  find_library(WAYLAND_CURSOR_LIBRARIES NAMES wayland-cursor   HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
+  if(WAYLAND_CURSOR_INCLUDE_DIRS AND WAYLAND_CURSOR_LIBRARIES)
+    set(Wayland_Cursor_FOUND TRUE)
+  else()
+    set(Wayland_Cursor_FOUND FALSE)
+  endif()
+  mark_as_advanced(WAYLAND_CURSOR_INCLUDE_DIRS WAYLAND_CURSOR_LIBRARIES)
+
+  find_path(WAYLAND_EGL_INCLUDE_DIRS    NAMES wayland-egl.h    HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
+  find_library(WAYLAND_EGL_LIBRARIES    NAMES wayland-egl      HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
+  if(WAYLAND_EGL_INCLUDE_DIRS AND WAYLAND_EGL_LIBRARIES)
+    set(Wayland_EGL_FOUND TRUE)
+  else()
+    set(Wayland_EGL_FOUND FALSE)
+  endif()
+  mark_as_advanced(WAYLAND_EGL_INCLUDE_DIRS WAYLAND_EGL_LIBRARIES)
+
+  find_path(WAYLAND_SERVER_INCLUDE_DIRS NAMES wayland-server.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
+  find_library(WAYLAND_SERVER_LIBRARIES NAMES wayland-server   HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
+  if(WAYLAND_SERVER_INCLUDE_DIRS AND WAYLAND_SERVER_LIBRARIES)
+    set(Wayland_Server_FOUND TRUE)
+  else()
+    set(Wayland_Server_FOUND FALSE)
+  endif()
+  mark_as_advanced(WAYLAND_SERVER_INCLUDE_DIRS WAYLAND_SERVER_LIBRARIES)
+
+  set(WAYLAND_INCLUDE_DIRS ${WAYLAND_CLIENT_INCLUDE_DIRS} ${WAYLAND_SERVER_INCLUDE_DIRS} ${WAYLAND_EGL_INCLUDE_DIRS} ${WAYLAND_CURSOR_INCLUDE_DIRS})
+  set(WAYLAND_LIBRARIES ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_SERVER_LIBRARIES} ${WAYLAND_EGL_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES})
+  mark_as_advanced(WAYLAND_INCLUDE_DIRS WAYLAND_LIBRARIES)
+
+  list(REMOVE_DUPLICATES WAYLAND_INCLUDE_DIRS)
+
+  include(FindPackageHandleStandardArgs)
+
+  find_package_handle_standard_args(Wayland REQUIRED_VARS WAYLAND_LIBRARIES WAYLAND_INCLUDE_DIRS HANDLE_COMPONENTS)
+
+ENDIF ()
diff --git a/libobs-opengl/CMakeLists.txt b/libobs-opengl/CMakeLists.txt
index 973c5da3..08e06f0d 100644
--- a/libobs-opengl/CMakeLists.txt
+++ b/libobs-opengl/CMakeLists.txt
@@ -32,7 +32,7 @@ elseif(APPLE)
 		${COCOA}
 		${IOSURF}
 		${OPENGL_gl_LIBRARY})
-else() #This needs to change to be more specific to get ready for Wayland
+else()
 	find_package(XCB COMPONENTS XCB REQUIRED)
 	find_package(X11_XCB REQUIRED)
 
diff --git a/libobs-opengl/gl-nix.c b/libobs-opengl/gl-nix.c
index 9ed3d198..581e16a4 100644
--- a/libobs-opengl/gl-nix.c
+++ b/libobs-opengl/gl-nix.c
@@ -32,6 +32,11 @@ static void init_winsys(void)
 	case OBS_NIX_PLATFORM_X11_EGL:
 		gl_vtable = gl_x11_egl_get_winsys_vtable();
 		break;
+#ifdef ENABLE_WAYLAND
+	case OBS_NIX_PLATFORM_WAYLAND:
+		blog(LOG_ERROR, "EGL/Wayland not implemented yet");
+		break;
+#endif
 	}
 
 	assert(gl_vtable != NULL);
diff --git a/libobs/CMakeLists.txt b/libobs/CMakeLists.txt
index 7a786350..860ad1c8 100644
--- a/libobs/CMakeLists.txt
+++ b/libobs/CMakeLists.txt
@@ -190,6 +190,21 @@ elseif(UNIX)
 	set(libobs_PLATFORM_HEADERS
 		obs-nix-platform.h)
 
+	if(ENABLE_WAYLAND)
+		find_package(Wayland COMPONENTS Client REQUIRED)
+
+		set(libobs_PLATFORM_SOURCES ${libobs_PLATFORM_SOURCES}
+			obs-nix-wayland.c)
+
+		include_directories(
+			${WAYLAND_CLIENT_INCLUDE_DIR})
+		add_definitions(
+			${WAYLAND_DEFINITIONS})
+		set(libobs_PLATFORM_DEPS
+			${libobs_PLATFORM_DEPS}
+			${WAYLAND_CLIENT_LIBRARIES})
+	endif()
+
 	if(NEEDS_SIMDE)
 		set(libobs_PLATFORM_HEADERS
 			${libobs_PLATFORM_HEADERS}
diff --git a/libobs/obs-nix-platform.h b/libobs/obs-nix-platform.h
index 4cf9d8cd..cef700d7 100644
--- a/libobs/obs-nix-platform.h
+++ b/libobs/obs-nix-platform.h
@@ -26,6 +26,10 @@ extern "C" {
 enum obs_nix_platform_type {
 	OBS_NIX_PLATFORM_X11_GLX,
 	OBS_NIX_PLATFORM_X11_EGL,
+#ifdef ENABLE_WAYLAND
+	OBS_NIX_PLATFORM_WAYLAND,
+#endif
+
 };
 
 /**
diff --git a/libobs/obs-nix-wayland.c b/libobs/obs-nix-wayland.c
new file mode 100644
index 00000000..b242017f
--- /dev/null
+++ b/libobs/obs-nix-wayland.c
@@ -0,0 +1,88 @@
+/******************************************************************************
+    Copyright (C) 2019 by Jason Francis <cycl0ps@tuta.io>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+******************************************************************************/
+
+#include "obs-internal.h"
+#include "obs-nix-platform.h"
+#include "obs-nix-wayland.h"
+
+#include <wayland-client.h>
+
+void obs_nix_wayland_log_info(void)
+{
+	struct wl_display *display = obs_get_nix_platform_display();
+	if (display == NULL) {
+		blog(LOG_INFO, "Unable to connect to Wayland server");
+		return;
+	}
+	//TODO: query some information about the wayland server if possible
+	blog(LOG_INFO, "Connected to Wayland server");
+}
+
+static bool
+obs_nix_wayland_hotkeys_platform_init(struct obs_core_hotkeys *hotkeys)
+{
+	UNUSED_PARAMETER(hotkeys);
+	return true;
+}
+
+static void
+obs_nix_wayland_hotkeys_platform_free(struct obs_core_hotkeys *hotkeys)
+{
+	UNUSED_PARAMETER(hotkeys);
+}
+
+static bool
+obs_nix_wayland_hotkeys_platform_is_pressed(obs_hotkeys_platform_t *context,
+					    obs_key_t key)
+{
+	UNUSED_PARAMETER(context);
+	UNUSED_PARAMETER(key);
+	return false;
+}
+
+static void obs_nix_wayland_key_to_str(obs_key_t key, struct dstr *dstr)
+{
+	UNUSED_PARAMETER(key);
+	UNUSED_PARAMETER(dstr);
+}
+
+static obs_key_t obs_nix_wayland_key_from_virtual_key(int sym)
+{
+	UNUSED_PARAMETER(sym);
+	return OBS_KEY_NONE;
+}
+
+static int obs_nix_wayland_key_to_virtual_key(obs_key_t key)
+{
+	UNUSED_PARAMETER(key);
+	return 0;
+}
+
+static const struct obs_nix_hotkeys_vtable wayland_hotkeys_vtable = {
+	.init = obs_nix_wayland_hotkeys_platform_init,
+	.free = obs_nix_wayland_hotkeys_platform_free,
+	.is_pressed = obs_nix_wayland_hotkeys_platform_is_pressed,
+	.key_to_str = obs_nix_wayland_key_to_str,
+	.key_from_virtual_key = obs_nix_wayland_key_from_virtual_key,
+	.key_to_virtual_key = obs_nix_wayland_key_to_virtual_key,
+
+};
+
+const struct obs_nix_hotkeys_vtable *obs_nix_wayland_get_hotkeys_vtable(void)
+{
+	return &wayland_hotkeys_vtable;
+}
diff --git a/libobs/obs-nix-wayland.h b/libobs/obs-nix-wayland.h
new file mode 100644
index 00000000..d44720c5
--- /dev/null
+++ b/libobs/obs-nix-wayland.h
@@ -0,0 +1,24 @@
+/******************************************************************************
+    Copyright (C) 2019 by Jason Francis <cycl0ps@tuta.io>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+******************************************************************************/
+
+#pragma once
+
+#include "obs-nix.h"
+
+void obs_nix_wayland_log_info(void);
+
+const struct obs_nix_hotkeys_vtable *obs_nix_wayland_get_hotkeys_vtable(void);
diff --git a/libobs/obs-nix.c b/libobs/obs-nix.c
index 9c52279a..ec7f8e25 100644
--- a/libobs/obs-nix.c
+++ b/libobs/obs-nix.c
@@ -20,6 +20,11 @@
 #include "obs-nix.h"
 #include "obs-nix-platform.h"
 #include "obs-nix-x11.h"
+
+#ifdef ENABLE_WAYLAND
+#include "obs-nix-wayland.h"
+#endif
+
 #if defined(__FreeBSD__)
 #define _GNU_SOURCE
 #endif
@@ -295,6 +300,10 @@ void log_system_info(void)
 	case OBS_NIX_PLATFORM_X11_EGL:
 		obs_nix_x11_log_info();
 		break;
+#ifdef ENABLE_WAYLAND
+	case OBS_NIX_PLATFORM_WAYLAND:
+		break;
+#endif
 	}
 }
 
@@ -305,6 +314,11 @@ bool obs_hotkeys_platform_init(struct obs_core_hotkeys *hotkeys)
 	case OBS_NIX_PLATFORM_X11_EGL:
 		hotkeys_vtable = obs_nix_x11_get_hotkeys_vtable();
 		break;
+#ifdef ENABLE_WAYLAND
+	case OBS_NIX_PLATFORM_WAYLAND:
+		hotkeys_vtable = obs_nix_wayland_get_hotkeys_vtable();
+		break;
+#endif
 	}
 
 	return hotkeys_vtable->init(hotkeys);
diff --git a/libobs/obsconfig.h.in b/libobs/obsconfig.h.in
index 1a09ebea..82d2e3af 100644
--- a/libobs/obsconfig.h.in
+++ b/libobs/obsconfig.h.in
@@ -24,6 +24,8 @@
 #define LIBOBS_IMAGEMAGICK_DIR_STYLE_7GE 7
 #define LIBOBS_IMAGEMAGICK_DIR_STYLE @LIBOBS_IMAGEMAGICK_DIR_STYLE@
 
+#cmakedefine ENABLE_WAYLAND
+
 /* NOTE: Release candidate version numbers internally are always the previous
  * main release number!  For example, if the current public release is 21.0 and
  * the build is 22.0 release candidate 1, internally the build number (defined
-- 
2.28.0