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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index c72575f..8d7beb3 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -306,6 +306,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
SetMinMaxDimensions(SDL_Window *window, SDL_bool commit)
{
SDL_WindowData *wind = window->driverdata;
@@ -351,9 +365,7 @@ SetMinMaxDimensions(SDL_Window *window, SDL_bool commit)
max_height);
if (commit) {
- 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);
+ CommitLibdecorFrame(window);
wl_surface_commit(wind->surface);
}
} 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);
wl_surface_commit(wind->surface);
} else {
- 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);
+ CommitLibdecorFrame(window);
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);
wl_surface_commit(wind->surface);
} else {
- 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);
+ CommitLibdecorFrame(window);
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 void
@@ -1086,7 +1080,7 @@ Wayland_move_window(SDL_Window *window,
if (fs_display_changed &&
(!wind->fs_output_width || !wind->fs_output_height)) {
ConfigureWindowGeometry(window);
- CommitWindowGeometry(window);
+ CommitLibdecorFrame(window);
}
break;
@@ -1762,7 +1756,7 @@ Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
* geometry and trigger a commit.
*/
ConfigureWindowGeometry(window);
- CommitWindowGeometry(window);
+ CommitLibdecorFrame(window);
/* Roundtrip required to receive the updated window dimensions */
WAYLAND_wl_display_roundtrip(viddata->display);
@@ -2146,7 +2140,7 @@ void Wayland_SetWindowSize(_THIS, SDL_Window * window)
/* Update the window geometry. */
ConfigureWindowGeometry(window);
- CommitWindowGeometry(window);
+ CommitLibdecorFrame(window);
/* windowed is unconditionally set, so we can trust it here */
wind->floating_width = window->windowed.w;