# HG changeset patch # User Nathaniel R. Lewis # Date 1492211785 25200 # Fri Apr 14 16:16:25 2017 -0700 # Node ID 18ced04a865f2a93d796fd1827be1a0951173071 # Parent b141211c5d0a2d3110c1aae2c295ec887438a009 wayland: Added support for fullscreen shell compositors diff -r b141211c5d0a -r 18ced04a865f cmake/sdlchecks.cmake --- a/cmake/sdlchecks.cmake Thu Apr 13 13:28:52 2017 -0400 +++ b/cmake/sdlchecks.cmake Fri Apr 14 16:16:25 2017 -0700 @@ -655,7 +655,7 @@ WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_CORE_PROTOCOL_DIR}/wayland.xml" "wayland") - foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1) + foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1 fullscreen-shell-unstable-v1) string(REGEX REPLACE "\\-unstable\\-.*$" "" PROTSUBDIR ${_PROTL}) WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_PROTOCOLS_DIR}/unstable/${PROTSUBDIR}/${_PROTL}.xml" "${_PROTL}") endforeach() diff -r b141211c5d0a -r 18ced04a865f configure --- a/configure Thu Apr 13 13:28:52 2017 -0400 +++ b/configure Fri Apr 14 16:16:25 2017 -0700 @@ -19064,7 +19064,7 @@ fi - WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1" + WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1 fullscreen-shell-unstable-v1" SOURCES="$SOURCES $srcdir/src/video/wayland/*.c" EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS -I\$(gen)" diff -r b141211c5d0a -r 18ced04a865f configure.in --- a/configure.in Thu Apr 13 13:28:52 2017 -0400 +++ b/configure.in Fri Apr 14 16:16:25 2017 -0700 @@ -1341,7 +1341,7 @@ AC_DEFINE(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH, 1, [ ]) fi - WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1" + WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1 fullscreen-shell-unstable-v1" SOURCES="$SOURCES $srcdir/src/video/wayland/*.c" EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS -I\$(gen)" diff -r b141211c5d0a -r 18ced04a865f src/video/wayland/SDL_waylandevents.c --- a/src/video/wayland/SDL_waylandevents.c Thu Apr 13 13:28:52 2017 -0400 +++ b/src/video/wayland/SDL_waylandevents.c Fri Apr 14 16:16:25 2017 -0700 @@ -157,7 +157,9 @@ }; switch (rc) { case SDL_HITTEST_DRAGGABLE: - wl_shell_surface_move(window_data->shell_surface, input->seat, serial); + if (input->display->shell) { + wl_shell_surface_move(window_data->shell_surface, input->seat, serial); + } return SDL_TRUE; case SDL_HITTEST_RESIZE_TOPLEFT: @@ -168,7 +170,9 @@ case SDL_HITTEST_RESIZE_BOTTOM: case SDL_HITTEST_RESIZE_BOTTOMLEFT: case SDL_HITTEST_RESIZE_LEFT: - wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]); + if (input->display->shell) { + wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]); + } return SDL_TRUE; default: return SDL_FALSE; diff -r b141211c5d0a -r 18ced04a865f src/video/wayland/SDL_waylandvideo.c --- a/src/video/wayland/SDL_waylandvideo.c Thu Apr 13 13:28:52 2017 -0400 +++ b/src/video/wayland/SDL_waylandvideo.c Fri Apr 14 16:16:25 2017 -0700 @@ -43,6 +43,7 @@ #include "SDL_waylanddyn.h" #include +#include "fullscreen-shell-unstable-v1-client-protocol.h" #define WAYLANDVID_DRIVER_NAME "wayland" @@ -319,6 +320,8 @@ Wayland_display_add_relative_pointer_manager(d, id); } else if (strcmp(interface, "zwp_pointer_constraints_v1") == 0) { Wayland_display_add_pointer_constraints(d, id); + } else if (strcmp(interface, "zwp_fullscreen_shell_v1") == 0) { + d->fullscreen_shell = wl_registry_bind(d->registry, id, &zwp_fullscreen_shell_v1_interface, 1); } else if (strcmp(interface, "wl_data_device_manager") == 0) { d->data_device_manager = wl_registry_bind(d->registry, id, &wl_data_device_manager_interface, 3); #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH @@ -427,6 +430,9 @@ Wayland_touch_destroy(data); #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + if (data->fullscreen_shell) + zwp_fullscreen_shell_v1_destroy(data->fullscreen_shell); + if (data->shm) wl_shm_destroy(data->shm); diff -r b141211c5d0a -r 18ced04a865f src/video/wayland/SDL_waylandvideo.h --- a/src/video/wayland/SDL_waylandvideo.h Thu Apr 13 13:28:52 2017 -0400 +++ b/src/video/wayland/SDL_waylandvideo.h Fri Apr 14 16:16:25 2017 -0700 @@ -44,6 +44,7 @@ struct wl_cursor_theme *cursor_theme; struct wl_pointer *pointer; struct wl_shell *shell; + struct zwp_fullscreen_shell_v1 *fullscreen_shell; struct zwp_relative_pointer_manager_v1 *relative_pointer_manager; struct zwp_pointer_constraints_v1 *pointer_constraints; struct wl_data_device_manager *data_device_manager; diff -r b141211c5d0a -r 18ced04a865f src/video/wayland/SDL_waylandwindow.c --- a/src/video/wayland/SDL_waylandwindow.c Thu Apr 13 13:28:52 2017 -0400 +++ b/src/video/wayland/SDL_waylandwindow.c Fri Apr 14 16:16:25 2017 -0700 @@ -33,6 +33,16 @@ #include "SDL_waylanddyn.h" #include "SDL_hints.h" +#include "fullscreen-shell-unstable-v1-client-protocol.h" + +static void +Wayland_PresentWindowFullscreen(SDL_VideoData *display, SDL_Window *window, + struct wl_output *output); + +static void +Wayland_PresentWindowWindowed(SDL_VideoData *display, SDL_Window *window, + struct wl_output *output); + static void handle_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial) @@ -146,14 +156,13 @@ void Wayland_ShowWindow(_THIS, SDL_Window *window) { - SDL_WindowData *wind = window->driverdata; + SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); + struct wl_output *output = display->driverdata; if (window->flags & SDL_WINDOW_FULLSCREEN) - wl_shell_surface_set_fullscreen(wind->shell_surface, - WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, - 0, (struct wl_output *)window->fullscreen_mode.driverdata); + Wayland_PresentWindowFullscreen(_this->driverdata, window, output); else - wl_shell_surface_set_toplevel(wind->shell_surface); + Wayland_PresentWindowWindowed(_this->driverdata, window, output); WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); } @@ -227,14 +236,12 @@ Wayland_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * _display, SDL_bool fullscreen) { - SDL_WindowData *wind = window->driverdata; + struct wl_output *output = _display->driverdata; if (fullscreen) - wl_shell_surface_set_fullscreen(wind->shell_surface, - WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE, - 0, (struct wl_output *)_display->driverdata); + Wayland_PresentWindowFullscreen(_this->driverdata, window, output); else - wl_shell_surface_set_toplevel(wind->shell_surface); + Wayland_PresentWindowWindowed(_this->driverdata, window, output); WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); } @@ -243,20 +250,24 @@ Wayland_RestoreWindow(_THIS, SDL_Window * window) { SDL_WindowData *wind = window->driverdata; + SDL_VideoData *vid = _this->driverdata; - wl_shell_surface_set_toplevel(wind->shell_surface); - - WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); + if (vid->shell) { + wl_shell_surface_set_toplevel(wind->shell_surface); + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); + } } void Wayland_MaximizeWindow(_THIS, SDL_Window * window) { SDL_WindowData *wind = window->driverdata; + SDL_VideoData *vid = _this->driverdata; - wl_shell_surface_set_maximized(wind->shell_surface, NULL); - - WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); + if (vid->shell) { + wl_shell_surface_set_maximized(wind->shell_surface, NULL); + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); + } } int Wayland_CreateWindow(_THIS, SDL_Window *window) @@ -290,9 +301,10 @@ data->surface = wl_compositor_create_surface(c->compositor); wl_surface_set_user_data(data->surface, data); - data->shell_surface = wl_shell_get_shell_surface(c->shell, - data->surface); - wl_shell_surface_set_class (data->shell_surface, c->classname); + + if (c->shell) { + data->shell_surface = wl_shell_get_shell_surface(c->shell, data->surface); + } #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH if (c->surface_extension) { data->extended_surface = qt_surface_extension_get_extended_surface( @@ -314,6 +326,7 @@ } if (data->shell_surface) { + wl_shell_surface_set_class(data->shell_surface, c->classname); wl_shell_surface_set_user_data(data->shell_surface, data); wl_shell_surface_add_listener(data->shell_surface, &shell_surface_listener, data); @@ -358,8 +371,9 @@ void Wayland_SetWindowTitle(_THIS, SDL_Window * window) { SDL_WindowData *wind = window->driverdata; + SDL_VideoData *vid = _this->driverdata; - if (window->title != NULL) { + if (vid->shell != NULL && window->title != NULL) { wl_shell_surface_set_title(wind->shell_surface, window->title); } @@ -393,6 +407,46 @@ window->driverdata = NULL; } +static void +Wayland_PresentWindowFullscreen(SDL_VideoData *display, SDL_Window *window, + struct wl_output *output) +{ + SDL_WindowData *wind = window->driverdata; + + /* Standard Compositor */ + if (display->shell) { + wl_shell_surface_set_fullscreen(wind->shell_surface, + WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE, + 0, output); + } + + /* Fullscreen compositor */ + else if (display->fullscreen_shell) { + zwp_fullscreen_shell_v1_present_surface(display->fullscreen_shell, wind->surface, + ZWP_FULLSCREEN_SHELL_V1_PRESENT_METHOD_ZOOM, + output); + } +} + +static void +Wayland_PresentWindowWindowed(SDL_VideoData *display, SDL_Window *window, + struct wl_output *output) +{ + SDL_WindowData *wind = window->driverdata; + + /* Standard Compositor */ + if (display->shell) { + wl_shell_surface_set_toplevel(wind->shell_surface); + } + + /* Fullscreen compositor */ + else if (display->fullscreen_shell) { + zwp_fullscreen_shell_v1_present_surface(display->fullscreen_shell, wind->surface, + ZWP_FULLSCREEN_SHELL_V1_PRESENT_METHOD_DEFAULT, + output); + } +} + #endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */ /* vi: set ts=4 sw=4 expandtab: */