22 #include "../../SDL_internal.h"
24 #if SDL_VIDEO_DRIVER_WAYLAND
29 #include "../../events/SDL_events_c.h"
40 #include <sys/types.h>
43 #include <xkbcommon/xkbcommon.h>
46 #include <wayland-util.h>
48 #include "xdg-shell-client-protocol.h"
49 #include "xdg-shell-unstable-v6-client-protocol.h"
51 #define WAYLANDVID_DRIVER_NAME "wayland"
55 Wayland_VideoInit(
_THIS);
63 Wayland_VideoQuit(
_THIS);
77 #if defined(__LINUX__) || defined(__FREEBSD__)
84 spot =
SDL_getenv(
"SDL_VIDEO_WAYLAND_WMCLASS");
96 #if defined(__LINUX__) || defined(__FREEBSD__)
97 #if defined(__LINUX__)
99 #elif defined(__FREEBSD__)
103 #error Where can we find the executable name?
105 linksize = readlink(procfile, linkfile,
sizeof(linkfile) - 1);
107 linkfile[linksize] =
'\0';
123 Wayland_Available(
void)
125 struct wl_display *display =
NULL;
127 display = WAYLAND_wl_display_connect(
NULL);
128 if (display !=
NULL) {
129 WAYLAND_wl_display_disconnect(display);
134 return (display !=
NULL);
145 Wayland_CreateDevice(
int devindex)
201 device->
free = Wayland_DeleteDevice;
207 WAYLANDVID_DRIVER_NAME,
"SDL Wayland video driver",
208 Wayland_Available, Wayland_CreateDevice
212 display_handle_geometry(
void *
data,
230 display_handle_mode(
void *
data,
248 if (flags & WL_OUTPUT_MODE_CURRENT) {
255 display_handle_done(
void *data,
256 struct wl_output *output)
265 display_handle_scale(
void *data,
266 struct wl_output *output,
272 static const struct wl_output_listener output_listener = {
273 display_handle_geometry,
290 output = wl_registry_bind(d->
registry,
id, &wl_output_interface, 2);
297 wl_output_add_listener(output, &output_listener, display);
300 #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
302 windowmanager_hints(
void *data,
struct qt_windowmanager *qt_windowmanager,
308 windowmanager_quit(
void *data,
struct qt_windowmanager *qt_windowmanager)
313 static const struct qt_windowmanager_listener windowmanager_listener = {
321 handle_ping_zxdg_shell(
void *data,
struct zxdg_shell_v6 *zxdg,
uint32_t serial)
323 zxdg_shell_v6_pong(zxdg, serial);
326 static const struct zxdg_shell_v6_listener shell_listener_zxdg = {
327 handle_ping_zxdg_shell
332 handle_ping_xdg_wm_base(
void *data,
struct xdg_wm_base *xdg,
uint32_t serial)
334 xdg_wm_base_pong(xdg, serial);
337 static const struct xdg_wm_base_listener shell_listener_xdg = {
338 handle_ping_xdg_wm_base
343 display_handle_global(
void *data,
struct wl_registry *registry,
uint32_t id,
344 const char *interface,
uint32_t version)
348 if (strcmp(interface,
"wl_compositor") == 0) {
350 }
else if (strcmp(interface,
"wl_output") == 0) {
351 Wayland_add_display(d,
id);
352 }
else if (strcmp(interface,
"wl_seat") == 0) {
354 }
else if (strcmp(interface,
"xdg_wm_base") == 0) {
355 d->
shell.
xdg = wl_registry_bind(d->
registry,
id, &xdg_wm_base_interface, 1);
356 xdg_wm_base_add_listener(d->
shell.
xdg, &shell_listener_xdg,
NULL);
357 }
else if (strcmp(interface,
"zxdg_shell_v6") == 0) {
359 zxdg_shell_v6_add_listener(d->
shell.
zxdg, &shell_listener_zxdg,
NULL);
360 }
else if (strcmp(interface,
"wl_shell") == 0) {
361 d->
shell.
wl = wl_registry_bind(d->
registry,
id, &wl_shell_interface, 1);
362 }
else if (strcmp(interface,
"wl_shm") == 0) {
363 d->
shm = wl_registry_bind(registry,
id, &wl_shm_interface, 1);
365 }
else if (strcmp(interface,
"zwp_relative_pointer_manager_v1") == 0) {
367 }
else if (strcmp(interface,
"zwp_pointer_constraints_v1") == 0) {
369 }
else if (strcmp(interface,
"wl_data_device_manager") == 0) {
372 #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
373 }
else if (strcmp(interface,
"qt_touch_extension") == 0) {
374 Wayland_touch_create(d,
id);
375 }
else if (strcmp(interface,
"qt_surface_extension") == 0) {
376 d->surface_extension = wl_registry_bind(registry,
id,
377 &qt_surface_extension_interface, 1);
378 }
else if (strcmp(interface,
"qt_windowmanager") == 0) {
379 d->windowmanager = wl_registry_bind(registry,
id,
380 &qt_windowmanager_interface, 1);
381 qt_windowmanager_add_listener(d->windowmanager, &windowmanager_listener, d);
386 static const struct wl_registry_listener registry_listener = {
387 display_handle_global,
392 Wayland_VideoInit(
_THIS)
397 memset(data, 0,
sizeof *data);
408 return SDL_SetError(
"Failed to connect to a Wayland display");
413 return SDL_SetError(
"Failed to get the Wayland registry");
416 wl_registry_add_listener(data->
registry, ®istry_listener, data);
419 WAYLAND_wl_display_roundtrip(data->
display);
422 WAYLAND_wl_display_roundtrip(data->
display);
429 WAYLAND_wl_display_flush(data->
display);
448 Wayland_VideoQuit(
_THIS)
453 Wayland_FiniMouse ();
474 #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
475 if (data->windowmanager)
476 qt_windowmanager_destroy(data->windowmanager);
478 if (data->surface_extension)
479 qt_surface_extension_destroy(data->surface_extension);
481 Wayland_touch_destroy(data);
485 wl_shm_destroy(data->
shm);
491 wl_shell_destroy(data->
shell.
wl);
494 xdg_wm_base_destroy(data->
shell.
xdg);
503 wl_registry_destroy(data->
registry);
506 WAYLAND_wl_display_flush(data->
display);
507 WAYLAND_wl_display_disconnect(data->
display);