Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
authorSam Lantinga <slouken@libsdl.org>
Fri, 09 Aug 2013 23:13:52 -0700
changeset 7617 918703f5cff8
parent 7616 1eaa3b3c55c5
child 7618 d381f183aa07
Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11window.c
src/video/x11/SDL_x11window.h
--- a/src/video/x11/SDL_x11video.c	Fri Aug 09 21:09:49 2013 -0700
+++ b/src/video/x11/SDL_x11video.c	Fri Aug 09 23:13:52 2013 -0700
@@ -362,6 +362,8 @@
     device->SetWindowIcon = X11_SetWindowIcon;
     device->SetWindowPosition = X11_SetWindowPosition;
     device->SetWindowSize = X11_SetWindowSize;
+    device->SetWindowMinimumSize = X11_SetWindowMinimumSize;
+    device->SetWindowMaximumSize = X11_SetWindowMaximumSize;
     device->ShowWindow = X11_ShowWindow;
     device->HideWindow = X11_HideWindow;
     device->RaiseWindow = X11_RaiseWindow;
--- a/src/video/x11/SDL_x11window.c	Fri Aug 09 21:09:49 2013 -0700
+++ b/src/video/x11/SDL_x11window.c	Fri Aug 09 23:13:52 2013 -0700
@@ -742,6 +742,64 @@
 }
 
 void
+X11_SetWindowMinimumSize(_THIS, SDL_Window * window)
+{
+    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+    Display *display = data->videodata->display;
+
+    if (window->flags & SDL_WINDOW_RESIZABLE) {
+         XSizeHints *sizehints = XAllocSizeHints();
+         long userhints;
+
+         XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
+
+         sizehints->min_width = window->min_w;
+         sizehints->min_height = window->min_h;
+         sizehints->flags |= PMinSize;
+
+         XSetWMNormalHints(display, data->xwindow, sizehints);
+
+         XFree(sizehints);
+
+        /* See comment in X11_SetWindowSize. */
+        XResizeWindow(display, data->xwindow, window->w, window->h);
+        XMoveWindow(display, data->xwindow, window->x, window->y);
+        XRaiseWindow(display, data->xwindow);
+    }
+
+    XFlush(display);
+}
+
+void
+X11_SetWindowMaximumSize(_THIS, SDL_Window * window)
+{
+    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+    Display *display = data->videodata->display;
+
+    if (window->flags & SDL_WINDOW_RESIZABLE) {
+         XSizeHints *sizehints = XAllocSizeHints();
+         long userhints;
+
+         XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
+
+         sizehints->max_width = window->max_w;
+         sizehints->max_height = window->max_h;
+         sizehints->flags |= PMaxSize;
+
+         XSetWMNormalHints(display, data->xwindow, sizehints);
+
+         XFree(sizehints);
+
+        /* See comment in X11_SetWindowSize. */
+        XResizeWindow(display, data->xwindow, window->w, window->h);
+        XMoveWindow(display, data->xwindow, window->x, window->y);
+        XRaiseWindow(display, data->xwindow);
+    }
+
+    XFlush(display);
+}
+
+void
 X11_SetWindowSize(_THIS, SDL_Window * window)
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
@@ -760,6 +818,7 @@
 
          sizehints->min_width = sizehints->max_width = window->w;
          sizehints->min_height = sizehints->max_height = window->h;
+         sizehints->flags |= PMinSize | PMaxSize;
 
          XSetWMNormalHints(display, data->xwindow, sizehints);
 
--- a/src/video/x11/SDL_x11window.h	Fri Aug 09 21:09:49 2013 -0700
+++ b/src/video/x11/SDL_x11window.h	Fri Aug 09 23:13:52 2013 -0700
@@ -70,6 +70,8 @@
 extern void X11_SetWindowTitle(_THIS, SDL_Window * window);
 extern void X11_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
 extern void X11_SetWindowPosition(_THIS, SDL_Window * window);
+extern void X11_SetWindowMinimumSize(_THIS, SDL_Window * window);
+extern void X11_SetWindowMaximumSize(_THIS, SDL_Window * window);
 extern void X11_SetWindowSize(_THIS, SDL_Window * window);
 extern void X11_ShowWindow(_THIS, SDL_Window * window);
 extern void X11_HideWindow(_THIS, SDL_Window * window);