Skip to content

Commit

Permalink
ogc: add env variable to support Wiimote held sideways (#60)
Browse files Browse the repository at this point in the history
Applications using the SDL GameController API can easily reconfigure the
gamepad keys, but the lower-level Joystick APIs does not offer the same
option. To make life easier for applications using the plain Joystick
API, add an environment variable that automatically remaps the
directional keys to match a Wiimote held sideways.

This avoid complicating the application's input code.
  • Loading branch information
mardy authored Mar 10, 2024
1 parent cf19790 commit 853b3d6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/joystick/ogc/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ static bool s_hardware_queried = false;
#ifdef __wii__
static bool s_wii_has_new_data[MAX_WII_JOYSTICKS];
static bool s_accelerometers_as_axes = false;
static bool s_wiimote_sideways = false;

static void SDLCALL
on_hint_accel_as_joystick_cb(void *userdata, const char *name,
Expand Down Expand Up @@ -325,6 +326,12 @@ static int OGC_JoystickInit(void)
#ifdef __wii__
SDL_AddHintCallback(SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
on_hint_accel_as_joystick_cb, NULL);
/* If this is set, the Wiimote directional keys will be translated. */
{
const char *sideways_joystick_env = getenv("SDL_WII_JOYSTICK_SIDEWAYS");
s_wiimote_sideways =
sideways_joystick_env && strcmp(sideways_joystick_env, "1") == 0;
}
#endif

/* Initialize the needed variables */
Expand Down Expand Up @@ -737,13 +744,13 @@ static void HandleWiiHats(SDL_Joystick *joystick,
int hat = SDL_HAT_CENTERED;

if (pressed & buttons[0])
hat |= SDL_HAT_UP;
hat |= s_wiimote_sideways ? SDL_HAT_LEFT : SDL_HAT_UP;
if (pressed & buttons[1])
hat |= SDL_HAT_DOWN;
hat |= s_wiimote_sideways ? SDL_HAT_RIGHT : SDL_HAT_DOWN;
if (pressed & buttons[2])
hat |= SDL_HAT_LEFT;
hat |= s_wiimote_sideways ? SDL_HAT_DOWN : SDL_HAT_LEFT;
if (pressed & buttons[3])
hat |= SDL_HAT_RIGHT;
hat |= s_wiimote_sideways ? SDL_HAT_UP : SDL_HAT_RIGHT;
SDL_PrivateJoystickHat(joystick, 0, hat);
}
}
Expand Down

0 comments on commit 853b3d6

Please sign in to comment.