Integrate 8067023 and 8067041 to SDL3:

Change 8067023 by mikela:
	Add SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED to SDL_RaiseWindow

	- When set to false, this allows SDL_RaiseWindow to bring a chosen window to the top of the stack but not force input focus to it

Change 8067041 by mikela:
	Rename SDL_HINT_WINDOW_NO_ACTIVATION_WHEN_SHOWN to SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN
This commit is contained in:
Sam Lantinga 2023-05-18 09:21:29 -07:00
parent e61b5ceefe
commit 87186a893c
2 changed files with 26 additions and 6 deletions

View File

@ -441,6 +441,18 @@ extern "C" {
*/
#define SDL_HINT_FORCE_RAISEWINDOW "SDL_HINT_FORCE_RAISEWINDOW"
/**
* \brief A variable controlling whether the window is activated when the SDL_RaiseWindow function is called
*
* This variable can be set to the following values:
* "0" - The window is not activated when the SDL_RaiseWindow function is called
* "1" - The window is activated when the SDL_RaiseWindow function is called
*
* By default SDL will activate the window when the SDL_RaiseWindow function is called.
* At present this is only available for MS Windows.
*/
#define SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED "SDL_WINDOW_ACTIVATE_WHEN_RAISED"
/**
* \brief A variable controlling how 3D acceleration is used to accelerate the SDL screen surface.
*
@ -2025,12 +2037,12 @@ extern "C" {
* \brief A variable controlling whether the window is activated when the SDL_ShowWindow function is called
*
* This variable can be set to the following values:
* "0" - The window is activated when the SDL_ShowWindow function is called
* "1" - The window is not activated when the SDL_ShowWindow function is called
* "0" - The window is not activated when the SDL_ShowWindow function is called
* "1" - The window is activated when the SDL_ShowWindow function is called
*
* By default SDL will activate the window when the SDL_ShowWindow function is called
*/
#define SDL_HINT_WINDOW_NO_ACTIVATION_WHEN_SHOWN "SDL_WINDOW_NO_ACTIVATION_WHEN_SHOWN"
#define SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN "SDL_WINDOW_ACTIVATE_WHEN_SHOWN"
/** \brief Allows back-button-press events on Windows Phone to be marked as handled
*

View File

@ -840,13 +840,15 @@ void WIN_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
HWND hwnd;
int nCmdShow;
SDL_bool bActivate = SDL_GetHintBoolean(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, SDL_TRUE);
if (window->parent) {
/* Update our position in case our parent moved while we were hidden */
WIN_SetWindowPosition(_this, window);
}
hwnd = window->driverdata->hwnd;
nCmdShow = SDL_GetHintBoolean(SDL_HINT_WINDOW_NO_ACTIVATION_WHEN_SHOWN, SDL_FALSE) ? SW_SHOWNA : SW_SHOW;
nCmdShow = bActivate ? SW_SHOW : SW_SHOWNA;
style = GetWindowLong(hwnd, GWL_EXSTYLE);
if (style & WS_EX_NOACTIVATE) {
nCmdShow = SW_SHOWNOACTIVATE;
@ -892,12 +894,14 @@ void WIN_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window)
* for "security" reasons. Apparently, the following song-and-dance gets
* around their objections. */
SDL_bool bForce = SDL_GetHintBoolean(SDL_HINT_FORCE_RAISEWINDOW, SDL_FALSE);
SDL_bool bActivate = SDL_GetHintBoolean(SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED, SDL_TRUE);
HWND hCurWnd = NULL;
DWORD dwMyID = 0u;
DWORD dwCurID = 0u;
HWND hwnd = window->driverdata->hwnd;
SDL_WindowData *data = window->driverdata;
HWND hwnd = data->hwnd;
if (bForce) {
hCurWnd = GetForegroundWindow();
dwMyID = GetCurrentThreadId();
@ -909,7 +913,11 @@ void WIN_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window)
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
}
}
SetForegroundWindow(hwnd);
if (bActivate) {
SetForegroundWindow(hwnd);
} else {
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, data->copybits_flag | SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
}
if (bForce) {
AttachThreadInput(dwCurID, dwMyID, FALSE);
SetFocus(hwnd);