Browse Source

wayland: Simplify resize logic

Non-size configuration events are filtered out, so there is no need to enqueue an event when setting the size, as it won't be overwritten in the configure event when only changing state.
Frank Praznik 11 months ago
parent
commit
37672f52da
2 changed files with 15 additions and 51 deletions
  1. 15 43
      src/video/wayland/SDL_waylandwindow.c
  2. 0 8
      src/video/wayland/SDL_waylandwindow.h

+ 15 - 43
src/video/wayland/SDL_waylandwindow.c

@@ -2430,58 +2430,30 @@ int Wayland_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
     return SDL_SetError("wayland cannot position non-popup windows");
 }
 
-static void size_event_handler(void *data, struct wl_callback *callback, uint32_t callback_data)
-{
-    /* Get the window from the ID as it may have been destroyed */
-    SDL_WindowID windowID = (SDL_WindowID)((uintptr_t)data);
-    SDL_Window *window = SDL_GetWindowFromID(windowID);
-
-    if (window && window->driverdata) {
-        SDL_WindowData *wind = window->driverdata;
-
-        /* Fullscreen windows do not get explicitly resized, and not strictly
-         * obeying the size of maximized windows is a protocol violation.
-         */
-        if (!(window->flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_MAXIMIZED))) {
-            wind->requested.width = wind->pending_size_event.width;
-            wind->requested.height = wind->pending_size_event.height;
-            if (wind->scale_to_display) {
-                wind->requested.logical_width = PixelToPoint(window, wind->pending_size_event.width);
-                wind->requested.logical_height = PixelToPoint(window, wind->pending_size_event.height);
-            }
-
-            ConfigureWindowGeometry(window);
-        }
-
-        /* Always commit, as this may be in response to a min/max limit change. */
-        CommitLibdecorFrame(window);
-    }
-
-    wl_callback_destroy(callback);
-}
-
-static struct wl_callback_listener size_event_listener = {
-    size_event_handler
-};
-
 void Wayland_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
 {
     SDL_WindowData *wind = window->driverdata;
 
-    if (wind->shell_surface_type != WAYLAND_SURFACE_CUSTOM) {
-        /* Queue an event to send the window size. */
-        struct wl_callback *cb = wl_display_sync(_this->driverdata->display);
-
-        wind->pending_size_event.width = window->floating.w;
-        wind->pending_size_event.height = window->floating.h;
-        wl_callback_add_listener(cb, &size_event_listener, (void *)((uintptr_t)window->id));
-    } else {
-        /* We are being informed of a size change on a custom surface, just configure. */
+    /* Fullscreen windows do not get explicitly resized, and not strictly
+     * obeying the size of maximized windows is a protocol violation.
+     *
+     * Calling this on a custom surface is informative, so the size must
+     * always be passed through.
+     */
+    if (!(window->flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_MAXIMIZED)) ||
+        wind->shell_surface_type == WAYLAND_SURFACE_CUSTOM) {
         wind->requested.width = window->floating.w;
         wind->requested.height = window->floating.h;
+        if (wind->scale_to_display) {
+            wind->requested.logical_width = PixelToPoint(window, window->floating.w);
+            wind->requested.logical_height = PixelToPoint(window, window->floating.h);
+        }
 
         ConfigureWindowGeometry(window);
     }
+
+    /* Always commit, as this may be in response to a min/max limit change. */
+    CommitLibdecorFrame(window);
 }
 
 void Wayland_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h)

+ 0 - 8
src/video/wayland/SDL_waylandwindow.h

@@ -114,14 +114,6 @@ struct SDL_WindowData
         float y;
     } pointer_scale;
 
-    /* The current pending user requested resize event. */
-    struct
-    {
-        /* These units can represent points or pixels, depending on the scaling mode. */
-        int width;
-        int height;
-    } pending_size_event;
-
     /* The in-flight window size request. */
     struct
     {