SDL: Renamed SDL_WINDOW_FOREIGN to SDL_WINDOW_EXTERNAL

From e0c45c6c98bc74b49a01ed7320eed284ca0ec085 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 13 Nov 2023 12:21:23 -0800
Subject: [PATCH] Renamed SDL_WINDOW_FOREIGN to SDL_WINDOW_EXTERNAL

---
 docs/README-migration.md              |  4 ++--
 include/SDL3/SDL_video.h              | 12 ++++++------
 src/test/SDL_test_common.c            |  6 +++---
 src/video/SDL_video.c                 | 20 ++++++++++----------
 src/video/cocoa/SDL_cocoavulkan.m     |  2 +-
 src/video/cocoa/SDL_cocoawindow.m     | 10 +++++-----
 src/video/windows/SDL_windowswindow.c | 14 +++++++-------
 src/video/x11/SDL_x11window.c         | 13 +++++++------
 test/testautomation_video.c           |  2 +-
 test/testnative.c                     |  2 +-
 10 files changed, 43 insertions(+), 42 deletions(-)

diff --git a/docs/README-migration.md b/docs/README-migration.md
index eeda40d173bb..a93074cd67c6 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -562,7 +562,7 @@ The following hints have been removed:
 * SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL - replaced with the "opengl" property in SDL_CreateWindowWithProperties()
 * SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN - replaced with the "vulkan" property in SDL_CreateWindowWithProperties()
 * SDL_HINT_VIDEO_HIGHDPI_DISABLED - high DPI support is always enabled
-* SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT - replaced with the "native.win32.pixel_format_hwnd" in SDL_CreateWindowWithProperties()
+* SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT - replaced with the "win32.pixel_format_hwnd" in SDL_CreateWindowWithProperties()
 * SDL_HINT_VIDEO_X11_FORCE_EGL - use SDL_HINT_VIDEO_FORCE_EGL instead
 * SDL_HINT_VIDEO_X11_XINERAMA - Xinerama no longer supported by the X11 backend
 * SDL_HINT_VIDEO_X11_XVIDMODE - Xvidmode no longer supported by the X11 backend
@@ -1330,7 +1330,7 @@ The following functions have been removed:
 * SDL_GetNumVideoDisplays() - replaced with SDL_GetDisplays()
 * SDL_GetWindowData() - use SDL_GetWindowProperties() instead
 * SDL_SetWindowData() - use SDL_GetWindowProperties() instead
-* SDL_CreateWindowFrom() - use SDL_CreateWindowWithProperties() with "native.*" properties instead
+* SDL_CreateWindowFrom() - use SDL_CreateWindowWithProperties() with the properties that allow you to wrap an existing window
 
 SDL_Window id type is named SDL_WindowID
 
diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h
index 3a80cf9633d2..b0cb063b8187 100644
--- a/include/SDL3/SDL_video.h
+++ b/include/SDL3/SDL_video.h
@@ -138,7 +138,7 @@ typedef enum
     SDL_WINDOW_MOUSE_GRABBED        = 0x00000100,   /**< window has grabbed mouse input */
     SDL_WINDOW_INPUT_FOCUS          = 0x00000200,   /**< window has input focus */
     SDL_WINDOW_MOUSE_FOCUS          = 0x00000400,   /**< window has mouse focus */
-    SDL_WINDOW_FOREIGN              = 0x00000800,   /**< window not created by SDL */
+    SDL_WINDOW_EXTERNAL             = 0x00000800,   /**< window not created by SDL */
     SDL_WINDOW_HIGH_PIXEL_DENSITY   = 0x00002000,   /**< window uses high pixel density back buffer if possible */
     SDL_WINDOW_MOUSE_CAPTURE        = 0x00004000,   /**< window has mouse captured (unrelated to MOUSE_GRABBED) */
     SDL_WINDOW_ALWAYS_ON_TOP        = 0x00008000,   /**< window should always be above others */
@@ -827,17 +827,17 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_CreatePopupWindow(SDL_Window *parent, in
  *
  * On macOS:
  *
- * - "native.cocoa.window" (pointer) - the (__unsafe_unretained) NSWindow associated with the window, if you want to wrap an existing window.
- * - "native.cocoa.view" (pointer) - the (__unsafe_unretained) NSView associated with the window, defaults to [window contentView]
+ * - "cocoa.window" (pointer) - the (__unsafe_unretained) NSWindow associated with the window, if you want to wrap an existing window.
+ * - "cocoa.view" (pointer) - the (__unsafe_unretained) NSView associated with the window, defaults to [window contentView]
  *
  * On Windows:
  *
- * - "native.win32.hwnd" (pointer) - the HWND associated with the window, if you want to wrap an existing window.
- * - "native.win32.pixel_format_hwnd" (pointer) - optional, another window to share pixel format with, useful for OpenGL windows
+ * - "win32.hwnd" (pointer) - the HWND associated with the window, if you want to wrap an existing window.
+ * - "win32.pixel_format_hwnd" (pointer) - optional, another window to share pixel format with, useful for OpenGL windows
  *
  * On X11:
  *
- * - "native.x11.window" (number) - the X11 Window associated with the window, if you want to wrap an existing window.
+ * - "x11.window" (number) - the X11 Window associated with the window, if you want to wrap an existing window.
  *
  * The SDL_Window is implicitly shown if the "hidden" property is not set.
  *
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index aa5639495510..12b7fee5e3b0 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -783,8 +783,8 @@ static void SDLTest_PrintWindowFlag(char *text, size_t maxlen, Uint32 flag)
     case SDL_WINDOW_MOUSE_FOCUS:
         SDL_snprintfcat(text, maxlen, "MOUSE_FOCUS");
         break;
-    case SDL_WINDOW_FOREIGN:
-        SDL_snprintfcat(text, maxlen, "FOREIGN");
+    case SDL_WINDOW_EXTERNAL:
+        SDL_snprintfcat(text, maxlen, "EXTERNAL");
         break;
     case SDL_WINDOW_HIGH_PIXEL_DENSITY:
         SDL_snprintfcat(text, maxlen, "HIGH_PIXEL_DENSITY");
@@ -835,7 +835,7 @@ static void SDLTest_PrintWindowFlags(char *text, size_t maxlen, Uint32 flags)
         SDL_WINDOW_MOUSE_GRABBED,
         SDL_WINDOW_INPUT_FOCUS,
         SDL_WINDOW_MOUSE_FOCUS,
-        SDL_WINDOW_FOREIGN,
+        SDL_WINDOW_EXTERNAL,
         SDL_WINDOW_HIGH_PIXEL_DENSITY,
         SDL_WINDOW_MOUSE_CAPTURE,
         SDL_WINDOW_ALWAYS_ON_TOP,
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 1e325794a369..ee6972193980 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -2170,15 +2170,15 @@ int SDL_RecreateWindow(SDL_Window *window, Uint32 flags)
         return SDL_ContextNotSupported("Metal");
     }
 
-    if (window->flags & SDL_WINDOW_FOREIGN) {
-        /* Can't destroy and re-create foreign windows, hrm */
-        flags |= SDL_WINDOW_FOREIGN;
+    if (window->flags & SDL_WINDOW_EXTERNAL) {
+        /* Can't destroy and re-create external windows, hrm */
+        flags |= SDL_WINDOW_EXTERNAL;
     } else {
-        flags &= ~SDL_WINDOW_FOREIGN;
+        flags &= ~SDL_WINDOW_EXTERNAL;
     }
 
     /* Restore video mode, etc. */
-    if (!(window->flags & SDL_WINDOW_FOREIGN)) {
+    if (!(window->flags & SDL_WINDOW_EXTERNAL)) {
         const SDL_bool restore_on_show = window->restore_on_show;
         SDL_HideWindow(window);
         window->restore_on_show = restore_on_show;
@@ -2223,7 +2223,7 @@ int SDL_RecreateWindow(SDL_Window *window, Uint32 flags)
         SDL_Vulkan_UnloadLibrary();
     }
 
-    if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) {
+    if (_this->DestroyWindow && !(flags & SDL_WINDOW_EXTERNAL)) {
         _this->DestroyWindow(_this, window);
     }
 
@@ -2244,7 +2244,7 @@ int SDL_RecreateWindow(SDL_Window *window, Uint32 flags)
     window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
     window->is_destroying = SDL_FALSE;
 
-    if (_this->CreateSDLWindow && !(flags & SDL_WINDOW_FOREIGN)) {
+    if (_this->CreateSDLWindow && !(flags & SDL_WINDOW_EXTERNAL)) {
         if (_this->CreateSDLWindow(_this, window, 0) < 0) {
             if (loaded_opengl) {
                 SDL_GL_UnloadLibrary();
@@ -2258,8 +2258,8 @@ int SDL_RecreateWindow(SDL_Window *window, Uint32 flags)
         }
     }
 
-    if (flags & SDL_WINDOW_FOREIGN) {
-        window->flags |= SDL_WINDOW_FOREIGN;
+    if (flags & SDL_WINDOW_EXTERNAL) {
+        window->flags |= SDL_WINDOW_EXTERNAL;
     }
 
     if (_this->SetWindowTitle && window->title) {
@@ -3556,7 +3556,7 @@ void SDL_DestroyWindow(SDL_Window *window)
 
     /* Restore video mode, etc. */
     SDL_UpdateFullscreenMode(window, SDL_FALSE);
-    if (!(window->flags & SDL_WINDOW_FOREIGN)) {
+    if (!(window->flags & SDL_WINDOW_EXTERNAL)) {
         SDL_HideWindow(window);
     }
 
diff --git a/src/video/cocoa/SDL_cocoavulkan.m b/src/video/cocoa/SDL_cocoavulkan.m
index a018db5a8280..3586e8f64bd0 100644
--- a/src/video/cocoa/SDL_cocoavulkan.m
+++ b/src/video/cocoa/SDL_cocoavulkan.m
@@ -256,7 +256,7 @@ SDL_bool Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
         return SDL_FALSE;
     }
 
-    if (window->flags & SDL_WINDOW_FOREIGN) {
+    if (window->flags & SDL_WINDOW_EXTERNAL) {
         @autoreleasepool {
             SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
             if (![data.sdlContentView.layer isKindOfClass:[CAMetalLayer class]]) {
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 64b541b21ef5..b4c0bf7d2a89 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -1861,7 +1861,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow
          */
         [nswindow setOneShot:NO];
 
-        if (window->flags & SDL_WINDOW_FOREIGN) {
+        if (window->flags & SDL_WINDOW_EXTERNAL) {
             /* Query the title from the existing window */
             NSString *title = [nswindow title];
             if (title) {
@@ -1883,7 +1883,7 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie
 {
     @autoreleasepool {
         SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->driverdata;
-        const void *data = SDL_GetProperty(create_props, "native.data", NULL);
+        const void *data = SDL_GetProperty(create_props, "sdl2-compat.external_window", NULL);
         NSWindow *nswindow = nil;
         NSView *nsview = nil;
 
@@ -1896,8 +1896,8 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie
                 SDL_assert(false);
             }
         } else {
-            nswindow = (__bridge NSWindow *)SDL_GetProperty(create_props, "native.cocoa.window", NULL);
-            nsview = (__bridge NSView *)SDL_GetProperty(create_props, "native.cocoa.view", NULL);
+            nswindow = (__bridge NSWindow *)SDL_GetProperty(create_props, "cocoa.window", NULL);
+            nsview = (__bridge NSView *)SDL_GetProperty(create_props, "cocoa.view", NULL);
         }
         if (nswindow && !nsview) {
             nsview = [nswindow contentView];
@@ -1906,7 +1906,7 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie
             nswindow = [nsview window];
         }
         if (nswindow) {
-            window->flags |= SDL_WINDOW_FOREIGN;
+            window->flags |= SDL_WINDOW_EXTERNAL;
         } else {
             int x, y;
             NSScreen *screen;
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index 8a3b6cc2d0cf..2665a21ae91a 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -347,7 +347,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd
             int w = rect.right;
             int h = rect.bottom;
 
-            if (window->flags & SDL_WINDOW_FOREIGN) {
+            if (window->flags & SDL_WINDOW_EXTERNAL) {
                 window->windowed.w = window->w = w;
                 window->windowed.h = window->h = h;
             } else if ((window->windowed.w && window->windowed.w != w) || (window->windowed.h && window->windowed.h != h)) {
@@ -370,7 +370,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd
         point.x = 0;
         point.y = 0;
         if (ClientToScreen(hwnd, &point)) {
-            if (window->flags & SDL_WINDOW_FOREIGN) {
+            if (window->flags & SDL_WINDOW_EXTERNAL) {
                 window->windowed.x = point.x;
                 window->windowed.y = point.y;
             }
@@ -443,7 +443,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd
 
     data->initializing = SDL_FALSE;
 
-    if (window->flags & SDL_WINDOW_FOREIGN) {
+    if (window->flags & SDL_WINDOW_EXTERNAL) {
         /* Query the title from the existing window */
         LPTSTR title;
         int titleLen;
@@ -490,7 +490,7 @@ static void CleanupWindowData(SDL_VideoDevice *_this, SDL_Window *window)
         ReleaseDC(data->hwnd, data->hdc);
         RemoveProp(data->hwnd, TEXT("SDL_WindowData"));
 #endif
-        if (!(window->flags & SDL_WINDOW_FOREIGN)) {
+        if (!(window->flags & SDL_WINDOW_EXTERNAL)) {
             DestroyWindow(data->hwnd);
             if (data->destroy_parent_with_window && data->parent) {
                 DestroyWindow(data->parent);
@@ -566,10 +566,10 @@ static void WIN_SetKeyboardFocus(SDL_Window *window)
 
 int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
 {
-    HWND hwnd = (HWND)SDL_GetProperty(create_props, "native.win32.hwnd", SDL_GetProperty(create_props, "native.data", NULL));
+    HWND hwnd = (HWND)SDL_GetProperty(create_props, "win32.hwnd", SDL_GetProperty(create_props, "sdl2-compat.external_window", NULL));
     HWND parent = NULL;
     if (hwnd) {
-        window->flags |= SDL_WINDOW_FOREIGN;
+        window->flags |= SDL_WINDOW_EXTERNAL;
 
         if (SetupWindowData(_this, window, hwnd, parent) < 0) {
             return -1;
@@ -643,7 +643,7 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI
         }
     }
 
-    HWND share_hwnd = (HWND)SDL_GetProperty(create_props, "native.win32.pixel_format_hwnd", NULL);
+    HWND share_hwnd = (HWND)SDL_GetProperty(create_props, "win32.pixel_format_hwnd", NULL);
     if (share_hwnd) {
         HDC hdc = GetDC(share_hwnd);
         int pixel_format = GetPixelFormat(hdc);
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index 99238f105cfa..373590ec2cf7 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -379,7 +379,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w)
         }
     }
 
-    if (window->flags & SDL_WINDOW_FOREIGN) {
+    if (window->flags & SDL_WINDOW_EXTERNAL) {
         /* Query the title from the existing window */
         window->title = X11_GetWindowTitle(_this, w);
     }
@@ -427,9 +427,10 @@ static void SetWindowBordered(Display *display, int screen, Window window, SDL_b
 
 int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
 {
-    Window w = (Window)SDL_GetNumberProperty(create_props, "native.x11.window", (Window)SDL_GetProperty(create_props, "native.data", NULL));
+    Window w = (Window)SDL_GetNumberProperty(create_props, "x11.window",
+                (Window)SDL_GetProperty(create_props, "sdl2-compat.external_window", NULL));
     if (w) {
-        window->flags |= SDL_WINDOW_FOREIGN;
+        window->flags |= SDL_WINDOW_EXTERNAL;
 
         if (SetupWindowData(_this, window, w) < 0) {
             return -1;
@@ -1335,7 +1336,7 @@ void X11_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
         /* Blocking wait for "MapNotify" event.
          * We use X11_XIfEvent because pXWindowEvent takes a mask rather than a type,
          * and XCheckTypedWindowEvent doesn't block */
-        if (!(window->flags & SDL_WINDOW_FOREIGN)) {
+        if (!(window->flags & SDL_WINDOW_EXTERNAL)) {
             X11_XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
         }
         X11_XFlush(display);
@@ -1371,7 +1372,7 @@ void X11_HideWindow(SDL_VideoDevice *_this, SDL_Window *window)
     if (X11_IsWindowMapped(_this, window)) {
         X11_XWithdrawWindow(display, data->xwindow, displaydata->screen);
         /* Blocking wait for "UnmapNotify" event */
-        if (!(window->flags & SDL_WINDOW_FOREIGN)) {
+        if (!(window->flags & SDL_WINDOW_EXTERNAL)) {
             X11_XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
         }
         X11_XFlush(display);
@@ -1845,7 +1846,7 @@ void X11_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
             X11_XDestroyIC(data->ic);
         }
 #endif
-        if (!(window->flags & SDL_WINDOW_FOREIGN)) {
+        if (!(window->flags & SDL_WINDOW_EXTERNAL)) {
             X11_XDestroyWindow(display, data->xwindow);
             X11_XFlush(display);
         }
diff --git a/test/testautomation_video.c b/test/testautomation_video.c
index e7c3de32be93..50b88cdceed8 100644
--- a/test/testautomation_video.c
+++ b/test/testautomation_video.c
@@ -233,7 +233,7 @@ static int video_createWindowVariousFlags(void *arg)
             flags = SDL_WINDOW_MOUSE_FOCUS;
             break;
         case 12:
-            flags = SDL_WINDOW_FOREIGN;
+            flags = SDL_WINDOW_EXTERNAL;
             break;
         case 13:
             flags = SDL_WINDOW_KEYBOARD_GRABBED;
diff --git a/test/testnative.c b/test/testnative.c
index ab306ee1a199..e18195301f07 100644
--- a/test/testnative.c
+++ b/test/testnative.c
@@ -148,7 +148,7 @@ int main(int argc, char *argv[])
         quit(3);
     }
     props = SDL_CreateProperties();
-    SDL_SetProperty(props, "native.data", native_window);
+    SDL_SetProperty(props, "sdl2-compat.external_window", native_window);
     window = SDL_CreateWindowWithProperties(props);
     SDL_DestroyProperties(props);
     if (!window) {