Browse Source

x11: Always disable the borders when leaving fullscreen from a borderless window created as fullscreen

Borderless windows flagged as fullscreen at creation time turn on the borders, because doing so prevents some window managers from wrongly positioning the borderless window, and in these cases the borders need to be removed whether fullscreen is exited programmatically or via a compositor event. Set a flag when forcing the borders on, so they will be removed in all cases later.
Frank Praznik 10 months ago
parent
commit
85a2a201b1
3 changed files with 12 additions and 4 deletions
  1. 6 0
      src/video/x11/SDL_x11events.c
  2. 5 4
      src/video/x11/SDL_x11window.c
  3. 1 0
      src/video/x11/SDL_x11window.h

+ 6 - 0
src/video/x11/SDL_x11events.c

@@ -1723,6 +1723,12 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent)
 
                         /* Need to restore or update any limits changed while the window was fullscreen. */
                         X11_SetWindowMinMax(data->window, !!(flags & SDL_WINDOW_MAXIMIZED));
+
+                        /* Toggle the borders if they were forced on while creating a borderless fullscreen window. */
+                        if (data->fullscreen_borders_forced_on) {
+                            data->toggle_borders = SDL_TRUE;
+                            data->fullscreen_borders_forced_on = SDL_FALSE;
+                        }
                     }
 
                     if ((flags & SDL_WINDOW_FULLSCREEN) &&

+ 5 - 4
src/video/x11/SDL_x11window.c

@@ -755,6 +755,10 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI
     }
     windowdata = window->driverdata;
 
+    /* Set the flag if the borders were forced on when creating a fullscreen window for later removal. */
+    windowdata->fullscreen_borders_forced_on = !!(window->pending_flags & SDL_WINDOW_FULLSCREEN) &&
+                                               !!(window->flags & SDL_WINDOW_BORDERLESS);
+
 #if defined(SDL_VIDEO_OPENGL_ES) || defined(SDL_VIDEO_OPENGL_ES2) || defined(SDL_VIDEO_OPENGL_EGL)
     if ((window->flags & SDL_WINDOW_OPENGL) &&
         ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) ||
@@ -1320,6 +1324,7 @@ void X11_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool
     } else {
         /* If fullscreen, set a flag to toggle the borders when returning to windowed mode. */
         data->toggle_borders = SDL_TRUE;
+        data->fullscreen_borders_forced_on = SDL_FALSE;
     }
 }
 
@@ -1734,10 +1739,6 @@ static int X11_SetWindowFullscreenViaWM(SDL_VideoDevice *_this, SDL_Window *wind
         X11_SetNetWMState(_this, data->xwindow, flags);
     }
 
-    if ((window->flags & SDL_WINDOW_BORDERLESS) && !fullscreen) {
-        SetWindowBordered(display, displaydata->screen, data->xwindow, SDL_FALSE);
-    }
-
     if (data->visual->class == DirectColor) {
         if (fullscreen) {
             X11_XInstallColormap(display, data->colormap);

+ 1 - 0
src/video/x11/SDL_x11window.h

@@ -101,6 +101,7 @@ struct SDL_WindowData
     SDL_bool disable_size_position_events;
     SDL_bool previous_borders_nonzero;
     SDL_bool toggle_borders;
+    SDL_bool fullscreen_borders_forced_on;
     SDL_HitTestResult hit_test_result;
 };