Skip to content

Commit

Permalink
Update SDL3.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Jul 17, 2024
1 parent d07cb28 commit 5a2599f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
10 changes: 5 additions & 5 deletions application/input/input_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ bool InputTrackerSDL::process_sdl_event(const SDL_Event &e, InputTracker &tracke

void InputTrackerSDL::add_gamepad(SDL_JoystickID id, InputTracker &tracker, const Dispatcher &dispatcher)
{
int player_index = SDL_GetJoystickInstancePlayerIndex(id);
int player_index = SDL_GetJoystickPlayerIndexForID(id);
if (player_index >= 0 && player_index < int(InputTracker::Joypads) && !pads[player_index])
{
uint32_t vid = SDL_GetGamepadInstanceVendor(id);
uint32_t pid = SDL_GetGamepadInstanceProduct(id);
const char *name = SDL_GetGamepadInstanceName(id);
uint32_t vid = SDL_GetGamepadVendorForID(id);
uint32_t pid = SDL_GetGamepadProductForID(id);
const char *name = SDL_GetGamepadNameForID(id);
LOGI("Plugging in controller: \"%s\" (%u/%u).\n", name, vid, pid);
const char *mapping = SDL_GetGamepadInstanceMapping(id);
const char *mapping = SDL_GetGamepadMappingForID(id);
LOGI(" Using mapping: \"%s\"\n", mapping);
pads[player_index] = SDL_OpenGamepad(id);
ids[player_index] = id;
Expand Down
21 changes: 9 additions & 12 deletions application/platforms/application_sdl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ struct WSIPlatformSDL : GraniteWSIPlatform
#ifdef _WIN32
SDL_PropertiesID props = SDL_GetWindowProperties(window);
SDL_LockProperties(props);
auto hwnd = static_cast<HWND>(SDL_GetProperty(props, "SDL.window.win32.hwnd", nullptr));
auto hwnd = static_cast<HWND>(SDL_GetPointerProperty(props, "SDL.window.win32.hwnd", nullptr));
SDL_UnlockProperties(props);
return reinterpret_cast<uintptr_t>(hwnd);
#else
Expand All @@ -287,7 +287,7 @@ struct WSIPlatformSDL : GraniteWSIPlatform
{
SDL_PropertiesID props = SDL_GetWindowProperties(window);
SDL_LockProperties(props);
auto hwnd = static_cast<HWND>(SDL_GetProperty(props, "SDL.window.win32.hwnd", nullptr));
auto hwnd = static_cast<HWND>(SDL_GetPointerProperty(props, "SDL.window.win32.hwnd", nullptr));
SDL_UnlockProperties(props);

push_task_to_async_thread([this, hwnd]() {
Expand Down Expand Up @@ -513,17 +513,17 @@ struct WSIPlatformSDL : GraniteWSIPlatform
else
state = KeyState::Released;

if (state == KeyState::Pressed && e.key.keysym.sym == SDLK_ESCAPE)
if (state == KeyState::Pressed && e.key.key == SDLK_ESCAPE)
{
return false;
}
else if (state == KeyState::Pressed && e.key.keysym.sym == SDLK_RETURN &&
(e.key.keysym.mod & SDL_KMOD_ALT) != 0)
else if (state == KeyState::Pressed && e.key.key == SDLK_RETURN &&
(e.key.mod & SDL_KMOD_ALT) != 0)
{
toggle_fullscreen();
}
else if (state == KeyState::Pressed && tolower(e.key.keysym.sym) == 'v' &&
(e.key.keysym.mod & SDL_KMOD_LCTRL) != 0)
else if (state == KeyState::Pressed && tolower(e.key.key) == 'v' &&
(e.key.mod & SDL_KMOD_LCTRL) != 0)
{
push_non_pollable_task_to_async_thread([c = clipboard]() mutable {
if (auto *manager = GRANITE_EVENT_MANAGER())
Expand All @@ -532,7 +532,7 @@ struct WSIPlatformSDL : GraniteWSIPlatform
}
else
{
Key key = sdl_key_to_granite_key(e.key.keysym.sym);
Key key = sdl_key_to_granite_key(e.key.key);
push_task_to_async_thread([=]() {
get_input_tracker().key_event(key, state);
});
Expand All @@ -558,12 +558,9 @@ struct WSIPlatformSDL : GraniteWSIPlatform
case SDL_EVENT_CLIPBOARD_UPDATE:
if (SDL_HasClipboardText())
{
char *text = SDL_GetClipboardText();
const char *text = SDL_GetClipboardText();
if (text)
{
clipboard = text;
SDL_free(text);
}
else
clipboard.clear();
}
Expand Down
2 changes: 1 addition & 1 deletion third_party/sdl3
Submodule sdl3 updated 716 files

0 comments on commit 5a2599f

Please sign in to comment.