SDL: Clear the undefined position state when the window is placed

From 2897de9efc926b34d3fd96a58f9a94580ffdb421 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 24 Feb 2023 18:04:54 -0800
Subject: [PATCH] Clear the undefined position state when the window is placed

This allows the window to be recreated in the same location if needed, for example if recreated because of switching to OpenGL rendering.
---
 src/events/SDL_windowevents.c         | 6 ++----
 src/video/windows/SDL_windowswindow.c | 8 --------
 src/video/x11/SDL_x11window.c         | 6 ------
 3 files changed, 2 insertions(+), 18 deletions(-)

diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c
index befe1ff9713c..8addc8d0ff72 100644
--- a/src/events/SDL_windowevents.c
+++ b/src/events/SDL_windowevents.c
@@ -63,10 +63,8 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
         window->flags |= SDL_WINDOW_HIDDEN;
         break;
     case SDL_EVENT_WINDOW_MOVED:
-        if (SDL_WINDOWPOS_ISUNDEFINED(data1) ||
-            SDL_WINDOWPOS_ISUNDEFINED(data2)) {
-            return 0;
-        }
+        window->undefined_x = SDL_FALSE;
+        window->undefined_y = SDL_FALSE;
         if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
             window->windowed.x = data1;
             window->windowed.y = data2;
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index 0433f426499e..ba482e47c9b6 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -490,7 +490,6 @@ int WIN_CreateWindow(_THIS, SDL_Window *window)
     DWORD style = STYLE_BASIC;
     int x, y;
     int w, h;
-    SDL_bool undefined_position = SDL_FALSE;
 
     if (window->flags & SDL_WINDOW_SKIP_TASKBAR) {
         parent = CreateWindow(SDL_Appname, TEXT(""), STYLE_BASIC, 0, 0, 32, 32, NULL, NULL, SDL_Instance, NULL);
@@ -503,7 +502,6 @@ int WIN_CreateWindow(_THIS, SDL_Window *window)
 
     if (window->undefined_x && window->undefined_y &&
         window->last_displayID == SDL_GetPrimaryDisplay()) {
-        undefined_position = SDL_TRUE;
         x = CW_USEDEFAULT;
         y = CW_USEDEFAULT; /* Not actually used */
     }
@@ -523,12 +521,6 @@ int WIN_CreateWindow(_THIS, SDL_Window *window)
         return -1;
     }
 
-    if (undefined_position) {
-        /* Record where the window ended up */
-        window->windowed.x = window->x;
-        window->windowed.y = window->y;
-    }
-
     /* Inform Windows of the frame change so we can respond to WM_NCCALCSIZE */
     SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
 
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index 33a8cc4129b9..1f2d0d773d6a 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -644,12 +644,6 @@ int X11_CreateWindow(_THIS, SDL_Window *window)
     }
     windowdata = window->driverdata;
 
-    if (undefined_position) {
-        /* Record where the window ended up */
-        window->windowed.x = window->x;
-        window->windowed.y = window->y;
-    }
-
 #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 || SDL_VIDEO_OPENGL_EGL
     if ((window->flags & SDL_WINDOW_OPENGL) &&
         ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) ||