From 2056c54548b1cd0f54cf114fc761b98f31595d63 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 21 Oct 2025 14:10:49 -0400
Subject: [PATCH] kmsdrm: Allow windows to be marked as "unfocusable".
In this case, it means a newly-created window on a specific display won't
get mouse/keyboard input (which, presumably, will continue to go to a window
on a different physical display instead).
This also makes SDL_SetWindowFocusable() functional on the kmsdrm backend, to
change this flag later, but to be clear, there are no window focus events to
jump between displays in this backend, so this is only useful to manually
tweak things later.
Fixes #14289.
---
src/video/kmsdrm/SDL_kmsdrmvideo.c | 15 +++++++++++----
src/video/kmsdrm/SDL_kmsdrmvideo.h | 1 +
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index 29c3cf5ce9013..0ca82426e7cf0 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -685,6 +685,7 @@ static SDL_VideoDevice *KMSDRM_CreateDevice(void)
device->MinimizeWindow = KMSDRM_MinimizeWindow;
device->RestoreWindow = KMSDRM_RestoreWindow;
device->DestroyWindow = KMSDRM_DestroyWindow;
+ device->SetWindowFocusable = KMSDRM_SetWindowFocusable;
device->GL_LoadLibrary = KMSDRM_GLES_LoadLibrary;
device->GL_GetProcAddress = KMSDRM_GLES_GetProcAddress;
@@ -2197,10 +2198,12 @@ bool KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_KMSDRM_DRM_FD_NUMBER, viddata->drm_fd);
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_KMSDRM_GBM_DEVICE_POINTER, viddata->gbm_dev);
- /* Focus on the newly created window.
- SDL_SetMouseFocus() also takes care of calling KMSDRM_ShowCursor() if necessary. */
- SDL_SetMouseFocus(window);
- SDL_SetKeyboardFocus(window);
+ if ((window->flags & SDL_WINDOW_NOT_FOCUSABLE) == 0) {
+ /* Focus on the newly created window.
+ SDL_SetMouseFocus() also takes care of calling KMSDRM_ShowCursor() if necessary. */
+ SDL_SetMouseFocus(window);
+ SDL_SetKeyboardFocus(window);
+ }
// Tell the app that the window has moved to top-left.
SDL_Rect display_bounds;
@@ -2253,5 +2256,9 @@ void KMSDRM_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window)
void KMSDRM_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
}
+bool KMSDRM_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable)
+{
+ return true; // this just has to exist or SDL_SetWindowFocusable() will refuse to change the window flag.
+}
#endif // SDL_VIDEO_DRIVER_KMSDRM
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h
index 7c920c137c68c..86609e98fd53b 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.h
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h
@@ -237,5 +237,6 @@ extern void KMSDRM_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void KMSDRM_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void KMSDRM_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void KMSDRM_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
+extern bool KMSDRM_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable);
#endif // SDL_kmsdrmvideo_h