Added SDL_GetWindowBordersSize().
authorRyan C. Gordon <icculus@icculus.org>
Tue, 05 Jan 2016 02:29:06 -0500
changeset 10024 9a1189c7b891
parent 10023 d8015905fef6
child 10025 bf4f8cde1c54
Added SDL_GetWindowBordersSize(). This is currently only implemented for X11. This patch is based on work in Unreal Engine 4's fork of SDL, compliments of Epic Games.
include/SDL_video.h
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11window.c
src/video/x11/SDL_x11window.h
--- a/include/SDL_video.h	Tue Jan 05 02:27:26 2016 -0500
+++ b/include/SDL_video.h	Tue Jan 05 02:29:06 2016 -0500
@@ -612,6 +612,25 @@
                                                int *h);
 
 /**
+ *  \brief Get the size of a window's borders (decorations) around the client area.
+ *
+ *  \param window The window to query.
+ *  \param top Pointer to variable for storing the size of the top border. NULL is permitted.
+ *  \param left Pointer to variable for storing the size of the left border. NULL is permitted.
+ *  \param bottom Pointer to variable for storing the size of the bottom border. NULL is permitted.
+ *  \param right Pointer to variable for storing the size of the right border. NULL is permitted.
+ *
+ *  \return 0 on success, or -1 if getting this information is not supported.
+ *
+ *  \note if this function fails (returns -1), the size values will be
+ *        initialized to 0, 0, 0, 0 (if a non-NULL pointer is provided), as
+ *        if the window in question was borderless.
+ */
+extern DECLSPEC int SDLCALL SDL_GetWindowBordersSize(SDL_Window * window,
+                                                     int *top, int *left,
+                                                     int *bottom, int *right);
+
+/**
  *  \brief Set the minimum size of a window's client area.
  *
  *  \param window    The window to set a new minimum size.
--- a/src/dynapi/SDL_dynapi_overrides.h	Tue Jan 05 02:27:26 2016 -0500
+++ b/src/dynapi/SDL_dynapi_overrides.h	Tue Jan 05 02:29:06 2016 -0500
@@ -598,3 +598,4 @@
 #define SDL_GameControllerFromInstanceID SDL_GameControllerFromInstanceID_REAL
 #define SDL_JoystickFromInstanceID SDL_JoystickFromInstanceID_REAL
 #define SDL_GetDisplayUsableBounds SDL_GetDisplayUsableBounds_REAL
+#define SDL_GetWindowBordersSize SDL_GetWindowBordersSize_REAL
--- a/src/dynapi/SDL_dynapi_procs.h	Tue Jan 05 02:27:26 2016 -0500
+++ b/src/dynapi/SDL_dynapi_procs.h	Tue Jan 05 02:29:06 2016 -0500
@@ -632,3 +632,4 @@
 SDL_DYNAPI_PROC(SDL_GameController*,SDL_GameControllerFromInstanceID,(SDL_JoystickID a),(a),return)
 SDL_DYNAPI_PROC(SDL_Joystick*,SDL_JoystickFromInstanceID,(SDL_JoystickID a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_GetDisplayUsableBounds,(int a, SDL_Rect *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetWindowBordersSize,(SDL_Window *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return)
--- a/src/video/SDL_sysvideo.h	Tue Jan 05 02:27:26 2016 -0500
+++ b/src/video/SDL_sysvideo.h	Tue Jan 05 02:29:06 2016 -0500
@@ -206,6 +206,7 @@
     void (*SetWindowSize) (_THIS, SDL_Window * window);
     void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
     void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
+    int (*GetWindowBordersSize) (_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right);
     void (*ShowWindow) (_THIS, SDL_Window * window);
     void (*HideWindow) (_THIS, SDL_Window * window);
     void (*RaiseWindow) (_THIS, SDL_Window * window);
--- a/src/video/SDL_video.c	Tue Jan 05 02:27:26 2016 -0500
+++ b/src/video/SDL_video.c	Tue Jan 05 02:29:06 2016 -0500
@@ -1907,6 +1907,28 @@
     }
 }
 
+int
+SDL_GetWindowBordersSize(SDL_Window * window, int *top, int *left, int *bottom, int *right)
+{
+    int dummy = 0;
+
+    if (!top) { top = &dummy; }
+    if (!left) { left = &dummy; }
+    if (!right) { right = &dummy; }
+    if (!bottom) { bottom = &dummy; }
+
+    /* Always initialize, so applications don't have to care */
+    *top = *left = *bottom = *right = 0;
+
+    CHECK_WINDOW_MAGIC(window, -1);
+
+    if (!_this->GetWindowBordersSize) {
+        return SDL_Unsupported();
+    }
+
+    return _this->GetWindowBordersSize(_this, window, top, left, bottom, right);
+}
+
 void
 SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
 {
--- a/src/video/x11/SDL_x11video.c	Tue Jan 05 02:27:26 2016 -0500
+++ b/src/video/x11/SDL_x11video.c	Tue Jan 05 02:29:06 2016 -0500
@@ -232,6 +232,7 @@
     device->SetWindowSize = X11_SetWindowSize;
     device->SetWindowMinimumSize = X11_SetWindowMinimumSize;
     device->SetWindowMaximumSize = X11_SetWindowMaximumSize;
+    device->GetWindowBordersSize = X11_GetWindowBordersSize;
     device->ShowWindow = X11_ShowWindow;
     device->HideWindow = X11_HideWindow;
     device->RaiseWindow = X11_RaiseWindow;
--- a/src/video/x11/SDL_x11window.c	Tue Jan 05 02:27:26 2016 -0500
+++ b/src/video/x11/SDL_x11window.c	Tue Jan 05 02:29:06 2016 -0500
@@ -895,6 +895,34 @@
     X11_XFlush(display);
 }
 
+int
+X11_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right)
+{
+    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+    Display *display = data->videodata->display;
+    Atom _NET_FRAME_EXTENTS = X11_XInternAtom(display, "_NET_FRAME_EXTENTS", 0);
+    Atom type;
+    int format;
+    unsigned long nitems, bytes_after;
+    unsigned char *property;
+    int result = -1;
+
+    if (X11_XGetWindowProperty(display, data->xwindow, _NET_FRAME_EXTENTS,
+                               0, 16, 0, XA_CARDINAL, &type, &format,
+                               &nitems, &bytes_after, &property) == Success) {
+        if (type != None && nitems == 4) {
+            *left = (int) (((long*)property)[0]);
+            *right = (int) (((long*)property)[1]);
+            *top = (int) (((long*)property)[2]);
+            *bottom = (int) (((long*)property)[3]);
+            result = 0;
+        }
+        X11_XFree(property);
+    }
+
+    return result;
+}
+
 void
 X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
 {
--- a/src/video/x11/SDL_x11window.h	Tue Jan 05 02:27:26 2016 -0500
+++ b/src/video/x11/SDL_x11window.h	Tue Jan 05 02:29:06 2016 -0500
@@ -79,6 +79,7 @@
 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 int X11_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right);
 extern void X11_SetWindowSize(_THIS, SDL_Window * window);
 extern void X11_ShowWindow(_THIS, SDL_Window * window);
 extern void X11_HideWindow(_THIS, SDL_Window * window);