Browse Source

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.
Ryan C. Gordon 1 month ago
parent
commit
2056c54548
2 changed files with 12 additions and 4 deletions
  1. 11 4
      src/video/kmsdrm/SDL_kmsdrmvideo.c
  2. 1 0
      src/video/kmsdrm/SDL_kmsdrmvideo.h

+ 11 - 4
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

+ 1 - 0
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