Skip to content

Commit 853b3d6

Browse files
authored
ogc: add env variable to support Wiimote held sideways (#60)
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.
1 parent cf19790 commit 853b3d6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/joystick/ogc/SDL_sysjoystick.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ static bool s_hardware_queried = false;
193193
#ifdef __wii__
194194
static bool s_wii_has_new_data[MAX_WII_JOYSTICKS];
195195
static bool s_accelerometers_as_axes = false;
196+
static bool s_wiimote_sideways = false;
196197

197198
static void SDLCALL
198199
on_hint_accel_as_joystick_cb(void *userdata, const char *name,
@@ -325,6 +326,12 @@ static int OGC_JoystickInit(void)
325326
#ifdef __wii__
326327
SDL_AddHintCallback(SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
327328
on_hint_accel_as_joystick_cb, NULL);
329+
/* If this is set, the Wiimote directional keys will be translated. */
330+
{
331+
const char *sideways_joystick_env = getenv("SDL_WII_JOYSTICK_SIDEWAYS");
332+
s_wiimote_sideways =
333+
sideways_joystick_env && strcmp(sideways_joystick_env, "1") == 0;
334+
}
328335
#endif
329336

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

739746
if (pressed & buttons[0])
740-
hat |= SDL_HAT_UP;
747+
hat |= s_wiimote_sideways ? SDL_HAT_LEFT : SDL_HAT_UP;
741748
if (pressed & buttons[1])
742-
hat |= SDL_HAT_DOWN;
749+
hat |= s_wiimote_sideways ? SDL_HAT_RIGHT : SDL_HAT_DOWN;
743750
if (pressed & buttons[2])
744-
hat |= SDL_HAT_LEFT;
751+
hat |= s_wiimote_sideways ? SDL_HAT_DOWN : SDL_HAT_LEFT;
745752
if (pressed & buttons[3])
746-
hat |= SDL_HAT_RIGHT;
753+
hat |= s_wiimote_sideways ? SDL_HAT_UP : SDL_HAT_RIGHT;
747754
SDL_PrivateJoystickHat(joystick, 0, hat);
748755
}
749756
}

0 commit comments

Comments
 (0)