ref: e0331a01741905ac665adce1da0fb04e86db4b05
parent: bbc098c3ee39ed3167d020275bf1df039df8fd41
author: Simon Howard <fraggle@gmail.com>
date: Thu May 15 21:19:14 EDT 2014
setup: Don't leave joystick subsystem running. Only init the joystick subsystem when we need to call the joystick API functions, and quit the subsystem when we are finished. This avoids conflicts with the joystick widgets that quit the subsystem while the main code relies on it running. This fixes a bug where trying to calibrate the joystick twice would fail on the second attempt.
--- a/src/setup/joystick.c
+++ b/src/setup/joystick.c
@@ -361,6 +361,23 @@
LoadConfigurationSet(jstype->configs);
}
+static void InitJoystick(void)
+{
+ if (!joystick_initted)
+ {
+ joystick_initted = SDL_Init(SDL_INIT_JOYSTICK) >= 0;
+ }
+}
+
+static void UnInitJoystick(void)
+{
+ if (joystick_initted)
+ {
+ SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
+ joystick_initted = 0;
+ }
+}
+
// Set the label showing the name of the currently selected joystick
static void SetJoystickButtonLabel(void)
@@ -367,6 +384,8 @@
{
char *name;
+ InitJoystick();
+
name = "None set";
if (joystick_initted
@@ -376,6 +395,8 @@
}
TXT_SetButtonLabel(joystick_button, name);
+
+ UnInitJoystick();
}
// Try to open all joysticks visible to SDL.
@@ -386,10 +407,7 @@
int num_joysticks;
int result;
- if (!joystick_initted)
- {
- return 0;
- }
+ InitJoystick();
// SDL_JoystickOpen() all joysticks.
@@ -447,6 +465,8 @@
free(all_joysticks);
all_joysticks = NULL;
+
+ UnInitJoystick();
}
static void CalibrateXAxis(void)
@@ -544,15 +564,6 @@
// GUI
//
-static void JoystickWindowClosed(TXT_UNCAST_ARG(window), TXT_UNCAST_ARG(unused))
-{
- if (joystick_initted)
- {
- SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
- joystick_initted = 0;
- }
-}
-
static void AddJoystickControl(txt_table_t *table, char *label, int *var)
{
txt_joystick_input_t *joy_input;
@@ -569,11 +580,6 @@
txt_table_t *button_table, *axis_table;
txt_table_t *joystick_table;
- if (!joystick_initted)
- {
- joystick_initted = SDL_Init(SDL_INIT_JOYSTICK) >= 0;
- }
-
window = TXT_NewWindow("Gamepad/Joystick configuration");
TXT_AddWidgets(window,
@@ -639,8 +645,6 @@
AddJoystickControl(button_table, "Activate menu", &joybmenu);
TXT_SignalConnect(joystick_button, "pressed", CalibrateJoystick, NULL);
- TXT_SignalConnect(window, "closed", JoystickWindowClosed, NULL);
-
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, TestConfigAction());
SetJoystickButtonLabel();