Added SDL_SetWindowModalFor().
authorRyan C. Gordon <icculus@icculus.org>
Tue, 21 Apr 2015 09:45:58 -0400
changeset 10027f7ab0613164a
parent 10026 5f73f513b9f5
child 10028 da668b612d10
Added SDL_SetWindowModalFor().

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:28:56 2016 -0500
     1.2 +++ b/include/SDL_video.h	Tue Apr 21 09:45:58 2015 -0400
     1.3 @@ -874,6 +874,16 @@
     1.4  extern DECLSPEC int SDLCALL SDL_GetWindowOpacity(SDL_Window * window, float * out_opacity);
     1.5  
     1.6  /**
     1.7 + *  \brief Sets the window as a modal for another window (@TODO: reconsider this function and/or its name)
     1.8 + *
     1.9 + *  \param modal_window The window that should be modal
    1.10 + *  \param parent_window The parent window
    1.11 + * 
    1.12 + *  \return 0 on success, or -1 otherwise.
    1.13 + */
    1.14 +extern DECLSPEC int SDLCALL SDL_SetWindowModalFor(SDL_Window * modal_window, SDL_Window * parent_window);
    1.15 +
    1.16 +/**
    1.17   *  \brief Explicitly sets input focus to the window.
    1.18   *
    1.19   *  You almost certainly want SDL_RaiseWindow() instead of this function. Use
     2.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Tue Jan 05 02:28:56 2016 -0500
     2.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Tue Apr 21 09:45:58 2015 -0400
     2.3 @@ -602,3 +602,4 @@
     2.4  #define SDL_SetWindowOpacity SDL_SetWindowOpacity_REAL
     2.5  #define SDL_GetWindowOpacity SDL_GetWindowOpacity_REAL
     2.6  #define SDL_SetWindowInputFocus SDL_SetWindowInputFocus_REAL
     2.7 +#define SDL_SetWindowModalFor SDL_SetWindowModalFor_REAL
     3.1 --- a/src/dynapi/SDL_dynapi_procs.h	Tue Jan 05 02:28:56 2016 -0500
     3.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Tue Apr 21 09:45:58 2015 -0400
     3.3 @@ -636,3 +636,4 @@
     3.4  SDL_DYNAPI_PROC(int,SDL_SetWindowOpacity,(SDL_Window *a, float b),(a,b),return)
     3.5  SDL_DYNAPI_PROC(int,SDL_GetWindowOpacity,(SDL_Window *a, float *b),(a,b),return)
     3.6  SDL_DYNAPI_PROC(int,SDL_SetWindowInputFocus,(SDL_Window *a),(a),return)
     3.7 +SDL_DYNAPI_PROC(int,SDL_SetWindowModalFor,(SDL_Window *a, SDL_Window *b),(a,b),return)
     4.1 --- a/src/video/SDL_sysvideo.h	Tue Jan 05 02:28:56 2016 -0500
     4.2 +++ b/src/video/SDL_sysvideo.h	Tue Apr 21 09:45:58 2015 -0400
     4.3 @@ -210,6 +210,7 @@
     4.4      void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
     4.5      int (*GetWindowBordersSize) (_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right);
     4.6      int (*SetWindowOpacity) (_THIS, SDL_Window * window, float opacity);
     4.7 +    int (*SetWindowModalFor) (_THIS, SDL_Window * modal_window, SDL_Window * parent_window);
     4.8      int (*SetWindowInputFocus) (_THIS, SDL_Window * window);
     4.9      void (*ShowWindow) (_THIS, SDL_Window * window);
    4.10      void (*HideWindow) (_THIS, SDL_Window * window);
     5.1 --- a/src/video/SDL_video.c	Tue Jan 05 02:28:56 2016 -0500
     5.2 +++ b/src/video/SDL_video.c	Tue Apr 21 09:45:58 2015 -0400
     5.3 @@ -2228,6 +2228,19 @@
     5.4      return 0;
     5.5  }
     5.6  
     5.7 +int
     5.8 +SDL_SetWindowModalFor(SDL_Window * modal_window, SDL_Window * parent_window)
     5.9 +{
    5.10 +    CHECK_WINDOW_MAGIC(modal_window, -1);
    5.11 +    CHECK_WINDOW_MAGIC(parent_window, -1);
    5.12 +
    5.13 +    if (!_this->SetWindowModalFor) {
    5.14 +        return SDL_Unsupported();
    5.15 +    }
    5.16 +    
    5.17 +    return _this->SetWindowModalFor(_this, modal_window, parent_window);
    5.18 +}
    5.19 +
    5.20  int 
    5.21  SDL_SetWindowInputFocus(SDL_Window * window)
    5.22  {
     6.1 --- a/src/video/x11/SDL_x11video.c	Tue Jan 05 02:28:56 2016 -0500
     6.2 +++ b/src/video/x11/SDL_x11video.c	Tue Apr 21 09:45:58 2015 -0400
     6.3 @@ -234,6 +234,7 @@
     6.4      device->SetWindowMaximumSize = X11_SetWindowMaximumSize;
     6.5      device->GetWindowBordersSize = X11_GetWindowBordersSize;
     6.6      device->SetWindowOpacity = X11_SetWindowOpacity;
     6.7 +    device->SetWindowModalFor = X11_SetWindowModalFor;
     6.8      device->SetWindowInputFocus = X11_SetWindowInputFocus;
     6.9      device->ShowWindow = X11_ShowWindow;
    6.10      device->HideWindow = X11_HideWindow;
     7.1 --- a/src/video/x11/SDL_x11window.c	Tue Jan 05 02:28:56 2016 -0500
     7.2 +++ b/src/video/x11/SDL_x11window.c	Tue Apr 21 09:45:58 2015 -0400
     7.3 @@ -942,6 +942,16 @@
     7.4      return 0;
     7.5  }
     7.6  
     7.7 +int 
     7.8 +X11_SetWindowModalFor(_THIS, SDL_Window * modal_window, SDL_Window * parent_window) {
     7.9 +    SDL_WindowData *data = (SDL_WindowData *) modal_window->driverdata;
    7.10 +    SDL_WindowData *parent_data = (SDL_WindowData *) parent_window->driverdata;
    7.11 +    Display *display = data->videodata->display;
    7.12 +
    7.13 +    X11_XSetTransientForHint(display, data->xwindow, parent_data->xwindow);
    7.14 +    return 0;
    7.15 +}
    7.16 +
    7.17  int
    7.18  X11_SetWindowInputFocus(_THIS, SDL_Window * window) 
    7.19  {
     8.1 --- a/src/video/x11/SDL_x11window.h	Tue Jan 05 02:28:56 2016 -0500
     8.2 +++ b/src/video/x11/SDL_x11window.h	Tue Apr 21 09:45:58 2015 -0400
     8.3 @@ -81,6 +81,7 @@
     8.4  extern void X11_SetWindowMaximumSize(_THIS, SDL_Window * window);
     8.5  extern int X11_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right);
     8.6  extern int X11_SetWindowOpacity(_THIS, SDL_Window * window, float opacity);
     8.7 +extern int X11_SetWindowModalFor(_THIS, SDL_Window * modal_window, SDL_Window * parent_window);
     8.8  extern int X11_SetWindowInputFocus(_THIS, SDL_Window * window);
     8.9  extern void X11_SetWindowSize(_THIS, SDL_Window * window);
    8.10  extern void X11_ShowWindow(_THIS, SDL_Window * window);