1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#ifndef SDL_waylanddyn_h_
22#define SDL_waylanddyn_h_
23
24#include "SDL_internal.h"
25
26/* We can't include wayland-client.h here
27 * but we need some structs from it
28 */
29struct wl_interface;
30struct wl_proxy;
31struct wl_event_queue;
32struct wl_display;
33struct wl_surface;
34struct wl_shm;
35
36// We also need some for libdecor
37struct wl_seat;
38struct wl_output;
39struct libdecor;
40struct libdecor_frame;
41struct libdecor_state;
42struct libdecor_configuration;
43struct libdecor_interface;
44struct libdecor_frame_interface;
45enum libdecor_resize_edge;
46enum libdecor_capabilities;
47enum libdecor_window_state;
48
49#include "wayland-cursor.h"
50#include "wayland-util.h"
51#include "xkbcommon/xkbcommon.h"
52#include "xkbcommon/xkbcommon-compose.h"
53
54// Must be included before our #defines, see Bugzilla #4957
55#include "wayland-client-core.h"
56
57#define SDL_WAYLAND_CHECK_VERSION(x, y, z) \
58 (WAYLAND_VERSION_MAJOR > x || \
59 (WAYLAND_VERSION_MAJOR == x && WAYLAND_VERSION_MINOR > y) || \
60 (WAYLAND_VERSION_MAJOR == x && WAYLAND_VERSION_MINOR == y && WAYLAND_VERSION_MICRO >= z))
61
62#ifdef HAVE_LIBDECOR_H
63#define SDL_LIBDECOR_CHECK_VERSION(x, y, z) \
64 (SDL_LIBDECOR_VERSION_MAJOR > x || \
65 (SDL_LIBDECOR_VERSION_MAJOR == x && SDL_LIBDECOR_VERSION_MINOR > y) || \
66 (SDL_LIBDECOR_VERSION_MAJOR == x && SDL_LIBDECOR_VERSION_MINOR == y && SDL_LIBDECOR_VERSION_PATCH >= z))
67#endif
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73extern bool SDL_WAYLAND_LoadSymbols(void);
74extern void SDL_WAYLAND_UnloadSymbols(void);
75
76#define SDL_WAYLAND_MODULE(modname) extern int SDL_WAYLAND_HAVE_##modname;
77#define SDL_WAYLAND_SYM(rc, fn, params) \
78 typedef rc(*SDL_DYNWAYLANDFN_##fn) params; \
79 extern SDL_DYNWAYLANDFN_##fn WAYLAND_##fn;
80#define SDL_WAYLAND_SYM_OPT(rc, fn, params) \
81 typedef rc(*SDL_DYNWAYLANDFN_##fn) params; \
82 extern SDL_DYNWAYLANDFN_##fn WAYLAND_##fn;
83#define SDL_WAYLAND_INTERFACE(iface) extern const struct wl_interface *WAYLAND_##iface;
84#include "SDL_waylandsym.h"
85
86#ifdef __cplusplus
87}
88#endif
89
90#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
91
92#if defined(_WAYLAND_CLIENT_H) || defined(WAYLAND_CLIENT_H)
93#error Do not include wayland-client ahead of SDL_waylanddyn.h in dynamic loading mode
94#endif
95
96/* wayland-client-protocol.h included from wayland-client.h
97 * has inline functions that require these to be defined in dynamic loading mode
98 */
99
100#define wl_proxy_create (*WAYLAND_wl_proxy_create)
101#define wl_proxy_destroy (*WAYLAND_wl_proxy_destroy)
102#define wl_proxy_marshal (*WAYLAND_wl_proxy_marshal)
103#define wl_proxy_set_user_data (*WAYLAND_wl_proxy_set_user_data)
104#define wl_proxy_get_user_data (*WAYLAND_wl_proxy_get_user_data)
105#define wl_proxy_get_version (*WAYLAND_wl_proxy_get_version)
106#define wl_proxy_add_listener (*WAYLAND_wl_proxy_add_listener)
107#define wl_proxy_marshal_constructor (*WAYLAND_wl_proxy_marshal_constructor)
108#define wl_proxy_marshal_constructor_versioned (*WAYLAND_wl_proxy_marshal_constructor_versioned)
109#define wl_proxy_set_tag (*WAYLAND_wl_proxy_set_tag)
110#define wl_proxy_get_tag (*WAYLAND_wl_proxy_get_tag)
111#define wl_proxy_marshal_flags (*WAYLAND_wl_proxy_marshal_flags)
112#define wl_proxy_marshal_array_flags (*WAYLAND_wl_proxy_marshal_array_flags)
113#define wl_display_reconnect (*WAYLAND_wl_display_reconnect)
114
115#define wl_seat_interface (*WAYLAND_wl_seat_interface)
116#define wl_surface_interface (*WAYLAND_wl_surface_interface)
117#define wl_shm_pool_interface (*WAYLAND_wl_shm_pool_interface)
118#define wl_buffer_interface (*WAYLAND_wl_buffer_interface)
119#define wl_registry_interface (*WAYLAND_wl_registry_interface)
120#define wl_region_interface (*WAYLAND_wl_region_interface)
121#define wl_pointer_interface (*WAYLAND_wl_pointer_interface)
122#define wl_keyboard_interface (*WAYLAND_wl_keyboard_interface)
123#define wl_compositor_interface (*WAYLAND_wl_compositor_interface)
124#define wl_output_interface (*WAYLAND_wl_output_interface)
125#define wl_shm_interface (*WAYLAND_wl_shm_interface)
126#define wl_data_device_interface (*WAYLAND_wl_data_device_interface)
127#define wl_data_offer_interface (*WAYLAND_wl_data_offer_interface)
128#define wl_data_source_interface (*WAYLAND_wl_data_source_interface)
129#define wl_data_device_manager_interface (*WAYLAND_wl_data_device_manager_interface)
130
131/*
132 * These must be included before libdecor.h, otherwise the libdecor header
133 * pulls in the system Wayland protocol headers instead of ours.
134 */
135#include "wayland-client-protocol.h"
136#include "wayland-egl.h"
137
138#ifdef HAVE_LIBDECOR_H
139// Must be included before our defines
140#include <libdecor.h>
141
142#define libdecor_unref (*WAYLAND_libdecor_unref)
143#define libdecor_new (*WAYLAND_libdecor_new)
144#define libdecor_decorate (*WAYLAND_libdecor_decorate)
145#define libdecor_frame_unref (*WAYLAND_libdecor_frame_unref)
146#define libdecor_frame_set_title (*WAYLAND_libdecor_frame_set_title)
147#define libdecor_frame_set_app_id (*WAYLAND_libdecor_frame_set_app_id)
148#define libdecor_frame_set_max_content_size (*WAYLAND_libdecor_frame_set_max_content_size)
149#define libdecor_frame_get_max_content_size (*WAYLAND_libdecor_frame_get_max_content_size)
150#define libdecor_frame_set_min_content_size (*WAYLAND_libdecor_frame_set_min_content_size)
151#define libdecor_frame_get_min_content_size (*WAYLAND_libdecor_frame_get_min_content_size)
152#define libdecor_frame_resize (*WAYLAND_libdecor_frame_resize)
153#define libdecor_frame_move (*WAYLAND_libdecor_frame_move)
154#define libdecor_frame_commit (*WAYLAND_libdecor_frame_commit)
155#define libdecor_frame_set_minimized (*WAYLAND_libdecor_frame_set_minimized)
156#define libdecor_frame_set_maximized (*WAYLAND_libdecor_frame_set_maximized)
157#define libdecor_frame_unset_maximized (*WAYLAND_libdecor_frame_unset_maximized)
158#define libdecor_frame_set_fullscreen (*WAYLAND_libdecor_frame_set_fullscreen)
159#define libdecor_frame_unset_fullscreen (*WAYLAND_libdecor_frame_unset_fullscreen)
160#define libdecor_frame_set_capabilities (*WAYLAND_libdecor_frame_set_capabilities)
161#define libdecor_frame_unset_capabilities (*WAYLAND_libdecor_frame_unset_capabilities)
162#define libdecor_frame_has_capability (*WAYLAND_libdecor_frame_has_capability)
163#define libdecor_frame_set_visibility (*WAYLAND_libdecor_frame_set_visibility)
164#define libdecor_frame_is_visible (*WAYLAND_libdecor_frame_is_visible)
165#define libdecor_frame_is_floating (*WAYLAND_libdecor_frame_is_floating)
166#define libdecor_frame_set_parent (*WAYLAND_libdecor_frame_set_parent)
167#define libdecor_frame_show_window_menu (*WAYLAND_libdecor_frame_show_window_menu)
168#define libdecor_frame_get_wm_capabilities (*WAYLAND_libdecor_frame_get_wm_capabilities)
169#define libdecor_frame_get_xdg_surface (*WAYLAND_libdecor_frame_get_xdg_surface)
170#define libdecor_frame_get_xdg_toplevel (*WAYLAND_libdecor_frame_get_xdg_toplevel)
171#define libdecor_frame_translate_coordinate (*WAYLAND_libdecor_frame_translate_coordinate)
172#define libdecor_frame_map (*WAYLAND_libdecor_frame_map)
173#define libdecor_state_new (*WAYLAND_libdecor_state_new)
174#define libdecor_state_free (*WAYLAND_libdecor_state_free)
175#define libdecor_configuration_get_content_size (*WAYLAND_libdecor_configuration_get_content_size)
176#define libdecor_configuration_get_window_state (*WAYLAND_libdecor_configuration_get_window_state)
177#define libdecor_dispatch (*WAYLAND_libdecor_dispatch)
178#endif
179
180#else // SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
181
182/*
183 * These must be included before libdecor.h, otherwise the libdecor header
184 * pulls in the system Wayland protocol headers instead of ours.
185 */
186#include "wayland-client-protocol.h"
187#include "wayland-egl.h"
188
189#ifdef HAVE_LIBDECOR_H
190#include <libdecor.h>
191#endif
192
193#endif // SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
194
195#endif // SDL_waylanddyn_h_
196