SDL: x11: Try to keep SDL_WINDOW_FULLSCREEN* in sync with window manager.

From 0249df9d960f9bc28b476e1171c5501fc37cca12 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 5 Apr 2022 23:04:19 -0400
Subject: [PATCH] x11: Try to keep SDL_WINDOW_FULLSCREEN* in sync with window
 manager.

So if Gnome/KDE/etc have a keyboard shortcut or titlebar decoration to
make any window go fullscreen (with the _NET_WM_FULLSCREEN flag on the
_NET_WM_STATE property), we update the SDL window flag.

Fixes #5390.
---
 src/video/x11/SDL_x11events.c | 7 +++++++
 src/video/x11/SDL_x11window.c | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index 31e739c7047..c96b90055f8 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -1434,6 +1434,13 @@ X11_DispatchEvent(_THIS, XEvent *xevent)
                     }
                 }
 
+                if (changed & SDL_WINDOW_FULLSCREEN_DESKTOP) {
+                    /* FULLSCREEN_DESKTOP encompasses two bits: SDL_WINDOW_FULLSCREEN, plus a bit to note it's FULLSCREEN_DESKTOP */
+                    const Uint32 fsmasked = flags & SDL_WINDOW_FULLSCREEN_DESKTOP;
+                    data->window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
+                    data->window->flags |= fsmasked;
+                }
+
                 if (changed & SDL_WINDOW_MAXIMIZED) {
                     if (flags & SDL_WINDOW_MAXIMIZED) {
                         SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index 5574c6eb2d3..d56d9283ebe 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -222,7 +222,7 @@ X11_GetNetWMState(_THIS, Window xwindow)
         }
 
         if (fullscreen == 1) {
-            flags |= SDL_WINDOW_FULLSCREEN;
+            flags |= SDL_WINDOW_FULLSCREEN;  /* !!! FIXME: arguably this is more like FULLSCREEN_DESKTOP...? */
         }
 
         /* If the window is unmapped, numItems will be zero and _NET_WM_STATE_HIDDEN