SDL_CreateWindowWithPosition() and SDL_CreateWindowFrom() have been replaced with SDL_CreateWindowWithProperties()

This is a more general interface that can be extended in the future as needed.
This commit is contained in:
Sam Lantinga 2023-11-13 11:29:30 -08:00
parent 2c1fbe1967
commit 229b7b9d50
47 changed files with 470 additions and 573 deletions

View File

@ -559,10 +559,10 @@ The following hints have been removed:
* SDL_HINT_IME_SUPPORT_EXTENDED_TEXT - the normal text editing event has extended text
* SDL_HINT_MOUSE_RELATIVE_SCALING - mouse coordinates are no longer automatically scaled by the SDL renderer
* SDL_HINT_RENDER_LOGICAL_SIZE_MODE - the logical size mode is explicitly set with SDL_SetRenderLogicalPresentation()
* SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL - replaced with the "opengl" property in SDL_CreateWindowFrom()
* SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN - replaced with the "vulkan" property in SDL_CreateWindowFrom()
* 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 "win32.pixel_format_hwnd" in SDL_CreateWindowFrom()
* SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT - replaced with the "native.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
@ -1261,9 +1261,7 @@ Rather than iterating over displays using display index, there is a new function
}
```
SDL_CreateWindow() has been simplified and no longer takes a window position. You can use SDL_CreateWindowWithPosition() if you need to set the window position when creating it.
SDL_CreateWindowFrom() now takes a set of properties that describe the native window and options.
SDL_CreateWindow() has been simplified and no longer takes a window position. You can use SDL_CreateWindowWithProperties() if you need to set the window position when creating it.
The SDL_WINDOWPOS_UNDEFINED_DISPLAY() and SDL_WINDOWPOS_CENTERED_DISPLAY() macros take a display ID instead of display index. The display ID 0 has a special meaning in this case, and is used to indicate the primary display.
@ -1332,6 +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_Window id type is named SDL_WindowID

View File

@ -89,42 +89,41 @@ typedef enum
/**
* The type used to identify a window
*
* \sa SDL_CreateWindow()
* \sa SDL_CreateWindowFrom()
* \sa SDL_CreateWindowWithPosition()
* \sa SDL_DestroyWindow()
* \sa SDL_FlashWindow()
* \sa SDL_GetWindowFlags()
* \sa SDL_GetWindowGrab()
* \sa SDL_GetWindowKeyboardGrab()
* \sa SDL_GetWindowMouseGrab()
* \sa SDL_GetWindowPosition()
* \sa SDL_GetWindowSize()
* \sa SDL_GetWindowTitle()
* \sa SDL_HideWindow()
* \sa SDL_MaximizeWindow()
* \sa SDL_MinimizeWindow()
* \sa SDL_RaiseWindow()
* \sa SDL_RestoreWindow()
* \sa SDL_SetWindowFullscreen()
* \sa SDL_SetWindowGrab()
* \sa SDL_SetWindowKeyboardGrab()
* \sa SDL_SetWindowMouseGrab()
* \sa SDL_SetWindowIcon()
* \sa SDL_SetWindowPosition()
* \sa SDL_SetWindowSize()
* \sa SDL_SetWindowBordered()
* \sa SDL_SetWindowResizable()
* \sa SDL_SetWindowTitle()
* \sa SDL_ShowWindow()
* \sa SDL_ShowWindowSystemMenu()
* \sa SDL_CreateWindow
* \sa SDL_CreateWindowWithProperties
* \sa SDL_DestroyWindow
* \sa SDL_FlashWindow
* \sa SDL_GetWindowFlags
* \sa SDL_GetWindowGrab
* \sa SDL_GetWindowKeyboardGrab
* \sa SDL_GetWindowMouseGrab
* \sa SDL_GetWindowPosition
* \sa SDL_GetWindowSize
* \sa SDL_GetWindowTitle
* \sa SDL_HideWindow
* \sa SDL_MaximizeWindow
* \sa SDL_MinimizeWindow
* \sa SDL_RaiseWindow
* \sa SDL_RestoreWindow
* \sa SDL_SetWindowFullscreen
* \sa SDL_SetWindowGrab
* \sa SDL_SetWindowKeyboardGrab
* \sa SDL_SetWindowMouseGrab
* \sa SDL_SetWindowIcon
* \sa SDL_SetWindowPosition
* \sa SDL_SetWindowSize
* \sa SDL_SetWindowBordered
* \sa SDL_SetWindowResizable
* \sa SDL_SetWindowTitle
* \sa SDL_ShowWindow
* \sa SDL_ShowWindowSystemMenu
*/
typedef struct SDL_Window SDL_Window;
/**
* The flags on a window
*
* \sa SDL_GetWindowFlags()
* \sa SDL_GetWindowFlags
*/
typedef enum
{
@ -144,8 +143,8 @@ typedef enum
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 */
SDL_WINDOW_UTILITY = 0x00020000, /**< window should be treated as a utility window, not showing in the task bar and window list */
SDL_WINDOW_TOOLTIP = 0x00040000, /**< window should be treated as a tooltip and must be created using SDL_CreatePopupWindow() */
SDL_WINDOW_POPUP_MENU = 0x00080000, /**< window should be treated as a popup menu and must be created using SDL_CreatePopupWindow() */
SDL_WINDOW_TOOLTIP = 0x00040000, /**< window should be treated as a tooltip */
SDL_WINDOW_POPUP_MENU = 0x00080000, /**< window should be treated as a popup menu */
SDL_WINDOW_KEYBOARD_GRABBED = 0x00100000, /**< window has grabbed keyboard input */
SDL_WINDOW_VULKAN = 0x10000000, /**< window usable for Vulkan surface */
SDL_WINDOW_METAL = 0x20000000, /**< window usable for Metal view */
@ -713,11 +712,6 @@ extern DECLSPEC Uint32 SDLCALL SDL_GetWindowPixelFormat(SDL_Window *window);
* window is created and should be queried again if you get an
* SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event.
*
* If the window is set fullscreen, the width and height parameters `w` and
* `h` will not be used. However, invalid size parameters (e.g. too large) may
* still fail. Window size is actually limited to 16384 x 16384 for all
* platforms at window creation.
*
* If the window is created with any of the SDL_WINDOW_OPENGL or
* SDL_WINDOW_VULKAN flags, then the corresponding LoadLibrary function
* (SDL_GL_LoadLibrary or SDL_Vulkan_LoadLibrary) is called and the
@ -743,79 +737,11 @@ extern DECLSPEC Uint32 SDLCALL SDL_GetWindowPixelFormat(SDL_Window *window);
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_CreatePopupWindow
* \sa SDL_CreateWindowFrom
* \sa SDL_CreateWindowWithPosition
* \sa SDL_CreateWindowWithProperties
* \sa SDL_DestroyWindow
*/
extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindow(const char *title, int w, int h, Uint32 flags);
/**
* Create a window with the specified position, dimensions, and flags.
*
* `flags` may be any of the following OR'd together:
*
* - `SDL_WINDOW_FULLSCREEN`: fullscreen window at desktop resolution
* - `SDL_WINDOW_OPENGL`: window usable with an OpenGL context
* - `SDL_WINDOW_VULKAN`: window usable with a Vulkan instance
* - `SDL_WINDOW_METAL`: window usable with a Metal instance
* - `SDL_WINDOW_HIDDEN`: window is not visible
* - `SDL_WINDOW_BORDERLESS`: no window decoration
* - `SDL_WINDOW_RESIZABLE`: window can be resized
* - `SDL_WINDOW_MINIMIZED`: window is minimized
* - `SDL_WINDOW_MAXIMIZED`: window is maximized
* - `SDL_WINDOW_MOUSE_GRABBED`: window has grabbed mouse focus
*
* The SDL_Window is implicitly shown if SDL_WINDOW_HIDDEN is not set.
*
* On Apple's macOS, you **must** set the NSHighResolutionCapable Info.plist
* property to YES, otherwise you will not receive a High-DPI OpenGL canvas.
*
* The window pixel size may differ from its window coordinate size if the
* window is on a high pixel density display. Use SDL_GetWindowSize() to query
* the client area's size in window coordinates, and
* SDL_GetWindowSizeInPixels() or SDL_GetRenderOutputSize() to query the
* drawable size in pixels. Note that the drawable size can vary after the
* window is created and should be queried again if you get an
* SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event.
*
* If the window is set fullscreen, the width and height parameters `w` and
* `h` will not be used. However, invalid size parameters (e.g. too large) may
* still fail. Window size is actually limited to 16384 x 16384 for all
* platforms at window creation.
*
* If the window is created with any of the SDL_WINDOW_OPENGL or
* SDL_WINDOW_VULKAN flags, then the corresponding LoadLibrary function
* (SDL_GL_LoadLibrary or SDL_Vulkan_LoadLibrary) is called and the
* corresponding UnloadLibrary function is called by SDL_DestroyWindow().
*
* If SDL_WINDOW_VULKAN is specified and there isn't a working Vulkan driver,
* SDL_CreateWindow() will fail because SDL_Vulkan_LoadLibrary() will fail.
*
* If SDL_WINDOW_METAL is specified on an OS that does not support Metal,
* SDL_CreateWindow() will fail.
*
* On non-Apple devices, SDL requires you to either not link to the Vulkan
* loader or link to a dynamic library version. This limitation may be removed
* in a future version of SDL.
*
* \param title the title of the window, in UTF-8 encoding
* \param x the x position of the window, or `SDL_WINDOWPOS_CENTERED`
* \param y the y position of the window, or `SDL_WINDOWPOS_CENTERED`
* \param w the width of the window
* \param h the height of the window
* \param flags 0, or one or more SDL_WindowFlags OR'd together
* \returns the window that was created or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_CreatePopupWindow
* \sa SDL_CreateWindow
* \sa SDL_CreateWindowFrom
* \sa SDL_DestroyWindow
*/
extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindowWithPosition(const char *title, int x, int y, int w, int h, Uint32 flags);
/**
* Create a child popup window of the specified parent window.
*
@ -824,10 +750,12 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindowWithPosition(const char *tit
* input events. - 'SDL_WINDOW_POPUP_MENU': The popup window is a popup menu.
* The topmost popup menu will implicitly gain the keyboard focus.
*
* The following flags are not relevant to popup window creation and will be
* ignored: - 'SDL_WINDOW_MINIMIZED' - 'SDL_WINDOW_MAXIMIZED' -
* 'SDL_WINDOW_FULLSCREEN' - 'SDL_WINDOW_BORDERLESS' -
* 'SDL_WINDOW_SKIP_TASKBAR'
* The following flags are not relevant to popup window creation and will be ignored:
*
* - 'SDL_WINDOW_MINIMIZED'
* - 'SDL_WINDOW_MAXIMIZED'
* - 'SDL_WINDOW_FULLSCREEN'
* - 'SDL_WINDOW_BORDERLESS'
*
* The parent parameter **must** be non-null and a valid window. The parent of
* a popup window can be either a regular, toplevel window, or another popup
@ -862,45 +790,60 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindowWithPosition(const char *tit
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_CreateWindow
* \sa SDL_CreateWindowWithProperties
* \sa SDL_DestroyWindow
* \sa SDL_GetWindowParent
*/
extern DECLSPEC SDL_Window *SDLCALL SDL_CreatePopupWindow(SDL_Window *parent, int offset_x, int offset_y, int w, int h, Uint32 flags);
/**
* Create an SDL window from properties representing an existing native
* window.
* Create a window with the specified properties.
*
* These are the supported properties:
*
* - "always-on-top" (boolean) - true if the window should be always on top
* - "borderless" (boolean) - true if the window has no window decoration
* - "focusable" (boolean) - true if the window should accept keyboard input (defaults true)
* - "fullscreen" (boolean) - true if the window should start in fullscreen mode at desktop resolution
* - "height" (number) - the height of the window
* - "hidden" (boolean) - true if the window should start hidden
* - "high-pixel-density" (boolean) - true if the window uses a high pixel density buffer if possible
* - "maximized" (boolean) - true if the window should start maximized
* - "menu" (boolean) - true if the window is a popup menu
* - "metal" (string) - true if the window will be used with Metal rendering
* - "minimized" (boolean) - true if the window should start minimized
* - "mouse-grabbed" (boolean) - true if the window starts with grabbed mouse focus
* - "opengl" (boolean) - true if the window will be used with OpenGL rendering
* - "parent" (pointer) - an SDL_Window that will be the parent of this window, required for windows with the "toolip" and "menu" properties
* - "resizable" (boolean) - true if the window should be resizable
* - "title" (string) - the title of the window, in UTF-8 encoding
* - "transparent" (string) - true if the window show transparent in the areas with alpha of 0
* - "tooltip" (boolean) - true if the window is a tooltip
* - "utility" (boolean) - true if the window is a utility window, not showing in the task bar and window list
* - "vulkan" (string) - true if the window will be used with Vulkan rendering
* - "width" (number) - the width of the window
* - "x" (number) - the x position of the window, or `SDL_WINDOWPOS_CENTERED`, defaults to `SDL_WINDOWPOS_UNDEFINED`. This is relative to the parent for windows with the "parent" property set.
* - "y" (number) - the y position of the window, or `SDL_WINDOWPOS_CENTERED`, defaults to `SDL_WINDOWPOS_UNDEFINED`. This is relative to the parent for windows with the "parent" property set.
*
* On macOS:
*
* ```
* "cocoa.window" (pointer) - the (__unsafe_unretained) NSWindow associated with the window
* "cocoa.view" (pointer) - optional, the (__unsafe_unretained) NSView associated with the window, defaults to [window contentView]
* ```
* - "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]
*
* On Windows:
*
* ```
* "win32.hwnd" (pointer) - the HWND associated with the window
* "win32.pixel_format_hwnd" (pointer) - optional, another window to share pixel format with, useful for OpenGL 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
*
* On X11:
*
* ```
* "x11.window" (number) - the X11 Window associated with the window
* ```
* - "native.x11.window" (number) - the X11 Window associated with the window, if you want to wrap an existing window.
*
* On all platforms:
* The SDL_Window is implicitly shown if the "hidden" property is not set.
*
* ```
* "opengl" (boolean) - optional, true if the window will be used with OpenGL rendering
* "vulkan" (boolean) - optional, true if the window will be used with Vulkan rendering
* ```
* Windows with the "tooltip" and "menu" properties are popup windows and have the behaviors and guidelines outlined in `SDL_CreatePopupWindow()`.
*
* \param props a set of properties describing the native window and options
* \param props the properties to use
* \returns the window that was created or NULL on failure; call
* SDL_GetError() for more information.
*
@ -909,7 +852,7 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_CreatePopupWindow(SDL_Window *parent, in
* \sa SDL_CreateWindow
* \sa SDL_DestroyWindow
*/
extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindowFrom(SDL_PropertiesID props);
extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindowWithProperties(SDL_PropertiesID props);
/**
* Get the numeric ID of a window.
@ -1912,8 +1855,9 @@ extern DECLSPEC int SDLCALL SDL_FlashWindow(SDL_Window *window, SDL_FlashOperati
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_CreatePopupWindow
* \sa SDL_CreateWindow
* \sa SDL_CreateWindowFrom
* \sa SDL_CreateWindowWithProperties
*/
extern DECLSPEC void SDLCALL SDL_DestroyWindow(SDL_Window *window);

View File

@ -69,8 +69,7 @@ SDL3_0.0.0 {
SDL_CreateThreadWithStackSize;
SDL_CreateWindow;
SDL_CreateWindowAndRenderer;
SDL_CreateWindowFrom;
SDL_CreateWindowWithPosition;
SDL_CreateWindowWithProperties;
SDL_CursorVisible;
SDL_DXGIGetOutputInfo;
SDL_DelEventWatch;

View File

@ -93,8 +93,7 @@
#define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL
#define SDL_CreateWindow SDL_CreateWindow_REAL
#define SDL_CreateWindowAndRenderer SDL_CreateWindowAndRenderer_REAL
#define SDL_CreateWindowFrom SDL_CreateWindowFrom_REAL
#define SDL_CreateWindowWithPosition SDL_CreateWindowWithPosition_REAL
#define SDL_CreateWindowWithProperties SDL_CreateWindowWithProperties_REAL
#define SDL_CursorVisible SDL_CursorVisible_REAL
#define SDL_DXGIGetOutputInfo SDL_DXGIGetOutputInfo_REAL
#define SDL_DelEventWatch SDL_DelEventWatch_REAL

View File

@ -157,8 +157,7 @@ SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTexture,(SDL_Renderer *a, Uint32 b, int c
SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTextureFromSurface,(SDL_Renderer *a, SDL_Surface *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindow,(const char *a, int b, int c, Uint32 d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_CreateWindowAndRenderer,(int a, int b, Uint32 c, SDL_Window **d, SDL_Renderer **e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindowFrom,(SDL_PropertiesID a),(a),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindowWithPosition,(const char *a, int b, int c, int d, int e, Uint32 f),(a,b,c,d,e,f),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindowWithProperties,(SDL_PropertiesID a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_CursorVisible,(void),(),return)
SDL_DYNAPI_PROC(void,SDL_DelEventWatch,(SDL_EventFilter a, void *b),(a,b),)
SDL_DYNAPI_PROC(void,SDL_DelHintCallback,(const char *a, SDL_HintCallback b, void *c),(a,b,c),)

View File

@ -1347,6 +1347,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
for (i = 0; i < state->num_windows; ++i) {
char title[1024];
SDL_Rect r;
SDL_PropertiesID props;
r.x = state->window_x;
r.y = state->window_y;
@ -1369,7 +1370,15 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
} else {
SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
}
state->windows[i] = SDL_CreateWindowWithPosition(title, r.x, r.y, r.w, r.h, state->window_flags);
props = SDL_CreateProperties();
SDL_SetStringProperty(props, "title", title);
SDL_SetNumberProperty(props, "x", r.x);
SDL_SetNumberProperty(props, "y", r.y);
SDL_SetNumberProperty(props, "width", r.w);
SDL_SetNumberProperty(props, "height", r.h);
SDL_SetNumberProperty(props, "flags", state->window_flags);
state->windows[i] = SDL_CreateWindowWithProperties(props);
SDL_DestroyProperties(props);
if (!state->windows[i]) {
SDL_Log("Couldn't create window: %s\n",
SDL_GetError());

View File

@ -222,8 +222,7 @@ struct SDL_VideoDevice
/*
* Window functions
*/
int (*CreateSDLWindow)(SDL_VideoDevice *_this, SDL_Window *window);
int (*CreateSDLWindowFrom)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
int (*CreateSDLWindow)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
void (*SetWindowTitle)(SDL_VideoDevice *_this, SDL_Window *window);
int (*SetWindowIcon)(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon);
int (*SetWindowPosition)(SDL_VideoDevice *_this, SDL_Window *window);

View File

@ -1844,9 +1844,59 @@ static int SDL_DllNotSupported(const char *name)
return SDL_SetError("No dynamic %s support in current SDL video driver (%s)", name, _this->name);
}
static SDL_Window *SDL_CreateWindowInternal(const char *title, int x, int y, int w, int h, SDL_Window *parent, Uint32 flags)
static struct {
const char *property_name;
Uint32 flag;
SDL_bool invert_value;
} SDL_WindowFlagProperties[] = {
{ "always-on-top", SDL_WINDOW_ALWAYS_ON_TOP, SDL_FALSE },
{ "borderless", SDL_WINDOW_BORDERLESS, SDL_FALSE },
{ "focusable", SDL_WINDOW_NOT_FOCUSABLE, SDL_TRUE },
{ "fullscreen", SDL_WINDOW_FULLSCREEN, SDL_FALSE },
{ "hidden", SDL_WINDOW_HIDDEN, SDL_FALSE },
{ "high-pixel-density", SDL_WINDOW_HIGH_PIXEL_DENSITY, SDL_FALSE },
{ "maximized", SDL_WINDOW_MAXIMIZED, SDL_FALSE },
{ "menu", SDL_WINDOW_POPUP_MENU, SDL_FALSE },
{ "metal", SDL_WINDOW_METAL, SDL_FALSE },
{ "minimized", SDL_WINDOW_MINIMIZED, SDL_FALSE },
{ "mouse-grabbed", SDL_WINDOW_MOUSE_GRABBED, SDL_FALSE },
{ "opengl", SDL_WINDOW_OPENGL, SDL_FALSE },
{ "resizable", SDL_WINDOW_RESIZABLE, SDL_FALSE },
{ "transparent", SDL_WINDOW_TRANSPARENT, SDL_FALSE },
{ "tooltip", SDL_WINDOW_TOOLTIP, SDL_FALSE },
{ "utility", SDL_WINDOW_UTILITY, SDL_FALSE },
{ "vulkan", SDL_WINDOW_VULKAN, SDL_FALSE }
};
static Uint32 SDL_GetWindowFlagProperties(SDL_PropertiesID props)
{
unsigned i;
Uint32 flags = (Uint32)SDL_GetNumberProperty(props, "flags", 0);
for (i = 0; i < SDL_arraysize(SDL_WindowFlagProperties); ++i) {
if (SDL_WindowFlagProperties[i].invert_value) {
if (!SDL_GetBooleanProperty(props, SDL_WindowFlagProperties[i].property_name, SDL_TRUE)) {
flags |= SDL_WindowFlagProperties[i].flag;
}
} else {
if (SDL_GetBooleanProperty(props, SDL_WindowFlagProperties[i].property_name, SDL_FALSE)) {
flags |= SDL_WindowFlagProperties[i].flag;
}
}
}
return flags;
}
SDL_Window *SDL_CreateWindowWithProperties(SDL_PropertiesID props)
{
SDL_Window *window;
const char *title = SDL_GetStringProperty(props, "title", NULL);
int x = (int)SDL_GetNumberProperty(props, "x", SDL_WINDOWPOS_UNDEFINED);
int y = (int)SDL_GetNumberProperty(props, "y", SDL_WINDOWPOS_UNDEFINED);
int w = (int)SDL_GetNumberProperty(props, "width", 0);
int h = (int)SDL_GetNumberProperty(props, "height", 0);
SDL_Window *parent = SDL_GetProperty(props, "parent", NULL);
Uint32 flags = SDL_GetWindowFlagProperties(props);
Uint32 type_flags, graphics_flags;
SDL_bool undefined_x = SDL_FALSE;
SDL_bool undefined_y = SDL_FALSE;
@ -1863,22 +1913,32 @@ static SDL_Window *SDL_CreateWindowInternal(const char *title, int x, int y, int
}
}
/* Make sure the display list is up to date for window placement */
if (_this->RefreshDisplays) {
_this->RefreshDisplays(_this);
if ((flags & (SDL_WINDOW_TOOLTIP | SDL_WINDOW_POPUP_MENU)) != 0) {
if (!(_this->quirk_flags & VIDEO_DEVICE_QUIRK_HAS_POPUP_WINDOW_SUPPORT)) {
SDL_Unsupported();
return NULL;
}
/* ensure no more than one of these flags is set */
/* Tooltip and popup menu window must specify a parent window */
if (!parent || parent->magic != &_this->window_magic) {
SDL_SetError("Tooltip and popup menu windows must specify a parent window");
return NULL;
}
/* Remove invalid flags */
flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS);
}
/* Ensure no more than one of these flags is set */
type_flags = flags & (SDL_WINDOW_UTILITY | SDL_WINDOW_TOOLTIP | SDL_WINDOW_POPUP_MENU);
if (type_flags & (type_flags - 1)) {
SDL_SetError("Conflicting window type flags specified: 0x%.8x", (unsigned int)type_flags);
return NULL;
}
/* Tooltip and popup menu window must specify a parent window */
if (!parent && ((type_flags & SDL_WINDOW_TOOLTIP) || (type_flags & SDL_WINDOW_POPUP_MENU))) {
SDL_SetError("Tooltip and popup menu windows must specify a parent window");
return NULL;
/* Make sure the display list is up to date for window placement */
if (_this->RefreshDisplays) {
_this->RefreshDisplays(_this);
}
/* Some platforms can't create zero-sized windows */
@ -1889,14 +1949,6 @@ static SDL_Window *SDL_CreateWindowInternal(const char *title, int x, int y, int
h = 1;
}
/* Some platforms blow up if the windows are too large. Raise it later? */
if (w > 16384) {
w = 16384;
}
if (h > 16384) {
h = 16384;
}
if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISUNDEFINED(y) ||
SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
SDL_DisplayID displayID = 0;
@ -2013,7 +2065,7 @@ static SDL_Window *SDL_CreateWindowInternal(const char *title, int x, int y, int
parent->first_child = window;
}
if (_this->CreateSDLWindow && _this->CreateSDLWindow(_this, window) < 0) {
if (_this->CreateSDLWindow && _this->CreateSDLWindow(_this, window, props) < 0) {
SDL_DestroyWindow(window);
return NULL;
}
@ -2057,28 +2109,23 @@ static SDL_Window *SDL_CreateWindowInternal(const char *title, int x, int y, int
SDL_Window *SDL_CreateWindow(const char *title, int w, int h, Uint32 flags)
{
return SDL_CreateWindowInternal(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w , h, NULL, flags);
}
SDL_Window *SDL_CreateWindowWithPosition(const char *title, int x, int y, int w, int h, Uint32 flags)
{
return SDL_CreateWindowInternal(title, x, y, w , h, NULL, flags);
SDL_Window *window;
SDL_PropertiesID props = SDL_CreateProperties();
if (title && *title) {
SDL_SetStringProperty(props, "title", title);
}
SDL_SetNumberProperty(props, "width", w);
SDL_SetNumberProperty(props, "height", h);
SDL_SetNumberProperty(props, "flags", flags);
window = SDL_CreateWindowWithProperties(props);
SDL_DestroyProperties(props);
return window;
}
SDL_Window *SDL_CreatePopupWindow(SDL_Window *parent, int offset_x, int offset_y, int w, int h, Uint32 flags)
{
if (!_this) {
SDL_UninitializedVideo();
return NULL;
}
if (!(_this->quirk_flags & VIDEO_DEVICE_QUIRK_HAS_POPUP_WINDOW_SUPPORT)) {
SDL_Unsupported();
return NULL;
}
/* Parent must be a valid window */
CHECK_WINDOW_MAGIC(parent, NULL);
SDL_Window *window;
SDL_PropertiesID props = SDL_CreateProperties();
/* Popups must specify either the tooltip or popup menu window flags */
if (!(flags & (SDL_WINDOW_TOOLTIP | SDL_WINDOW_POPUP_MENU))) {
@ -2086,81 +2133,14 @@ SDL_Window *SDL_CreatePopupWindow(SDL_Window *parent, int offset_x, int offset_y
return NULL;
}
/* Remove invalid flags */
flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS);
return SDL_CreateWindowInternal(NULL, offset_x, offset_y, w, h, parent, flags);
}
SDL_Window *SDL_CreateWindowFrom(SDL_PropertiesID props)
{
SDL_Window *window;
Uint32 flags = SDL_WINDOW_FOREIGN;
if (!props) {
SDL_InvalidParamError("props");
return NULL;
}
if (!_this) {
SDL_UninitializedVideo();
return NULL;
}
if (!_this->CreateSDLWindowFrom) {
SDL_Unsupported();
return NULL;
}
if (SDL_GetBooleanProperty(props, "opengl", SDL_FALSE)) {
if (!_this->GL_CreateContext) {
SDL_ContextNotSupported("OpenGL");
return NULL;
}
if (SDL_GL_LoadLibrary(NULL) < 0) {
return NULL;
}
flags |= SDL_WINDOW_OPENGL;
}
if (SDL_GetBooleanProperty(props, "vulkan", SDL_FALSE)) {
if (!_this->Vulkan_CreateSurface) {
SDL_ContextNotSupported("Vulkan");
return NULL;
}
if (flags & SDL_WINDOW_OPENGL) {
SDL_SetError("Vulkan and OpenGL not supported on same window");
return NULL;
}
if (SDL_Vulkan_LoadLibrary(NULL) < 0) {
return NULL;
}
flags |= SDL_WINDOW_VULKAN;
}
window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
if (!window) {
SDL_OutOfMemory();
return NULL;
}
window->magic = &_this->window_magic;
window->id = SDL_GetNextObjectID();
window->flags = flags;
window->is_destroying = SDL_FALSE;
window->display_scale = 1.0f;
window->opacity = 1.0f;
window->next = _this->windows;
if (_this->windows) {
_this->windows->prev = window;
}
_this->windows = window;
if (_this->CreateSDLWindowFrom(_this, window, props) < 0) {
SDL_DestroyWindow(window);
return NULL;
}
window->last_displayID = SDL_GetDisplayForWindow(window);
PrepareDragAndDropSupport(window);
SDL_SetProperty(props, "parent", parent);
SDL_SetNumberProperty(props, "x", offset_x);
SDL_SetNumberProperty(props, "y", offset_y);
SDL_SetNumberProperty(props, "width", w);
SDL_SetNumberProperty(props, "height", h);
SDL_SetNumberProperty(props, "flags", flags);
window = SDL_CreateWindowWithProperties(props);
SDL_DestroyProperties(props);
return window;
}
@ -2265,7 +2245,7 @@ int SDL_RecreateWindow(SDL_Window *window, Uint32 flags)
window->is_destroying = SDL_FALSE;
if (_this->CreateSDLWindow && !(flags & SDL_WINDOW_FOREIGN)) {
if (_this->CreateSDLWindow(_this, window) < 0) {
if (_this->CreateSDLWindow(_this, window, 0) < 0) {
if (loaded_opengl) {
SDL_GL_UnloadLibrary();
window->flags &= ~SDL_WINDOW_OPENGL;

View File

@ -35,7 +35,7 @@
/* Currently only one window */
SDL_Window *Android_Window = NULL;
int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_WindowData *data;
int retval = 0;

View File

@ -26,7 +26,7 @@
#include "../../core/android/SDL_android.h"
#include "../SDL_egl_c.h"
extern int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern void Android_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
extern void Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen);
extern void Android_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window);

View File

@ -90,7 +90,6 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void)
device->SuspendScreenSaver = Cocoa_SuspendScreenSaver;
device->CreateSDLWindow = Cocoa_CreateWindow;
device->CreateSDLWindowFrom = Cocoa_CreateWindowFrom;
device->SetWindowTitle = Cocoa_SetWindowTitle;
device->SetWindowIcon = Cocoa_SetWindowIcon;
device->SetWindowPosition = Cocoa_SetWindowPosition;

View File

@ -141,8 +141,7 @@ typedef enum
#endif
@end
extern int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int Cocoa_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
extern int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern void Cocoa_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
extern int Cocoa_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon);
extern int Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);

View File

@ -1752,7 +1752,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
@end
static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow *nswindow, NSView *nsview, SDL_bool created)
static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow *nswindow, NSView *nsview)
{
@autoreleasepool {
SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->driverdata;
@ -1765,7 +1765,6 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow
}
data.window = window;
data.nswindow = nswindow;
data.created = created;
data.videodata = videodata;
data.window_number = nswindow.windowNumber;
data.nscontexts = [[NSMutableArray alloc] init];
@ -1862,6 +1861,14 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow
*/
[nswindow setOneShot:NO];
if (window->flags & SDL_WINDOW_FOREIGN) {
/* Query the title from the existing window */
NSString *title = [nswindow title];
if (title) {
window->title = SDL_strdup([title UTF8String]);
}
}
SDL_PropertiesID props = SDL_GetWindowProperties(window);
SDL_SetProperty(props, "SDL.window.cocoa.window", (__bridge void *)data.nswindow);
SDL_SetNumberProperty(props, "SDL.window.cocoa.metal_view_tag", SDL_METALVIEW_TAG);
@ -1872,18 +1879,41 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow
}
}
int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
@autoreleasepool {
SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->driverdata;
NSWindow *nswindow;
const void *data = SDL_GetProperty(create_props, "native.data", NULL);
NSWindow *nswindow = nil;
NSView *nsview = nil;
if (data) {
if ([(__bridge id)data isKindOfClass:[NSWindow class]]) {
nswindow = (__bridge NSWindow *)data;
} else if ([(__bridge id)data isKindOfClass:[NSView class]]) {
nsview = (__bridge NSView *)data;
} else {
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);
}
if (nswindow && !nsview) {
nsview = [nswindow contentView];
}
if (nsview && !nswindow) {
nswindow = [nsview window];
}
if (nswindow) {
window->flags |= SDL_WINDOW_FOREIGN;
} else {
int x, y;
NSScreen *screen;
NSRect rect, screenRect;
BOOL fullscreen;
NSUInteger style;
SDLView *contentView;
BOOL highdpi;
SDL_RelativeToGlobalForWindow(window, window->x, window->y, &x, &y);
rect.origin.x = x;
@ -1937,6 +1967,13 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
}
}
/* Create a default view for this window */
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
contentView = [[SDLView alloc] initWithFrame:rect];
[contentView setSDLWindow:window];
nsview = contentView;
}
if (window->flags & SDL_WINDOW_ALWAYS_ON_TOP) {
[nswindow setLevel:NSFloatingWindowLevel];
}
@ -1947,11 +1984,6 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
nswindow.backgroundColor = [NSColor clearColor];
}
/* Create a default view for this window */
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
contentView = [[SDLView alloc] initWithFrame:rect];
[contentView setSDLWindow:window];
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#ifdef __clang__
#pragma clang diagnostic push
@ -1959,8 +1991,8 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
#endif
/* Note: as of the macOS 10.15 SDK, this defaults to YES instead of NO when
* the NSHighResolutionCapable boolean is set in Info.plist. */
highdpi = (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) ? YES : NO;
[contentView setWantsBestResolutionOpenGLSurface:highdpi];
BOOL highdpi = (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) ? YES : NO;
[nsview setWantsBestResolutionOpenGLSurface:highdpi];
#ifdef __clang__
#pragma clang diagnostic pop
#endif
@ -1969,19 +2001,19 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
#ifdef SDL_VIDEO_OPENGL_EGL
if ((window->flags & SDL_WINDOW_OPENGL) &&
_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
[contentView setWantsLayer:TRUE];
[nsview setWantsLayer:TRUE];
if ((window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) &&
[nswindow.screen respondsToSelector:@selector(backingScaleFactor)]) {
contentView.layer.contentsScale = nswindow.screen.backingScaleFactor;
nsview.layer.contentsScale = nswindow.screen.backingScaleFactor;
} else {
contentView.layer.contentsScale = 1;
nsview.layer.contentsScale = 1;
}
}
#endif /* SDL_VIDEO_OPENGL_EGL */
#endif /* SDL_VIDEO_OPENGL_ES2 */
[nswindow setContentView:contentView];
[nswindow setContentView:nsview];
if (SetupWindowData(_this, window, nswindow, contentView, SDL_TRUE) < 0) {
if (SetupWindowData(_this, window, nswindow, nsview) < 0) {
return -1;
}
@ -2007,60 +2039,6 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
}
}
int Cocoa_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props)
{
@autoreleasepool {
const void *data = SDL_GetProperty(props, "data", NULL);
NSWindow *nswindow = nil;
NSView *nsview = nil;
NSString *title;
BOOL highdpi;
if (data) {
if ([(__bridge id)data isKindOfClass:[NSWindow class]]) {
nswindow = (__bridge NSWindow *)data;
} else if ([(__bridge id)data isKindOfClass:[NSView class]]) {
nsview = (__bridge NSView *)data;
} else {
SDL_assert(false);
}
} else {
nswindow = (__bridge NSWindow *)SDL_GetProperty(props, "cocoa.window", NULL);
nsview = (__bridge NSView *)SDL_GetProperty(props, "cocoa.view", NULL);
}
if (nswindow && !nsview) {
nsview = [nswindow contentView];
}
if (nsview && !nswindow) {
nswindow = [nsview window];
}
if (!nswindow) {
return SDL_SetError("Couldn't find property cocoa.window");
}
/* Query the title from the existing window */
title = [nswindow title];
if (title) {
window->title = SDL_strdup([title UTF8String]);
}
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
/* Note: as of the macOS 10.15 SDK, this defaults to YES instead of NO when
* the NSHighResolutionCapable boolean is set in Info.plist. */
highdpi = (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) ? YES : NO;
[nsview setWantsBestResolutionOpenGLSurface:highdpi];
#ifdef __clang__
#pragma clang diagnostic pop
#endif
return SetupWindowData(_this, window, nswindow, nsview, SDL_FALSE);
}
}
void Cocoa_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window)
{
@autoreleasepool {

View File

@ -40,7 +40,7 @@ static int Emscripten_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *d
static void Emscripten_VideoQuit(SDL_VideoDevice *_this);
static int Emscripten_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
static void Emscripten_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);
static void Emscripten_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h);
static void Emscripten_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
@ -171,7 +171,7 @@ static void Emscripten_PumpEvents(SDL_VideoDevice *_this)
/* do nothing. */
}
static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props)
{
SDL_WindowData *wdata;
double scaled_w, scaled_h;

View File

@ -76,7 +76,7 @@ static int _InitWindow(SDL_VideoDevice *_this, SDL_Window *window) {
return 0;
}
int HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window) {
int HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) {
if (_InitWindow(_this, window) < 0) {
return -1;
}

View File

@ -24,7 +24,7 @@
#include "../SDL_sysvideo.h"
extern int HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern void HAIKU_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
extern int HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
extern void HAIKU_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);

View File

@ -1443,7 +1443,7 @@ void KMSDRM_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
/* reflect it: if it's fullscreen, KMSDRM_SetWindwoFullscreen() will */
/* be called by SDL later, and we can manage it there. */
/**********************************************************************/
int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_WindowData *windata = NULL;
SDL_VideoData *viddata = _this->driverdata;

View File

@ -121,7 +121,7 @@ int KMSDRM_VideoInit(SDL_VideoDevice *_this);
void KMSDRM_VideoQuit(SDL_VideoDevice *_this);
int KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
int KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
void KMSDRM_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
int KMSDRM_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
void KMSDRM_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);

View File

@ -36,7 +36,7 @@ static int AddN3DSDisplay(gfxScreen_t screen);
static int N3DS_VideoInit(SDL_VideoDevice *_this);
static void N3DS_VideoQuit(SDL_VideoDevice *_this);
static int N3DS_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
static int N3DS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
static int N3DS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
static void N3DS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
struct SDL_DisplayData
@ -150,7 +150,7 @@ static int N3DS_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *displ
return 0;
}
static int N3DS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
static int N3DS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_DisplayData *display_data;
SDL_WindowData *window_data = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));

View File

@ -32,7 +32,7 @@ const TUint32 WindowClientHandle = 9210;
void DisableKeyBlocking(SDL_VideoDevice *_this);
void ConstructWindowL(SDL_VideoDevice *_this);
int NGAGE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int NGAGE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
NGAGE_Window *ngage_window = (NGAGE_Window *)SDL_calloc(1, sizeof(NGAGE_Window));

View File

@ -32,7 +32,7 @@ typedef struct
} NGAGE_Window;
extern int NGAGE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int NGAGE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern void NGAGE_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
#endif /* SDL_ngagewindow */

View File

@ -27,7 +27,7 @@
#include "SDL_offscreenwindow.h"
int OFFSCREEN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int OFFSCREEN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_WindowData *offscreen_window = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));

View File

@ -33,7 +33,7 @@ struct SDL_WindowData
#endif
};
extern int OFFSCREEN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int OFFSCREEN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern void OFFSCREEN_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
#endif /* SDL_offscreenwindow_h */

View File

@ -55,7 +55,7 @@ static void PS2_DeleteDevice(SDL_VideoDevice *device)
SDL_free(device);
}
static int PS2_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
static int PS2_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_SetKeyboardFocus(window);

View File

@ -185,7 +185,7 @@ int PSP_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Di
} \
} while (0)
int PSP_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int PSP_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_WindowData *wdata;

View File

@ -49,7 +49,7 @@ int PSP_VideoInit(SDL_VideoDevice *_this);
void PSP_VideoQuit(SDL_VideoDevice *_this);
int PSP_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
int PSP_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
int PSP_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
int PSP_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
void PSP_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
int PSP_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
void PSP_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);

View File

@ -216,7 +216,7 @@ static void RPI_vsync_callback(DISPMANX_UPDATE_HANDLE_T u, void *data)
SDL_UnlockMutex(wdata->vsync_cond_mutex);
}
int RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_WindowData *wdata;
SDL_VideoDisplay *display;

View File

@ -63,7 +63,7 @@ int RPI_VideoInit(SDL_VideoDevice *_this);
void RPI_VideoQuit(SDL_VideoDevice *_this);
int RPI_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
int RPI_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
int RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
int RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
void RPI_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
int RPI_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
void RPI_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);

View File

@ -28,7 +28,7 @@
#include "SDL_riscosvideo.h"
#include "SDL_riscoswindow.h"
int RISCOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int RISCOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_WindowData *driverdata;

View File

@ -32,7 +32,7 @@ struct SDL_WindowData
sprite_header *fb_sprite;
};
extern int RISCOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int RISCOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern void RISCOS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
#endif /* SDL_riscoswindow_h_ */

View File

@ -26,7 +26,7 @@
#import "SDL_uikitview.h"
#import "SDL_uikitviewcontroller.h"
extern int UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern void UIKit_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
extern void UIKit_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void UIKit_HideWindow(SDL_VideoDevice *_this, SDL_Window *window);

View File

@ -160,7 +160,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, UIWindow
return 0;
}
int UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
@autoreleasepool {
SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);

View File

@ -218,7 +218,7 @@ void VITA_VideoQuit(SDL_VideoDevice *_this)
VITA_QuitTouch();
}
int VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_WindowData *wdata;
#ifdef SDL_VIDEO_VITA_PVR

View File

@ -62,7 +62,7 @@ int VITA_VideoInit(SDL_VideoDevice *_this);
void VITA_VideoQuit(SDL_VideoDevice *_this);
int VITA_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
int VITA_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
int VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
int VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
void VITA_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
int VITA_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
void VITA_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);

View File

@ -238,7 +238,7 @@ void VIVANTE_VideoQuit(SDL_VideoDevice *_this)
#endif
}
int VIVANTE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int VIVANTE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_VideoData *videodata = _this->driverdata;
SDL_DisplayData *displaydata;

View File

@ -72,7 +72,7 @@ int VIVANTE_VideoInit(SDL_VideoDevice *_this);
void VIVANTE_VideoQuit(SDL_VideoDevice *_this);
int VIVANTE_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
int VIVANTE_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
int VIVANTE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
int VIVANTE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
void VIVANTE_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
int VIVANTE_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
void VIVANTE_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);

View File

@ -1981,7 +1981,7 @@ void Wayland_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, S
}
}
int Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_WindowData *data;
SDL_VideoData *c;

View File

@ -137,7 +137,7 @@ extern void Wayland_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *wi
extern void Wayland_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void Wayland_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool bordered);
extern void Wayland_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool resizable);
extern int Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern int Wayland_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
extern void Wayland_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);
extern void Wayland_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window *window);

View File

@ -176,7 +176,6 @@ static SDL_VideoDevice *WIN_CreateDevice(void)
#endif
device->CreateSDLWindow = WIN_CreateWindow;
device->CreateSDLWindowFrom = WIN_CreateWindowFrom;
device->SetWindowTitle = WIN_SetWindowTitle;
device->SetWindowIcon = WIN_SetWindowIcon;
device->SetWindowPosition = WIN_SetWindowPosition;

View File

@ -276,7 +276,7 @@ static void SDLCALL WIN_MouseRelativeModeCenterChanged(void *userdata, const cha
data->mouse_relative_mode_center = SDL_GetStringBoolean(hint, SDL_TRUE);
}
static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd, HWND parent, SDL_bool created)
static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd, HWND parent)
{
SDL_VideoData *videodata = _this->driverdata;
SDL_WindowData *data;
@ -295,8 +295,6 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd
data->hdc = GetDC(hwnd);
#endif
data->hinstance = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
data->created = created;
data->high_surrogate = 0;
data->mouse_button_flags = (WPARAM)-1;
data->last_pointer_update = (LPARAM)-1;
data->videodata = videodata;
@ -349,7 +347,10 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd
int w = rect.right;
int h = rect.bottom;
if ((window->windowed.w && window->windowed.w != w) || (window->windowed.h && window->windowed.h != h)) {
if (window->flags & SDL_WINDOW_FOREIGN) {
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)) {
/* We tried to create a window larger than the desktop and Windows didn't allow it. Override! */
int x, y;
/* Figure out what the window area will be */
@ -369,6 +370,10 @@ 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) {
window->windowed.x = point.x;
window->windowed.y = point.y;
}
window->x = point.x;
window->y = point.y;
}
@ -438,6 +443,27 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd
data->initializing = SDL_FALSE;
if (window->flags & SDL_WINDOW_FOREIGN) {
/* Query the title from the existing window */
LPTSTR title;
int titleLen;
SDL_bool isstack;
titleLen = GetWindowTextLength(hwnd);
title = SDL_small_alloc(TCHAR, titleLen + 1, &isstack);
if (title) {
titleLen = GetWindowText(hwnd, title, titleLen + 1);
} else {
titleLen = 0;
}
if (titleLen > 0) {
window->title = WIN_StringToUTF8(title);
}
if (title) {
SDL_small_free(title, isstack);
}
}
SDL_PropertiesID props = SDL_GetWindowProperties(window);
SDL_SetProperty(props, "SDL.window.win32.hwnd", data->hwnd);
SDL_SetProperty(props, "SDL.window.win32.hdc", data->hdc);
@ -464,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 (data->created) {
if (!(window->flags & SDL_WINDOW_FOREIGN)) {
DestroyWindow(data->hwnd);
if (data->destroy_parent_with_window && data->parent) {
DestroyWindow(data->parent);
@ -538,9 +564,17 @@ static void WIN_SetKeyboardFocus(SDL_Window *window)
SDL_SetKeyboardFocus(window);
}
int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
HWND hwnd, parent = NULL;
HWND hwnd = (HWND)SDL_GetProperty(create_props, "native.win32.hwnd", SDL_GetProperty(create_props, "native.data", NULL));
HWND parent = NULL;
if (hwnd) {
window->flags |= SDL_WINDOW_FOREIGN;
if (SetupWindowData(_this, window, hwnd, parent) < 0) {
return -1;
}
} else {
DWORD style = STYLE_BASIC;
DWORD styleEx = 0;
int x, y;
@ -569,7 +603,7 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
WIN_PumpEvents(_this);
if (SetupWindowData(_this, window, hwnd, parent, SDL_TRUE) < 0) {
if (SetupWindowData(_this, window, hwnd, parent) < 0) {
DestroyWindow(hwnd);
if (parent) {
DestroyWindow(parent);
@ -588,6 +622,7 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
window->flags &= ~SDL_WINDOW_HIDDEN;
ShowWindow(hwnd, SW_SHOWMINNOACTIVE);
}
}
/* FIXME: does not work on all hardware configurations with different renders (i.e. hybrid GPUs) */
if (window->flags & SDL_WINDOW_TRANSPARENT) {
@ -608,6 +643,21 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
}
}
HWND share_hwnd = (HWND)SDL_GetProperty(create_props, "native.win32.pixel_format_hwnd", NULL);
if (share_hwnd) {
HDC hdc = GetDC(share_hwnd);
int pixel_format = GetPixelFormat(hdc);
PIXELFORMATDESCRIPTOR pfd;
SDL_zero(pfd);
DescribePixelFormat(hdc, pixel_format, sizeof(pfd), &pfd);
ReleaseDC(share_hwnd, hdc);
if (!SetPixelFormat(window->driverdata->hdc, pixel_format, &pfd)) {
WIN_DestroyWindow(_this, window);
return WIN_SetError("SetPixelFormat()");
}
} else {
if (!(window->flags & SDL_WINDOW_OPENGL)) {
return 0;
}
@ -640,68 +690,11 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
#else
return SDL_SetError("Could not create GL window (WGL support not configured)");
#endif
}
return 0;
}
int WIN_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props)
{
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
return -1;
#else
HWND hwnd = (HWND)SDL_GetProperty(props, "win32.hwnd", SDL_GetProperty(props, "data", NULL));
LPTSTR title;
int titleLen;
SDL_bool isstack;
if (!hwnd) {
return SDL_SetError("Couldn't find property win32.hwnd");
}
/* Query the title from the existing window */
titleLen = GetWindowTextLength(hwnd);
title = SDL_small_alloc(TCHAR, titleLen + 1, &isstack);
if (title) {
titleLen = GetWindowText(hwnd, title, titleLen + 1);
} else {
titleLen = 0;
}
if (titleLen > 0) {
window->title = WIN_StringToUTF8(title);
}
if (title) {
SDL_small_free(title, isstack);
}
if (SetupWindowData(_this, window, hwnd, GetParent(hwnd), SDL_FALSE) < 0) {
return -1;
}
#ifdef SDL_VIDEO_OPENGL_WGL
{
HWND share_hwnd = (HWND)SDL_GetProperty(props, "win32.pixel_format_hwnd", NULL);
if (share_hwnd) {
HDC hdc = GetDC(share_hwnd);
int pixel_format = GetPixelFormat(hdc);
PIXELFORMATDESCRIPTOR pfd;
SDL_zero(pfd);
DescribePixelFormat(hdc, pixel_format, sizeof(pfd), &pfd);
ReleaseDC(share_hwnd, hdc);
if (!SetPixelFormat(window->driverdata->hdc, pixel_format, &pfd)) {
return WIN_SetError("SetPixelFormat()");
}
} else if (window->flags & SDL_WINDOW_OPENGL) {
/* Try to set up the pixel format, if it hasn't been set by the application */
WIN_GL_SetupWindow(_this, window);
}
}
#endif
return 0;
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
}
void WIN_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)

View File

@ -45,7 +45,6 @@ struct SDL_WindowData
HBITMAP hbm;
WNDPROC wndproc;
HHOOK keyboard_hook;
SDL_bool created;
WPARAM mouse_button_flags;
LPARAM last_pointer_update;
WCHAR high_surrogate;
@ -75,8 +74,7 @@ struct SDL_WindowData
UINT copybits_flag;
};
extern int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int WIN_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
extern int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern void WIN_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
extern int WIN_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon);
extern int WIN_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);

View File

@ -74,7 +74,7 @@ static int WINRT_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *displa
static void WINRT_VideoQuit(SDL_VideoDevice *_this);
/* Window functions */
static int WINRT_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
static int WINRT_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
static void WINRT_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);
static void WINRT_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen);
static void WINRT_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
@ -581,7 +581,7 @@ static bool WINRT_IsCoreWindowActive(CoreWindow ^ coreWindow)
return true;
}
int WINRT_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
int WINRT_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
// Make sure that only one window gets created, at least until multimonitor
// support is added.

View File

@ -181,7 +181,6 @@ static SDL_VideoDevice *X11_CreateDevice(void)
device->SendWakeupEvent = X11_SendWakeupEvent;
device->CreateSDLWindow = X11_CreateWindow;
device->CreateSDLWindowFrom = X11_CreateWindowFrom;
device->SetWindowTitle = X11_SetWindowTitle;
device->SetWindowIcon = X11_SetWindowIcon;
device->SetWindowPosition = X11_SetWindowPosition;

View File

@ -295,7 +295,7 @@ Uint32 X11_GetNetWMState(SDL_VideoDevice *_this, SDL_Window *window, Window xwin
return flags;
}
static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w, BOOL created)
static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w)
{
SDL_VideoData *videodata = _this->driverdata;
SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window);
@ -320,7 +320,6 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w,
NULL);
}
#endif
data->created = created;
data->videodata = videodata;
/* Associate the data with the window */
@ -380,8 +379,10 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w,
}
}
/* All done! */
window->driverdata = data;
if (window->flags & SDL_WINDOW_FOREIGN) {
/* Query the title from the existing window */
window->title = X11_GetWindowTitle(_this, w);
}
SDL_PropertiesID props = SDL_GetWindowProperties(window);
int screen = (displaydata ? displaydata->screen : 0);
@ -389,6 +390,8 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w,
SDL_SetNumberProperty(props, "SDL.window.x11.screen", screen);
SDL_SetNumberProperty(props, "SDL.window.x11.window", data->xwindow);
/* All done! */
window->driverdata = data;
return 0;
}
@ -422,8 +425,18 @@ static void SetWindowBordered(Display *display, int screen, Window window, SDL_b
}
}
int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
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));
if (w) {
window->flags |= SDL_WINDOW_FOREIGN;
if (SetupWindowData(_this, window, w) < 0) {
return -1;
}
return 0;
}
SDL_VideoData *data = _this->driverdata;
SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window);
const SDL_bool force_override_redirect = SDL_GetHintBoolean(SDL_HINT_X11_FORCE_OVERRIDE_REDIRECT, SDL_FALSE);
@ -433,7 +446,6 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
Visual *visual;
int depth;
XSetWindowAttributes xattr;
Window w;
XSizeHints *sizehints;
XWMHints *wmhints;
XClassHint *classhints;
@ -706,7 +718,7 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
X11_XSetWMProtocols(display, w, protocols, proto_count);
}
if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {
if (SetupWindowData(_this, window, w) < 0) {
X11_XDestroyWindow(display, w);
return -1;
}
@ -777,21 +789,6 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
return 0;
}
int X11_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props)
{
Window w = (Window)SDL_GetNumberProperty(props, "x11.window", (Window)SDL_GetProperty(props, "data", NULL));
if (!w) {
return SDL_SetError("Couldn't find property x11.window");
}
window->title = X11_GetWindowTitle(_this, w);
if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
return -1;
}
return 0;
}
char *X11_GetWindowTitle(SDL_VideoDevice *_this, Window xwindow)
{
SDL_VideoData *data = _this->driverdata;
@ -1848,7 +1845,7 @@ void X11_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
X11_XDestroyIC(data->ic);
}
#endif
if (data->created) {
if (!(window->flags & SDL_WINDOW_FOREIGN)) {
X11_XDestroyWindow(display, data->xwindow);
X11_XFlush(display);
}

View File

@ -84,8 +84,7 @@ struct SDL_WindowData
extern void X11_SetNetWMState(SDL_VideoDevice *_this, Window xwindow, Uint32 flags);
extern Uint32 X11_GetNetWMState(SDL_VideoDevice *_this, SDL_Window *window, Window xwindow);
extern int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int X11_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
extern int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern char *X11_GetWindowTitle(SDL_VideoDevice *_this, Window xwindow);
extern void X11_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
extern int X11_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon);

View File

@ -1676,6 +1676,7 @@ static int video_setWindowCenteredOnDisplay(void *arg)
int currentDisplay;
int expectedDisplay;
SDL_Rect expectedDisplayRect;
SDL_PropertiesID props;
/* xVariation is the display we start on */
expectedDisplay = displays[xVariation % displayNum];
@ -1687,7 +1688,14 @@ static int video_setWindowCenteredOnDisplay(void *arg)
expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
window = SDL_CreateWindowWithPosition(title, x, y, w, h, 0);
props = SDL_CreateProperties();
SDL_SetStringProperty(props, "title", title);
SDL_SetNumberProperty(props, "x", x);
SDL_SetNumberProperty(props, "w", y);
SDL_SetNumberProperty(props, "width", w);
SDL_SetNumberProperty(props, "height", h);
window = SDL_CreateWindowWithProperties(props);
SDL_DestroyProperties(props);
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");

View File

@ -148,8 +148,8 @@ int main(int argc, char *argv[])
quit(3);
}
props = SDL_CreateProperties();
SDL_SetProperty(props, "data", native_window);
window = SDL_CreateWindowFrom(props);
SDL_SetProperty(props, "native.data", native_window);
window = SDL_CreateWindowWithProperties(props);
SDL_DestroyProperties(props);
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window: %s\n", SDL_GetError());