src/video/wayland/SDL_waylandwindow.c
changeset 12400 28303fca62bd
parent 12381 dc9108cd4340
child 12426 779d711b6b5e
equal deleted inserted replaced
12399:2ea6e539b218 12400:28303fca62bd
    53 handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
    53 handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
    54                  uint32_t edges, int32_t width, int32_t height)
    54                  uint32_t edges, int32_t width, int32_t height)
    55 {
    55 {
    56     SDL_WindowData *wind = (SDL_WindowData *)data;
    56     SDL_WindowData *wind = (SDL_WindowData *)data;
    57     SDL_Window *window = wind->sdlwindow;
    57     SDL_Window *window = wind->sdlwindow;
    58     struct wl_region *region;
       
    59 
    58 
    60     /* wl_shell_surface spec states that this is a suggestion.
    59     /* wl_shell_surface spec states that this is a suggestion.
    61        Ignore if less than or greater than max/min size. */
    60        Ignore if less than or greater than max/min size. */
    62 
    61 
    63     if (width == 0 || height == 0) {
    62     if (width == 0 || height == 0) {
    66 
    65 
    67     if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    66     if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    68         if ((window->flags & SDL_WINDOW_RESIZABLE)) {
    67         if ((window->flags & SDL_WINDOW_RESIZABLE)) {
    69             if (window->max_w > 0) {
    68             if (window->max_w > 0) {
    70                 width = SDL_min(width, window->max_w);
    69                 width = SDL_min(width, window->max_w);
    71             } 
    70             }
    72             width = SDL_max(width, window->min_w);
    71             width = SDL_max(width, window->min_w);
    73 
    72 
    74             if (window->max_h > 0) {
    73             if (window->max_h > 0) {
    75                 height = SDL_min(height, window->max_h);
    74                 height = SDL_min(height, window->max_h);
    76             }
    75             }
    78         } else {
    77         } else {
    79             return;
    78             return;
    80         }
    79         }
    81     }
    80     }
    82 
    81 
    83     WAYLAND_wl_egl_window_resize(wind->egl_window, width, height, 0, 0);
    82     wind->resize.width = width;
    84     region = wl_compositor_create_region(wind->waylandData->compositor);
    83     wind->resize.height = height;
    85     wl_region_add(region, 0, 0, width, height);
    84     wind->resize.pending = SDL_TRUE;
    86     wl_surface_set_opaque_region(wind->surface, region);
       
    87     wl_region_destroy(region);
       
    88 
       
    89     SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height);
       
    90     window->w = width;
       
    91     window->h = height;
       
    92 }
    85 }
    93 
    86 
    94 static void
    87 static void
    95 handle_popup_done_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface)
    88 handle_popup_done_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface)
    96 {
    89 {
   110 {
   103 {
   111     SDL_WindowData *wind = (SDL_WindowData *)data;
   104     SDL_WindowData *wind = (SDL_WindowData *)data;
   112     SDL_Window *window = wind->sdlwindow;
   105     SDL_Window *window = wind->sdlwindow;
   113     struct wl_region *region;
   106     struct wl_region *region;
   114 
   107 
   115     wind->shell_surface.zxdg.initial_configure_seen = SDL_TRUE;
   108     if (!wind->shell_surface.zxdg.initial_configure_seen) {
   116 
   109         SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, wind->resize.width, wind->resize.height);
   117     WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
   110         window->w = wind->resize.width;
   118 
   111         window->h = wind->resize.height;
   119     region = wl_compositor_create_region(wind->waylandData->compositor);
   112 
   120     wl_region_add(region, 0, 0, window->w, window->h);
   113         WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
   121     wl_surface_set_opaque_region(wind->surface, region);
   114 
   122     wl_region_destroy(region);
   115         zxdg_surface_v6_ack_configure(zxdg, serial);
   123     zxdg_surface_v6_ack_configure(zxdg, serial);
   116 
       
   117         region = wl_compositor_create_region(wind->waylandData->compositor);
       
   118         wl_region_add(region, 0, 0, window->w, window->h);
       
   119         wl_surface_set_opaque_region(wind->surface, region);
       
   120         wl_region_destroy(region);
       
   121 
       
   122         wind->shell_surface.zxdg.initial_configure_seen = SDL_TRUE;
       
   123     } else {
       
   124         wind->resize.pending = SDL_TRUE;
       
   125         wind->resize.serial = serial;
       
   126     }
   124 }
   127 }
   125 
   128 
   126 static const struct zxdg_surface_v6_listener shell_surface_listener_zxdg = {
   129 static const struct zxdg_surface_v6_listener shell_surface_listener_zxdg = {
   127     handle_configure_zxdg_shell_surface
   130     handle_configure_zxdg_shell_surface
   128 };
   131 };
   136               struct wl_array *states)
   139               struct wl_array *states)
   137 {
   140 {
   138     SDL_WindowData *wind = (SDL_WindowData *)data;
   141     SDL_WindowData *wind = (SDL_WindowData *)data;
   139     SDL_Window *window = wind->sdlwindow;
   142     SDL_Window *window = wind->sdlwindow;
   140 
   143 
   141     /* wl_shell_surface spec states that this is a suggestion.
   144     enum zxdg_toplevel_v6_state *state;
   142        Ignore if less than or greater than max/min size. */
   145     SDL_bool fullscreen = SDL_FALSE;
   143 
   146     wl_array_for_each(state, states) {
   144     if (width == 0 || height == 0) {
   147         if (*state == ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN) {
   145         return;
   148             fullscreen = SDL_TRUE;
   146     }
   149         }
   147 
   150     }
   148     if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
   151 
       
   152     if (!fullscreen) {
       
   153         if (width == 0 || height == 0) {
       
   154             width = window->windowed.w;
       
   155             height = window->windowed.h;
       
   156         }
       
   157 
       
   158         /* zxdg_toplevel spec states that this is a suggestion.
       
   159            Ignore if less than or greater than max/min size. */
       
   160 
   149         if ((window->flags & SDL_WINDOW_RESIZABLE)) {
   161         if ((window->flags & SDL_WINDOW_RESIZABLE)) {
   150             if (window->max_w > 0) {
   162             if (window->max_w > 0) {
   151                 width = SDL_min(width, window->max_w);
   163                 width = SDL_min(width, window->max_w);
   152             } 
   164             }
   153             width = SDL_max(width, window->min_w);
   165             width = SDL_max(width, window->min_w);
   154 
   166 
   155             if (window->max_h > 0) {
   167             if (window->max_h > 0) {
   156                 height = SDL_min(height, window->max_h);
   168                 height = SDL_min(height, window->max_h);
   157             }
   169             }
   158             height = SDL_max(height, window->min_h);
   170             height = SDL_max(height, window->min_h);
   159         } else {
   171         } else {
       
   172             wind->resize.width = window->w;
       
   173             wind->resize.height = window->h;
   160             return;
   174             return;
   161         }
   175         }
   162     }
   176     }
   163 
   177 
   164     SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height);
   178     if (width == 0 || height == 0) {
   165     window->w = width;
   179         wind->resize.width = window->w;
   166     window->h = height;
   180         wind->resize.height = window->h;
       
   181         return;
       
   182     }
       
   183 
       
   184     wind->resize.width = width;
       
   185     wind->resize.height = height;
   167 }
   186 }
   168 
   187 
   169 static void
   188 static void
   170 handle_close_zxdg_toplevel(void *data, struct zxdg_toplevel_v6 *zxdg_toplevel_v6)
   189 handle_close_zxdg_toplevel(void *data, struct zxdg_toplevel_v6 *zxdg_toplevel_v6)
   171 {
   190 {
   185 {
   204 {
   186     SDL_WindowData *wind = (SDL_WindowData *)data;
   205     SDL_WindowData *wind = (SDL_WindowData *)data;
   187     SDL_Window *window = wind->sdlwindow;
   206     SDL_Window *window = wind->sdlwindow;
   188     struct wl_region *region;
   207     struct wl_region *region;
   189 
   208 
   190     wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE;
   209     if (!wind->shell_surface.xdg.initial_configure_seen) {
   191 
   210         SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, wind->resize.width, wind->resize.height);
   192     WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
   211         window->w = wind->resize.width;
   193 
   212         window->h = wind->resize.height;
   194     region = wl_compositor_create_region(wind->waylandData->compositor);
   213 
   195     wl_region_add(region, 0, 0, window->w, window->h);
   214         WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
   196     wl_surface_set_opaque_region(wind->surface, region);
   215 
   197     wl_region_destroy(region);
   216         xdg_surface_ack_configure(xdg, serial);
   198     xdg_surface_ack_configure(xdg, serial);
   217 
       
   218         region = wl_compositor_create_region(wind->waylandData->compositor);
       
   219         wl_region_add(region, 0, 0, window->w, window->h);
       
   220         wl_surface_set_opaque_region(wind->surface, region);
       
   221         wl_region_destroy(region);
       
   222 
       
   223         wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE;
       
   224     } else {
       
   225         wind->resize.pending = SDL_TRUE;
       
   226         wind->resize.serial = serial;
       
   227     }
   199 }
   228 }
   200 
   229 
   201 static const struct xdg_surface_listener shell_surface_listener_xdg = {
   230 static const struct xdg_surface_listener shell_surface_listener_xdg = {
   202     handle_configure_xdg_shell_surface
   231     handle_configure_xdg_shell_surface
   203 };
   232 };
   211               struct wl_array *states)
   240               struct wl_array *states)
   212 {
   241 {
   213     SDL_WindowData *wind = (SDL_WindowData *)data;
   242     SDL_WindowData *wind = (SDL_WindowData *)data;
   214     SDL_Window *window = wind->sdlwindow;
   243     SDL_Window *window = wind->sdlwindow;
   215 
   244 
   216     /* wl_shell_surface spec states that this is a suggestion.
   245     enum xdg_toplevel_state *state;
   217        Ignore if less than or greater than max/min size. */
   246     SDL_bool fullscreen = SDL_FALSE;
   218 
   247     wl_array_for_each(state, states) {
   219     if (width == 0 || height == 0) {
   248         if (*state == XDG_TOPLEVEL_STATE_FULLSCREEN) {
   220         return;
   249             fullscreen = SDL_TRUE;
   221     }
   250         }
   222 
   251      }
   223     if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
   252 
       
   253     if (!fullscreen) {
       
   254         if (width == 0 || height == 0) {
       
   255             width = window->windowed.w;
       
   256             height = window->windowed.h;
       
   257         }
       
   258 
       
   259         /* xdg_toplevel spec states that this is a suggestion.
       
   260            Ignore if less than or greater than max/min size. */
       
   261 
   224         if ((window->flags & SDL_WINDOW_RESIZABLE)) {
   262         if ((window->flags & SDL_WINDOW_RESIZABLE)) {
   225             if (window->max_w > 0) {
   263             if (window->max_w > 0) {
   226                 width = SDL_min(width, window->max_w);
   264                 width = SDL_min(width, window->max_w);
   227             } 
   265             }
   228             width = SDL_max(width, window->min_w);
   266             width = SDL_max(width, window->min_w);
   229 
   267 
   230             if (window->max_h > 0) {
   268             if (window->max_h > 0) {
   231                 height = SDL_min(height, window->max_h);
   269                 height = SDL_min(height, window->max_h);
   232             }
   270             }
   233             height = SDL_max(height, window->min_h);
   271             height = SDL_max(height, window->min_h);
   234         } else {
   272         } else {
       
   273             wind->resize.width = window->w;
       
   274             wind->resize.height = window->h;
   235             return;
   275             return;
   236         }
   276         }
   237     }
   277     }
   238 
   278 
   239     if (width == window->w && height == window->h) {
   279     if (width == 0 || height == 0) {
       
   280         wind->resize.width = window->w;
       
   281         wind->resize.height = window->h;
   240         return;
   282         return;
   241     }
   283     }
   242 
   284 
   243     SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height);
   285     wind->resize.width = width;
   244     window->w = width;
   286     wind->resize.height = height;
   245     window->h = height;
       
   246 }
   287 }
   247 
   288 
   248 static void
   289 static void
   249 handle_close_xdg_toplevel(void *data, struct xdg_toplevel *xdg_toplevel)
   290 handle_close_xdg_toplevel(void *data, struct xdg_toplevel *xdg_toplevel)
   250 {
   291 {
   505         window->y = 0;
   546         window->y = 0;
   506     }
   547     }
   507 
   548 
   508     data->waylandData = c;
   549     data->waylandData = c;
   509     data->sdlwindow = window;
   550     data->sdlwindow = window;
       
   551 
       
   552     data->resize.pending = SDL_FALSE;
   510 
   553 
   511     data->surface =
   554     data->surface =
   512         wl_compositor_create_surface(c->compositor);
   555         wl_compositor_create_surface(c->compositor);
   513     wl_surface_set_user_data(data->surface, data);
   556     wl_surface_set_user_data(data->surface, data);
   514 
   557