wayland: fix resizing and fullscreen toggling For starters, we need to correctly respond to 0,0 configure after unsetting fullscreen. Also, turns out that there should be no drawing calls at all in between eglSwapBuffers and wl_egl_window_resize, as otherwise EGL can already allocate a wrongly sized buffer for a next frame, so handle those together.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
diff --git a/src/video/wayland/SDL_waylandopengles.c b/src/video/wayland/SDL_waylandopengles.c
index 9c0b845..aafd71e 100644
--- a/src/video/wayland/SDL_waylandopengles.c
+++ b/src/video/wayland/SDL_waylandopengles.c
@@ -22,12 +22,17 @@
#if SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_windowevents_c.h"
#include "SDL_waylandvideo.h"
#include "SDL_waylandopengles.h"
#include "SDL_waylandwindow.h"
#include "SDL_waylandevents_c.h"
#include "SDL_waylanddyn.h"
+#include "xdg-shell-client-protocol.h"
+#include "xdg-shell-unstable-v6-client-protocol.h"
+
/* EGL implementation of SDL OpenGL ES support */
int
@@ -57,10 +62,37 @@ Wayland_GLES_CreateContext(_THIS, SDL_Window * window)
int
Wayland_GLES_SwapWindow(_THIS, SDL_Window *window)
{
- if (SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface) < 0) {
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ struct wl_region *region;
+
+ if (SDL_EGL_SwapBuffers(_this, data->egl_surface) < 0) {
return -1;
}
- WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
+
+ // Wayland-EGL forbids drawing calls in-between SwapBuffers and wl_egl_window_resize
+ if (data->resize.pending) {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, data->resize.width, data->resize.height);
+ window->w = data->resize.width;
+ window->h = data->resize.height;
+
+ WAYLAND_wl_egl_window_resize(data->egl_window, window->w, window->h, 0, 0);
+
+ if (data->waylandData->shell.xdg) {
+ xdg_surface_ack_configure(data->shell_surface.xdg.surface, data->resize.serial);
+ } else if (data->waylandData->shell.zxdg) {
+ zxdg_surface_v6_ack_configure(data->shell_surface.zxdg.surface, data->resize.serial);
+ }
+
+ region = wl_compositor_create_region(data->waylandData->compositor);
+ wl_region_add(region, 0, 0, window->w, window->h);
+ wl_surface_set_opaque_region(data->surface, region);
+ wl_region_destroy(region);
+
+ data->resize.pending = SDL_FALSE;
+ }
+
+ WAYLAND_wl_display_flush( data->waylandData->display );
+
return 0;
}
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index 828d69c..6858991 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -55,7 +55,6 @@ handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_sur
{
SDL_WindowData *wind = (SDL_WindowData *)data;
SDL_Window *window = wind->sdlwindow;
- struct wl_region *region;
/* wl_shell_surface spec states that this is a suggestion.
Ignore if less than or greater than max/min size. */
@@ -68,7 +67,7 @@ handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_sur
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) {
@@ -80,15 +79,9 @@ handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_sur
}
}
- 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, width, height);
- wl_surface_set_opaque_region(wind->surface, region);
- wl_region_destroy(region);
-
- SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height);
- window->w = width;
- window->h = height;
+ wind->resize.width = width;
+ wind->resize.height = height;
+ wind->resize.pending = SDL_TRUE;
}
static void
@@ -112,15 +105,25 @@ handle_configure_zxdg_shell_surface(void *data, struct zxdg_surface_v6 *zxdg, ui
SDL_Window *window = wind->sdlwindow;
struct wl_region *region;
- wind->shell_surface.zxdg.initial_configure_seen = SDL_TRUE;
+ if (!wind->shell_surface.zxdg.initial_configure_seen) {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, wind->resize.width, wind->resize.height);
+ window->w = wind->resize.width;
+ window->h = wind->resize.height;
- WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
+ 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);
- zxdg_surface_v6_ack_configure(zxdg, serial);
+ zxdg_surface_v6_ack_configure(zxdg, serial);
+
+ 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);
+
+ wind->shell_surface.zxdg.initial_configure_seen = SDL_TRUE;
+ } else {
+ wind->resize.pending = SDL_TRUE;
+ wind->resize.serial = serial;
+ }
}
static const struct zxdg_surface_v6_listener shell_surface_listener_zxdg = {
@@ -138,18 +141,27 @@ handle_configure_zxdg_toplevel(void *data,
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;
+ enum zxdg_toplevel_v6_state *state;
+ SDL_bool fullscreen = SDL_FALSE;
+ wl_array_for_each(state, states) {
+ if (*state == ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN) {
+ fullscreen = SDL_TRUE;
+ }
}
- if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+ if (!fullscreen) {
+ if (width == 0 || height == 0) {
+ width = window->windowed.w;
+ height = window->windowed.h;
+ }
+
+ /* zxdg_toplevel spec states that this is a suggestion.
+ Ignore if less than or greater than max/min size. */
+
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) {
@@ -157,13 +169,20 @@ handle_configure_zxdg_toplevel(void *data,
}
height = SDL_max(height, window->min_h);
} else {
+ wind->resize.width = window->w;
+ wind->resize.height = window->h;
return;
}
}
- SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height);
- window->w = width;
- window->h = height;
+ if (width == 0 || height == 0) {
+ wind->resize.width = window->w;
+ wind->resize.height = window->h;
+ return;
+ }
+
+ wind->resize.width = width;
+ wind->resize.height = height;
}
static void
@@ -187,15 +206,25 @@ handle_configure_xdg_shell_surface(void *data, struct xdg_surface *xdg, uint32_t
SDL_Window *window = wind->sdlwindow;
struct wl_region *region;
- wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE;
+ if (!wind->shell_surface.xdg.initial_configure_seen) {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, wind->resize.width, wind->resize.height);
+ window->w = wind->resize.width;
+ window->h = wind->resize.height;
- WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
+ 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);
+ xdg_surface_ack_configure(xdg, serial);
+
+ 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);
+
+ wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE;
+ } else {
+ wind->resize.pending = SDL_TRUE;
+ wind->resize.serial = serial;
+ }
}
static const struct xdg_surface_listener shell_surface_listener_xdg = {
@@ -213,18 +242,27 @@ handle_configure_xdg_toplevel(void *data,
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. */
+ enum xdg_toplevel_state *state;
+ SDL_bool fullscreen = SDL_FALSE;
+ wl_array_for_each(state, states) {
+ if (*state == XDG_TOPLEVEL_STATE_FULLSCREEN) {
+ fullscreen = SDL_TRUE;
+ }
+ }
- if (width == 0 || height == 0) {
- return;
- }
+ if (!fullscreen) {
+ if (width == 0 || height == 0) {
+ width = window->windowed.w;
+ height = window->windowed.h;
+ }
+
+ /* xdg_toplevel spec states that this is a suggestion.
+ Ignore if less than or greater than max/min size. */
- 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) {
@@ -232,17 +270,20 @@ handle_configure_xdg_toplevel(void *data,
}
height = SDL_max(height, window->min_h);
} else {
+ wind->resize.width = window->w;
+ wind->resize.height = window->h;
return;
}
}
- if (width == window->w && height == window->h) {
+ if (width == 0 || height == 0) {
+ wind->resize.width = window->w;
+ wind->resize.height = window->h;
return;
}
- SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height);
- window->w = width;
- window->h = height;
+ wind->resize.width = width;
+ wind->resize.height = height;
}
static void
@@ -508,6 +549,8 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
data->waylandData = c;
data->sdlwindow = window;
+ data->resize.pending = SDL_FALSE;
+
data->surface =
wl_compositor_create_surface(c->compositor);
wl_surface_set_user_data(data->surface, data);
diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h
index 38a204e..6481eff 100644
--- a/src/video/wayland/SDL_waylandwindow.h
+++ b/src/video/wayland/SDL_waylandwindow.h
@@ -66,7 +66,13 @@ typedef struct {
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
struct qt_extended_surface *extended_surface;
-#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+
+ struct {
+ SDL_bool pending;
+ uint32_t serial;
+ int width, height;
+ } resize;
} SDL_WindowData;
extern void Wayland_ShowWindow(_THIS, SDL_Window *window);