From 0ff5d55a0773fc55dd6d9b052a0ba1b068383077 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 23 Nov 2020 21:07:28 -0500 Subject: [PATCH] x11: Don't try to grab the pointer on an unmapped window (thanks, Lee!) Fixes Bugzilla #5352. --- src/video/x11/SDL_x11events.c | 8 ++++++-- src/video/x11/SDL_x11window.c | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index c560b547b..12030fb69 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -433,8 +433,12 @@ X11_DispatchFocusOut(_THIS, SDL_WindowData *data) static void X11_DispatchMapNotify(SDL_WindowData *data) { - SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESTORED, 0, 0); - SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); + SDL_Window *window = data->window; + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0); + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0); + if (!(window->flags & SDL_WINDOW_HIDDEN) && (window->flags & SDL_WINDOW_INPUT_FOCUS)) { + SDL_UpdateWindowGrab(window); + } } static void diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 9a00000ec..b9a59ff8a 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -1576,6 +1576,13 @@ X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed) oldstyle_fullscreen = X11_IsWindowLegacyFullscreen(_this, window); if (oldstyle_fullscreen || grabbed) { + /* If the window is unmapped, XGrab calls return GrabNotViewable, + so when we get a MapNotify later, we'll try to update the grab as + appropriate. */ + if (window->flags & SDL_WINDOW_HIDDEN) { + return; + } + /* Try to grab the mouse */ if (!data->videodata->broken_pointer_grab) { const unsigned int mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask;