Added SDL_GetWindowBordersSize().
authorRyan C. Gordon <icculus@icculus.org>
Tue, 05 Jan 2016 02:29:06 -0500
changeset 100249a1189c7b891
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
     1.1 --- a/include/SDL_video.h	Tue Jan 05 02:27:26 2016 -0500
     1.2 +++ b/include/SDL_video.h	Tue Jan 05 02:29:06 2016 -0500
     1.3 @@ -612,6 +612,25 @@
     1.4                                                 int *h);
     1.5  
     1.6  /**
     1.7 + *  \brief Get the size of a window's borders (decorations) around the client area.
     1.8 + *
     1.9 + *  \param window The window to query.
    1.10 + *  \param top Pointer to variable for storing the size of the top border. NULL is permitted.
    1.11 + *  \param left Pointer to variable for storing the size of the left border. NULL is permitted.
    1.12 + *  \param bottom Pointer to variable for storing the size of the bottom border. NULL is permitted.
    1.13 + *  \param right Pointer to variable for storing the size of the right border. NULL is permitted.
    1.14 + *
    1.15 + *  \return 0 on success, or -1 if getting this information is not supported.
    1.16 + *
    1.17 + *  \note if this function fails (returns -1), the size values will be
    1.18 + *        initialized to 0, 0, 0, 0 (if a non-NULL pointer is provided), as
    1.19 + *        if the window in question was borderless.
    1.20 + */
    1.21 +extern DECLSPEC int SDLCALL SDL_GetWindowBordersSize(SDL_Window * window,
    1.22 +                                                     int *top, int *left,
    1.23 +                                                     int *bottom, int *right);
    1.24 +
    1.25 +/**
    1.26   *  \brief Set the minimum size of a window's client area.
    1.27   *
    1.28   *  \param window    The window to set a new minimum size.
     2.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Tue Jan 05 02:27:26 2016 -0500
     2.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Tue Jan 05 02:29:06 2016 -0500
     2.3 @@ -598,3 +598,4 @@
     2.4  #define SDL_GameControllerFromInstanceID SDL_GameControllerFromInstanceID_REAL
     2.5  #define SDL_JoystickFromInstanceID SDL_JoystickFromInstanceID_REAL
     2.6  #define SDL_GetDisplayUsableBounds SDL_GetDisplayUsableBounds_REAL
     2.7 +#define SDL_GetWindowBordersSize SDL_GetWindowBordersSize_REAL
     3.1 --- a/src/dynapi/SDL_dynapi_procs.h	Tue Jan 05 02:27:26 2016 -0500
     3.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Tue Jan 05 02:29:06 2016 -0500
     3.3 @@ -632,3 +632,4 @@
     3.4  SDL_DYNAPI_PROC(SDL_GameController*,SDL_GameControllerFromInstanceID,(SDL_JoystickID a),(a),return)
     3.5  SDL_DYNAPI_PROC(SDL_Joystick*,SDL_JoystickFromInstanceID,(SDL_JoystickID a),(a),return)
     3.6  SDL_DYNAPI_PROC(int,SDL_GetDisplayUsableBounds,(int a, SDL_Rect *b),(a,b),return)
     3.7 +SDL_DYNAPI_PROC(int,SDL_GetWindowBordersSize,(SDL_Window *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return)
     4.1 --- a/src/video/SDL_sysvideo.h	Tue Jan 05 02:27:26 2016 -0500
     4.2 +++ b/src/video/SDL_sysvideo.h	Tue Jan 05 02:29:06 2016 -0500
     4.3 @@ -206,6 +206,7 @@
     4.4      void (*SetWindowSize) (_THIS, SDL_Window * window);
     4.5      void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
     4.6      void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
     4.7 +    int (*GetWindowBordersSize) (_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right);
     4.8      void (*ShowWindow) (_THIS, SDL_Window * window);
     4.9      void (*HideWindow) (_THIS, SDL_Window * window);
    4.10      void (*RaiseWindow) (_THIS, SDL_Window * window);
     5.1 --- a/src/video/SDL_video.c	Tue Jan 05 02:27:26 2016 -0500
     5.2 +++ b/src/video/SDL_video.c	Tue Jan 05 02:29:06 2016 -0500
     5.3 @@ -1907,6 +1907,28 @@
     5.4      }
     5.5  }
     5.6  
     5.7 +int
     5.8 +SDL_GetWindowBordersSize(SDL_Window * window, int *top, int *left, int *bottom, int *right)
     5.9 +{
    5.10 +    int dummy = 0;
    5.11 +
    5.12 +    if (!top) { top = &dummy; }
    5.13 +    if (!left) { left = &dummy; }
    5.14 +    if (!right) { right = &dummy; }
    5.15 +    if (!bottom) { bottom = &dummy; }
    5.16 +
    5.17 +    /* Always initialize, so applications don't have to care */
    5.18 +    *top = *left = *bottom = *right = 0;
    5.19 +
    5.20 +    CHECK_WINDOW_MAGIC(window, -1);
    5.21 +
    5.22 +    if (!_this->GetWindowBordersSize) {
    5.23 +        return SDL_Unsupported();
    5.24 +    }
    5.25 +
    5.26 +    return _this->GetWindowBordersSize(_this, window, top, left, bottom, right);
    5.27 +}
    5.28 +
    5.29  void
    5.30  SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
    5.31  {
     6.1 --- a/src/video/x11/SDL_x11video.c	Tue Jan 05 02:27:26 2016 -0500
     6.2 +++ b/src/video/x11/SDL_x11video.c	Tue Jan 05 02:29:06 2016 -0500
     6.3 @@ -232,6 +232,7 @@
     6.4      device->SetWindowSize = X11_SetWindowSize;
     6.5      device->SetWindowMinimumSize = X11_SetWindowMinimumSize;
     6.6      device->SetWindowMaximumSize = X11_SetWindowMaximumSize;
     6.7 +    device->GetWindowBordersSize = X11_GetWindowBordersSize;
     6.8      device->ShowWindow = X11_ShowWindow;
     6.9      device->HideWindow = X11_HideWindow;
    6.10      device->RaiseWindow = X11_RaiseWindow;
     7.1 --- a/src/video/x11/SDL_x11window.c	Tue Jan 05 02:27:26 2016 -0500
     7.2 +++ b/src/video/x11/SDL_x11window.c	Tue Jan 05 02:29:06 2016 -0500
     7.3 @@ -895,6 +895,34 @@
     7.4      X11_XFlush(display);
     7.5  }
     7.6  
     7.7 +int
     7.8 +X11_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right)
     7.9 +{
    7.10 +    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    7.11 +    Display *display = data->videodata->display;
    7.12 +    Atom _NET_FRAME_EXTENTS = X11_XInternAtom(display, "_NET_FRAME_EXTENTS", 0);
    7.13 +    Atom type;
    7.14 +    int format;
    7.15 +    unsigned long nitems, bytes_after;
    7.16 +    unsigned char *property;
    7.17 +    int result = -1;
    7.18 +
    7.19 +    if (X11_XGetWindowProperty(display, data->xwindow, _NET_FRAME_EXTENTS,
    7.20 +                               0, 16, 0, XA_CARDINAL, &type, &format,
    7.21 +                               &nitems, &bytes_after, &property) == Success) {
    7.22 +        if (type != None && nitems == 4) {
    7.23 +            *left = (int) (((long*)property)[0]);
    7.24 +            *right = (int) (((long*)property)[1]);
    7.25 +            *top = (int) (((long*)property)[2]);
    7.26 +            *bottom = (int) (((long*)property)[3]);
    7.27 +            result = 0;
    7.28 +        }
    7.29 +        X11_XFree(property);
    7.30 +    }
    7.31 +
    7.32 +    return result;
    7.33 +}
    7.34 +
    7.35  void
    7.36  X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
    7.37  {
     8.1 --- a/src/video/x11/SDL_x11window.h	Tue Jan 05 02:27:26 2016 -0500
     8.2 +++ b/src/video/x11/SDL_x11window.h	Tue Jan 05 02:29:06 2016 -0500
     8.3 @@ -79,6 +79,7 @@
     8.4  extern void X11_SetWindowPosition(_THIS, SDL_Window * window);
     8.5  extern void X11_SetWindowMinimumSize(_THIS, SDL_Window * window);
     8.6  extern void X11_SetWindowMaximumSize(_THIS, SDL_Window * window);
     8.7 +extern int X11_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right);
     8.8  extern void X11_SetWindowSize(_THIS, SDL_Window * window);
     8.9  extern void X11_ShowWindow(_THIS, SDL_Window * window);
    8.10  extern void X11_HideWindow(_THIS, SDL_Window * window);