Repository navigation
SDL3 migration, Phase 2: event loop restructuring - #269
Merged
Merged
Conversation
Ports she/sdl3/{she.cpp,sdl3_display,sdl3_surface} for window/renderer/
surface creation & teardown, pixel-format API renames, and the SDL2->SDL3
return-code convention flip. Event loop and tablet/WM-info code remain
TODO(#73) stubs, deferred to later migration phases.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Ports she/sdl3/she.cpp's SDL_PollEvent translation, keycode tables, and set_input_rect()/SDL_EventState from the SDL2 backend: ~25 event-constant renames (SDL_WINDOWEVENT flattened into top-level SDL_EVENT_WINDOW_*, SDL_MOUSEMOTION/BUTTON/WHEEL -> SDL_EVENT_MOUSE_*, SDL_KEYDOWN/UP -> SDL_EVENT_KEY_*, SDL_DROPFILE -> SDL_EVENT_DROP_FILE, ...), ~64 SDLK_a..z -> SDLK_A..Z renames, and float mouse/wheel coordinates cast back to she::Event's int gfx::Point. Also fixes three real bugs flagged for this phase rather than just renaming them: - Drops the SDL_free(drop.file) call: SDL3's drop.data is owned by SDL and freed with the event, so keeping it was a double free on every drag-and-drop. - Sets SDL_HINT_KEYCODE_OPTIONS=unmodified before SDL_Init so Shift/Ctrl+ Shift shortcuts keep working (SDL3 otherwise reports e.g. SDLK_EXCLAIM for Shift+1, which isn't in keyCodeMapping and was silently dropped). - Resets pressed-modifier state on SDL_EVENT_WINDOW_FOCUS_LOST, fixing stuck Ctrl/Alt after Alt-Tab (also present in the SDL2 backend). SDL_SYSWMEVENT and tablet/WM-info handling (EasyTab, nativeHandle()) have no SDL3 event equivalent reachable from here and remain a separate migration phase; adds a public SDL3Display::window() accessor needed by the ported set_input_rect()/SDL_StartTextInput() calls. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of #73. Closes #262. Stacked on #268 (Phase 1) — base branch is
nidrax/sdl3-phase1-core-port, nottrunk, so the diff here is just the event-loop work; will re-targettrunkonce #268 merges.Ports
SDL2EventQueue::getEventInternal's ~17-case outer event switch (plus the nested 15-caseSDL_WINDOWEVENTswitch, now flattened into top-levelSDL_EVENT_WINDOW_*cases), the keycode/modifier tables,set_input_rect, andSDL_EventStatefrom the SDL2 backend intoshe/sdl3/she.cpp.Mechanical renames: ~25 event-constant renames, ~64
SDLK_a..z→SDLK_A..Z, 10 field-access changes (keysym.sym/keysym.scancode→key.key/key.scancode,drop.file→drop.data, ...), 7 signature changes (SDL_StartTextInput/SDL_StopTextInput/SDL_SetTextInputAreanow take anSDL_Window*— added a publicSDL3Display::window()accessor for this).Three real bugs fixed, not just renamed (as flagged in the issue):
SDL_free(drop.file)call — SDL3'sdrop.datais owned by SDL and freed with the event, so keeping it was a double free on every drag-and-drop.SDL_SetHint(SDL_HINT_KEYCODE_OPTIONS, "unmodified")beforeSDL_Init— SDL3 otherwise applies Shift/Caps Lock to the reported keycode (e.g. Shift+1 →SDLK_EXCLAIM, not inkeyCodeMapping), silently dropping Shift/Ctrl+Shift shortcuts.floatmouse/wheel coordinates back tointexplicitly where they're stored inshe::Event'sgfx::Point— SDL2 had these as ints, so the old brace-init would otherwise be a narrowing-conversion compile error.Also fixed while touching this code (per the issue's "worth fixing" note): pressed-modifier state is now reset on
SDL_EVENT_WINDOW_FOCUS_LOST, so Ctrl/Alt no longer gets stuck after Alt-Tab (this bug also exists in the SDL2 backend, left alone there).New SDL3 event types with no SDL2 equivalent (window enter/leave-fullscreen, occlusion, HDR/ICC/display-scale changes, display hotplug, mouse/keyboard hotplug, clipboard update, drop begin/complete/position) are silently swallowed via range checks (
SDL_EVENT_WINDOW_FIRST..LAST,SDL_EVENT_DISPLAY_FIRST..LAST) plus a few explicit cases, so they don't flood the "Unknown event" log.Out of scope, per the issue's boundaries:
SDL_SYSWMEVENThas no SDL3 equivalent reachable from this file (removed outright; replaced bySDL_SetWindowsMessageHook/SDL_SetX11EventHook), so tablet/WM-info handling (EasyTab,nativeHandle()) remains a separate phase — nothing here depends on it.Test plan
cmake -DUSE_SDL2_BACKEND=off -DUSE_SDL3_BACKEND=onbuilds clean.bin/bespritedunder a boundedtimeout: window/renderer/theme load as before, and — unlike Phase 1, where the process neededSIGKILLbecause there was no event loop to observe anything — the process now exits cleanly within the timeout with zero "Unknown event" spam in the log.🤖 Generated with Claude Code