diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c index 5591e59e11..0c7636988a 100644 --- a/src/video/wayland/SDL_waylandwindow.c +++ b/src/video/wayland/SDL_waylandwindow.c @@ -2108,7 +2108,7 @@ void Wayland_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window) wl_surface_commit(data->surface); } - // Make sure the window can't be resized to 0 or it can be spuriously closed by the window manager. + // Make sure the window can't be resized to 0, or it can be spuriously closed by the window manager. data->system_limits.min_width = SDL_max(data->system_limits.min_width, 1); data->system_limits.min_height = SDL_max(data->system_limits.min_height, 1); @@ -2151,6 +2151,13 @@ void Wayland_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window) } } + // No frame callback on an external surface, as it may already have one attached. + if (!(window->flags & SDL_WINDOW_EXTERNAL)) { + // Fire a callback when the compositor wants a new frame. + data->surface_frame_callback = wl_surface_frame(data->surface); + wl_callback_add_listener(data->surface_frame_callback, &surface_frame_listener, data); + } + data->show_hide_sync_required = true; struct wl_callback *cb = wl_display_sync(_this->internal->display); wl_callback_add_listener(cb, &show_hide_sync_listener, (void *)((uintptr_t)window->id)); @@ -2217,6 +2224,11 @@ void Wayland_HideWindow(SDL_VideoDevice *_this, SDL_Window *window) wind->shell_surface_status = WAYLAND_SHELL_SURFACE_STATUS_HIDDEN; + if (wind->surface_frame_callback) { + wl_callback_destroy(wind->surface_frame_callback); + wind->surface_frame_callback = NULL; + } + if (wind->server_decoration) { zxdg_toplevel_decoration_v1_destroy(wind->server_decoration); wind->server_decoration = NULL; @@ -2806,13 +2818,6 @@ bool Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Proper wl_callback_add_listener(data->gles_swap_frame_callback, &gles_swap_frame_listener, data); } - // No frame callback on external surfaces as it may already have one attached. - if (!external_surface) { - // Fire a callback when the compositor wants a new frame to set the surface damage region. - data->surface_frame_callback = wl_surface_frame(data->surface); - wl_callback_add_listener(data->surface_frame_callback, &surface_frame_listener, data); - } - if (window->flags & SDL_WINDOW_TRANSPARENT) { if (_this->gl_config.alpha_size == 0) { _this->gl_config.alpha_size = 8; @@ -3346,10 +3351,6 @@ void Wayland_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) WAYLAND_wl_event_queue_destroy(wind->gles_swap_frame_event_queue); } - if (wind->surface_frame_callback) { - wl_callback_destroy(wind->surface_frame_callback); - } - if (!(window->flags & SDL_WINDOW_EXTERNAL)) { wl_surface_destroy(wind->surface); } else {