Added SDL_SetWindowInputFocus().
authorRyan C. Gordon <icculus@icculus.org>
Tue, 05 Jan 2016 02:28:56 -0500
changeset 10026 5f73f513b9f5
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
--- a/include/SDL_video.h	Tue Jan 05 02:46:10 2016 -0500
+++ b/include/SDL_video.h	Tue Jan 05 02:28:56 2016 -0500
@@ -874,6 +874,20 @@
 extern DECLSPEC int SDLCALL SDL_GetWindowOpacity(SDL_Window * window, float * out_opacity);
 
 /**
+ *  \brief Explicitly sets input focus to the window.
+ *
+ *  You almost certainly want SDL_RaiseWindow() instead of this function. Use
+ *  this with caution, as you might give focus to a window that's completely
+ *  obscured by other windows.
+ *
+ *  \param window The window that should get the input focus
+ * 
+ *  \return 0 on success, or -1 otherwise.
+ *  \sa SDL_RaiseWindow()
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowInputFocus(SDL_Window * window);
+
+/**
  *  \brief Set the gamma ramp for a window.
  *
  *  \param window The window for which the gamma ramp should be set.
--- a/src/dynapi/SDL_dynapi_overrides.h	Tue Jan 05 02:46:10 2016 -0500
+++ b/src/dynapi/SDL_dynapi_overrides.h	Tue Jan 05 02:28:56 2016 -0500
@@ -601,3 +601,4 @@
 #define SDL_GetWindowBordersSize SDL_GetWindowBordersSize_REAL
 #define SDL_SetWindowOpacity SDL_SetWindowOpacity_REAL
 #define SDL_GetWindowOpacity SDL_GetWindowOpacity_REAL
+#define SDL_SetWindowInputFocus SDL_SetWindowInputFocus_REAL
--- a/src/dynapi/SDL_dynapi_procs.h	Tue Jan 05 02:46:10 2016 -0500
+++ b/src/dynapi/SDL_dynapi_procs.h	Tue Jan 05 02:28:56 2016 -0500
@@ -635,3 +635,4 @@
 SDL_DYNAPI_PROC(int,SDL_GetWindowBordersSize,(SDL_Window *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(int,SDL_SetWindowOpacity,(SDL_Window *a, float b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_GetWindowOpacity,(SDL_Window *a, float *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_SetWindowInputFocus,(SDL_Window *a),(a),return)
--- a/src/video/SDL_sysvideo.h	Tue Jan 05 02:46:10 2016 -0500
+++ b/src/video/SDL_sysvideo.h	Tue Jan 05 02:28:56 2016 -0500
@@ -210,6 +210,7 @@
     void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
     int (*GetWindowBordersSize) (_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right);
     int (*SetWindowOpacity) (_THIS, SDL_Window * window, float opacity);
+    int (*SetWindowInputFocus) (_THIS, SDL_Window * window);
     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:46:10 2016 -0500
+++ b/src/video/SDL_video.c	Tue Jan 05 02:28:56 2016 -0500
@@ -2228,6 +2228,19 @@
     return 0;
 }
 
+int 
+SDL_SetWindowInputFocus(SDL_Window * window)
+{
+    CHECK_WINDOW_MAGIC(window, -1);
+
+    if (!_this->SetWindowInputFocus) {
+        return SDL_Unsupported();
+    }
+    
+    return _this->SetWindowInputFocus(_this, window);
+}
+
+
 int
 SDL_SetWindowGammaRamp(SDL_Window * window, const Uint16 * red,
                                             const Uint16 * green,
--- a/src/video/x11/SDL_x11video.c	Tue Jan 05 02:46:10 2016 -0500
+++ b/src/video/x11/SDL_x11video.c	Tue Jan 05 02:28:56 2016 -0500
@@ -234,6 +234,7 @@
     device->SetWindowMaximumSize = X11_SetWindowMaximumSize;
     device->GetWindowBordersSize = X11_GetWindowBordersSize;
     device->SetWindowOpacity = X11_SetWindowOpacity;
+    device->SetWindowInputFocus = X11_SetWindowInputFocus;
     device->ShowWindow = X11_ShowWindow;
     device->HideWindow = X11_HideWindow;
     device->RaiseWindow = X11_RaiseWindow;
--- a/src/video/x11/SDL_x11window.c	Tue Jan 05 02:46:10 2016 -0500
+++ b/src/video/x11/SDL_x11window.c	Tue Jan 05 02:28:56 2016 -0500
@@ -942,6 +942,19 @@
     return 0;
 }
 
+int
+X11_SetWindowInputFocus(_THIS, SDL_Window * window) 
+{
+    if (X11_IsWindowMapped(_this, window)) {
+        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+        Display *display = data->videodata->display;
+        X11_XSetInputFocus(display, data->xwindow, RevertToNone, CurrentTime);
+        X11_XFlush(display);
+        return 0;
+    }
+    return -1;
+}
+
 void
 X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
 {
--- a/src/video/x11/SDL_x11window.h	Tue Jan 05 02:46:10 2016 -0500
+++ b/src/video/x11/SDL_x11window.h	Tue Jan 05 02:28:56 2016 -0500
@@ -81,6 +81,7 @@
 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 int X11_SetWindowOpacity(_THIS, SDL_Window * window, float opacity);
+extern int X11_SetWindowInputFocus(_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);