Skip to content

Commit

Permalink
libobs: Add a Wayland platform
Browse files Browse the repository at this point in the history
Introduce the OBS_PLATFORM_WAYLAND enum value, and try to detect
it when OBS Studio runs by looking into the platform name.
  • Loading branch information
GeorgesStavracas committed Mar 10, 2020
1 parent b492263 commit 5707ede
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ 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(ENABLE_WAYLAND)
find_package(Wayland REQUIRED)
endif()

if(USE_XDG)
add_definitions(-DUSE_XDG)
endif()
Expand Down
5 changes: 5 additions & 0 deletions UI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ if (APPLE)
set_target_properties(obs PROPERTIES LINK_FLAGS "-pagezero_size 10000 -image_base 100000000")
endif()

if (ENABLE_WAYLAND)
find_package(Qt5Gui)
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
endif()

define_graphic_modules(obs)

install_obs_core(obs)
Expand Down
20 changes: 20 additions & 0 deletions UI/obs-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
#if !defined(_WIN32) && !defined(__APPLE__)
#define IS_UNIX 1
#include <QX11Info>

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

#endif

#include <iostream>
Expand Down Expand Up @@ -1340,12 +1345,27 @@ bool OBSApp::OBSInit()

qRegisterMetaType<VoidFunc>();

obs_set_platform(OBS_PLATFORM_DEFAULT);

#if defined(IS_UNIX)
if (QApplication::platformName() == "xcb") {
obs_set_platform_display(QX11Info::display());
}

#ifdef ENABLE_WAYLAND
if (QApplication::platformName().contains("wayland")) {
obs_set_platform(OBS_PLATFORM_WAYLAND);
QPlatformNativeInterface *native =
QGuiApplication::platformNativeInterface();
obs_set_platform_display(
native->nativeResourceForIntegration("display"));

blog(LOG_INFO, "Platform: Wayland");
}
#endif

#endif // IS_UNIX

if (!StartupOBS(locale.c_str(), GetProfilerNameStore()))
return false;

Expand Down
66 changes: 66 additions & 0 deletions cmake/Modules/FindWayland.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 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_DIR - 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_DIR WAYLAND_CLIENT_LIBRARIES
# WAYLAND_SERVER_FOUND WAYLAND_SERVER_INCLUDE_DIR WAYLAND_SERVER_LIBRARIES
# WAYLAND_EGL_FOUND WAYLAND_EGL_INCLUDE_DIR WAYLAND_EGL_LIBRARIES
#
# Copyright (c) 2013 Martin Gräßlin <[email protected]>
#
# 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)
IF (WAYLAND_INCLUDE_DIR AND WAYLAND_LIBRARIES)
# In the cache already
SET(WAYLAND_FIND_QUIETLY TRUE)
ENDIF ()

# 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_DIR NAMES wayland-client.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
FIND_PATH(WAYLAND_SERVER_INCLUDE_DIR NAMES wayland-server.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
FIND_PATH(WAYLAND_EGL_INCLUDE_DIR NAMES wayland-egl.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
FIND_PATH(WAYLAND_CURSOR_INCLUDE_DIR NAMES wayland-cursor.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})

FIND_LIBRARY(WAYLAND_CLIENT_LIBRARIES NAMES wayland-client HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
FIND_LIBRARY(WAYLAND_SERVER_LIBRARIES NAMES wayland-server HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
FIND_LIBRARY(WAYLAND_EGL_LIBRARIES NAMES wayland-egl HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
FIND_LIBRARY(WAYLAND_CURSOR_LIBRARIES NAMES wayland-cursor HINTS ${PKG_WAYLAND_LIBRARY_DIRS})

set(WAYLAND_INCLUDE_DIR ${WAYLAND_CLIENT_INCLUDE_DIR} ${WAYLAND_SERVER_INCLUDE_DIR} ${WAYLAND_EGL_INCLUDE_DIR} ${WAYLAND_CURSOR_INCLUDE_DIR})

set(WAYLAND_LIBRARIES ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_SERVER_LIBRARIES} ${WAYLAND_EGL_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES})

list(REMOVE_DUPLICATES WAYLAND_INCLUDE_DIR)

include(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CLIENT DEFAULT_MSG WAYLAND_CLIENT_LIBRARIES WAYLAND_CLIENT_INCLUDE_DIR)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_SERVER DEFAULT_MSG WAYLAND_SERVER_LIBRARIES WAYLAND_SERVER_INCLUDE_DIR)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_EGL DEFAULT_MSG WAYLAND_EGL_LIBRARIES WAYLAND_EGL_INCLUDE_DIR)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CURSOR DEFAULT_MSG WAYLAND_CURSOR_LIBRARIES WAYLAND_CURSOR_INCLUDE_DIR)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND DEFAULT_MSG WAYLAND_LIBRARIES WAYLAND_INCLUDE_DIR)

MARK_AS_ADVANCED(
WAYLAND_INCLUDE_DIR WAYLAND_LIBRARIES
WAYLAND_CLIENT_INCLUDE_DIR WAYLAND_CLIENT_LIBRARIES
WAYLAND_SERVER_INCLUDE_DIR WAYLAND_SERVER_LIBRARIES
WAYLAND_EGL_INCLUDE_DIR WAYLAND_EGL_LIBRARIES
WAYLAND_CURSOR_INCLUDE_DIR WAYLAND_CURSOR_LIBRARIES
)

ENDIF ()
2 changes: 1 addition & 1 deletion libobs-opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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)

Expand Down
20 changes: 17 additions & 3 deletions libobs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ if(UNIX)
else()
set(USE_XINPUT "0")
endif()

if (ENABLE_WAYLAND)
find_package(Qt5Gui)
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
endif()

find_package(PulseAudio)
if (NOT "${PULSEAUDIO_LIBRARY}" STREQUAL "")
message(STATUS "Found PulseAudio - Audio Monitor enabled")
Expand Down Expand Up @@ -175,6 +181,11 @@ elseif(UNIX)
util/pipe-posix.c
util/platform-nix.c)

if(ENABLE_WAYLAND)
set(libobs_PLATFORM_SOURCES ${libobs_PLATFORM_SOURCES}
obs-nix-wayland.c)
endif()

if(NEEDS_SIMDE)
set(libobs_PLATFORM_HEADERS
util/simde/check.h
Expand Down Expand Up @@ -212,12 +223,15 @@ elseif(UNIX)
endif()

include_directories(
${X11_XCB_INCLUDE_DIRS})
${X11_XCB_INCLUDE_DIRS}
${WAYLAND_CLIENT_INCLUDE_DIR})
add_definitions(
${X11_XCB_DEFINITIONS})
${X11_XCB_DEFINITIONS}
${WAYLAND_DEFINITIONS})
set(libobs_PLATFORM_DEPS
${libobs_PLATFORM_DEPS}
${X11_XCB_LIBRARIES})
${X11_XCB_LIBRARIES}
${WAYLAND_CLIENT_LIBRARIES})

if(USE_XINPUT)
include_directories(
Expand Down
90 changes: 90 additions & 0 deletions libobs/obs-nix-wayland.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/******************************************************************************
Copyright (C) 2019 by Jason Francis <[email protected]>
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-wayland.h"

#include <wayland-client.h>

void obs_nix_wayland_log_info(void)
{
struct wl_display *display = obs_get_platform_display();
if (display == NULL) {
blog(LOG_INFO, "Unable to connect to Wayland server");
return;
}
blog(LOG_INFO, "Connected to Wayland server");
}

/*
* Placeholders here until wayland gets a global hotkey protocol.
*/

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;
}
21 changes: 21 additions & 0 deletions libobs/obs-nix-wayland.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/******************************************************************************
Copyright (C) 2019 by Jason Francis <[email protected]>
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);
15 changes: 15 additions & 0 deletions libobs/obs-nix.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#include "obs-internal.h"
#include "obs-nix.h"
#include "obs-nix-x11.h"

#ifdef ENABLE_WAYLAND
#include "obs-nix-wayland.h"
#endif

#if defined(__FreeBSD__)
#define _GNU_SOURCE
#endif
Expand Down Expand Up @@ -293,6 +298,11 @@ void log_system_info(void)
case OBS_PLATFORM_DEFAULT:
obs_nix_x11_log_info();
break;
#ifdef ENABLE_WAYLAND
case OBS_PLATFORM_WAYLAND:
obs_nix_wayland_log_info();
break;
#endif
}
}

Expand All @@ -302,6 +312,11 @@ bool obs_hotkeys_platform_init(struct obs_core_hotkeys *hotkeys)
case OBS_PLATFORM_DEFAULT:
hotkeys_vtable = obs_nix_x11_get_hotkeys_vtable();
break;
#ifdef ENABLE_WAYLAND
case OBS_PLATFORM_WAYLAND:
hotkeys_vtable = obs_nix_wayland_get_hotkeys_vtable();
break;
#endif
}

return hotkeys_vtable->init(hotkeys);
Expand Down
3 changes: 3 additions & 0 deletions libobs/obs-platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ extern "C" {

enum obs_platform_type {
OBS_PLATFORM_DEFAULT,
#ifdef ENABLE_WAYLAND
OBS_PLATFORM_WAYLAND,
#endif
};

/**
Expand Down
2 changes: 2 additions & 0 deletions libobs/obsconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5707ede

Please sign in to comment.