Skip to content

SDL3 migration, Phase 2: event loop restructuring - #269

Merged
Nidrax merged 3 commits into
trunkfrom
nidrax/sdl3-phase2-event-loop
Sep 26, 2026
Merged

Nidrax merged 3 commits into
trunkfrom
nidrax/sdl3-phase2-event-loop

Conversation

@Nidrax

@Nidrax Nidrax commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Part of #73. Closes #262. Stacked on #268 (Phase 1) — base branch is nidrax/sdl3-phase1-core-port, not trunk, so the diff here is just the event-loop work; will re-target trunk once #268 merges.

Ports SDL2EventQueue::getEventInternal's ~17-case outer event switch (plus the nested 15-case SDL_WINDOWEVENT switch, now flattened into top-level SDL_EVENT_WINDOW_* cases), the keycode/modifier tables, set_input_rect, and SDL_EventState from the SDL2 backend into she/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_SetTextInputArea now take an SDL_Window* — added a public SDL3Display::window() accessor for this).

Three real bugs fixed, not just renamed (as flagged in the issue):

  1. Dropped 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.
  2. SDL_SetHint(SDL_HINT_KEYCODE_OPTIONS, "unmodified") before SDL_Init — SDL3 otherwise applies Shift/Caps Lock to the reported keycode (e.g. Shift+1 → SDLK_EXCLAIM, not in keyCodeMapping), silently dropping Shift/Ctrl+Shift shortcuts.
  3. Cast the now-float mouse/wheel coordinates back to int explicitly where they're stored in she::Event's gfx::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_SYSWMEVENT has no SDL3 equivalent reachable from this file (removed outright; replaced by SDL_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=on builds clean.
  • Launched bin/besprited under a bounded timeout: window/renderer/theme load as before, and — unlike Phase 1, where the process needed SIGKILL because there was no event loop to observe anything — the process now exits cleanly within the timeout with zero "Unknown event" spam in the log.
  • Manual mouse/keyboard/drag-and-drop interaction — not exercised in this sandboxed session (no way to drive real input events here); worth a manual pass before merge.

🤖 Generated with Claude Code

Nidrax and others added 2 commits September 25, 2026 01:40
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>
Base automatically changed from nidrax/sdl3-phase1-core-port to trunk September 26, 2026 10:59
@Nidrax
Nidrax merged commit 856a1bc into trunk Sep 26, 2026
17 checks passed
@Nidrax
Nidrax deleted the nidrax/sdl3-phase2-event-loop branch September 26, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDL3 migration, Phase 2: event loop restructuring

1 participant