mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-12 01:53:04 +08:00
Added support for raw mouse and keyboard using GameInput on Windows
Fixes https://github.com/libsdl-org/SDL/issues/10442
This commit is contained in:
@@ -573,6 +573,7 @@
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsevents.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsframebuffer.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowskeyboard.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsgameinput.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsmessagebox.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsmodes.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsmouse.h" />
|
||||
@@ -850,6 +851,7 @@
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsevents.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsframebuffer.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowskeyboard.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsgameinput.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsmessagebox.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsmodes.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsmouse.c" />
|
||||
|
||||
@@ -217,6 +217,7 @@
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsevents.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsframebuffer.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowskeyboard.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsgameinput.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsmessagebox.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsmodes.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsmouse.c" />
|
||||
@@ -447,6 +448,7 @@
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsevents.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsframebuffer.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowskeyboard.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsgameinput.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsmessagebox.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsmodes.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsmouse.h" />
|
||||
|
||||
@@ -479,6 +479,7 @@
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsevents.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsframebuffer.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowskeyboard.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsgameinput.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsmessagebox.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsmodes.h" />
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsmouse.h" />
|
||||
@@ -708,6 +709,7 @@
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsevents.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsframebuffer.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowskeyboard.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsgameinput.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsmessagebox.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsmodes.c" />
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsmouse.c" />
|
||||
|
||||
@@ -684,6 +684,9 @@
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowskeyboard.h">
|
||||
<Filter>video\windows</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsgameinput.h">
|
||||
<Filter>video\windows</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\video\windows\SDL_windowsmessagebox.h">
|
||||
<Filter>video\windows</Filter>
|
||||
</ClInclude>
|
||||
@@ -1340,6 +1343,9 @@
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowskeyboard.c">
|
||||
<Filter>video\windows</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsgameinput.c">
|
||||
<Filter>video\windows</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\video\windows\SDL_windowsmessagebox.c">
|
||||
<Filter>video\windows</Filter>
|
||||
</ClCompile>
|
||||
|
||||
@@ -3823,6 +3823,20 @@ extern "C" {
|
||||
*/
|
||||
#define SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP "SDL_WINDOWS_ENABLE_MESSAGELOOP"
|
||||
|
||||
/**
|
||||
* A variable controlling whether GameInput is used for raw keyboard and mouse on Windows.
|
||||
*
|
||||
* The variable can be set to the following values:
|
||||
*
|
||||
* - "0": GameInput is not used for raw keyboard and mouse events.
|
||||
* - "1": GameInput is used for raw keyboard and mouse events, if available. (default)
|
||||
*
|
||||
* This hint should be set before SDL is initialized.
|
||||
*
|
||||
* \since This hint is available since SDL 3.0.0.
|
||||
*/
|
||||
#define SDL_HINT_WINDOWS_GAMEINPUT "SDL_WINDOWS_GAMEINPUT"
|
||||
|
||||
/**
|
||||
* A variable controlling whether raw keyboard events are used on Windows.
|
||||
*
|
||||
|
||||
@@ -2233,6 +2233,10 @@ void WIN_PumpEvents(SDL_VideoDevice *_this)
|
||||
SDL_Window *focusWindow;
|
||||
#endif
|
||||
|
||||
if (_this->internal->gameinput_context) {
|
||||
WIN_UpdateGameInput(_this);
|
||||
}
|
||||
|
||||
if (g_WindowsEnableMessageLoop) {
|
||||
SDL_processing_messages = SDL_TRUE;
|
||||
|
||||
@@ -2310,7 +2314,9 @@ void WIN_PumpEvents(SDL_VideoDevice *_this)
|
||||
/* Update mouse capture */
|
||||
WIN_UpdateMouseCapture();
|
||||
|
||||
WIN_CheckKeyboardAndMouseHotplug(_this, SDL_FALSE);
|
||||
if (!_this->internal->gameinput_context) {
|
||||
WIN_CheckKeyboardAndMouseHotplug(_this, SDL_FALSE);
|
||||
}
|
||||
|
||||
WIN_UpdateIMECandidates(_this);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2024 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
typedef struct WIN_GameInputData WIN_GameInputData;
|
||||
|
||||
extern int WIN_InitGameInput(SDL_VideoDevice *_this);
|
||||
extern int WIN_UpdateGameInputEnabled(SDL_VideoDevice *_this);
|
||||
extern void WIN_UpdateGameInput(SDL_VideoDevice *_this);
|
||||
extern void WIN_QuitGameInput(SDL_VideoDevice *_this);
|
||||
|
||||
@@ -203,14 +203,36 @@ int WIN_SetRawMouseEnabled(SDL_VideoDevice *_this, SDL_bool enabled)
|
||||
{
|
||||
SDL_VideoData *data = _this->internal;
|
||||
data->raw_mouse_enabled = enabled;
|
||||
return WIN_UpdateRawInputEnabled(_this);
|
||||
if (data->gameinput_context) {
|
||||
if (WIN_UpdateGameInputEnabled(_this) < 0) {
|
||||
data->raw_mouse_enabled = !enabled;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (WIN_UpdateRawInputEnabled(_this) < 0) {
|
||||
data->raw_mouse_enabled = !enabled;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WIN_SetRawKeyboardEnabled(SDL_VideoDevice *_this, SDL_bool enabled)
|
||||
{
|
||||
SDL_VideoData *data = _this->internal;
|
||||
data->raw_keyboard_enabled = enabled;
|
||||
return WIN_UpdateRawInputEnabled(_this);
|
||||
if (data->gameinput_context) {
|
||||
if (WIN_UpdateGameInputEnabled(_this) < 0) {
|
||||
data->raw_keyboard_enabled = !enabled;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (WIN_UpdateRawInputEnabled(_this) < 0) {
|
||||
data->raw_keyboard_enabled = !enabled;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -491,6 +491,10 @@ int WIN_VideoInit(SDL_VideoDevice *_this)
|
||||
SDL_Log("DPI awareness: %s", WIN_GetDPIAwareness(_this));
|
||||
#endif
|
||||
|
||||
if (SDL_GetHintBoolean(SDL_HINT_WINDOWS_GAMEINPUT, SDL_TRUE)) {
|
||||
WIN_InitGameInput(_this);
|
||||
}
|
||||
|
||||
#if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
|
||||
/* For Xbox, we just need to create the single display */
|
||||
{
|
||||
@@ -511,7 +515,9 @@ int WIN_VideoInit(SDL_VideoDevice *_this)
|
||||
WIN_InitKeyboard(_this);
|
||||
WIN_InitMouse(_this);
|
||||
WIN_InitDeviceNotification();
|
||||
WIN_CheckKeyboardAndMouseHotplug(_this, SDL_TRUE);
|
||||
if (!_this->internal->gameinput_context) {
|
||||
WIN_CheckKeyboardAndMouseHotplug(_this, SDL_TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_AddHintCallback(SDL_HINT_WINDOWS_RAW_KEYBOARD, UpdateWindowsRawKeyboard, _this);
|
||||
@@ -530,13 +536,6 @@ void WIN_VideoQuit(SDL_VideoDevice *_this)
|
||||
{
|
||||
SDL_VideoData *data = _this->internal;
|
||||
|
||||
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
|
||||
WIN_QuitModes(_this);
|
||||
WIN_QuitDeviceNotification();
|
||||
WIN_QuitKeyboard(_this);
|
||||
WIN_QuitMouse(_this);
|
||||
#endif
|
||||
|
||||
SDL_DelHintCallback(SDL_HINT_WINDOWS_RAW_KEYBOARD, UpdateWindowsRawKeyboard, _this);
|
||||
SDL_DelHintCallback(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, UpdateWindowsEnableMessageLoop, NULL);
|
||||
SDL_DelHintCallback(SDL_HINT_WINDOWS_ENABLE_MENU_MNEMONICS, UpdateWindowsEnableMenuMnemonics, NULL);
|
||||
@@ -544,13 +543,20 @@ void WIN_VideoQuit(SDL_VideoDevice *_this)
|
||||
|
||||
WIN_SetRawMouseEnabled(_this, SDL_FALSE);
|
||||
WIN_SetRawKeyboardEnabled(_this, SDL_FALSE);
|
||||
WIN_QuitGameInput(_this);
|
||||
|
||||
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
|
||||
WIN_QuitModes(_this);
|
||||
WIN_QuitDeviceNotification();
|
||||
WIN_QuitKeyboard(_this);
|
||||
WIN_QuitMouse(_this);
|
||||
|
||||
#if !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES))
|
||||
if (data->oleinitialized) {
|
||||
OleUninitialize();
|
||||
data->oleinitialized = SDL_FALSE;
|
||||
}
|
||||
#endif /* !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)) */
|
||||
|
||||
if (data->coinitialized) {
|
||||
WIN_CoUninitialize();
|
||||
data->coinitialized = SDL_FALSE;
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
|
||||
#include "SDL_windowsclipboard.h"
|
||||
#include "SDL_windowsevents.h"
|
||||
#include "SDL_windowsgameinput.h"
|
||||
#include "SDL_windowsopengl.h"
|
||||
|
||||
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
|
||||
@@ -437,6 +438,8 @@ struct SDL_VideoData
|
||||
SDL_bool pending_E1_key_sequence;
|
||||
Uint32 raw_input_enabled;
|
||||
|
||||
WIN_GameInputData *gameinput_context;
|
||||
|
||||
#ifndef SDL_DISABLE_WINDOWS_IME
|
||||
SDL_bool ime_initialized;
|
||||
SDL_bool ime_enabled;
|
||||
|
||||
Reference in New Issue
Block a user