wayland: Explicitly set min/max size for xdg-shell
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index 3ddeef0..95b1af9 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -206,6 +206,8 @@ Wayland_CreateDevice(int devindex)
device->SetWindowBordered = Wayland_SetWindowBordered;
device->SetWindowResizable = Wayland_SetWindowResizable;
device->SetWindowSize = Wayland_SetWindowSize;
+ device->SetWindowMinimumSize = Wayland_SetWindowMinimumSize;
+ device->SetWindowMaximumSize = Wayland_SetWindowMaximumSize;
device->SetWindowTitle = Wayland_SetWindowTitle;
device->DestroyWindow = Wayland_DestroyWindow;
device->SetWindowHitTest = Wayland_SetWindowHitTest;
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index 90e3928..5491d2d 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -634,11 +634,40 @@ Wayland_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
void
Wayland_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
{
- /* No-op, this is handled by the xdg-shell/wl_shell callbacks.
- * Also note that we do NOT implement SetMaximumSize/SetMinimumSize, as
- * those are also no-ops for the same reason, but SDL_video.c does not
- * require a driver implementation.
- */
+ int min_width, min_height, max_width, max_height;
+ SDL_VideoData *data = _this->driverdata;
+ SDL_WindowData *wind = window->driverdata;
+
+ if (resizable) {
+ /* FIXME: Is there a better way to get max window size from Wayland? -flibit */
+ const int maxsize = 0x7FFFFFFF;
+ min_width = window->min_w;
+ min_height = window->min_h;
+ max_width = (window->max_w == 0) ? maxsize : window->max_w;
+ max_height = (window->max_h == 0) ? maxsize : window->max_h;
+ } else {
+ min_width = window->w;
+ min_height = window->h;
+ max_width = window->w;
+ max_height = window->h;
+ }
+
+ /* Note that this is also handled by the xdg-shell/wl_shell callbacks! */
+ if (data->shell.xdg) {
+ xdg_toplevel_set_min_size(wind->shell_surface.xdg.roleobj.toplevel,
+ min_width,
+ min_height);
+ xdg_toplevel_set_max_size(wind->shell_surface.xdg.roleobj.toplevel,
+ max_width,
+ max_height);
+ } else if (data->shell.zxdg) {
+ zxdg_toplevel_v6_set_min_size(wind->shell_surface.zxdg.roleobj.toplevel,
+ min_width,
+ min_height);
+ zxdg_toplevel_v6_set_max_size(wind->shell_surface.zxdg.roleobj.toplevel,
+ max_width,
+ max_height);
+ }
}
void
@@ -757,12 +786,28 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
data->shell_surface.xdg.roleobj.toplevel = xdg_surface_get_toplevel(data->shell_surface.xdg.surface);
xdg_toplevel_add_listener(data->shell_surface.xdg.roleobj.toplevel, &toplevel_listener_xdg, data);
xdg_toplevel_set_app_id(data->shell_surface.xdg.roleobj.toplevel, c->classname);
+ if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
+ xdg_toplevel_set_min_size(data->shell_surface.xdg.roleobj.toplevel,
+ window->w,
+ window->h);
+ xdg_toplevel_set_max_size(data->shell_surface.xdg.roleobj.toplevel,
+ window->w,
+ window->h);
+ }
} else if (c->shell.zxdg) {
data->shell_surface.zxdg.surface = zxdg_shell_v6_get_xdg_surface(c->shell.zxdg, data->surface);
/* !!! FIXME: add popup role */
data->shell_surface.zxdg.roleobj.toplevel = zxdg_surface_v6_get_toplevel(data->shell_surface.zxdg.surface);
zxdg_toplevel_v6_add_listener(data->shell_surface.zxdg.roleobj.toplevel, &toplevel_listener_zxdg, data);
zxdg_toplevel_v6_set_app_id(data->shell_surface.zxdg.roleobj.toplevel, c->classname);
+ if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
+ zxdg_toplevel_v6_set_min_size(data->shell_surface.zxdg.roleobj.toplevel,
+ window->w,
+ window->h);
+ zxdg_toplevel_v6_set_max_size(data->shell_surface.zxdg.roleobj.toplevel,
+ window->w,
+ window->h);
+ }
} else {
data->shell_surface.wl = wl_shell_get_shell_surface(c->shell.wl, data->surface);
wl_shell_surface_set_class(data->shell_surface.wl, c->classname);
@@ -906,12 +951,68 @@ Wayland_HandlePendingResize(SDL_Window *window)
}
}
+void
+Wayland_SetWindowMinimumSize(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *data = _this->driverdata;
+ SDL_WindowData *wind = window->driverdata;
+
+ if (window->flags & SDL_WINDOW_RESIZABLE) {
+ if (data->shell.xdg) {
+ xdg_toplevel_set_min_size(wind->shell_surface.xdg.roleobj.toplevel,
+ window->min_w,
+ window->min_h);
+ } else if (data->shell.zxdg) {
+ zxdg_toplevel_v6_set_min_size(wind->shell_surface.zxdg.roleobj.toplevel,
+ window->min_w,
+ window->min_h);
+ }
+ }
+}
+
+void
+Wayland_SetWindowMaximumSize(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *data = _this->driverdata;
+ SDL_WindowData *wind = window->driverdata;
+
+ if (window->flags & SDL_WINDOW_RESIZABLE) {
+ if (data->shell.xdg) {
+ xdg_toplevel_set_max_size(wind->shell_surface.xdg.roleobj.toplevel,
+ window->max_w,
+ window->max_h);
+ } else if (data->shell.zxdg) {
+ zxdg_toplevel_v6_set_max_size(wind->shell_surface.zxdg.roleobj.toplevel,
+ window->max_w,
+ window->max_h);
+ }
+ }
+}
+
void Wayland_SetWindowSize(_THIS, SDL_Window * window)
{
SDL_VideoData *data = _this->driverdata;
SDL_WindowData *wind = window->driverdata;
struct wl_region *region;
+ if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
+ if (data->shell.xdg) {
+ xdg_toplevel_set_min_size(wind->shell_surface.xdg.roleobj.toplevel,
+ window->w,
+ window->h);
+ xdg_toplevel_set_max_size(wind->shell_surface.xdg.roleobj.toplevel,
+ window->w,
+ window->h);
+ } else if (data->shell.zxdg) {
+ zxdg_toplevel_v6_set_min_size(wind->shell_surface.zxdg.roleobj.toplevel,
+ window->w,
+ window->h);
+ zxdg_toplevel_v6_set_max_size(wind->shell_surface.zxdg.roleobj.toplevel,
+ window->w,
+ window->h);
+ }
+ }
+
wl_surface_set_buffer_scale(wind->surface, get_window_scale_factor(window));
if (wind->egl_window) {
diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h
index adaa9db..1545655 100644
--- a/src/video/wayland/SDL_waylandwindow.h
+++ b/src/video/wayland/SDL_waylandwindow.h
@@ -98,6 +98,8 @@ extern void Wayland_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool borde
extern void Wayland_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
extern int Wayland_CreateWindow(_THIS, SDL_Window *window);
extern void Wayland_SetWindowSize(_THIS, SDL_Window * window);
+extern void Wayland_SetWindowMinimumSize(_THIS, SDL_Window * window);
+extern void Wayland_SetWindowMaximumSize(_THIS, SDL_Window * window);
extern void Wayland_SetWindowTitle(_THIS, SDL_Window * window);
extern void Wayland_DestroyWindow(_THIS, SDL_Window *window);
extern void Wayland_SuspendScreenSaver(_THIS);