Commit b4c4060ad295dc28aab13c6a3f6b5bbaaff64609

Sebastian Krzyszkowiak 2021-08-02T04:52:25

wayland: Clean up Wayland_HandlePendingResize Commit 871c11191bfc7214061a3da37c112522a102ddf5 removed delayed resize handling, but it left the whole structure untouched that now became unnecessary. To help with code clarity, get rid of the structure where pending resize state used to be stored and pass all the data directly to Wayland_HandlePendingResize (now renamed to Wayland_HandleResize, since it's not "pending" anymore but applied immediately)

diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index f5ea3fa..e795b63 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -157,44 +157,18 @@ static const struct wl_callback_listener surface_frame_listener = {
 };
 
 
-static void Wayland_HandlePendingResize(SDL_Window *window);
+static void Wayland_HandleResize(SDL_Window *window, int width, int height, float scale);
 
 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;
-
-    if (!wind->shell_surface.xdg.initial_configure_seen) {
-        window->w = 0;
-        window->h = 0;
-        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, wind->resize.width, wind->resize.height);
-        window->w = wind->resize.width;
-        window->h = wind->resize.height;
-
-        wl_surface_set_buffer_scale(wind->surface, wind->scale_factor);
-        if (wind->egl_window) {
-            WAYLAND_wl_egl_window_resize(wind->egl_window,
-                                         window->w * wind->scale_factor,
-                                         window->h * wind->scale_factor,
-                                         0, 0);
-        }
-
-        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);
+    Wayland_HandleResize(window, window->w, window->h, wind->scale_factor);
+    xdg_surface_ack_configure(xdg, serial);
 
-        wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE;
-    } else {
-        wind->resize.pending = SDL_TRUE;
-        wind->resize.configure = SDL_TRUE;
-        wind->resize.serial = serial;
-        Wayland_HandlePendingResize(window);
-    }
+    wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE;
 }
 
 static const struct xdg_surface_listener shell_surface_listener_xdg = {
@@ -261,8 +235,6 @@ 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;
         }
     }
@@ -281,8 +253,6 @@ handle_configure_xdg_toplevel(void *data,
     }
 
     if (width == 0 || height == 0) {
-        wind->resize.width = window->w;
-        wind->resize.height = window->h;
         return;
     }
 
@@ -292,8 +262,8 @@ handle_configure_xdg_toplevel(void *data,
         wind->floating_height = height;
     }
 
-    wind->resize.width = width;
-    wind->resize.height = height;
+    window->w = width;
+    window->h = height;
 }
 
 static void
@@ -332,17 +302,9 @@ decoration_frame_configure(struct libdecor_frame *frame,
     width = (width == 0) ? window->w : width;
     height = (height == 0) ? window->h : height;
 
-    wind->resize.width = width;
-    wind->resize.height = height;
-
-    wind->resize.pending = SDL_TRUE;
-    wind->resize.configure = SDL_TRUE;
-    Wayland_HandlePendingResize(window);
+    Wayland_HandleResize(window, width, height, wind->scale_factor);
     wind->shell_surface.libdecor.initial_configure_seen = SDL_TRUE;
 
-    window->w = wind->resize.width;
-    window->h = wind->resize.height;
-
     /* window state */
     if (!libdecor_configuration_get_window_state(configuration, &window_state)) {
         window_state = LIBDECOR_WINDOW_STATE_NONE;
@@ -382,8 +344,6 @@ decoration_frame_configure(struct libdecor_frame *frame,
             }
             height = SDL_max(height, window->min_h);
         } else {
-            wind->resize.width = window->w;
-            wind->resize.height = window->h;
             return;
         }
     }
@@ -496,12 +456,7 @@ update_scale_factor(SDL_WindowData *window)
     }
 
     if (new_factor != old_factor) {
-        /* force the resize event to trigger, as the logical size didn't change */
-        window->resize.width = window->sdlwindow->w;
-        window->resize.height = window->sdlwindow->h;
-        window->resize.scale_factor = new_factor;
-        window->resize.pending = SDL_TRUE;
-        Wayland_HandlePendingResize(window->sdlwindow);
+        Wayland_HandleResize(window->sdlwindow, window->sdlwindow->w, window->sdlwindow->h, new_factor);
     }
 }
 
@@ -986,10 +941,7 @@ Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
      */
     if (!fullscreen) {
         SDL_WindowData *wind = (SDL_WindowData*) window->driverdata;
-        wind->resize.width = window->windowed.w;
-        wind->resize.height = window->windowed.h;
-        wind->resize.pending = SDL_TRUE;
-        Wayland_HandlePendingResize(window);
+        Wayland_HandleResize(window, window->windowed.w, window->windowed.h, wind->scale_factor);
     }
 }
 
@@ -1187,11 +1139,6 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
         }
     }
 
-    data->resize.pending = SDL_FALSE;
-    data->resize.width = window->w;
-    data->resize.height = window->h;
-    data->resize.scale_factor = data->scale_factor;
-
     data->outputs = NULL;
     data->num_outputs = 0;
 
@@ -1261,47 +1208,31 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
 
 
 static void
-Wayland_HandlePendingResize(SDL_Window *window)
+Wayland_HandleResize(SDL_Window *window, int width, int height, float scale)
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
 
-    if (data->resize.pending) {
-        struct wl_region *region;
-        if (data->scale_factor != data->resize.scale_factor || data->resize.configure) {
-            window->w = 0;
-            window->h = 0;
-        }
-        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, data->resize.width, data->resize.height);
-        window->w = data->resize.width;
-        window->h = data->resize.height;
-        data->scale_factor = data->resize.scale_factor;
-        wl_surface_set_buffer_scale(data->surface, data->scale_factor);
-        if (data->egl_window) {
-            WAYLAND_wl_egl_window_resize(data->egl_window,
-                                         window->w * data->scale_factor,
-                                         window->h * data->scale_factor,
-                                         0, 0);
-        }
-
-        if (data->resize.configure) {
-#ifdef HAVE_LIBDECOR_H
-           if (data->waylandData->shell.libdecor) {
-              /* this has already been acknowledged in the the frames's 'configure' callback */
-           } else
-#endif
-           if (data->waylandData->shell.xdg) {
-              xdg_surface_ack_configure(data->shell_surface.xdg.surface, data->resize.serial);
-           }
-           data->resize.configure = SDL_FALSE;
-        }
+    struct wl_region *region;
+    window->w = 0;
+    window->h = 0;
+    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height);
+    window->w = width;
+    window->h = height;
+    data->scale_factor = scale;
 
-        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);
+    wl_surface_set_buffer_scale(data->surface, data->scale_factor);
 
-        data->resize.pending = SDL_FALSE;
+    if (data->egl_window) {
+        WAYLAND_wl_egl_window_resize(data->egl_window,
+                                        window->w * data->scale_factor,
+                                        window->h * data->scale_factor,
+                                        0, 0);
     }
+
+    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);
 }
 
 void
diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h
index 8cc4d03..852a8dc 100644
--- a/src/video/wayland/SDL_waylandwindow.h
+++ b/src/video/wayland/SDL_waylandwindow.h
@@ -77,13 +77,6 @@ typedef struct {
     struct qt_extended_surface *extended_surface;
 #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
 
-    struct {
-        SDL_bool pending, configure;
-        uint32_t serial;
-        int width, height;
-        float scale_factor;
-    } resize;
-
     SDL_WaylandOutputData **outputs;
     int num_outputs;