From 210c135f744b757872eb0811988b53dca8e46462 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 18 Jun 2023 12:19:38 -0700 Subject: [PATCH] Implement SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED for X11 To match the focus stealing prevention logic from windows/osx. I didn't implement SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN as there is no standard mechanism for us to do so. In most cases marking a window as OverrideRedirect will cause to not acquire focus when mapped. And in steam we are doing that when appropriate. I still left a note in X11_ShowWindow() regarding this behaviour. --- src/video/x11/SDL_x11window.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index d15e206608..211096c7c1 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -1303,6 +1303,7 @@ void X11_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window) { SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; + SDL_bool bActivate = SDL_GetHintBoolean(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, SDL_TRUE); XEvent event; if (window->parent) { @@ -1310,6 +1311,10 @@ void X11_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window) X11_UpdateWindowPosition(window); } + /* Whether XMapRaised focuses the window is based on the window type and it is + * wm specific. There isn't much we can do here */ + (void)bActivate; + if (!X11_IsWindowMapped(_this, window)) { X11_XMapRaised(display, data->xwindow); /* Blocking wait for "MapNotify" event. @@ -1408,9 +1413,12 @@ void X11_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window) { SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; + SDL_bool bActivate = SDL_GetHintBoolean(SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED, SDL_TRUE); X11_XRaiseWindow(display, data->xwindow); - X11_SetWindowActive(_this, window); + if (bActivate) { + X11_SetWindowActive(_this, window); + } X11_XFlush(display); }