Xbox GDKX support (#5869)

* Xbox GDK support (14 squashed commits)

* Added basic keyboard testing

* Update readme

* Code review fixes

* Fixed issue where controller add/removal wasn't working (since the device notification events don't work on Xbox, have to use the joystick thread to poll XInput)
This commit is contained in:
chalonverse
2022-07-01 13:59:14 -07:00
committed by GitHub
parent 0025621b80
commit f317d619cc
77 changed files with 2573 additions and 74 deletions

View File

@@ -4390,7 +4390,7 @@ SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
retval = 0;
}
#endif
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (retval == -1 &&
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINDOWS) &&
WIN_ShowMessageBox(messageboxdata, buttonid) == 0) {

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsvideo.h"
#include "SDL_windowswindow.h"

View File

@@ -265,6 +265,7 @@ WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
return code;
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static SDL_bool
WIN_ShouldIgnoreFocusClick()
{
@@ -460,6 +461,7 @@ WIN_UpdateFocus(SDL_Window *window, SDL_bool expect_focus)
data->in_window_deactivation = SDL_FALSE;
}
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
static BOOL
WIN_ConvertUTF32toUTF8(UINT32 codepoint, char * text)
@@ -502,6 +504,7 @@ ShouldGenerateWindowCloseOnAltF4(void)
return !SDL_GetHintBoolean(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, SDL_FALSE);
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* We want to generate mouse events from mouse and pen, and touch events from touchscreens */
#define MI_WP_SIGNATURE 0xFF515700
#define MI_WP_SIGNATURE_MASK 0xFFFFFF00
@@ -532,6 +535,7 @@ static SDL_MOUSE_EVENT_SOURCE GetMouseMessageSource()
}
return SDL_MOUSE_EVENT_SOURCE_MOUSE;
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
static SDL_WindowData *
WIN_GetWindowDataFromHWND(HWND hwnd)
@@ -550,6 +554,7 @@ WIN_GetWindowDataFromHWND(HWND hwnd)
return NULL;
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
LRESULT CALLBACK
WIN_KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
@@ -635,6 +640,7 @@ static void WIN_CheckICMProfileChanged(SDL_Window* window)
}
}
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
LRESULT CALLBACK
WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
@@ -657,10 +663,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
/* Get the window data for the window */
data = WIN_GetWindowDataFromHWND(hwnd);
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (!data) {
/* Fallback */
data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData"));
}
#endif
if (!data) {
return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
}
@@ -677,8 +685,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
#endif /* WMMSG_DEBUG */
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata))
return 0;
#endif
switch (msg) {
@@ -692,6 +702,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
break;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
case WM_NCACTIVATE:
{
/* Don't immediately clip the cursor in case we're clicking minimize/maximize buttons */
@@ -941,6 +952,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
returnCode = 0;
break;
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
@@ -1022,6 +1034,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
returnCode = 0;
break;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#ifdef WM_INPUTLANGCHANGE
case WM_INPUTLANGCHANGE:
{
@@ -1621,6 +1634,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
return 0;
}
break;
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
}
/* If there's a window proc, assume it's going to handle messages */
@@ -1633,6 +1647,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static void WIN_UpdateClipCursorForWindows()
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
@@ -1679,6 +1694,7 @@ static void WIN_UpdateMouseCapture()
}
}
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
/* A message hook called before TranslateMessage() */
static SDL_WindowsMessageHook g_WindowsMessageHook = NULL;
@@ -1736,11 +1752,13 @@ WIN_SendWakeupEvent(_THIS, SDL_Window *window)
void
WIN_PumpEvents(_THIS)
{
const Uint8 *keystate;
MSG msg;
DWORD end_ticks = GetTickCount() + 1;
int new_messages = 0;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
const Uint8 *keystate;
SDL_Window *focusWindow;
#endif
if (g_WindowsEnableMessageLoop) {
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
@@ -1748,6 +1766,7 @@ WIN_PumpEvents(_THIS)
g_WindowsMessageHook(g_WindowsMessageHookData, msg.hwnd, msg.message, msg.wParam, msg.lParam);
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Don't dispatch any mouse motion queued prior to or including the last mouse warp */
if (msg.message == WM_MOUSEMOVE && SDL_last_warp_time) {
if (!SDL_TICKS_PASSED(msg.time, (SDL_last_warp_time + 1))) {
@@ -1757,6 +1776,7 @@ WIN_PumpEvents(_THIS)
/* This mouse message happened after the warp */
SDL_last_warp_time = 0;
}
#endif !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
TranslateMessage(&msg);
@@ -1777,6 +1797,7 @@ WIN_PumpEvents(_THIS)
}
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Windows loses a shift KEYUP event when you have both pressed at once and let go of one.
You won't get a KEYUP until both are released, and that keyup will only be for the second
key you released. Take heroic measures and check the keystate as of the last handled event,
@@ -1807,6 +1828,7 @@ WIN_PumpEvents(_THIS)
/* Update mouse capture */
WIN_UpdateMouseCapture();
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
#ifdef __GDK__
GDK_DispatchTaskQueue();
@@ -1821,8 +1843,10 @@ HINSTANCE SDL_Instance = NULL;
static void WIN_CleanRegisterApp(WNDCLASSEX wcex)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (wcex.hIcon) DestroyIcon(wcex.hIcon);
if (wcex.hIconSm) DestroyIcon(wcex.hIconSm);
#endif
SDL_free(SDL_Appname);
SDL_Appname = NULL;
}
@@ -1831,9 +1855,11 @@ static void WIN_CleanRegisterApp(WNDCLASSEX wcex)
int
SDL_RegisterApp(const char *name, Uint32 style, void *hInst)
{
const char *hint;
WNDCLASSEX wcex;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
const char *hint;
TCHAR path[MAX_PATH];
#endif
/* Only do this once... */
if (app_registered) {
@@ -1865,6 +1891,7 @@ SDL_RegisterApp(const char *name, Uint32 style, void *hInst)
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
hint = SDL_GetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON);
if (hint && *hint) {
wcex.hIcon = LoadIcon(SDL_Instance, MAKEINTRESOURCE(SDL_atoi(hint)));
@@ -1878,6 +1905,7 @@ SDL_RegisterApp(const char *name, Uint32 style, void *hInst)
GetModuleFileName(SDL_Instance, path, MAX_PATH);
ExtractIconEx(path, 0, &wcex.hIcon, &wcex.hIconSm, 1);
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
if (!RegisterClassEx(&wcex)) {
WIN_CleanRegisterApp(wcex);
@@ -1904,9 +1932,11 @@ SDL_UnregisterApp()
wcex.hIcon = NULL;
wcex.hIconSm = NULL;
/* Check for any registered window classes. */
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (GetClassInfoEx(SDL_Instance, SDL_Appname, &wcex)) {
UnregisterClass(SDL_Appname, SDL_Instance);
}
#endif
WIN_CleanRegisterApp(wcex);
}
}

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsvideo.h"

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsvideo.h"
#include "SDL_hints.h"

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#ifdef HAVE_LIMITS_H
#include <limits.h>

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsvideo.h"
#include "../../events/SDL_displayevents_c.h"

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsvideo.h"

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_loadso.h"
#include "SDL_windowsvideo.h"

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL
#if SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsvideo.h"
#include "SDL_windowsopengles.h"

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsshape.h"
#include "SDL_windowsvideo.h"

View File

@@ -65,6 +65,7 @@ UpdateWindowFrameUsableWhileCursorHidden(void *userdata, const char *name, const
}
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static void WIN_SuspendScreenSaver(_THIS)
{
if (_this->suspend_screensaver) {
@@ -73,6 +74,11 @@ static void WIN_SuspendScreenSaver(_THIS)
SetThreadExecutionState(ES_CONTINUOUS);
}
}
#endif
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
extern void D3D12_XBOX_GetResolution(Uint32 *width, Uint32 *height);
#endif
/* Windows driver bootstrap functions */
@@ -83,12 +89,14 @@ WIN_DeleteDevice(SDL_VideoDevice * device)
SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
SDL_UnregisterApp();
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (data->userDLL) {
SDL_UnloadObject(data->userDLL);
}
if (data->shcoreDLL) {
SDL_UnloadObject(data->shcoreDLL);
}
#endif
if (device->wakeup_lock) {
SDL_DestroyMutex(device->wakeup_lock);
}
@@ -119,6 +127,7 @@ WIN_CreateDevice(int devindex)
device->driverdata = data;
device->wakeup_lock = SDL_CreateMutex();
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
data->userDLL = SDL_LoadObject("USER32.DLL");
if (data->userDLL) {
data->CloseTouchInputHandle = (BOOL (WINAPI *)(HTOUCHINPUT)) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle");
@@ -145,19 +154,24 @@ WIN_CreateDevice(int devindex)
} else {
SDL_ClearError();
}
#endif /* #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) */
/* Set the function pointers */
device->VideoInit = WIN_VideoInit;
device->VideoQuit = WIN_VideoQuit;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
device->GetDisplayBounds = WIN_GetDisplayBounds;
device->GetDisplayUsableBounds = WIN_GetDisplayUsableBounds;
device->GetDisplayDPI = WIN_GetDisplayDPI;
device->GetDisplayModes = WIN_GetDisplayModes;
device->SetDisplayMode = WIN_SetDisplayMode;
#endif
device->PumpEvents = WIN_PumpEvents;
device->WaitEventTimeout = WIN_WaitEventTimeout;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
device->SendWakeupEvent = WIN_SendWakeupEvent;
device->SuspendScreenSaver = WIN_SuspendScreenSaver;
#endif
device->CreateSDLWindow = WIN_CreateWindow;
device->CreateSDLWindowFrom = WIN_CreateWindowFrom;
@@ -177,14 +191,17 @@ WIN_CreateDevice(int devindex)
device->SetWindowResizable = WIN_SetWindowResizable;
device->SetWindowAlwaysOnTop = WIN_SetWindowAlwaysOnTop;
device->SetWindowFullscreen = WIN_SetWindowFullscreen;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
device->SetWindowGammaRamp = WIN_SetWindowGammaRamp;
device->GetWindowICCProfile = WIN_GetWindowICCProfile;
device->GetWindowGammaRamp = WIN_GetWindowGammaRamp;
device->SetWindowMouseRect = WIN_SetWindowMouseRect;
device->SetWindowMouseGrab = WIN_SetWindowMouseGrab;
device->SetWindowKeyboardGrab = WIN_SetWindowKeyboardGrab;
#endif
device->DestroyWindow = WIN_DestroyWindow;
device->GetWindowWMInfo = WIN_GetWindowWMInfo;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
device->CreateWindowFramebuffer = WIN_CreateWindowFramebuffer;
device->UpdateWindowFramebuffer = WIN_UpdateWindowFramebuffer;
device->DestroyWindowFramebuffer = WIN_DestroyWindowFramebuffer;
@@ -196,6 +213,7 @@ WIN_CreateDevice(int devindex)
device->shape_driver.CreateShaper = Win32_CreateShaper;
device->shape_driver.SetWindowShape = Win32_SetWindowShape;
device->shape_driver.ResizeWindowShape = Win32_ResizeWindowShape;
#endif
#if SDL_VIDEO_OPENGL_WGL
device->GL_LoadLibrary = WIN_GL_LoadLibrary;
@@ -229,6 +247,7 @@ WIN_CreateDevice(int devindex)
device->Vulkan_GetDrawableSize = WIN_GL_GetDrawableSize;
#endif
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
device->StartTextInput = WIN_StartTextInput;
device->StopTextInput = WIN_StopTextInput;
device->SetTextInputRect = WIN_SetTextInputRect;
@@ -238,6 +257,7 @@ WIN_CreateDevice(int devindex)
device->SetClipboardText = WIN_SetClipboardText;
device->GetClipboardText = WIN_GetClipboardText;
device->HasClipboardText = WIN_HasClipboardText;
#endif
device->free = WIN_DeleteDevice;
@@ -252,6 +272,7 @@ VideoBootStrap WINDOWS_bootstrap = {
static BOOL
WIN_DeclareDPIAwareUnaware(_THIS)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
SDL_VideoData* data = (SDL_VideoData*)_this->driverdata;
if (data->SetProcessDpiAwarenessContext) {
@@ -260,12 +281,14 @@ WIN_DeclareDPIAwareUnaware(_THIS)
/* Windows 8.1 */
return SUCCEEDED(data->SetProcessDpiAwareness(PROCESS_DPI_UNAWARE));
}
#endif
return FALSE;
}
static BOOL
WIN_DeclareDPIAwareSystem(_THIS)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
SDL_VideoData* data = (SDL_VideoData*)_this->driverdata;
if (data->SetProcessDpiAwarenessContext) {
@@ -278,12 +301,14 @@ WIN_DeclareDPIAwareSystem(_THIS)
/* Windows Vista */
return data->SetProcessDPIAware();
}
#endif
return FALSE;
}
static BOOL
WIN_DeclareDPIAwarePerMonitor(_THIS)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
if (data->SetProcessDpiAwarenessContext) {
@@ -296,12 +321,16 @@ WIN_DeclareDPIAwarePerMonitor(_THIS)
/* Older OS: fall back to system DPI aware */
return WIN_DeclareDPIAwareSystem(_this);
}
#endif
return FALSE;
}
static BOOL
WIN_DeclareDPIAwarePerMonitorV2(_THIS)
{
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
return FALSE;
#else
SDL_VideoData* data = (SDL_VideoData*)_this->driverdata;
/* Declare DPI aware (may have been done in external code or a manifest, as well) */
@@ -332,6 +361,7 @@ WIN_DeclareDPIAwarePerMonitorV2(_THIS)
/* Older OS: fall back to per-monitor (or system) */
return WIN_DeclareDPIAwarePerMonitor(_this);
}
#endif
}
#ifdef HIGHDPI_DEBUG
@@ -402,17 +432,38 @@ WIN_VideoInit(_THIS)
SDL_Log("DPI awareness: %s", WIN_GetDPIAwareness(_this));
#endif
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
/* For Xbox, we just need to create the single display */
{
SDL_VideoDisplay display;
SDL_DisplayMode current_mode;
SDL_zero(current_mode);
D3D12_XBOX_GetResolution(&current_mode.w, &current_mode.h);
current_mode.refresh_rate = 60;
current_mode.format = SDL_PIXELFORMAT_ARGB8888;
SDL_zero(display);
display.desktop_mode = current_mode;
display.current_mode = current_mode;
SDL_AddVideoDisplay(&display, SDL_FALSE);
}
#else /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
if (WIN_InitModes(_this) < 0) {
return -1;
}
WIN_InitKeyboard(_this);
WIN_InitMouse(_this);
#endif
SDL_AddHintCallback(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, UpdateWindowsEnableMessageLoop, NULL);
SDL_AddHintCallback(SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, UpdateWindowFrameUsableWhileCursorHidden, NULL);
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
data->_SDL_WAKEUP = RegisterWindowMessageA("_SDL_WAKEUP");
#endif
return 0;
}
@@ -420,12 +471,15 @@ WIN_VideoInit(_THIS)
void
WIN_VideoQuit(_THIS)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
WIN_QuitModes(_this);
WIN_QuitKeyboard(_this);
WIN_QuitMouse(_this);
#endif
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#define D3D_DEBUG_INFO
#include <d3d9.h>
@@ -526,6 +580,7 @@ SDL_Direct3D9GetAdapterIndex(int displayIndex)
return adapterIndex;
}
}
#endif /* !defined(__XBOXONE__) && !defined(__XBOXSERIES__) */
#if HAVE_DXGI_H
#define CINTERFACE
@@ -640,6 +695,7 @@ SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
SDL_bool
WIN_IsPerMonitorV2DPIAware(_THIS)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
SDL_VideoData* data = (SDL_VideoData*) _this->driverdata;
if (data->AreDpiAwarenessContextsEqual && data->GetThreadDpiAwarenessContext) {
@@ -647,6 +703,7 @@ WIN_IsPerMonitorV2DPIAware(_THIS)
return (SDL_bool)data->AreDpiAwarenessContextsEqual(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2,
data->GetThreadDpiAwarenessContext());
}
#endif
return SDL_FALSE;
}

View File

@@ -27,7 +27,7 @@
#include "../SDL_sysvideo.h"
#if defined(_MSC_VER) && (_MSC_VER >= 1500)
#if defined(_MSC_VER) && (_MSC_VER >= 1500) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include <msctf.h>
#else
#include "SDL_msctf.h"
@@ -41,11 +41,15 @@
#include "SDL_windowsclipboard.h"
#include "SDL_windowsevents.h"
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowskeyboard.h"
#include "SDL_windowsmodes.h"
#include "SDL_windowsmouse.h"
#include "SDL_windowsopengl.h"
#include "SDL_windowsopengles.h"
#endif
#include "SDL_windowswindow.h"
#include "SDL_events.h"
#include "SDL_loadso.h"
@@ -330,6 +334,7 @@ typedef struct
void *data;
} TSFSink;
#ifndef SDL_DISABLE_WINDOWS_IME
/* Definition from Win98DDK version of IMM.H */
typedef struct tagINPUTCONTEXT2 {
HWND hWnd;
@@ -353,6 +358,7 @@ typedef struct tagINPUTCONTEXT2 {
DWORD fdwInit;
DWORD dwReserve[3];
} INPUTCONTEXT2, *PINPUTCONTEXT2, NEAR *NPINPUTCONTEXT2, FAR *LPINPUTCONTEXT2;
#endif /* !SDL_DISABLE_WINDOWS_IME */
/* Private display data */
@@ -362,6 +368,7 @@ typedef struct SDL_VideoData
DWORD clipboard_count;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) /* Xbox doesn't support user32/shcore*/
/* Touch input functions */
void* userDLL;
BOOL (WINAPI *CloseTouchInputHandle)( HTOUCHINPUT );
@@ -384,9 +391,11 @@ typedef struct SDL_VideoData
UINT *dpiX,
UINT *dpiY );
HRESULT (WINAPI *SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS dpiAwareness);
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
SDL_bool dpi_scaling_enabled;
#ifndef SDL_DISABLE_WINDOWS_IME
SDL_bool ime_com_initialized;
struct ITfThreadMgr *ime_threadmgr;
SDL_bool ime_initialized;
@@ -435,6 +444,7 @@ typedef struct SDL_VideoData
TSFSink *ime_uielemsink;
TSFSink *ime_ippasink;
LONG ime_uicontext;
#endif /* !SDL_DISABLE_WINDOWS_IME */
BYTE pre_hook_key_state[256];
UINT _SDL_WAKEUP;

View File

@@ -125,8 +125,10 @@ WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x
{
SDL_VideoData* videodata = SDL_GetVideoDevice() ? SDL_GetVideoDevice()->driverdata : NULL;
RECT rect;
int dpi;
int dpi = 96;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
UINT frame_dpi;
#endif
/* Client rect, in SDL screen coordinates */
*x = (use_current ? window->x : window->windowed.x);
@@ -135,7 +137,9 @@ WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x
*height = (use_current ? window->h : window->windowed.h);
/* Convert client rect from SDL coordinates to pixels (no-op if DPI scaling not enabled) */
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
WIN_ScreenPointFromSDL(x, y, &dpi);
#endif
/* Note, use the guessed DPI returned from WIN_ScreenPointFromSDL rather than the cached one in
data->scaling_dpi.
@@ -158,6 +162,9 @@ WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x
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 defined(__XBOXONE__) || defined(__XBOXSERIES__)
AdjustWindowRectEx(&rect, style, menu, 0);
#else
if (WIN_IsPerMonitorV2DPIAware(SDL_GetVideoDevice())) {
/* With per-monitor v2, the window border/titlebar size depend on the DPI, so we need to call AdjustWindowRectExForDpi instead of
AdjustWindowRectEx. */
@@ -180,7 +187,8 @@ WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x
videodata->AdjustWindowRectExForDpi(&rect, style, menu, 0, frame_dpi);
} else {
AdjustWindowRectEx(&rect, style, menu, 0);
}
}
#endif
}
/* Final rect in Windows screen space, including the frame */
@@ -208,7 +216,11 @@ WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height
BOOL menu;
style = GetWindowLong(hwnd, GWL_STYLE);
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
menu = FALSE;
#else
menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
#endif
WIN_AdjustWindowRectWithStyle(window, style, menu, x, y, width, height, use_current);
}
@@ -245,6 +257,9 @@ WIN_MouseRelativeModeCenterChanged(void *userdata, const char *name, const char
static int
WIN_GetScalingDPIForHWND(const SDL_VideoData *videodata, HWND hwnd)
{
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
return 96;
#else
/* DPI scaling not requested? */
if (!videodata->dpi_scaling_enabled) {
return 96;
@@ -277,6 +292,7 @@ WIN_GetScalingDPIForHWND(const SDL_VideoData *videodata, HWND hwnd)
}
return 96;
}
#endif
}
static int
@@ -293,7 +309,9 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre
data->window = window;
data->hwnd = hwnd;
data->parent = parent;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
data->hdc = GetDC(hwnd);
#endif
data->hinstance = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
data->created = created;
data->high_surrogate = 0;
@@ -311,12 +329,14 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre
window->driverdata = data;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Associate the data with the window */
if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
ReleaseDC(hwnd, data->hdc);
SDL_free(data);
return WIN_SetError("SetProp() failed");
}
#endif
/* Set up the window proc function */
#ifdef GWLP_WNDPROC
@@ -357,6 +377,7 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre
}
}
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
{
POINT point;
point.x = 0;
@@ -369,6 +390,7 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre
window->y = y;
}
}
#endif
{
DWORD style = GetWindowLong(hwnd, GWL_STYLE);
if (style & WS_VISIBLE) {
@@ -403,16 +425,22 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre
window->flags &= ~SDL_WINDOW_MINIMIZED;
}
}
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
window->flags |= SDL_WINDOW_INPUT_FOCUS;
#else
if (GetFocus() == hwnd) {
window->flags |= SDL_WINDOW_INPUT_FOCUS;
SDL_SetKeyboardFocus(window);
WIN_UpdateClipCursor(window);
}
#endif
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Enable multi-touch */
if (videodata->RegisterTouchWindow) {
videodata->RegisterTouchWindow(hwnd, (TWF_FINETOUCH|TWF_WANTPALM));
}
#endif
/* Force the SDL_WINDOW_ALLOW_HIGHDPI window flag if we are doing DPI scaling */
if (videodata->dpi_scaling_enabled) {
@@ -432,11 +460,13 @@ static void CleanupWindowData(_THIS, SDL_Window * window)
if (data) {
SDL_DelHintCallback(SDL_HINT_MOUSE_RELATIVE_MODE_CENTER, WIN_MouseRelativeModeCenterChanged, data);
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (data->keyboard_hook) {
UnhookWindowsHookEx(data->keyboard_hook);
}
ReleaseDC(data->hwnd, data->hdc);
RemoveProp(data->hwnd, TEXT("SDL_WindowData"));
#endif
if (data->created) {
DestroyWindow(data->hwnd);
if (data->parent) {
@@ -538,6 +568,9 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
int
WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
{
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
return -1;
#else
HWND hwnd = (HWND) data;
LPTSTR title;
int titleLen;
@@ -589,20 +622,24 @@ WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
}
#endif
return 0;
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
}
void
WIN_SetWindowTitle(_THIS, SDL_Window * window)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
LPTSTR title = WIN_UTF8ToString(window->title);
SetWindowText(hwnd, title);
SDL_free(title);
#endif
}
void
WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
HICON hicon = NULL;
BYTE *icon_bmp;
@@ -654,6 +691,7 @@ WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
/* Set the icon in the task manager (should we do this?) */
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
#endif
}
void
@@ -674,6 +712,21 @@ WIN_SetWindowSize(_THIS, SDL_Window * window)
int
WIN_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right)
{
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
RECT rcClient;
/* rcClient stores the size of the inner window, while rcWindow stores the outer size relative to the top-left
* screen position; so the top/left values of rcClient are always {0,0} and bottom/right are {height,width} */
GetClientRect(hwnd, &rcClient);
*top = rcClient.top;
*left = rcClient.left;
*bottom = rcClient.bottom;
*right = rcClient.right;
return 0;
#else /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
RECT rcClient, rcWindow;
POINT ptDiff;
@@ -712,6 +765,7 @@ WIN_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *b
*right = rcWindow.right - rcClient.right;
return 0;
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
}
void
@@ -740,6 +794,7 @@ WIN_HideWindow(_THIS, SDL_Window * window)
void
WIN_RaiseWindow(_THIS, SDL_Window * window)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* If desired, raise the window more forcefully.
* Technique taken from http://stackoverflow.com/questions/916259/ .
* Specifically, http://stackoverflow.com/a/34414846 .
@@ -772,6 +827,7 @@ WIN_RaiseWindow(_THIS, SDL_Window * window)
SetFocus(hwnd);
SetActiveWindow(hwnd);
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
}
void
@@ -850,6 +906,7 @@ WIN_RestoreWindow(_THIS, SDL_Window * window)
void
WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
HWND hwnd = data->hwnd;
@@ -932,8 +989,11 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
#ifdef HIGHDPI_DEBUG
SDL_Log("WIN_SetWindowFullscreen: %d finished. Set window to %d,%d, %dx%d", (int)fullscreen, x, y, w, h);
#endif
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
int
WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
{
@@ -1063,6 +1123,7 @@ WIN_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
WIN_UngrabKeyboard(window);
}
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
void
WIN_DestroyWindow(_THIS, SDL_Window * window)
@@ -1165,6 +1226,7 @@ SDL_HelperWindowDestroy(void)
}
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
void WIN_OnWindowEnter(_THIS, SDL_Window * window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
@@ -1277,10 +1339,14 @@ WIN_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
{
return 0; /* just succeed, the real work is done elsewhere. */
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
int
WIN_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
{
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
return -1;
#else
const SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
const HWND hwnd = data->hwnd;
const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
@@ -1309,6 +1375,7 @@ WIN_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
}
return 0;
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
}
/**
@@ -1366,6 +1433,7 @@ WIN_ClientPointFromSDL(const SDL_Window *window, int *x, int *y)
*y = MulDiv(*y, data->scaling_dpi, 96);
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
void
WIN_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept)
{
@@ -1400,6 +1468,7 @@ WIN_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation)
return 0;
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
#endif /* SDL_VIDEO_DRIVER_WINDOWS */

View File

@@ -25,6 +25,8 @@
#if SDL_VIDEO_OPENGL_EGL
#include "../SDL_egl_c.h"
#else
#include "../SDL_sysvideo.h"
#endif
/* Set up for C function definitions, even when using C++ */