update SDL3 to 3.2.0

This commit is contained in:
Sasha Szpakowski
2025-01-24 21:20:11 -04:00
parent f27a1c24b3
commit 3582488fbc
1209 changed files with 26017 additions and 18421 deletions
+74 -44
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -147,6 +147,8 @@ static ATOM SDL_HelperWindowClass = 0;
- WS_CAPTION: this seems to enable the Windows minimize animation
- WS_SYSMENU: enables system context menu on task bar
This will also cause the task bar to overlap the window and other windowed behaviors, so only use this for windows that shouldn't appear to be fullscreen
- WS_THICKFRAME: allows hit-testing to resize window (doesn't actually add a frame to a borderless window).
- WS_MAXIMIZEBOX: window will respond to Windows maximize commands sent to all windows, and the window will fill the usable desktop area rather than the whole screen
*/
#define STYLE_BASIC (WS_CLIPSIBLINGS | WS_CLIPCHILDREN)
@@ -180,16 +182,27 @@ static DWORD GetWindowStyle(SDL_Window *window)
style |= STYLE_NORMAL;
}
/* The WS_MAXIMIZEBOX style flag needs to be retained for as long as the window is maximized,
* or restoration from minimized can fail, and leaving maximized can result in an odd size.
*/
if (window->flags & SDL_WINDOW_RESIZABLE) {
/* You can have a borderless resizable window, but Windows doesn't always draw it correctly,
see https://bugzilla.libsdl.org/show_bug.cgi?id=4466
*/
if (!(window->flags & SDL_WINDOW_BORDERLESS) ||
SDL_GetHintBoolean("SDL_BORDERLESS_RESIZABLE_STYLE", false)) {
SDL_GetHintBoolean("SDL_BORDERLESS_RESIZABLE_STYLE", true)) {
style |= STYLE_RESIZABLE;
}
}
if (window->internal && window->internal->force_ws_maximizebox) {
/* Even if the resizable flag is cleared, WS_MAXIMIZEBOX is still needed as long
* as the window is maximized, or de-maximizing or minimizing and restoring the
* maximized window can result in the window disappearing or being the wrong size.
*/
style |= WS_MAXIMIZEBOX;
}
// Need to set initialize minimize style, or when we call ShowWindow with WS_MINIMIZE it will activate a random window
if (window->flags & SDL_WINDOW_MINIMIZED) {
style |= WS_MINIMIZE;
@@ -260,7 +273,7 @@ static bool WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, DWORD
/* borderless windows will have WM_NCCALCSIZE return 0 for the non-client area. When this happens, it looks like windows will send a resize message
expanding the window client area to the previous window + chrome size, so shouldn't need to adjust the window size for the set styles.
*/
if (!(window->flags & SDL_WINDOW_BORDERLESS)) {
if (!(window->flags & SDL_WINDOW_BORDERLESS) && !SDL_WINDOW_IS_POPUP(window)) {
#if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
AdjustWindowRectEx(&rect, style, menu, 0);
#else
@@ -664,19 +677,21 @@ static void CleanupWindowData(SDL_VideoDevice *_this, SDL_Window *window)
window->internal = NULL;
}
static void WIN_ConstrainPopup(SDL_Window *window)
static void WIN_ConstrainPopup(SDL_Window *window, bool output_to_pending)
{
// Clamp popup windows to the output borders
if (SDL_WINDOW_IS_POPUP(window)) {
SDL_Window *w;
SDL_DisplayID displayID;
SDL_Rect rect;
int abs_x = window->floating.x;
int abs_y = window->floating.y;
int abs_x = window->last_position_pending ? window->pending.x : window->floating.x;
int abs_y = window->last_position_pending ? window->pending.y : window->floating.y;
const int width = window->last_size_pending ? window->pending.w : window->floating.w;
const int height = window->last_size_pending ? window->pending.h : window->floating.h;
int offset_x = 0, offset_y = 0;
// Calculate the total offset from the parents
for (w = window->parent; w->parent; w = w->parent) {
for (w = window->parent; SDL_WINDOW_IS_POPUP(w); w = w->parent) {
offset_x += w->x;
offset_y += w->y;
}
@@ -689,31 +704,43 @@ static void WIN_ConstrainPopup(SDL_Window *window)
// Constrain the popup window to the display of the toplevel parent
displayID = SDL_GetDisplayForWindow(w);
SDL_GetDisplayBounds(displayID, &rect);
if (abs_x + window->floating.w > rect.x + rect.w) {
abs_x -= (abs_x + window->floating.w) - (rect.x + rect.w);
if (abs_x + width > rect.x + rect.w) {
abs_x -= (abs_x + width) - (rect.x + rect.w);
}
if (abs_y + window->floating.h > rect.y + rect.h) {
abs_y -= (abs_y + window->floating.h) - (rect.y + rect.h);
if (abs_y + height > rect.y + rect.h) {
abs_y -= (abs_y + height) - (rect.y + rect.h);
}
abs_x = SDL_max(abs_x, rect.x);
abs_y = SDL_max(abs_y, rect.y);
window->floating.x = abs_x - offset_x;
window->floating.y = abs_y - offset_y;
if (output_to_pending) {
window->pending.x = abs_x - offset_x;
window->pending.y = abs_y - offset_y;
window->pending.w = width;
window->pending.h = height;
} else {
window->floating.x = abs_x - offset_x;
window->floating.y = abs_y - offset_y;
window->floating.w = width;
window->floating.h = height;
}
}
}
static void WIN_SetKeyboardFocus(SDL_Window *window)
static void WIN_SetKeyboardFocus(SDL_Window *window, bool set_active_focus)
{
SDL_Window *topmost = window;
SDL_Window *toplevel = window;
// Find the topmost parent
while (topmost->parent) {
topmost = topmost->parent;
while (SDL_WINDOW_IS_POPUP(toplevel)) {
toplevel = toplevel->parent;
}
topmost->internal->keyboard_focus = window;
SDL_SetKeyboardFocus(window);
toplevel->internal->keyboard_focus = window;
if (set_active_focus && !window->is_hiding && !window->is_destroying) {
SDL_SetKeyboardFocus(window);
}
}
bool WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
@@ -742,7 +769,7 @@ bool WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properties
styleEx |= GetWindowStyleEx(window);
// Figure out what the window area will be
WIN_ConstrainPopup(window);
WIN_ConstrainPopup(window, false);
WIN_AdjustWindowRectWithStyle(window, style, styleEx, FALSE, &x, &y, &w, &h, SDL_WINDOWRECT_FLOATING);
hwnd = CreateWindowEx(styleEx, SDL_Appname, TEXT(""), style,
@@ -938,7 +965,7 @@ bool WIN_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
*/
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
if (!(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
WIN_ConstrainPopup(window);
WIN_ConstrainPopup(window, true);
return WIN_SetWindowPositionInternal(window,
window->internal->copybits_flag | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOSIZE |
SWP_NOACTIVATE, SDL_WINDOWRECT_PENDING);
@@ -1053,7 +1080,7 @@ void WIN_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
bool bActivate = SDL_GetHintBoolean(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, true);
if (window->parent) {
if (SDL_WINDOW_IS_POPUP(window)) {
// Update our position in case our parent moved while we were hidden
WIN_SetWindowPosition(_this, window);
}
@@ -1071,9 +1098,7 @@ void WIN_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
}
if (window->flags & SDL_WINDOW_POPUP_MENU && bActivate) {
if (window->parent == SDL_GetKeyboardFocus()) {
WIN_SetKeyboardFocus(window);
}
WIN_SetKeyboardFocus(window, window->parent == SDL_GetKeyboardFocus());
}
if (window->flags & SDL_WINDOW_MODAL) {
WIN_SetWindowModal(_this, window, true);
@@ -1092,16 +1117,20 @@ void WIN_HideWindow(SDL_VideoDevice *_this, SDL_Window *window)
// Transfer keyboard focus back to the parent
if (window->flags & SDL_WINDOW_POPUP_MENU) {
if (window == SDL_GetKeyboardFocus()) {
SDL_Window *new_focus = window->parent;
SDL_Window *new_focus = window->parent;
bool set_focus = window == SDL_GetKeyboardFocus();
// Find the highest level window that isn't being hidden or destroyed.
while (new_focus->parent && (new_focus->is_hiding || new_focus->is_destroying)) {
new_focus = new_focus->parent;
// Find the highest level window, up to the toplevel parent, that isn't being hidden or destroyed.
while (SDL_WINDOW_IS_POPUP(new_focus) && (new_focus->is_hiding || new_focus->is_destroying)) {
new_focus = new_focus->parent;
// If some window in the chain currently had keyboard focus, set it to the new lowest-level window.
if (!set_focus) {
set_focus = new_focus == SDL_GetKeyboardFocus();
}
WIN_SetKeyboardFocus(new_focus);
}
WIN_SetKeyboardFocus(new_focus, set_focus);
}
}
@@ -1139,9 +1168,7 @@ void WIN_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window)
if (bActivate) {
SetForegroundWindow(hwnd);
if (window->flags & SDL_WINDOW_POPUP_MENU) {
if (window->parent == SDL_GetKeyboardFocus()) {
WIN_SetKeyboardFocus(window);
}
WIN_SetKeyboardFocus(window, window->parent == SDL_GetKeyboardFocus());
}
} else {
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, data->copybits_flag | SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
@@ -1352,28 +1379,31 @@ SDL_FullscreenResult WIN_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window
https://bugzilla.libsdl.org/show_bug.cgi?id=3215 can reproduce!
*/
if (data->windowed_mode_was_maximized && !data->in_window_deactivation) {
style |= WS_MAXIMIZE;
enterMaximized = true;
data->disable_move_size_events = true;
}
menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
WIN_AdjustWindowRectWithStyle(window, style, styleEx, menu,
&x, &y,
&w, &h,
data->windowed_mode_was_maximized ? SDL_WINDOWRECT_WINDOWED : SDL_WINDOWRECT_FLOATING);
SDL_WINDOWRECT_FLOATING);
data->windowed_mode_was_maximized = false;
}
/* Always reset the window to the base floating size before possibly re-applying the maximized state,
* otherwise, the base floating size can seemingly be lost in some cases.
*/
SetWindowLong(hwnd, GWL_STYLE, style);
data->expected_resize = true;
SetWindowPos(hwnd, top, x, y, w, h, data->copybits_flag | SWP_NOACTIVATE);
data->expected_resize = false;
data->disable_move_size_events = false;
if (!enterMaximized) {
SetWindowPos(hwnd, top, x, y, w, h, data->copybits_flag | SWP_NOACTIVATE);
} else {
if (enterMaximized) {
WIN_MaximizeWindow(_this, window);
}
data->expected_resize = false;
#ifdef HIGHDPI_DEBUG
SDL_Log("WIN_SetWindowFullscreen: %d finished. Set window to %d,%d, %dx%d", (int)fullscreen, x, y, w, h);
#endif
@@ -1663,7 +1693,7 @@ void WIN_UpdateClipCursor(SDL_Window *window)
if (!GetClientScreenRect(data->hwnd, &client)) {
return;
}
RECT target = client;
if (lock_to_ctr) {
LONG cx = (client.left + client.right ) / 2;
@@ -1687,7 +1717,7 @@ void WIN_UpdateClipCursor(SDL_Window *window)
}
}
if (GetClipCursor(&client) &&
if (GetClipCursor(&client) &&
0 != SDL_memcmp(&target, &client, sizeof(client)) &&
ClipCursor(&target)) {
data->cursor_clipped_rect = target; // ClipCursor may fail if rect beyond screen