GHOST/Wayland: support dynamic loading libraries for Wayland

Add intern/wayland_dynload which is used when WITH_GHOST_WAYLAND_DYNLOAD
is enabled (off by default). When enabled, systems without Wayland
installed will fall back to X11.

This allows Blender to dynamically load:
- libwayland-client
- libwayland-cursor
- libwayland-egl
- libdecor-0 (when WITH_GHOST_WAYLAND_LIBDECOR is enabled).
This commit is contained in:
Campbell Barton 2022-07-05 14:49:36 +10:00
parent d9505831a4
commit e58e023e1a
Notes: blender-bot 2023-10-19 10:17:38 +02:00
Referenced by issue #76428, GHOST/Wayland Support
20 changed files with 931 additions and 9 deletions

View File

@ -229,6 +229,9 @@ if(UNIX AND NOT (APPLE OR HAIKU))
option(WITH_GHOST_WAYLAND_DBUS "Optionally build with DBUS support (used for Cursor themes). May hang on startup systems where DBUS is not used." OFF)
mark_as_advanced(WITH_GHOST_WAYLAND_DBUS)
option(WITH_GHOST_WAYLAND_DYNLOAD "Enable runtime dynamic WAYLAND libraries loading" OFF)
mark_as_advanced(WITH_GHOST_WAYLAND_DYNLOAD)
endif()
endif()

View File

@ -641,12 +641,17 @@ if(WITH_GHOST_WAYLAND)
endif()
list(APPEND PLATFORM_LINKLIBS
${wayland-client_LINK_LIBRARIES}
${wayland-egl_LINK_LIBRARIES}
${xkbcommon_LINK_LIBRARIES}
${wayland-cursor_LINK_LIBRARIES}
)
if(NOT WITH_GHOST_WAYLAND_DYNLOAD)
list(APPEND PLATFORM_LINKLIBS
${wayland-client_LINK_LIBRARIES}
${wayland-egl_LINK_LIBRARIES}
${wayland-cursor_LINK_LIBRARIES}
)
endif()
if(WITH_GHOST_WAYLAND_DBUS)
list(APPEND PLATFORM_LINKLIBS
${dbus_LINK_LIBRARIES}
@ -655,9 +660,11 @@ if(WITH_GHOST_WAYLAND)
endif()
if(WITH_GHOST_WAYLAND_LIBDECOR)
list(APPEND PLATFORM_LINKLIBS
${libdecor_LIBRARIES}
)
if(NOT WITH_GHOST_WAYLAND_DYNLOAD)
list(APPEND PLATFORM_LINKLIBS
${libdecor_LIBRARIES}
)
endif()
add_definitions(-DWITH_GHOST_WAYLAND_LIBDECOR)
endif()
endif()

View File

@ -67,3 +67,10 @@ endif()
if(UNIX AND NOT APPLE)
add_subdirectory(libc_compat)
endif()
if(UNIX AND NOT APPLE)
# Important this comes after "ghost" as it uses includes defined by GHOST's CMake.
if(WITH_GHOST_WAYLAND AND WITH_GHOST_WAYLAND_DYNLOAD)
add_subdirectory(wayland_dynload)
endif()
endif()

View File

@ -270,6 +270,16 @@ elseif(WITH_GHOST_X11 OR WITH_GHOST_WAYLAND)
${wayland-cursor_INCLUDE_DIRS}
)
if(WITH_GHOST_WAYLAND_DYNLOAD)
list(APPEND INC_SYS
../../intern/wayland_dynload/extern
)
list(APPEND LIB
bf_intern_wayland_dynload
)
add_definitions(-DWITH_GHOST_WAYLAND_DYNLOAD)
endif()
if(WITH_GHOST_WAYLAND_DBUS)
list(APPEND INC_SYS
${dbus_INCLUDE_DIRS}

View File

@ -37,12 +37,23 @@ GHOST_TSuccess GHOST_ISystem::createSystem()
{
GHOST_TSuccess success;
if (!m_system) {
#if defined(WITH_HEADLESS)
/* Pass. */
#elif defined(WITH_GHOST_WAYLAND)
# if defined(WITH_GHOST_WAYLAND_DYNLOAD)
const bool has_wayland_libraries = ghost_wl_dynload_libraries();
# else
const bool has_wayland_libraries = true;
# endif
#endif
#if defined(WITH_HEADLESS)
m_system = new GHOST_SystemNULL();
#elif defined(WITH_GHOST_X11) && defined(WITH_GHOST_WAYLAND)
/* Special case, try Wayland, fall back to X11. */
try {
m_system = new GHOST_SystemWayland();
m_system = has_wayland_libraries ? new GHOST_SystemWayland() : nullptr;
}
catch (const std::runtime_error &) {
/* fallback to X11. */
@ -55,7 +66,7 @@ GHOST_TSuccess GHOST_ISystem::createSystem()
#elif defined(WITH_GHOST_X11)
m_system = new GHOST_SystemX11();
#elif defined(WITH_GHOST_WAYLAND)
m_system = new GHOST_SystemWayland();
m_system = has_wayland_libraries ? new GHOST_SystemWayland() : nullptr;
#elif defined(WITH_GHOST_SDL)
m_system = new GHOST_SystemSDL();
#elif defined(WIN32)

View File

@ -16,7 +16,15 @@
#include "GHOST_ContextEGL.h"
#ifdef WITH_GHOST_WAYLAND_DYNLOAD
# include <wayland_dynload_API.h> /* For `ghost_wl_dynload_libraries`. */
#endif
#include <EGL/egl.h>
#ifdef WITH_GHOST_WAYLAND_DYNLOAD
# include <wayland_dynload_egl.h>
#endif
#include <wayland-egl.h>
#include <algorithm>
@ -26,6 +34,9 @@
#include <unordered_map>
#include <unordered_set>
#ifdef WITH_GHOST_WAYLAND_DYNLOAD
# include <wayland_dynload_cursor.h>
#endif
#include <wayland-cursor.h>
#include "GHOST_WaylandCursorSettings.h"
@ -3614,4 +3625,35 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod
return GHOST_kSuccess;
}
#ifdef WITH_GHOST_WAYLAND_DYNLOAD
bool ghost_wl_dynload_libraries()
{
/* Only report when `libwayland-client` is not found when building without X11,
* which will be used as a fallback. */
# ifdef WITH_GHOST_X11
bool verbose = false;
# else
bool verbose = true;
# endif
if (wayland_dynload_client_init(verbose) && /* `libwayland-client`. */
wayland_dynload_cursor_init(verbose) && /* `libwayland-cursor`. */
wayland_dynload_egl_init(verbose) && /* `libwayland-egl`. */
# ifdef WITH_GHOST_WAYLAND_LIBDECOR
wayland_dynload_libdecor_init(verbose) && /* `libdecor-0`. */
# endif
true) {
return true;
}
# ifdef WITH_GHOST_WAYLAND_LIBDECOR
wayland_dynload_libdecor_exit();
# endif
wayland_dynload_client_exit();
wayland_dynload_cursor_exit();
wayland_dynload_egl_exit();
return false;
}
#endif /* WITH_GHOST_WAYLAND_DYNLOAD */
/** \} */

View File

@ -11,9 +11,15 @@
#include "GHOST_System.h"
#include "GHOST_WindowWayland.h"
#ifdef WITH_GHOST_WAYLAND_DYNLOAD
# include <wayland_dynload_client.h>
#endif
#include <wayland-client.h>
#ifdef WITH_GHOST_WAYLAND_LIBDECOR
# ifdef WITH_GHOST_WAYLAND_DYNLOAD
# include <wayland_dynload_libdecor.h>
# endif
# include <libdecor.h>
#else
/* Generated by `wayland-scanner`. */
@ -35,6 +41,14 @@ bool ghost_wl_surface_own(const struct wl_surface *surface);
void ghost_wl_surface_tag(struct wl_surface *surface);
GHOST_WindowWayland *ghost_wl_surface_user_data(struct wl_surface *surface);
#ifdef WITH_GHOST_WAYLAND_DYNLOAD
/**
* Return true when all required WAYLAND libraries are present,
* Performs dynamic loading when `WITH_GHOST_WAYLAND_DYNLOAD` is in use.
*/
bool ghost_wl_dynload_libraries();
#endif
struct output_t {
struct wl_output *wl_output = nullptr;
struct zxdg_output_v1 *xdg_output = nullptr;

View File

@ -15,11 +15,18 @@
#include "GHOST_ContextNone.h"
#include <wayland-client-protocol.h>
#ifdef WITH_GHOST_WAYLAND_DYNLOAD
# include <wayland_dynload_egl.h>
#endif
#include <wayland-egl.h>
#include <algorithm> /* For `std::find`. */
#ifdef WITH_GHOST_WAYLAND_LIBDECOR
# ifdef WITH_GHOST_WAYLAND_DYNLOAD
# include <wayland_dynload_libdecor.h>
# endif
# include <libdecor.h>
#endif
@ -347,7 +354,7 @@ static void surface_handle_leave(void *data,
}
}
struct wl_surface_listener wl_surface_listener = {
static struct wl_surface_listener wl_surface_listener = {
surface_handle_enter,
surface_handle_leave,
};

View File

@ -0,0 +1,44 @@
# SPDX-License-Identifier: GPL-2.0-or-later
set(INC
extern
# For internal includes.
intern
)
set(INC_SYS
${wayland-client_INCLUDE_DIRS}
${wayland-egl_INCLUDE_DIRS}
${wayland-cursor_INCLUDE_DIRS}
)
set(SRC
intern/wayland_dynload_client.c
intern/wayland_dynload_cursor.c
intern/wayland_dynload_egl.c
intern/wayland_dynload_utils.c
extern/wayland_dynload_API.h
extern/wayland_dynload_client.h
extern/wayland_dynload_cursor.h
extern/wayland_dynload_egl.h
intern/wayland_dynload_utils.h
)
if(WITH_GHOST_WAYLAND_LIBDECOR)
list(APPEND INC_SYS
${libdecor_INCLUDE_DIRS}
)
list(APPEND SRC
intern/wayland_dynload_libdecor.c
extern/wayland_dynload_libdecor.h
)
endif()
set(LIB
)
blender_add_lib(bf_intern_wayland_dynload "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")

View File

@ -0,0 +1,31 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup intern_wayland_dynload
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
bool wayland_dynload_client_init(bool verbose);
void wayland_dynload_client_exit(void);
bool wayland_dynload_cursor_init(bool verbose);
void wayland_dynload_cursor_exit(void);
bool wayland_dynload_egl_init(bool verbose);
void wayland_dynload_egl_exit(void);
#ifdef WITH_GHOST_WAYLAND_LIBDECOR
bool wayland_dynload_libdecor_init(bool verbose);
void wayland_dynload_libdecor_exit(void);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,128 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup intern_wayland_dynload
*
* Wrapper functions for `<wayland-client.h>`.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WAYLAND_DYNLOAD_FN
WAYLAND_DYNLOAD_FN(wl_display_connect)
WAYLAND_DYNLOAD_FN(wl_display_disconnect)
WAYLAND_DYNLOAD_FN(wl_display_dispatch)
WAYLAND_DYNLOAD_FN(wl_display_roundtrip)
WAYLAND_DYNLOAD_FN(wl_display_flush)
WAYLAND_DYNLOAD_FN(wl_log_set_handler_client)
WAYLAND_DYNLOAD_FN(wl_proxy_add_listener)
WAYLAND_DYNLOAD_FN(wl_proxy_destroy)
WAYLAND_DYNLOAD_FN(wl_proxy_marshal_flags)
WAYLAND_DYNLOAD_FN(wl_proxy_marshal_array_flags)
WAYLAND_DYNLOAD_FN(wl_proxy_set_user_data)
WAYLAND_DYNLOAD_FN(wl_proxy_get_user_data)
WAYLAND_DYNLOAD_FN(wl_proxy_get_version)
WAYLAND_DYNLOAD_FN(wl_proxy_get_tag)
WAYLAND_DYNLOAD_FN(wl_proxy_set_tag)
#elif defined(WAYLAND_DYNLOAD_IFACE)
WAYLAND_DYNLOAD_IFACE(wl_buffer_interface)
WAYLAND_DYNLOAD_IFACE(wl_compositor_interface)
WAYLAND_DYNLOAD_IFACE(wl_data_device_interface)
WAYLAND_DYNLOAD_IFACE(wl_data_device_manager_interface)
WAYLAND_DYNLOAD_IFACE(wl_data_source_interface)
WAYLAND_DYNLOAD_IFACE(wl_keyboard_interface)
WAYLAND_DYNLOAD_IFACE(wl_output_interface)
WAYLAND_DYNLOAD_IFACE(wl_pointer_interface)
WAYLAND_DYNLOAD_IFACE(wl_region_interface)
WAYLAND_DYNLOAD_IFACE(wl_registry_interface)
WAYLAND_DYNLOAD_IFACE(wl_seat_interface)
WAYLAND_DYNLOAD_IFACE(wl_shm_interface)
WAYLAND_DYNLOAD_IFACE(wl_shm_pool_interface)
WAYLAND_DYNLOAD_IFACE(wl_surface_interface)
#else
/* Header guard. */
# if !defined(__WAYLAND_DYNLOAD_CLIENT_H__) && !defined(WAYLAND_DYNLOAD_VALIDATE)
# define __WAYLAND_DYNLOAD_CLIENT_H__
# ifndef WAYLAND_DYNLOAD_VALIDATE
# include <wayland-client-core.h>
extern struct WaylandDynload_Client wayland_dynload_client;
# endif
/* Support validating declarations against the header. */
# ifndef WAYLAND_DYNLOAD_VALIDATE
# define WL_DYN_FN(a) (*a)
# else
# define WL_DYN_FN(a) (a)
# endif
# ifndef WAYLAND_DYNLOAD_VALIDATE
struct WaylandDynload_Client {
# endif
struct wl_display *WL_DYN_FN(wl_display_connect)(const char *name);
void WL_DYN_FN(wl_display_disconnect)(struct wl_display *display);
int WL_DYN_FN(wl_display_dispatch)(struct wl_display *display);
int WL_DYN_FN(wl_display_roundtrip)(struct wl_display *display);
int WL_DYN_FN(wl_display_flush)(struct wl_display *display);
void WL_DYN_FN(wl_log_set_handler_client)(wl_log_func_t);
int WL_DYN_FN(wl_proxy_add_listener)(struct wl_proxy *proxy,
void (**implementation)(void),
void *data);
void WL_DYN_FN(wl_proxy_destroy)(struct wl_proxy *proxy);
struct wl_proxy *WL_DYN_FN(wl_proxy_marshal_flags)(struct wl_proxy *proxy,
uint32_t opcode,
const struct wl_interface *interface,
uint32_t version,
uint32_t flags,
...);
struct wl_proxy *WL_DYN_FN(wl_proxy_marshal_array_flags)(struct wl_proxy *proxy,
uint32_t opcode,
const struct wl_interface *interface,
uint32_t version,
uint32_t flags,
union wl_argument *args);
void WL_DYN_FN(wl_proxy_set_user_data)(struct wl_proxy *proxy, void *user_data);
void *WL_DYN_FN(wl_proxy_get_user_data)(struct wl_proxy *proxy);
uint32_t WL_DYN_FN(wl_proxy_get_version)(struct wl_proxy *proxy);
const char *const *WL_DYN_FN(wl_proxy_get_tag)(struct wl_proxy *proxy);
void WL_DYN_FN(wl_proxy_set_tag)(struct wl_proxy *proxy, const char *const *tag);
# ifndef WAYLAND_DYNLOAD_VALIDATE
};
# endif
# undef WL_DYN_FN
# ifndef WAYLAND_DYNLOAD_VALIDATE
# define wl_display_connect(...) (*wayland_dynload_client.wl_display_connect)(__VA_ARGS__)
# define wl_display_disconnect(...) \
(*wayland_dynload_client.wl_display_disconnect)(__VA_ARGS__)
# define wl_display_dispatch(...) (*wayland_dynload_client.wl_display_dispatch)(__VA_ARGS__)
# define wl_display_roundtrip(...) (*wayland_dynload_client.wl_display_roundtrip)(__VA_ARGS__)
# define wl_display_flush(...) (*wayland_dynload_client.wl_display_flush)(__VA_ARGS__)
# define wl_log_set_handler_client(...) \
(*wayland_dynload_client.wl_log_set_handler_client)(__VA_ARGS__)
# define wl_proxy_add_listener(...) \
(*wayland_dynload_client.wl_proxy_add_listener)(__VA_ARGS__)
# define wl_proxy_destroy(...) (*wayland_dynload_client.wl_proxy_destroy)(__VA_ARGS__)
# define wl_proxy_marshal_flags(...) \
(*wayland_dynload_client.wl_proxy_marshal_flags)(__VA_ARGS__)
# define wl_proxy_marshal_array_flags(...) \
(*wayland_dynload_client.wl_proxy_marshal_array_flags)(__VA_ARGS__)
# define wl_proxy_set_user_data(...) \
(*wayland_dynload_client.wl_proxy_set_user_data)(__VA_ARGS__)
# define wl_proxy_get_user_data(...) \
(*wayland_dynload_client.wl_proxy_get_user_data)(__VA_ARGS__)
# define wl_proxy_get_version(...) (*wayland_dynload_client.wl_proxy_get_version)(__VA_ARGS__)
# define wl_proxy_get_tag(...) (*wayland_dynload_client.wl_proxy_get_tag)(__VA_ARGS__)
# define wl_proxy_set_tag(...) (*wayland_dynload_client.wl_proxy_set_tag)(__VA_ARGS__)
# endif /* !WAYLAND_DYNLOAD_VALIDATE */
# endif /* !defined(__WAYLAND_DYNLOAD_CLIENT_H__) && !defined(WAYLAND_DYNLOAD_VALIDATE) */
#endif /* !defined(WAYLAND_DYNLOAD_FN) && !defined(WAYLAND_DYNLOAD_IFACE) */
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,76 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup intern_wayland_dynload
*
* Wrapper functions for `<wayland-cursor.h>`.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WAYLAND_DYNLOAD_FN
WAYLAND_DYNLOAD_FN(wl_cursor_theme_load)
WAYLAND_DYNLOAD_FN(wl_cursor_theme_destroy)
WAYLAND_DYNLOAD_FN(wl_cursor_theme_get_cursor)
WAYLAND_DYNLOAD_FN(wl_cursor_image_get_buffer)
WAYLAND_DYNLOAD_FN(wl_cursor_frame)
WAYLAND_DYNLOAD_FN(wl_cursor_frame_and_duration)
#elif defined(WAYLAND_DYNLOAD_IFACE)
/* No interfaces. */
#else
/* Header guard. */
# if !defined(__WAYLAND_DYNLOAD_CURSOR_H__) && !defined(WAYLAND_DYNLOAD_VALIDATE)
# define __WAYLAND_DYNLOAD_CURSOR_H__
# include <wayland-cursor.h>
extern struct WaylandDynload_Cursor wayland_dynload_cursor;
/* Support validating declarations against the header. */
# ifndef WAYLAND_DYNLOAD_VALIDATE
# define WL_DYN_FN(a) (*a)
# else
# define WL_DYN_FN(a) (a)
# endif
# ifndef WAYLAND_DYNLOAD_VALIDATE
struct WaylandDynload_Cursor {
# endif
struct wl_cursor_theme *WL_DYN_FN(wl_cursor_theme_load)(const char *name,
int size,
struct wl_shm *shm);
void WL_DYN_FN(wl_cursor_theme_destroy)(struct wl_cursor_theme *theme);
struct wl_cursor *WL_DYN_FN(wl_cursor_theme_get_cursor)(struct wl_cursor_theme *theme,
const char *name);
struct wl_buffer *WL_DYN_FN(wl_cursor_image_get_buffer)(struct wl_cursor_image *image);
int WL_DYN_FN(wl_cursor_frame)(struct wl_cursor *cursor, uint32_t time);
int WL_DYN_FN(wl_cursor_frame_and_duration)(struct wl_cursor *cursor,
uint32_t time,
uint32_t *duration);
# ifndef WAYLAND_DYNLOAD_VALIDATE
};
# endif
# undef WL_DYN_FN
# ifndef WAYLAND_DYNLOAD_VALIDATE
# define wl_cursor_theme_load(...) (*wayland_dynload_cursor.wl_cursor_theme_load)(__VA_ARGS__)
# define wl_cursor_theme_destroy(...) \
(*wayland_dynload_cursor.wl_cursor_theme_destroy)(__VA_ARGS__)
# define wl_cursor_theme_get_cursor(...) \
(*wayland_dynload_cursor.wl_cursor_theme_get_cursor)(__VA_ARGS__)
# define wl_cursor_image_get_buffer(...) \
(*wayland_dynload_cursor.wl_cursor_image_get_buffer)(__VA_ARGS__)
# define wl_cursor_frame(...) (*wayland_dynload_cursor.wl_cursor_frame)(__VA_ARGS__)
# define wl_cursor_frame_and_duration(...) \
(*wayland_dynload_cursor.wl_cursor_frame_and_duration)(__VA_ARGS__)
# endif /* !WAYLAND_DYNLOAD_VALIDATE */
# endif /* !__WAYLAND_DYNLOAD_CLIENT_H__ */
#endif /* !defined(WAYLAND_DYNLOAD_FN) && !defined(WAYLAND_DYNLOAD_IFACE) */
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,68 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup intern_wayland_dynload
*
* Wrapper functions for `<wayland-egl.h>`.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WAYLAND_DYNLOAD_FN
WAYLAND_DYNLOAD_FN(wl_egl_window_create)
WAYLAND_DYNLOAD_FN(wl_egl_window_destroy)
WAYLAND_DYNLOAD_FN(wl_egl_window_resize)
WAYLAND_DYNLOAD_FN(wl_egl_window_get_attached_size)
#elif defined(WAYLAND_DYNLOAD_IFACE)
/* No interfaces. */
#else
/* Header guard. */
# if !defined(__WAYLAND_DYNLOAD_EGL_H__) && !defined(WAYLAND_DYNLOAD_VALIDATE)
# define __WAYLAND_DYNLOAD_EGL_H__
# include <wayland-egl-core.h>
extern struct WaylandDynload_EGL wayland_dynload_egl;
/* Support validating declarations against the header. */
# ifndef WAYLAND_DYNLOAD_VALIDATE
# define WL_DYN_FN(a) (*a)
# else
# define WL_DYN_FN(a) (a)
# endif
# ifndef WAYLAND_DYNLOAD_VALIDATE
struct WaylandDynload_EGL {
# endif
struct wl_egl_window *WL_DYN_FN(wl_egl_window_create)(struct wl_surface *surface,
int width,
int height);
void WL_DYN_FN(wl_egl_window_destroy)(struct wl_egl_window *egl_window);
void WL_DYN_FN(wl_egl_window_resize)(
struct wl_egl_window *egl_window, int width, int height, int dx, int dy);
void WL_DYN_FN(wl_egl_window_get_attached_size)(struct wl_egl_window *egl_window,
int *width,
int *height);
# ifndef WAYLAND_DYNLOAD_VALIDATE
};
# endif
# undef WL_DYN_FN
# ifndef WAYLAND_DYNLOAD_VALIDATE
# define wl_egl_window_create(...) (*wayland_dynload_egl.wl_egl_window_create)(__VA_ARGS__)
# define wl_egl_window_destroy(...) (*wayland_dynload_egl.wl_egl_window_destroy)(__VA_ARGS__)
# define wl_egl_window_resize(...) (*wayland_dynload_egl.wl_egl_window_resize)(__VA_ARGS__)
# define wl_egl_window_get_attached_size(...) \
(*wayland_dynload_egl.wl_egl_window_get_attached_size)(__VA_ARGS__)
# endif /* !WAYLAND_DYNLOAD_VALIDATE */
# endif /* !defined(WAYLAND_DYNLOAD_FN) && !defined(WAYLAND_DYNLOAD_IFACE) */
#endif /* !defined(__WAYLAND_DYNLOAD_EGL_H__) && !defined(WAYLAND_DYNLOAD_VALIDATE) */
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,143 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup intern_wayland_dynload
*
* Wrapper functions for `<libdecor.h>`.
*
* \note Not part of WAYLAND, but used with WAYLAND by GHOST.
* It follows WAYLAND conventions and is a middle-ware library that depends on `libwayland-client`.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WAYLAND_DYNLOAD_FN
WAYLAND_DYNLOAD_FN(libdecor_configuration_get_content_size)
WAYLAND_DYNLOAD_FN(libdecor_configuration_get_window_state)
WAYLAND_DYNLOAD_FN(libdecor_decorate)
WAYLAND_DYNLOAD_FN(libdecor_dispatch)
WAYLAND_DYNLOAD_FN(libdecor_frame_commit)
WAYLAND_DYNLOAD_FN(libdecor_frame_map)
WAYLAND_DYNLOAD_FN(libdecor_frame_set_app_id)
WAYLAND_DYNLOAD_FN(libdecor_frame_set_fullscreen)
WAYLAND_DYNLOAD_FN(libdecor_frame_set_maximized)
WAYLAND_DYNLOAD_FN(libdecor_frame_set_min_content_size)
WAYLAND_DYNLOAD_FN(libdecor_frame_set_minimized)
WAYLAND_DYNLOAD_FN(libdecor_frame_set_parent)
WAYLAND_DYNLOAD_FN(libdecor_frame_set_title)
WAYLAND_DYNLOAD_FN(libdecor_frame_unref)
WAYLAND_DYNLOAD_FN(libdecor_frame_unset_fullscreen)
WAYLAND_DYNLOAD_FN(libdecor_frame_unset_maximized)
WAYLAND_DYNLOAD_FN(libdecor_new)
WAYLAND_DYNLOAD_FN(libdecor_state_free)
WAYLAND_DYNLOAD_FN(libdecor_state_new)
WAYLAND_DYNLOAD_FN(libdecor_unref)
#elif defined(WAYLAND_DYNLOAD_IFACE)
/* No interfaces. */
#else
/* Header guard. */
# if !defined(__WAYLAND_DYNLOAD_LIBDECOR_H__) && !defined(WAYLAND_DYNLOAD_VALIDATE)
# define __WAYLAND_DYNLOAD_LIBDECOR_H__
# ifndef WAYLAND_DYNLOAD_VALIDATE
# include <libdecor.h>
extern struct WaylandDynload_Libdecor wayland_dynload_libdecor;
# endif
/* Support validating declarations against the header. */
# ifndef WAYLAND_DYNLOAD_VALIDATE
# define WL_DYN_FN(sym) (*sym)
# else
# define WL_DYN_FN(sym) (sym)
# endif
# ifndef WAYLAND_DYNLOAD_VALIDATE
struct WaylandDynload_Libdecor {
# endif
bool WL_DYN_FN(libdecor_configuration_get_content_size)(
struct libdecor_configuration *configuration,
struct libdecor_frame *frame,
int *width,
int *height);
bool WL_DYN_FN(libdecor_configuration_get_window_state)(
struct libdecor_configuration *configuration, enum libdecor_window_state *window_state);
struct libdecor_frame *WL_DYN_FN(libdecor_decorate)(struct libdecor *context,
struct wl_surface *surface,
struct libdecor_frame_interface *iface,
void *user_data);
int WL_DYN_FN(libdecor_dispatch)(struct libdecor *context, int timeout);
void WL_DYN_FN(libdecor_frame_commit)(struct libdecor_frame *frame,
struct libdecor_state *state,
struct libdecor_configuration *configuration);
void WL_DYN_FN(libdecor_frame_map)(struct libdecor_frame *frame);
void WL_DYN_FN(libdecor_frame_set_app_id)(struct libdecor_frame *frame, const char *app_id);
void WL_DYN_FN(libdecor_frame_set_fullscreen)(struct libdecor_frame *frame,
struct wl_output *output);
void WL_DYN_FN(libdecor_frame_set_maximized)(struct libdecor_frame *frame);
void WL_DYN_FN(libdecor_frame_set_min_content_size)(struct libdecor_frame *frame,
int content_width,
int content_height);
void WL_DYN_FN(libdecor_frame_set_minimized)(struct libdecor_frame *frame);
void WL_DYN_FN(libdecor_frame_set_parent)(struct libdecor_frame *frame,
struct libdecor_frame *parent);
void WL_DYN_FN(libdecor_frame_set_title)(struct libdecor_frame *frame, const char *title);
void WL_DYN_FN(libdecor_frame_unref)(struct libdecor_frame *frame);
void WL_DYN_FN(libdecor_frame_unset_fullscreen)(struct libdecor_frame *frame);
void WL_DYN_FN(libdecor_frame_unset_maximized)(struct libdecor_frame *frame);
struct libdecor *WL_DYN_FN(libdecor_new)(struct wl_display *display,
struct libdecor_interface *iface);
void WL_DYN_FN(libdecor_state_free)(struct libdecor_state *state);
struct libdecor_state *WL_DYN_FN(libdecor_state_new)(int width, int height);
void WL_DYN_FN(libdecor_unref)(struct libdecor *context);
# ifndef WAYLAND_DYNLOAD_VALIDATE
};
# endif
# undef WL_DYN_FN
# ifndef WAYLAND_DYNLOAD_VALIDATE
# define libdecor_configuration_get_content_size(...) \
(*wayland_dynload_libdecor.libdecor_configuration_get_content_size)(__VA_ARGS__)
# define libdecor_configuration_get_window_state(...) \
(*wayland_dynload_libdecor.libdecor_configuration_get_window_state)(__VA_ARGS__)
# define libdecor_decorate(...) (*wayland_dynload_libdecor.libdecor_decorate)(__VA_ARGS__)
# define libdecor_dispatch(...) (*wayland_dynload_libdecor.libdecor_dispatch)(__VA_ARGS__)
# define libdecor_frame_commit(...) \
(*wayland_dynload_libdecor.libdecor_frame_commit)(__VA_ARGS__)
# define libdecor_frame_map(...) (*wayland_dynload_libdecor.libdecor_frame_map)(__VA_ARGS__)
# define libdecor_frame_set_app_id(...) \
(*wayland_dynload_libdecor.libdecor_frame_set_app_id)(__VA_ARGS__)
# define libdecor_frame_set_fullscreen(...) \
(*wayland_dynload_libdecor.libdecor_frame_set_fullscreen)(__VA_ARGS__)
# define libdecor_frame_set_maximized(...) \
(*wayland_dynload_libdecor.libdecor_frame_set_maximized)(__VA_ARGS__)
# define libdecor_frame_set_min_content_size(...) \
(*wayland_dynload_libdecor.libdecor_frame_set_min_content_size)(__VA_ARGS__)
# define libdecor_frame_set_minimized(...) \
(*wayland_dynload_libdecor.libdecor_frame_set_minimized)(__VA_ARGS__)
# define libdecor_frame_set_parent(...) \
(*wayland_dynload_libdecor.libdecor_frame_set_parent)(__VA_ARGS__)
# define libdecor_frame_set_title(...) \
(*wayland_dynload_libdecor.libdecor_frame_set_title)(__VA_ARGS__)
# define libdecor_frame_unref(...) \
(*wayland_dynload_libdecor.libdecor_frame_unref)(__VA_ARGS__)
# define libdecor_frame_unset_fullscreen(...) \
(*wayland_dynload_libdecor.libdecor_frame_unset_fullscreen)(__VA_ARGS__)
# define libdecor_frame_unset_maximized(...) \
(*wayland_dynload_libdecor.libdecor_frame_unset_maximized)(__VA_ARGS__)
# define libdecor_new(...) (*wayland_dynload_libdecor.libdecor_new)(__VA_ARGS__)
# define libdecor_state_free(...) (*wayland_dynload_libdecor.libdecor_state_free)(__VA_ARGS__)
# define libdecor_state_new(...) (*wayland_dynload_libdecor.libdecor_state_new)(__VA_ARGS__)
# define libdecor_unref(...) (*wayland_dynload_libdecor.libdecor_unref)(__VA_ARGS__)
# endif /* !WAYLAND_DYNLOAD_VALIDATE */
# endif /* !defined(__WAYLAND_DYNLOAD_LIBDECOR_H__) && !defined(WAYLAND_DYNLOAD_VALIDATE) */
#endif /* !defined(WAYLAND_DYNLOAD_FN) && !defined(WAYLAND_DYNLOAD_IFACE) */
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,79 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup intern_wayland_dynload
*
* Wrapper functions for `<wayland-client.h>`.
*/
#include <stdlib.h> /* `atexit`. */
#include <string.h>
#include "wayland_dynload_API.h"
#include "wayland_dynload_utils.h"
#include "wayland_dynload_client.h" /* Own include. */
/* Public handle. */
struct WaylandDynload_Client wayland_dynload_client = {NULL};
static DynamicLibrary lib = NULL;
#define WAYLAND_DYNLOAD_IFACE(symbol) \
extern struct wl_interface symbol; \
struct wl_interface symbol;
#include "wayland_dynload_client.h"
#undef WAYLAND_DYNLOAD_IFACE
bool wayland_dynload_client_init(const bool verbose)
{
/* Library paths. */
const char *paths[] = {
"libwayland-client.so.0",
"libwayland-client.so",
};
const int paths_num = sizeof(paths) / sizeof(*paths);
int path_found;
if (!(lib = dynamic_library_open_array_with_error(paths, paths_num, verbose, &path_found))) {
return false;
}
if (atexit(wayland_dynload_client_exit)) {
return false;
}
#define WAYLAND_DYNLOAD_IFACE(symbol) \
{ \
const void *symbol_val; \
if (!(symbol_val = dynamic_library_find_with_error(lib, #symbol, paths[path_found]))) { \
return false; \
} \
memcpy(&symbol, symbol_val, sizeof(symbol)); \
}
#include "wayland_dynload_client.h"
#undef WAYLAND_DYNLOAD_IFACE
#define WAYLAND_DYNLOAD_FN(symbol) \
if (!(wayland_dynload_client.symbol = dynamic_library_find_with_error( \
lib, #symbol, paths[path_found]))) { \
return false; \
}
#include "wayland_dynload_client.h"
#undef WAYLAND_DYNLOAD_FN
return true;
}
void wayland_dynload_client_exit(void)
{
if (lib != NULL) {
dynamic_library_close(lib); /* Ignore errors. */
lib = NULL;
}
}
/* Validate local signatures against the original header. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wredundant-decls"
#define WAYLAND_DYNLOAD_VALIDATE
#include "wayland_dynload_client.h"
#pragma GCC diagnostic pop

View File

@ -0,0 +1,61 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup intern_wayland_dynload
*
* Wrapper functions for `<wayland-cursor.h>`.
*/
#include <stdlib.h> /* `atexit`. */
#include <string.h>
#include "wayland_dynload_API.h"
#include "wayland_dynload_utils.h"
#include "wayland_dynload_cursor.h" /* Own include. */
struct WaylandDynload_Cursor wayland_dynload_cursor = {NULL};
static DynamicLibrary lib = NULL;
bool wayland_dynload_cursor_init(const bool verbose)
{
/* Library paths. */
const char *paths[] = {
"libwayland-cursor.so.0",
"libwayland-cursor.so",
};
const int paths_num = sizeof(paths) / sizeof(*paths);
int path_index;
if (!(lib = dynamic_library_open_array_with_error(paths, paths_num, verbose, &path_index))) {
return false;
}
if (atexit(wayland_dynload_cursor_exit)) {
return false;
}
#define WAYLAND_DYNLOAD_FN(symbol) \
if (!(wayland_dynload_cursor.symbol = dynamic_library_find_with_error( \
lib, #symbol, paths[path_index]))) { \
return false; \
}
#include "wayland_dynload_cursor.h"
#undef WAYLAND_DYNLOAD_FN
return true;
}
void wayland_dynload_cursor_exit(void)
{
if (lib != NULL) {
dynamic_library_close(lib); /* Ignore errors. */
lib = NULL;
}
}
/* Validate local signatures against the original header. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wredundant-decls"
#define WAYLAND_DYNLOAD_VALIDATE
#include "wayland_dynload_cursor.h"
#pragma GCC diagnostic pop

View File

@ -0,0 +1,61 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup intern_wayland_dynload
*
* Wrapper functions for `<wayland-egl.h>`.
*/
#include <stdlib.h> /* `atexit`. */
#include "wayland_dynload_API.h"
#include "wayland_dynload_utils.h"
#include "wayland_dynload_egl.h" /* Own include. */
/* Public handle. */
struct WaylandDynload_EGL wayland_dynload_egl = {NULL};
static DynamicLibrary lib = NULL;
bool wayland_dynload_egl_init(const bool verbose)
{
/* Library paths. */
const char *paths[] = {
"libwayland-egl.so.0",
"libwayland-egl.so",
};
const int paths_num = sizeof(paths) / sizeof(*paths);
int path_found = 0;
if (!(lib = dynamic_library_open_array_with_error(paths, paths_num, verbose, &path_found))) {
return false;
}
if (atexit(wayland_dynload_egl_exit)) {
return false;
}
#define WAYLAND_DYNLOAD_FN(symbol) \
if (!(wayland_dynload_egl.symbol = dynamic_library_find_with_error( \
lib, #symbol, paths[path_found]))) { \
return false; \
}
#include "wayland_dynload_egl.h"
#undef WAYLAND_DYNLOAD_FN
return true;
}
void wayland_dynload_egl_exit(void)
{
if (lib != NULL) {
dynamic_library_close(lib); /* Ignore errors. */
lib = NULL;
}
}
/* Validate local signatures against the original header. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wredundant-decls"
#define WAYLAND_DYNLOAD_VALIDATE
#include "wayland_dynload_egl.h"
#pragma GCC diagnostic pop

View File

@ -0,0 +1,61 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup intern_wayland_dynload
*
* Wrapper functions for `<libdecor.h>`.
*/
#include <stdlib.h> /* `atexit`. */
#include "wayland_dynload_API.h"
#include "wayland_dynload_utils.h"
#include "wayland_dynload_libdecor.h" /* Own include. */
/* Public handle. */
struct WaylandDynload_Libdecor wayland_dynload_libdecor = {NULL};
static DynamicLibrary lib = NULL;
bool wayland_dynload_libdecor_init(const bool verbose)
{
/* Library paths. */
const char *paths[] = {
"libdecor-0.so.0",
"libdecor-0.so",
};
const int paths_num = sizeof(paths) / sizeof(*paths);
int path_index;
if (!(lib = dynamic_library_open_array_with_error(paths, paths_num, verbose, &path_index))) {
return false;
}
if (atexit(wayland_dynload_libdecor_exit)) {
return false;
}
#define WAYLAND_DYNLOAD_FN(symbol) \
if (!(wayland_dynload_libdecor.symbol = dynamic_library_find_with_error( \
lib, #symbol, paths[path_index]))) { \
return false; \
}
#include "wayland_dynload_libdecor.h"
#undef WAYLAND_DYNLOAD_FN
return true;
}
void wayland_dynload_libdecor_exit(void)
{
if (lib != NULL) {
dynamic_library_close(lib); /* Ignore errors. */
lib = NULL;
}
}
/* Validate local signatures against the original header. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wredundant-decls"
#define WAYLAND_DYNLOAD_VALIDATE
#include "wayland_dynload_libdecor.h"
#pragma GCC diagnostic pop

View File

@ -0,0 +1,40 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup intern_wayland_dynload
*/
#include <stdio.h>
#include "wayland_dynload_utils.h"
DynamicLibrary dynamic_library_open_array_with_error(const char **paths,
const int paths_num,
const bool verbose,
int *r_path_index)
{
DynamicLibrary lib = NULL;
for (int a = 0; a < paths_num; a++) {
lib = dynamic_library_open(paths[a]);
if (lib) {
*r_path_index = a;
break;
}
}
if (lib == NULL) {
/* Use the last path as it's likely to be least specific. */
if (verbose) {
fprintf(stderr, "Unable to find '%s'\n", paths[paths_num - 1]);
}
}
return lib;
}
void *dynamic_library_find_with_error(DynamicLibrary lib, const char *symbol, const char *path_lib)
{
void *symbol_var = dynamic_library_find(lib, symbol);
if (symbol_var == NULL) {
fprintf(stderr, "Unable to find '%s' in '%s'.\n", symbol, path_lib);
}
return symbol_var;
}

View File

@ -0,0 +1,29 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup intern_wayland_dynload
*
* Utility defines.
*/
#pragma once
#include <dlfcn.h> /* Dynamic loading. */
#include <stdbool.h>
typedef void *DynamicLibrary;
#define dynamic_library_open(path) dlopen(path, RTLD_NOW)
#define dynamic_library_close(lib) dlclose(lib)
#define dynamic_library_find(lib, symbol) dlsym(lib, symbol)
/** Loads a library from an array, printing an error when the symbol isn't found. */
DynamicLibrary dynamic_library_open_array_with_error(const char **paths,
int paths_num,
bool verbose,
int *r_path_index);
/** Find a symbol, printing an error when the symbol isn't found. */
void *dynamic_library_find_with_error(DynamicLibrary lib,
const char *symbol,
const char *path_lib);