Skip to content

Commit 3083173

Browse files
committed
wayland: Clamp libdecor windows to toplevel bounds
1 parent b96bb15 commit 3083173

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/video/wayland/SDL_waylandwindow.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,13 @@ static void decoration_frame_configure(struct libdecor_frame *frame,
12751275
if (floating) {
12761276
width = window->floating.w;
12771277
height = window->floating.h;
1278+
1279+
// Clamp the window to the toplevel bounds, if any are set.
1280+
if (wind->shell_surface_status == WAYLAND_SHELL_SURFACE_STATUS_WAITING_FOR_CONFIGURE &&
1281+
wind->toplevel_bounds.width && wind->toplevel_bounds.height) {
1282+
width = SDL_min(wind->toplevel_bounds.width, width);
1283+
height = SDL_min(wind->toplevel_bounds.height, height);
1284+
}
12781285
} else {
12791286
width = window->windowed.w;
12801287
height = window->windowed.h;
@@ -1440,11 +1447,20 @@ static void decoration_dismiss_popup(struct libdecor_frame *frame, const char *s
14401447
// NOP
14411448
}
14421449

1450+
static void decoration_frame_toplevel_bounds(struct libdecor_frame *frame, int width, int height, void *user_data)
1451+
{
1452+
SDL_WindowData *wind = (SDL_WindowData *)user_data;
1453+
wind->toplevel_bounds.width = width;
1454+
wind->toplevel_bounds.height = height;
1455+
}
1456+
1457+
// Note: Functions pointers after dismiss_popup are cast to avoid compiler warnings if building against an older version.
14431458
static struct libdecor_frame_interface libdecor_frame_interface = {
14441459
decoration_frame_configure,
14451460
decoration_frame_close,
14461461
decoration_frame_commit,
1447-
decoration_dismiss_popup
1462+
decoration_dismiss_popup,
1463+
(void (*)(void))decoration_frame_toplevel_bounds
14481464
};
14491465
#endif
14501466

0 commit comments

Comments
 (0)