Added SDL_SetWindowInputFocus().
authorRyan C. Gordon <icculus@icculus.org>
Tue, 05 Jan 2016 02:28:56 -0500
changeset 100265f73f513b9f5
parent 10025 bf4f8cde1c54
child 10027 f7ab0613164a
Added SDL_SetWindowInputFocus().

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:46:10 2016 -0500
     1.2 +++ b/include/SDL_video.h	Tue Jan 05 02:28:56 2016 -0500
     1.3 @@ -874,6 +874,20 @@
     1.4  extern DECLSPEC int SDLCALL SDL_GetWindowOpacity(SDL_Window * window, float * out_opacity);
     1.5  
     1.6  /**
     1.7 + *  \brief Explicitly sets input focus to the window.
     1.8 + *
     1.9 + *  You almost certainly want SDL_RaiseWindow() instead of this function. Use
    1.10 + *  this with caution, as you might give focus to a window that's completely
    1.11 + *  obscured by other windows.
    1.12 + *
    1.13 + *  \param window The window that should get the input focus
    1.14 + * 
    1.15 + *  \return 0 on success, or -1 otherwise.
    1.16 + *  \sa SDL_RaiseWindow()
    1.17 + */
    1.18 +extern DECLSPEC int SDLCALL SDL_SetWindowInputFocus(SDL_Window * window);
    1.19 +
    1.20 +/**
    1.21   *  \brief Set the gamma ramp for a window.
    1.22   *
    1.23   *  \param window The window for which the gamma ramp should be set.
     2.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Tue Jan 05 02:46:10 2016 -0500
     2.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Tue Jan 05 02:28:56 2016 -0500
     2.3 @@ -601,3 +601,4 @@
     2.4  #define SDL_GetWindowBordersSize SDL_GetWindowBordersSize_REAL
     2.5  #define SDL_SetWindowOpacity SDL_SetWindowOpacity_REAL
     2.6  #define SDL_GetWindowOpacity SDL_GetWindowOpacity_REAL
     2.7 +#define SDL_SetWindowInputFocus SDL_SetWindowInputFocus_REAL
     3.1 --- a/src/dynapi/SDL_dynapi_procs.h	Tue Jan 05 02:46:10 2016 -0500
     3.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Tue Jan 05 02:28:56 2016 -0500
     3.3 @@ -635,3 +635,4 @@
     3.4  SDL_DYNAPI_PROC(int,SDL_GetWindowBordersSize,(SDL_Window *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return)
     3.5  SDL_DYNAPI_PROC(int,SDL_SetWindowOpacity,(SDL_Window *a, float b),(a,b),return)
     3.6  SDL_DYNAPI_PROC(int,SDL_GetWindowOpacity,(SDL_Window *a, float *b),(a,b),return)
     3.7 +SDL_DYNAPI_PROC(int,SDL_SetWindowInputFocus,(SDL_Window *a),(a),return)
     4.1 --- a/src/video/SDL_sysvideo.h	Tue Jan 05 02:46:10 2016 -0500
     4.2 +++ b/src/video/SDL_sysvideo.h	Tue Jan 05 02:28:56 2016 -0500
     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 (*SetWindowInputFocus) (_THIS, SDL_Window * window);
     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:46:10 2016 -0500
     5.2 +++ b/src/video/SDL_video.c	Tue Jan 05 02:28:56 2016 -0500
     5.3 @@ -2228,6 +2228,19 @@
     5.4      return 0;
     5.5  }
     5.6  
     5.7 +int 
     5.8 +SDL_SetWindowInputFocus(SDL_Window * window)
     5.9 +{
    5.10 +    CHECK_WINDOW_MAGIC(window, -1);
    5.11 +
    5.12 +    if (!_this->SetWindowInputFocus) {
    5.13 +        return SDL_Unsupported();
    5.14 +    }
    5.15 +    
    5.16 +    return _this->SetWindowInputFocus(_this, window);
    5.17 +}
    5.18 +
    5.19 +
    5.20  int
    5.21  SDL_SetWindowGammaRamp(SDL_Window * window, const Uint16 * red,
    5.22                                              const Uint16 * green,
     6.1 --- a/src/video/x11/SDL_x11video.c	Tue Jan 05 02:46:10 2016 -0500
     6.2 +++ b/src/video/x11/SDL_x11video.c	Tue Jan 05 02:28:56 2016 -0500
     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->SetWindowInputFocus = X11_SetWindowInputFocus;
     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:46:10 2016 -0500
     7.2 +++ b/src/video/x11/SDL_x11window.c	Tue Jan 05 02:28:56 2016 -0500
     7.3 @@ -942,6 +942,19 @@
     7.4      return 0;
     7.5  }
     7.6  
     7.7 +int
     7.8 +X11_SetWindowInputFocus(_THIS, SDL_Window * window) 
     7.9 +{
    7.10 +    if (X11_IsWindowMapped(_this, window)) {
    7.11 +        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    7.12 +        Display *display = data->videodata->display;
    7.13 +        X11_XSetInputFocus(display, data->xwindow, RevertToNone, CurrentTime);
    7.14 +        X11_XFlush(display);
    7.15 +        return 0;
    7.16 +    }
    7.17 +    return -1;
    7.18 +}
    7.19 +
    7.20  void
    7.21  X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
    7.22  {
     8.1 --- a/src/video/x11/SDL_x11window.h	Tue Jan 05 02:46:10 2016 -0500
     8.2 +++ b/src/video/x11/SDL_x11window.h	Tue Jan 05 02:28:56 2016 -0500
     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_SetWindowInputFocus(_THIS, SDL_Window * window);
     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);