SDL: Remove SDL_SetWindowInputFocus

From be13328cb16bb64e0fbd8ec1711bbf7f5a3b8d20 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Wed, 3 Jul 2024 11:15:30 -0400
Subject: [PATCH] Remove SDL_SetWindowInputFocus

This was added to SDL2 for the Unreal Engine's implementation of menus and dialogs on X11, window types for which SDL3 has added built-in, cross-platform support.

Remove this function, as it was only ever implemented for X11 and is now basically useless aside from allowing annoying or malicious client apps to discretely steal focus. As the documentation states: "You almost certainly want SDL_RaiseWindow() instead of this function."
---
 docs/README-migration.md          |  1 +
 include/SDL3/SDL_video.h          | 17 -----------------
 src/dynapi/SDL_dynapi.sym         |  1 -
 src/dynapi/SDL_dynapi_overrides.h |  1 -
 src/dynapi/SDL_dynapi_procs.h     |  1 -
 src/video/SDL_sysvideo.h          |  1 -
 src/video/SDL_video.c             | 12 ------------
 src/video/x11/SDL_x11video.c      |  1 -
 src/video/x11/SDL_x11window.c     | 12 ------------
 src/video/x11/SDL_x11window.h     |  1 -
 10 files changed, 1 insertion(+), 47 deletions(-)

diff --git a/docs/README-migration.md b/docs/README-migration.md
index 236af3de9f5c7..82f6cdc4f7091 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -1983,6 +1983,7 @@ The following functions have been removed:
 * SDL_GetWindowData() - use SDL_GetWindowProperties() instead
 * SDL_SetWindowData() - use SDL_GetWindowProperties() instead
 * SDL_CreateWindowFrom() - use SDL_CreateWindowWithProperties() with the properties that allow you to wrap an existing window
+* SDL_SetWindowInputFocus() - use SDL_RaiseWindow() instead
 
 The SDL_Window id type is named SDL_WindowID
 
diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h
index a64ff6431c40e..cdb911f71e78d 100644
--- a/include/SDL3/SDL_video.h
+++ b/include/SDL3/SDL_video.h
@@ -2177,23 +2177,6 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowOpacity(SDL_Window *window, float *
  */
 extern SDL_DECLSPEC int SDLCALL SDL_SetWindowModalFor(SDL_Window *modal_window, SDL_Window *parent_window);
 
-/**
- * Explicitly set 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 is completely
- * obscured by other windows.
- *
- * \param window the window that should get the input focus.
- * \returns 0 on success or a negative error code on failure; call
- *          SDL_GetError() for more information.
- *
- * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_RaiseWindow
- */
-extern SDL_DECLSPEC int SDLCALL SDL_SetWindowInputFocus(SDL_Window *window);
-
 /**
  * Set whether the window may have input focus.
  *
diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym
index b54b9fd052694..40d7177a8ae7a 100644
--- a/src/dynapi/SDL_dynapi.sym
+++ b/src/dynapi/SDL_dynapi.sym
@@ -762,7 +762,6 @@ SDL3_0.0.0 {
     SDL_SetWindowFullscreenMode;
     SDL_SetWindowHitTest;
     SDL_SetWindowIcon;
-    SDL_SetWindowInputFocus;
     SDL_SetWindowKeyboardGrab;
     SDL_SetWindowMaximumSize;
     SDL_SetWindowMinimumSize;
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index b8c98467b2d63..76f69d781b6ff 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -787,7 +787,6 @@
 #define SDL_SetWindowFullscreenMode SDL_SetWindowFullscreenMode_REAL
 #define SDL_SetWindowHitTest SDL_SetWindowHitTest_REAL
 #define SDL_SetWindowIcon SDL_SetWindowIcon_REAL
-#define SDL_SetWindowInputFocus SDL_SetWindowInputFocus_REAL
 #define SDL_SetWindowKeyboardGrab SDL_SetWindowKeyboardGrab_REAL
 #define SDL_SetWindowMaximumSize SDL_SetWindowMaximumSize_REAL
 #define SDL_SetWindowMinimumSize SDL_SetWindowMinimumSize_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 740da8cf6aba3..50613fd993636 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -797,7 +797,6 @@ SDL_DYNAPI_PROC(int,SDL_SetWindowFullscreen,(SDL_Window *a, SDL_bool b),(a,b),re
 SDL_DYNAPI_PROC(int,SDL_SetWindowFullscreenMode,(SDL_Window *a, const SDL_DisplayMode *b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_SetWindowHitTest,(SDL_Window *a, SDL_HitTest b, void *c),(a,b,c),return)
 SDL_DYNAPI_PROC(int,SDL_SetWindowIcon,(SDL_Window *a, SDL_Surface *b),(a,b),return)
-SDL_DYNAPI_PROC(int,SDL_SetWindowInputFocus,(SDL_Window *a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_SetWindowKeyboardGrab,(SDL_Window *a, SDL_bool b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_SetWindowMaximumSize,(SDL_Window *a, int b, int c),(a,b,c),return)
 SDL_DYNAPI_PROC(int,SDL_SetWindowMinimumSize,(SDL_Window *a, int b, int c),(a,b,c),return)
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 5437a838aab72..0a5e7b56b7a1b 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -252,7 +252,6 @@ struct SDL_VideoDevice
     void (*GetWindowSizeInPixels)(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h);
     int (*SetWindowOpacity)(SDL_VideoDevice *_this, SDL_Window *window, float opacity);
     int (*SetWindowModalFor)(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window);
-    int (*SetWindowInputFocus)(SDL_VideoDevice *_this, SDL_Window *window);
     void (*ShowWindow)(SDL_VideoDevice *_this, SDL_Window *window);
     void (*HideWindow)(SDL_VideoDevice *_this, SDL_Window *window);
     void (*RaiseWindow)(SDL_VideoDevice *_this, SDL_Window *window);
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 5b67b6d4f86a4..9363a46ff85b4 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -3511,18 +3511,6 @@ int SDL_SetWindowModalFor(SDL_Window *modal_window, SDL_Window *parent_window)
     return ret;
 }
 
-int SDL_SetWindowInputFocus(SDL_Window *window)
-{
-    CHECK_WINDOW_MAGIC(window, -1);
-    CHECK_WINDOW_NOT_POPUP(window, -1);
-
-    if (!_this->SetWindowInputFocus) {
-        return SDL_Unsupported();
-    }
-
-    return _this->SetWindowInputFocus(_this, window);
-}
-
 int SDL_SetWindowFocusable(SDL_Window *window, SDL_bool focusable)
 {
     CHECK_WINDOW_MAGIC(window, -1);
diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c
index 4f59aaeda56bf..2f87933f15aea 100644
--- a/src/video/x11/SDL_x11video.c
+++ b/src/video/x11/SDL_x11video.c
@@ -198,7 +198,6 @@ static SDL_VideoDevice *X11_CreateDevice(void)
     device->GetWindowBordersSize = X11_GetWindowBordersSize;
     device->SetWindowOpacity = X11_SetWindowOpacity;
     device->SetWindowModalFor = X11_SetWindowModalFor;
-    device->SetWindowInputFocus = X11_SetWindowInputFocus;
     device->ShowWindow = X11_ShowWindow;
     device->HideWindow = X11_HideWindow;
     device->RaiseWindow = X11_RaiseWindow;
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index 60e5a32817839..85818db8d01b0 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -1267,18 +1267,6 @@ int X11_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_
     return 0;
 }
 
-int X11_SetWindowInputFocus(SDL_VideoDevice *_this, SDL_Window *window)
-{
-    if (X11_IsWindowMapped(_this, window)) {
-        SDL_WindowData *data = window->driverdata;
-        Display *display = data->videodata->display;
-        X11_XSetInputFocus(display, data->xwindow, RevertToNone, CurrentTime);
-        X11_XFlush(display);
-        return 0;
-    }
-    return -1;
-}
-
 void X11_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool bordered)
 {
     const SDL_bool focused = (window->flags & SDL_WINDOW_INPUT_FOCUS) ? SDL_TRUE : SDL_FALSE;
diff --git a/src/video/x11/SDL_x11window.h b/src/video/x11/SDL_x11window.h
index 0681bf7dfbda8..5e4866766b5e2 100644
--- a/src/video/x11/SDL_x11window.h
+++ b/src/video/x11/SDL_x11window.h
@@ -119,7 +119,6 @@ extern void X11_SetWindowAspectRatio(SDL_VideoDevice *_this, SDL_Window *window)
 extern int X11_GetWindowBordersSize(SDL_VideoDevice *_this, SDL_Window *window, int *top, int *left, int *bottom, int *right);
 extern int X11_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity);
 extern int X11_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window);
-extern int X11_SetWindowInputFocus(SDL_VideoDevice *_this, SDL_Window *window);
 extern void X11_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);
 extern void X11_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window);
 extern void X11_HideWindow(SDL_VideoDevice *_this, SDL_Window *window);