src/video/wayland/SDL_waylandwindow.c
changeset 12400 28303fca62bd
parent 12381 dc9108cd4340
child 12426 779d711b6b5e
     1.1 --- a/src/video/wayland/SDL_waylandwindow.c	Tue Nov 06 23:45:50 2018 +0300
     1.2 +++ b/src/video/wayland/SDL_waylandwindow.c	Wed Nov 07 01:08:35 2018 +0100
     1.3 @@ -55,7 +55,6 @@
     1.4  {
     1.5      SDL_WindowData *wind = (SDL_WindowData *)data;
     1.6      SDL_Window *window = wind->sdlwindow;
     1.7 -    struct wl_region *region;
     1.8  
     1.9      /* wl_shell_surface spec states that this is a suggestion.
    1.10         Ignore if less than or greater than max/min size. */
    1.11 @@ -68,7 +67,7 @@
    1.12          if ((window->flags & SDL_WINDOW_RESIZABLE)) {
    1.13              if (window->max_w > 0) {
    1.14                  width = SDL_min(width, window->max_w);
    1.15 -            } 
    1.16 +            }
    1.17              width = SDL_max(width, window->min_w);
    1.18  
    1.19              if (window->max_h > 0) {
    1.20 @@ -80,15 +79,9 @@
    1.21          }
    1.22      }
    1.23  
    1.24 -    WAYLAND_wl_egl_window_resize(wind->egl_window, width, height, 0, 0);
    1.25 -    region = wl_compositor_create_region(wind->waylandData->compositor);
    1.26 -    wl_region_add(region, 0, 0, width, height);
    1.27 -    wl_surface_set_opaque_region(wind->surface, region);
    1.28 -    wl_region_destroy(region);
    1.29 -
    1.30 -    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height);
    1.31 -    window->w = width;
    1.32 -    window->h = height;
    1.33 +    wind->resize.width = width;
    1.34 +    wind->resize.height = height;
    1.35 +    wind->resize.pending = SDL_TRUE;
    1.36  }
    1.37  
    1.38  static void
    1.39 @@ -112,15 +105,25 @@
    1.40      SDL_Window *window = wind->sdlwindow;
    1.41      struct wl_region *region;
    1.42  
    1.43 -    wind->shell_surface.zxdg.initial_configure_seen = SDL_TRUE;
    1.44 +    if (!wind->shell_surface.zxdg.initial_configure_seen) {
    1.45 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, wind->resize.width, wind->resize.height);
    1.46 +        window->w = wind->resize.width;
    1.47 +        window->h = wind->resize.height;
    1.48  
    1.49 -    WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
    1.50 +        WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
    1.51  
    1.52 -    region = wl_compositor_create_region(wind->waylandData->compositor);
    1.53 -    wl_region_add(region, 0, 0, window->w, window->h);
    1.54 -    wl_surface_set_opaque_region(wind->surface, region);
    1.55 -    wl_region_destroy(region);
    1.56 -    zxdg_surface_v6_ack_configure(zxdg, serial);
    1.57 +        zxdg_surface_v6_ack_configure(zxdg, serial);
    1.58 +
    1.59 +        region = wl_compositor_create_region(wind->waylandData->compositor);
    1.60 +        wl_region_add(region, 0, 0, window->w, window->h);
    1.61 +        wl_surface_set_opaque_region(wind->surface, region);
    1.62 +        wl_region_destroy(region);
    1.63 +
    1.64 +        wind->shell_surface.zxdg.initial_configure_seen = SDL_TRUE;
    1.65 +    } else {
    1.66 +        wind->resize.pending = SDL_TRUE;
    1.67 +        wind->resize.serial = serial;
    1.68 +    }
    1.69  }
    1.70  
    1.71  static const struct zxdg_surface_v6_listener shell_surface_listener_zxdg = {
    1.72 @@ -138,18 +141,27 @@
    1.73      SDL_WindowData *wind = (SDL_WindowData *)data;
    1.74      SDL_Window *window = wind->sdlwindow;
    1.75  
    1.76 -    /* wl_shell_surface spec states that this is a suggestion.
    1.77 -       Ignore if less than or greater than max/min size. */
    1.78 -
    1.79 -    if (width == 0 || height == 0) {
    1.80 -        return;
    1.81 +    enum zxdg_toplevel_v6_state *state;
    1.82 +    SDL_bool fullscreen = SDL_FALSE;
    1.83 +    wl_array_for_each(state, states) {
    1.84 +        if (*state == ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN) {
    1.85 +            fullscreen = SDL_TRUE;
    1.86 +        }
    1.87      }
    1.88  
    1.89 -    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    1.90 +    if (!fullscreen) {
    1.91 +        if (width == 0 || height == 0) {
    1.92 +            width = window->windowed.w;
    1.93 +            height = window->windowed.h;
    1.94 +        }
    1.95 +
    1.96 +        /* zxdg_toplevel spec states that this is a suggestion.
    1.97 +           Ignore if less than or greater than max/min size. */
    1.98 +
    1.99          if ((window->flags & SDL_WINDOW_RESIZABLE)) {
   1.100              if (window->max_w > 0) {
   1.101                  width = SDL_min(width, window->max_w);
   1.102 -            } 
   1.103 +            }
   1.104              width = SDL_max(width, window->min_w);
   1.105  
   1.106              if (window->max_h > 0) {
   1.107 @@ -157,13 +169,20 @@
   1.108              }
   1.109              height = SDL_max(height, window->min_h);
   1.110          } else {
   1.111 +            wind->resize.width = window->w;
   1.112 +            wind->resize.height = window->h;
   1.113              return;
   1.114          }
   1.115      }
   1.116  
   1.117 -    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height);
   1.118 -    window->w = width;
   1.119 -    window->h = height;
   1.120 +    if (width == 0 || height == 0) {
   1.121 +        wind->resize.width = window->w;
   1.122 +        wind->resize.height = window->h;
   1.123 +        return;
   1.124 +    }
   1.125 +
   1.126 +    wind->resize.width = width;
   1.127 +    wind->resize.height = height;
   1.128  }
   1.129  
   1.130  static void
   1.131 @@ -187,15 +206,25 @@
   1.132      SDL_Window *window = wind->sdlwindow;
   1.133      struct wl_region *region;
   1.134  
   1.135 -    wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE;
   1.136 +    if (!wind->shell_surface.xdg.initial_configure_seen) {
   1.137 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, wind->resize.width, wind->resize.height);
   1.138 +        window->w = wind->resize.width;
   1.139 +        window->h = wind->resize.height;
   1.140  
   1.141 -    WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
   1.142 +        WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
   1.143  
   1.144 -    region = wl_compositor_create_region(wind->waylandData->compositor);
   1.145 -    wl_region_add(region, 0, 0, window->w, window->h);
   1.146 -    wl_surface_set_opaque_region(wind->surface, region);
   1.147 -    wl_region_destroy(region);
   1.148 -    xdg_surface_ack_configure(xdg, serial);
   1.149 +        xdg_surface_ack_configure(xdg, serial);
   1.150 +
   1.151 +        region = wl_compositor_create_region(wind->waylandData->compositor);
   1.152 +        wl_region_add(region, 0, 0, window->w, window->h);
   1.153 +        wl_surface_set_opaque_region(wind->surface, region);
   1.154 +        wl_region_destroy(region);
   1.155 +
   1.156 +        wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE;
   1.157 +    } else {
   1.158 +        wind->resize.pending = SDL_TRUE;
   1.159 +        wind->resize.serial = serial;
   1.160 +    }
   1.161  }
   1.162  
   1.163  static const struct xdg_surface_listener shell_surface_listener_xdg = {
   1.164 @@ -213,18 +242,27 @@
   1.165      SDL_WindowData *wind = (SDL_WindowData *)data;
   1.166      SDL_Window *window = wind->sdlwindow;
   1.167  
   1.168 -    /* wl_shell_surface spec states that this is a suggestion.
   1.169 -       Ignore if less than or greater than max/min size. */
   1.170 +    enum xdg_toplevel_state *state;
   1.171 +    SDL_bool fullscreen = SDL_FALSE;
   1.172 +    wl_array_for_each(state, states) {
   1.173 +        if (*state == XDG_TOPLEVEL_STATE_FULLSCREEN) {
   1.174 +            fullscreen = SDL_TRUE;
   1.175 +        }
   1.176 +     }
   1.177  
   1.178 -    if (width == 0 || height == 0) {
   1.179 -        return;
   1.180 -    }
   1.181 +    if (!fullscreen) {
   1.182 +        if (width == 0 || height == 0) {
   1.183 +            width = window->windowed.w;
   1.184 +            height = window->windowed.h;
   1.185 +        }
   1.186  
   1.187 -    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
   1.188 +        /* xdg_toplevel spec states that this is a suggestion.
   1.189 +           Ignore if less than or greater than max/min size. */
   1.190 +
   1.191          if ((window->flags & SDL_WINDOW_RESIZABLE)) {
   1.192              if (window->max_w > 0) {
   1.193                  width = SDL_min(width, window->max_w);
   1.194 -            } 
   1.195 +            }
   1.196              width = SDL_max(width, window->min_w);
   1.197  
   1.198              if (window->max_h > 0) {
   1.199 @@ -232,17 +270,20 @@
   1.200              }
   1.201              height = SDL_max(height, window->min_h);
   1.202          } else {
   1.203 +            wind->resize.width = window->w;
   1.204 +            wind->resize.height = window->h;
   1.205              return;
   1.206          }
   1.207      }
   1.208  
   1.209 -    if (width == window->w && height == window->h) {
   1.210 +    if (width == 0 || height == 0) {
   1.211 +        wind->resize.width = window->w;
   1.212 +        wind->resize.height = window->h;
   1.213          return;
   1.214      }
   1.215  
   1.216 -    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height);
   1.217 -    window->w = width;
   1.218 -    window->h = height;
   1.219 +    wind->resize.width = width;
   1.220 +    wind->resize.height = height;
   1.221  }
   1.222  
   1.223  static void
   1.224 @@ -508,6 +549,8 @@
   1.225      data->waylandData = c;
   1.226      data->sdlwindow = window;
   1.227  
   1.228 +    data->resize.pending = SDL_FALSE;
   1.229 +
   1.230      data->surface =
   1.231          wl_compositor_create_surface(c->compositor);
   1.232      wl_surface_set_user_data(data->surface, data);