diff options
Diffstat (limited to 'Source/3rdParty/SDL2/src/video/wayland')
7 files changed, 215 insertions, 46 deletions
diff --git a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandevents.c b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandevents.c index 53453a2..0c953a5 100644 --- a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandevents.c +++ b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandevents.c @@ -40,6 +40,7 @@ #include "pointer-constraints-unstable-v1-client-protocol.h" #include "relative-pointer-unstable-v1-client-protocol.h" +#include "xdg-shell-client-protocol.h" #include "xdg-shell-unstable-v6-client-protocol.h" #include <linux/input.h> @@ -177,6 +178,8 @@ Wayland_PumpEvents(_THIS) { SDL_VideoData *d = _this->driverdata; + WAYLAND_wl_display_flush(d->display); + if (SDL_IOReady(WAYLAND_wl_display_get_fd(d->display), SDL_FALSE, 0)) { WAYLAND_wl_display_dispatch(d->display); } @@ -263,7 +266,9 @@ ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial) switch (rc) { case SDL_HITTEST_DRAGGABLE: - if (input->display->shell.zxdg) { + if (input->display->shell.xdg) { + xdg_toplevel_move(window_data->shell_surface.xdg.roleobj.toplevel, input->seat, serial); + } else if (input->display->shell.zxdg) { zxdg_toplevel_v6_move(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial); } else { wl_shell_surface_move(window_data->shell_surface.wl, input->seat, serial); @@ -278,7 +283,9 @@ ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial) case SDL_HITTEST_RESIZE_BOTTOM: case SDL_HITTEST_RESIZE_BOTTOMLEFT: case SDL_HITTEST_RESIZE_LEFT: - if (input->display->shell.zxdg) { + if (input->display->shell.xdg) { + xdg_toplevel_resize(window_data->shell_surface.xdg.roleobj.toplevel, input->seat, serial, directions_zxdg[rc - SDL_HITTEST_RESIZE_TOPLEFT]); + } else if (input->display->shell.zxdg) { zxdg_toplevel_v6_resize(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial, directions_zxdg[rc - SDL_HITTEST_RESIZE_TOPLEFT]); } else { wl_shell_surface_resize(window_data->shell_surface.wl, input->seat, serial, directions_wl[rc - SDL_HITTEST_RESIZE_TOPLEFT]); @@ -742,7 +749,7 @@ static const struct wl_data_offer_listener data_offer_listener = { static void data_device_handle_data_offer(void *data, struct wl_data_device *wl_data_device, - struct wl_data_offer *id) + struct wl_data_offer *id) { SDL_WaylandDataOffer *data_offer = NULL; @@ -760,7 +767,7 @@ data_device_handle_data_offer(void *data, struct wl_data_device *wl_data_device, static void data_device_handle_enter(void *data, struct wl_data_device *wl_data_device, - uint32_t serial, struct wl_surface *surface, + uint32_t serial, struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y, struct wl_data_offer *id) { SDL_WaylandDataDevice *data_device = data; @@ -803,7 +810,7 @@ data_device_handle_leave(void *data, struct wl_data_device *wl_data_device) static void data_device_handle_motion(void *data, struct wl_data_device *wl_data_device, - uint32_t time, wl_fixed_t x, wl_fixed_t y) + uint32_t time, wl_fixed_t x, wl_fixed_t y) { } @@ -842,7 +849,7 @@ data_device_handle_drop(void *data, struct wl_data_device *wl_data_device) static void data_device_handle_selection(void *data, struct wl_data_device *wl_data_device, - struct wl_data_offer *id) + struct wl_data_offer *id) { SDL_WaylandDataDevice *data_device = data; SDL_WaylandDataOffer *offer = NULL; diff --git a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandtouch.c b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandtouch.c index 005b47f..1cf37c1 100644 --- a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandtouch.c +++ b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandtouch.c @@ -89,9 +89,9 @@ touch_handle_touch(void *data, */ SDL_TouchID deviceId = 1; - if (SDL_AddTouch(deviceId, "qt_touch_extension") < 0) { - SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); - } + if (SDL_AddTouch(deviceId, "qt_touch_extension") < 0) { + SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); + } switch (touchState) { case QtWaylandTouchPointPressed: diff --git a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandtouch.h b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandtouch.h index 9efc5a5..eba0da8 100644 --- a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandtouch.h +++ b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandtouch.h @@ -19,13 +19,13 @@ 3. This notice may not be removed or altered from any source distribution. */ +#ifndef SDL_waylandtouch_h_ +#define SDL_waylandtouch_h_ + #include "../../SDL_internal.h" #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH -#ifndef SDL_waylandtouch_h_ -#define SDL_waylandtouch_h_ - #include "SDL_waylandvideo.h" #include <stdint.h> #include <stddef.h> @@ -347,6 +347,6 @@ qt_windowmanager_open_url(struct qt_windowmanager *qt_windowmanager, uint32_t re QT_WINDOWMANAGER_OPEN_URL, remaining, url); } -#endif /* SDL_waylandtouch_h_ */ - #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + +#endif /* SDL_waylandtouch_h_ */ diff --git a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandvideo.c b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandvideo.c index 8401a08..b6155e7 100644 --- a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandvideo.c +++ b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandvideo.c @@ -45,6 +45,7 @@ #include "SDL_waylanddyn.h" #include <wayland-util.h> +#include "xdg-shell-client-protocol.h" #include "xdg-shell-unstable-v6-client-protocol.h" #define WAYLANDVID_DRIVER_NAME "wayland" @@ -67,10 +68,10 @@ static char * get_classname() { /* !!! FIXME: this is probably wrong, albeit harmless in many common cases. From protocol spec: - "The surface class identifies the general class of applications - to which the surface belongs. A common convention is to use the - file name (or the full path if it is a non-standard location) of - the application's .desktop file as the class." */ + "The surface class identifies the general class of applications + to which the surface belongs. A common convention is to use the + file name (or the full path if it is a non-standard location) of + the application's .desktop file as the class." */ char *spot; #if defined(__LINUX__) || defined(__FREEBSD__) @@ -328,6 +329,17 @@ static const struct zxdg_shell_v6_listener shell_listener_zxdg = { static void +handle_ping_xdg_wm_base(void *data, struct xdg_wm_base *xdg, uint32_t serial) +{ + xdg_wm_base_pong(xdg, serial); +} + +static const struct xdg_wm_base_listener shell_listener_xdg = { + handle_ping_xdg_wm_base +}; + + +static void display_handle_global(void *data, struct wl_registry *registry, uint32_t id, const char *interface, uint32_t version) { @@ -339,6 +351,9 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id, Wayland_add_display(d, id); } else if (strcmp(interface, "wl_seat") == 0) { Wayland_display_add_input(d, id); + } else if (strcmp(interface, "xdg_wm_base") == 0) { + d->shell.xdg = wl_registry_bind(d->registry, id, &xdg_wm_base_interface, 1); + xdg_wm_base_add_listener(d->shell.xdg, &shell_listener_xdg, NULL); } else if (strcmp(interface, "zxdg_shell_v6") == 0) { d->shell.zxdg = wl_registry_bind(d->registry, id, &zxdg_shell_v6_interface, 1); zxdg_shell_v6_add_listener(d->shell.zxdg, &shell_listener_zxdg, NULL); @@ -475,6 +490,9 @@ Wayland_VideoQuit(_THIS) if (data->shell.wl) wl_shell_destroy(data->shell.wl); + if (data->shell.xdg) + xdg_wm_base_destroy(data->shell.xdg); + if (data->shell.zxdg) zxdg_shell_v6_destroy(data->shell.zxdg); diff --git a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandvideo.h b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandvideo.h index 6ad68de..c16c0bd 100644 --- a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandvideo.h +++ b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandvideo.h @@ -24,6 +24,16 @@ #ifndef SDL_waylandvideo_h_ #define SDL_waylandvideo_h_ + +/* +!!! FIXME: xdg_wm_base is the stable replacement for zxdg_shell_v6. While it's +!!! FIXME: harmless to leave it here, consider deleting the obsolete codepath +!!! FIXME: soon, since Wayland (with xdg_wm_base) will probably be mainline +!!! FIXME: by the time people are relying on this SDL target. It's available +!!! FIXME: in Ubuntu 18.04 (and other distros). +*/ + + #include <EGL/egl.h> #include "wayland-util.h" @@ -44,7 +54,7 @@ typedef struct { struct wl_cursor_theme *cursor_theme; struct wl_pointer *pointer; struct { - /* !!! FIXME: add stable xdg_shell from 1.12 */ + struct xdg_wm_base *xdg; struct zxdg_shell_v6 *zxdg; struct wl_shell *wl; } shell; diff --git a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandwindow.c b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandwindow.c index 684022a..aa72991 100644 --- a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandwindow.c +++ b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandwindow.c @@ -33,6 +33,7 @@ #include "SDL_waylanddyn.h" #include "SDL_hints.h" +#include "xdg-shell-client-protocol.h" #include "xdg-shell-unstable-v6-client-protocol.h" /* On modern desktops, we probably will use the xdg-shell protocol instead @@ -78,19 +79,15 @@ handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_sur } } - if (width == window->w && height == window->h) { - return; - } - - window->w = width; - window->h = height; - WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0); - + WAYLAND_wl_egl_window_resize(wind->egl_window, width, height, 0, 0); region = wl_compositor_create_region(wind->waylandData->compositor); - wl_region_add(region, 0, 0, window->w, window->h); + wl_region_add(region, 0, 0, width, height); wl_surface_set_opaque_region(wind->surface, region); wl_region_destroy(region); - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, window->w, window->h); + + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height); + window->w = width; + window->h = height; } static void @@ -113,13 +110,15 @@ handle_configure_zxdg_shell_surface(void *data, struct zxdg_surface_v6 *zxdg, ui SDL_WindowData *wind = (SDL_WindowData *)data; SDL_Window *window = wind->sdlwindow; struct wl_region *region; + + wind->shell_surface.zxdg.initial_configure_seen = SDL_TRUE; + WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0); region = wl_compositor_create_region(wind->waylandData->compositor); wl_region_add(region, 0, 0, window->w, window->h); wl_surface_set_opaque_region(wind->surface, region); wl_region_destroy(region); - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, window->w, window->h); zxdg_surface_v6_ack_configure(zxdg, serial); } @@ -130,10 +129,10 @@ static const struct zxdg_surface_v6_listener shell_surface_listener_zxdg = { static void handle_configure_zxdg_toplevel(void *data, - struct zxdg_toplevel_v6 *zxdg_toplevel_v6, - int32_t width, - int32_t height, - struct wl_array *states) + struct zxdg_toplevel_v6 *zxdg_toplevel_v6, + int32_t width, + int32_t height, + struct wl_array *states) { SDL_WindowData *wind = (SDL_WindowData *)data; SDL_Window *window = wind->sdlwindow; @@ -161,10 +160,7 @@ handle_configure_zxdg_toplevel(void *data, } } - if (width == window->w && height == window->h) { - return; - } - + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height); window->w = width; window->h = height; } @@ -182,6 +178,87 @@ static const struct zxdg_toplevel_v6_listener toplevel_listener_zxdg = { }; + +static void +handle_configure_xdg_shell_surface(void *data, struct xdg_surface *xdg, uint32_t serial) +{ + SDL_WindowData *wind = (SDL_WindowData *)data; + SDL_Window *window = wind->sdlwindow; + struct wl_region *region; + + wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE; + + WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0); + + region = wl_compositor_create_region(wind->waylandData->compositor); + wl_region_add(region, 0, 0, window->w, window->h); + wl_surface_set_opaque_region(wind->surface, region); + wl_region_destroy(region); + xdg_surface_ack_configure(xdg, serial); +} + +static const struct xdg_surface_listener shell_surface_listener_xdg = { + handle_configure_xdg_shell_surface +}; + + +static void +handle_configure_xdg_toplevel(void *data, + struct xdg_toplevel *xdg_toplevel, + int32_t width, + int32_t height, + struct wl_array *states) +{ + SDL_WindowData *wind = (SDL_WindowData *)data; + SDL_Window *window = wind->sdlwindow; + + /* wl_shell_surface spec states that this is a suggestion. + Ignore if less than or greater than max/min size. */ + + if (width == 0 || height == 0) { + return; + } + + if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { + if ((window->flags & SDL_WINDOW_RESIZABLE)) { + if (window->max_w > 0) { + width = SDL_min(width, window->max_w); + } + width = SDL_max(width, window->min_w); + + if (window->max_h > 0) { + height = SDL_min(height, window->max_h); + } + height = SDL_max(height, window->min_h); + } else { + return; + } + } + + if (width == window->w && height == window->h) { + return; + } + + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height); + window->w = width; + window->h = height; +} + +static void +handle_close_xdg_toplevel(void *data, struct xdg_toplevel *xdg_toplevel) +{ + SDL_WindowData *window = (SDL_WindowData *)data; + SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0); +} + +static const struct xdg_toplevel_listener toplevel_listener_xdg = { + handle_configure_xdg_toplevel, + handle_close_xdg_toplevel +}; + + + + #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH static void handle_onscreen_visibility(void *data, @@ -254,7 +331,13 @@ SetFullscreen(_THIS, SDL_Window * window, struct wl_output *output) const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata; SDL_WindowData *wind = window->driverdata; - if (viddata->shell.zxdg) { + if (viddata->shell.xdg) { + if (output) { + xdg_toplevel_set_fullscreen(wind->shell_surface.xdg.roleobj.toplevel, output); + } else { + xdg_toplevel_unset_fullscreen(wind->shell_surface.xdg.roleobj.toplevel); + } + } else if (viddata->shell.zxdg) { if (output) { zxdg_toplevel_v6_set_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel, output); } else { @@ -359,7 +442,8 @@ Wayland_RestoreWindow(_THIS, SDL_Window * window) SDL_WindowData *wind = window->driverdata; const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata; - if (viddata->shell.zxdg) { + if (viddata->shell.xdg) { + } else if (viddata->shell.zxdg) { } else { wl_shell_surface_set_toplevel(wind->shell_surface.wl); } @@ -373,7 +457,9 @@ Wayland_MaximizeWindow(_THIS, SDL_Window * window) SDL_WindowData *wind = window->driverdata; SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata; - if (viddata->shell.zxdg) { + if (viddata->shell.xdg) { + xdg_toplevel_set_maximized(wind->shell_surface.xdg.roleobj.toplevel); + } else if (viddata->shell.zxdg) { zxdg_toplevel_v6_set_maximized(wind->shell_surface.zxdg.roleobj.toplevel); } else { wl_shell_surface_set_maximized(wind->shell_surface.wl, NULL); @@ -414,7 +500,13 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window) wl_compositor_create_surface(c->compositor); wl_surface_set_user_data(data->surface, data); - if (c->shell.zxdg) { + if (c->shell.xdg) { + data->shell_surface.xdg.surface = xdg_wm_base_get_xdg_surface(c->shell.xdg, data->surface); + /* !!! FIXME: add popup role */ + data->shell_surface.xdg.roleobj.toplevel = xdg_surface_get_toplevel(data->shell_surface.xdg.surface); + xdg_toplevel_add_listener(data->shell_surface.xdg.roleobj.toplevel, &toplevel_listener_xdg, data); + xdg_toplevel_set_app_id(data->shell_surface.xdg.roleobj.toplevel, c->classname); + } else if (c->shell.zxdg) { data->shell_surface.zxdg.surface = zxdg_shell_v6_get_xdg_surface(c->shell.zxdg, data->surface); /* !!! FIXME: add popup role */ data->shell_surface.zxdg.roleobj.toplevel = zxdg_surface_v6_get_toplevel(data->shell_surface.zxdg.surface); @@ -445,7 +537,12 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window) return SDL_SetError("failed to create a window surface"); } - if (c->shell.zxdg) { + if (c->shell.xdg) { + if (data->shell_surface.xdg.surface) { + xdg_surface_set_user_data(data->shell_surface.xdg.surface, data); + xdg_surface_add_listener(data->shell_surface.xdg.surface, &shell_surface_listener_xdg, data); + } + } else if (c->shell.zxdg) { if (data->shell_surface.zxdg.surface) { zxdg_surface_v6_set_user_data(data->shell_surface.zxdg.surface, data); zxdg_surface_v6_add_listener(data->shell_surface.zxdg.surface, &shell_surface_listener_zxdg, data); @@ -477,6 +574,24 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window) wl_surface_commit(data->surface); WAYLAND_wl_display_flush(c->display); + /* we have to wait until the surface gets a "configure" event, or + use of this surface will fail. This is a new rule for xdg_shell. */ + if (c->shell.xdg) { + if (data->shell_surface.xdg.surface) { + while (!data->shell_surface.xdg.initial_configure_seen) { + WAYLAND_wl_display_flush(c->display); + WAYLAND_wl_display_dispatch(c->display); + } + } + } else if (c->shell.zxdg) { + if (data->shell_surface.zxdg.surface) { + while (!data->shell_surface.zxdg.initial_configure_seen) { + WAYLAND_wl_display_flush(c->display); + WAYLAND_wl_display_dispatch(c->display); + } + } + } + return 0; } @@ -500,7 +615,9 @@ void Wayland_SetWindowTitle(_THIS, SDL_Window * window) SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata; if (window->title != NULL) { - if (viddata->shell.zxdg) { + if (viddata->shell.xdg) { + xdg_toplevel_set_title(wind->shell_surface.xdg.roleobj.toplevel, window->title); + } else if (viddata->shell.zxdg) { zxdg_toplevel_v6_set_title(wind->shell_surface.zxdg.roleobj.toplevel, window->title); } else { wl_shell_surface_set_title(wind->shell_surface.wl, window->title); @@ -519,7 +636,14 @@ void Wayland_DestroyWindow(_THIS, SDL_Window *window) SDL_EGL_DestroySurface(_this, wind->egl_surface); WAYLAND_wl_egl_window_destroy(wind->egl_window); - if (data->shell.zxdg) { + if (data->shell.xdg) { + if (wind->shell_surface.xdg.roleobj.toplevel) { + xdg_toplevel_destroy(wind->shell_surface.xdg.roleobj.toplevel); + } + if (wind->shell_surface.zxdg.surface) { + xdg_surface_destroy(wind->shell_surface.xdg.surface); + } + } else if (data->shell.zxdg) { if (wind->shell_surface.zxdg.roleobj.toplevel) { zxdg_toplevel_v6_destroy(wind->shell_surface.zxdg.roleobj.toplevel); } diff --git a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandwindow.h b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandwindow.h index 80d4f31..69b9889 100644 --- a/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandwindow.h +++ b/Source/3rdParty/SDL2/src/video/wayland/SDL_waylandwindow.h @@ -37,14 +37,24 @@ typedef struct { struct zxdg_toplevel_v6 *toplevel; struct zxdg_popup_v6 *popup; } roleobj; + SDL_bool initial_configure_seen; } SDL_zxdg_shell_surface; typedef struct { + struct xdg_surface *surface; + union { + struct xdg_toplevel *toplevel; + struct xdg_popup *popup; + } roleobj; + SDL_bool initial_configure_seen; +} SDL_xdg_shell_surface; + +typedef struct { SDL_Window *sdlwindow; SDL_VideoData *waylandData; struct wl_surface *surface; union { - /* !!! FIXME: add stable xdg_shell from 1.12 */ + SDL_xdg_shell_surface xdg; SDL_zxdg_shell_surface zxdg; struct wl_shell_surface *wl; } shell_surface; |