wayland: Factor out common libdecor frame commit code

The pattern of:
 libdecor_state_new()
 libdecor_frame_commit()
 libdecor_state_free()

 was used in several places. Factor it out into a common function.
This commit is contained in:
Frank Praznik 2022-10-09 11:11:55 -04:00 committed by Sam Lantinga
parent b0a9396b00
commit 6391ad970c
1 changed files with 20 additions and 26 deletions

View File

@ -305,6 +305,20 @@ ConfigureWindowGeometry(SDL_Window *window)
} }
} }
static void
CommitLibdecorFrame(SDL_Window *window)
{
#ifdef HAVE_LIBDECOR_H
SDL_WindowData *wind = (SDL_WindowData *) window->driverdata;
if (wind->shell_surface_type == WAYLAND_SURFACE_LIBDECOR && wind->shell_surface.libdecor.frame) {
struct libdecor_state *state = libdecor_state_new(wind->window_width, wind->window_height);
libdecor_frame_commit(wind->shell_surface.libdecor.frame, state, NULL);
libdecor_state_free(state);
}
#endif
}
static void static void
SetMinMaxDimensions(SDL_Window *window, SDL_bool commit) SetMinMaxDimensions(SDL_Window *window, SDL_bool commit)
{ {
@ -351,9 +365,7 @@ SetMinMaxDimensions(SDL_Window *window, SDL_bool commit)
max_height); max_height);
if (commit) { if (commit) {
struct libdecor_state *state = libdecor_state_new(wind->window_width, wind->window_height); CommitLibdecorFrame(window);
libdecor_frame_commit(wind->shell_surface.libdecor.frame, state, NULL);
libdecor_state_free(state);
wl_surface_commit(wind->surface); wl_surface_commit(wind->surface);
} }
} else } else
@ -405,9 +417,7 @@ SetFullscreen(SDL_Window *window, struct wl_output *output)
libdecor_frame_set_capabilities(wind->shell_surface.libdecor.frame, LIBDECOR_ACTION_RESIZE); libdecor_frame_set_capabilities(wind->shell_surface.libdecor.frame, LIBDECOR_ACTION_RESIZE);
wl_surface_commit(wind->surface); wl_surface_commit(wind->surface);
} else { } else {
struct libdecor_state *state = libdecor_state_new(wind->window_width, wind->window_height); CommitLibdecorFrame(window);
libdecor_frame_commit(wind->shell_surface.libdecor.frame, state, NULL);
libdecor_state_free(state);
wl_surface_commit(wind->surface); wl_surface_commit(wind->surface);
} }
@ -420,9 +430,7 @@ SetFullscreen(SDL_Window *window, struct wl_output *output)
libdecor_frame_unset_capabilities(wind->shell_surface.libdecor.frame, LIBDECOR_ACTION_RESIZE); libdecor_frame_unset_capabilities(wind->shell_surface.libdecor.frame, LIBDECOR_ACTION_RESIZE);
wl_surface_commit(wind->surface); wl_surface_commit(wind->surface);
} else { } else {
struct libdecor_state *state = libdecor_state_new(wind->window_width, wind->window_height); CommitLibdecorFrame(window);
libdecor_frame_commit(wind->shell_surface.libdecor.frame, state, NULL);
libdecor_state_free(state);
wl_surface_commit(wind->surface); wl_surface_commit(wind->surface);
} }
} }
@ -490,20 +498,6 @@ UpdateWindowFullscreen(SDL_Window *window, SDL_bool fullscreen)
} }
} }
static void
CommitWindowGeometry(SDL_Window *window)
{
#ifdef HAVE_LIBDECOR_H
SDL_WindowData *wind = (SDL_WindowData *) window->driverdata;
if (wind->shell_surface_type == WAYLAND_SURFACE_LIBDECOR && wind->shell_surface.libdecor.frame) {
struct libdecor_state *state = libdecor_state_new(wind->window_width, wind->window_height);
libdecor_frame_commit(wind->shell_surface.libdecor.frame, state, NULL);
libdecor_state_free(state);
}
#endif
}
static const struct wl_callback_listener surface_damage_frame_listener; static const struct wl_callback_listener surface_damage_frame_listener;
static void static void
@ -1086,7 +1080,7 @@ Wayland_move_window(SDL_Window *window,
if (fs_display_changed && if (fs_display_changed &&
(!wind->fs_output_width || !wind->fs_output_height)) { (!wind->fs_output_width || !wind->fs_output_height)) {
ConfigureWindowGeometry(window); ConfigureWindowGeometry(window);
CommitWindowGeometry(window); CommitLibdecorFrame(window);
} }
break; break;
@ -1762,7 +1756,7 @@ Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
* geometry and trigger a commit. * geometry and trigger a commit.
*/ */
ConfigureWindowGeometry(window); ConfigureWindowGeometry(window);
CommitWindowGeometry(window); CommitLibdecorFrame(window);
/* Roundtrip required to receive the updated window dimensions */ /* Roundtrip required to receive the updated window dimensions */
WAYLAND_wl_display_roundtrip(viddata->display); WAYLAND_wl_display_roundtrip(viddata->display);
@ -2146,7 +2140,7 @@ void Wayland_SetWindowSize(_THIS, SDL_Window * window)
/* Update the window geometry. */ /* Update the window geometry. */
ConfigureWindowGeometry(window); ConfigureWindowGeometry(window);
CommitWindowGeometry(window); CommitLibdecorFrame(window);
/* windowed is unconditionally set, so we can trust it here */ /* windowed is unconditionally set, so we can trust it here */
wind->floating_width = window->windowed.w; wind->floating_width = window->windowed.w;