Skip to content

Commit

Permalink
Reintroduced SDL changes for new kbd API. (#100)
Browse files Browse the repository at this point in the history
* Update SDL to use new KBD API.
  • Loading branch information
gyrovorbis authored Mar 1, 2025
1 parent b0d0423 commit 5c5613b
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions SDL/files/SDL_dcevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
[email protected]
Modified by Lawrence Sebald <[email protected]>
Modified by Falco Girgis <[email protected]>
*/

#include "SDL.h"
Expand All @@ -33,9 +34,7 @@
#include "SDL_dcvideo.h"
#include "SDL_dcevents_c.h"

#include <dc/maple.h>
#include <dc/maple/mouse.h>
#include <dc/maple/keyboard.h>
#include <kos.h>

const static unsigned short sdl_key[]= {
/*0*/ 0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
Expand Down Expand Up @@ -101,7 +100,11 @@ static void mouse_update(void) {
}

static void keyboard_update(void) {
#if KOS_VERSION_BELOW(2, 2, 0)
static kbd_state_t old_state;
#else
static kbd_mods_t old_mods;
#endif
kbd_state_t *state;
maple_device_t *dev;
int shiftkeys;
Expand All @@ -116,6 +119,7 @@ static void keyboard_update(void) {
if(!state)
return;

#if KOS_VERSION_BELOW(2, 2, 0)
shiftkeys = state->shift_keys ^ old_state.shift_keys;
for(i = 0; i < sizeof(sdl_shift); ++i) {
if((shiftkeys >> i) & 1) {
Expand All @@ -137,6 +141,28 @@ static void keyboard_update(void) {
}

old_state = *state;

#else /* KOS 2.2.0+ */
shiftkeys = state->modifiers.raw ^ old_mods.raw;
for(i = 0; i < sizeof(sdl_shift)/sizeof(sdl_shift[0]); ++i) {
if((shiftkeys >> i) & 1) {
keysym.sym = sdl_shift[i];
SDL_PrivateKeyboard(((state->modifiers.raw >> i) & 1) ?
SDL_PRESSED : SDL_RELEASED, &keysym);
}
}

for(i = 0; i < sizeof(sdl_key)/sizeof(sdl_key[0]); ++i) {
int key = sdl_key[i];
keysym.sym = key;

if(state->key_states[i].value == KEY_STATE_CHANGED_DOWN) {
SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
} else if(state->key_states[i].value == KEY_STATE_CHANGED_UP) {
SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
}
}
#endif
}

void DC_PumpEvents(_THIS) {
Expand All @@ -145,4 +171,4 @@ void DC_PumpEvents(_THIS) {
}

void DC_InitOSKeymap(_THIS) {
}
}

0 comments on commit 5c5613b

Please sign in to comment.