WIP: SDL Keyboard and Mouse support#296
Conversation
|
Could you explain a bit about the benefits of this approach vs. existing DirectInput? I am most certainly not opposed to improvements, however unless I am mistaken, this would this remove the stock software input method in its entirety? That is an approach that certainly comes with drawbacks. For instance, although DirectInput is better in virtually every way, there are still many people who use the stock input method to this day because they're used to and prefer it. |
There was a problem hiding this comment.
Pull request overview
This PR replaces the game’s DirectInput-based mouse path with SDL3 mouse input, removing the DirectInput toggle/settings/UI and wiring SDL init/polling into the main OS/game loops.
Changes:
- Removed DirectInput headers, runtime state, config serialization, and the “DirectInput” UI/console toggle.
- Added SDL3 initialization/teardown and per-frame SDL mouse polling.
- Hooked mouse delta retrieval to feed SDL relative motion and enabled SDL relative mouse mode when “keep centered” is active.
Reviewed changes
Copilot reviewed 9 out of 99 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| game_patch/rf/input.h | Removes DirectInput includes and DirectInput-related memory refs. |
| game_patch/os/os.cpp | Initializes SDL, polls SDL mouse each frame, and quits SDL on shutdown. |
| game_patch/misc/ui.cpp | Removes DirectInput checkbox and reflows panel controls. |
| game_patch/misc/alpine_settings.h | Removes persisted direct_input setting. |
| game_patch/misc/alpine_settings.cpp | Stops loading/saving the DirectInput config key. |
| game_patch/main/main.cpp | Creates the SDL window wrapper after RF init. |
| game_patch/input/mouse.cpp | Implements SDL relative motion accumulation + hooks into RF mouse delta flow. |
| game_patch/input/input.h | Exposes SDL mouse init/poll functions. |
| game_patch/CMakeLists.txt | Links SDL3 static target and additional Windows system libs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
also prepares for GooberRF#296
basically: consolidation. no need for two different Input APIs when you can have one that does it for you, and more future-proof. SDL is meant to be a hardware abstraction layer that does alot of things, it does Inputs so it'll use the best Input API available for the OS in question, and this applies to game controllers. as far as I can tell: SDL Mouse on Windows will use Raw Input (or Win32 WM_MOUSE?). As far as I can tell: overall Mouse Input performance on my own trackball should behave the same regardless. that being said, I've restored the ability to switch to stock input. |
while getting mouse hover to work
upgrade portions of the keyboard handler with SDL.
There was a problem hiding this comment.
Pull request overview
This PR migrates core mouse + keyboard input handling from DirectInput/Win32 message processing to an SDL3-driven polling approach, and adds SDL3 as a vendored FetchContent dependency (plus a new UI/config toggle to switch SDL mouse vs “stock” mouse input).
Changes:
- Add SDL3 (FetchContent) to the build and link AlpineFaction against
SDL3::SDL3-static, plus required Win32 libs for static SDL. - Introduce a central SDL event pump (
sdl_input_poll) and wire it into the OS poll loop; implement SDL-based mouse delta and keyboard event feeding into RF. - Replace the old “DirectInput” config/UI toggle with an “SDL mouse” toggle and persist it as
SDLMousein the config.
Reviewed changes
Copilot reviewed 12 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| vendor/sdl/LICENSE.txt | Adds SDL license text for the new SDL dependency. |
| vendor/sdl/CMakeLists.txt | FetchContent setup to build SDL3 from source (static). |
| vendor/CMakeLists.txt | Includes the new vendor/sdl subdirectory. |
| resources/licensing-info.txt | Adds SDL license block to licensing info aggregation. |
| game_patch/rf/input.h | Removes DirectInput-specific globals/includes from RF input header. |
| game_patch/os/os.cpp | Initializes SDL, polls SDL input during OS polling, and switches cursor show/hide to SDL helpers. |
| game_patch/misc/ui.cpp | Renames the options checkbox from DirectInput to SDL mouse and hooks toggle to SDL mouse enable/disable. |
| game_patch/misc/alpine_settings.h | Replaces direct_input config flag with sdl_mouse. |
| game_patch/misc/alpine_settings.cpp | Loads/saves the new SDLMouse config key instead of DirectInput. |
| game_patch/main/main.cpp | Creates the SDL window wrapper after RF init via mouse_init_sdl_window(). |
| game_patch/input/mouse.cpp | Implements SDL mouse deltas + relative mode integration; provides toggle and hooks. |
| game_patch/input/key.cpp | Implements SDL keyboard polling and replaces Win32 keyboard message forwarding with SDL-fed events. |
| game_patch/input/input.h | Declares SDL input polling and initialization helpers. |
| game_patch/input/input.cpp | Adds central SDL event pumping function used by OS poll hook. |
| game_patch/CMakeLists.txt | Adds input/input.cpp and links SDL3 static (plus extra Win32 libs). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
SDL Keyboard has been officially added into it. with that, i felt that it's complete enough for a full review. that being said, i did have to do last-minute timer fixes but i'm not too sure if the master branch is going to break it due to side effects |
the camera will no longer speen when disabling SDL Mouse
also swaps SDL3::SDL3-static with a simple SDL3::SDL3
added experimental support for On-Screen Keyboard across all Input Modes. Right now: it only applies if a game detects there's no keyboard attached, or using Steam Deck
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
…lling Co-authored-by: Copilot <copilot@github.com>
| // Sentinel scan code injected into Input Rebind UI, allowing additional input bindings. | ||
| static constexpr int CTRL_REBIND_SENTINEL = 0x58; // KEY_F12 | ||
|
|
||
| // Extra keyboard scan codes not in RF's original DInput table. | ||
| // Placed after CTRL_EXTRA_MOUSE_SCAN (0x75–0x79), before RF extended keys (0x9C+). | ||
| static constexpr int CTRL_EXTRA_KEY_SCAN_BASE = 0x7A; | ||
| static constexpr int CTRL_EXTRA_KEY_SCAN_COUNT = 14; |
| void os_init_sdl_window() | ||
| { | ||
| // Deferred after D3D device creation so SDL's hidden helper window does not | ||
| // interfere with exclusive fullscreen acquisition. | ||
| os_init_sdl_video(); | ||
|
|
||
| SDL_PropertiesID props = SDL_CreateProperties(); | ||
| SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_WIN32_HWND_POINTER, rf::main_wnd); | ||
| g_sdl_window = SDL_CreateWindowWithProperties(props); | ||
| SDL_DestroyProperties(props); | ||
| if (!g_sdl_window) { | ||
| xlog::error("SDL_CreateWindowWithProperties failed: {}", SDL_GetError()); | ||
| return; |
| case KEY_RAPOSTRO: return SDL_SCANCODE_APOSTROPHE; | ||
| case KEY_LAPOSTRO_DBG: return SDL_SCANCODE_GRAVE; | ||
| case KEY_LSHIFT: return SDL_SCANCODE_LSHIFT; | ||
| case KEY_SLASH: return SDL_SCANCODE_BACKSLASH; | ||
| case KEY_Z: return SDL_SCANCODE_Z; | ||
| case KEY_X: return SDL_SCANCODE_X; | ||
| case KEY_C: return SDL_SCANCODE_C; | ||
| case KEY_V: return SDL_SCANCODE_V; | ||
| case KEY_B: return SDL_SCANCODE_B; | ||
| case KEY_N: return SDL_SCANCODE_N; | ||
| case KEY_M: return SDL_SCANCODE_M; | ||
| case KEY_COMMA: return SDL_SCANCODE_COMMA; | ||
| case KEY_PERIOD: return SDL_SCANCODE_PERIOD; | ||
| case KEY_DIVIDE: return SDL_SCANCODE_SLASH; | ||
| case KEY_RSHIFT: return SDL_SCANCODE_RSHIFT; |
|
i will be putting this on hold for the time being due to an issue with how Exclusive Window handles it. Instead: I'll make a separate PR that focus on adding additional mouse input presses and Alt keys. |
This commit repurposes DirectInput mode with a Input Handling system, allowing introduction to SDL's Keyboard and Mouse Input systems alongside minor (accidental) improvements to the Windowing Management.
SDL also allow us to adds support for additional keybinds, including Mouse 3/4 buttons.
For those who prefer either the Legacy handling and/or it's DirectInput Mouse mode: you can always swap it back. (Note: SDL Cursor is always in use for Main Menu navigation regardless of Input handles)
optionally: this PR is best merged alongside #295 for the smoothest transition