From af25970c09659ce2ff3c628ec02890030714c72d Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 25 Jun 2018 00:30:07 +0200 Subject: [PATCH] Fix Joystick support (with SDL and SDL2) --- src/global.h | 5 ----- src/input.c | 8 ++++---- src/main.c | 9 +++++++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/global.h b/src/global.h index 56ec4657..d943213c 100644 --- a/src/global.h +++ b/src/global.h @@ -777,11 +777,6 @@ GFX2_GLOBAL iconv_t cd_utf16; // FROMCODE => UTF16 GFX2_GLOBAL iconv_t cd_utf16_inv; // UTF16 => FROMCODE #endif /* ENABLE_FILENAMES_ICONV */ -// -- Specific to SDL - -/// Pointer to the current joystick controller. -//GFX2_GLOBAL SDL_Joystick* Joystick; - /// Indicates "no keyboard shortcut". #define KEY_NONE 0 diff --git a/src/input.c b/src/input.c index b65c6830..05eef473 100644 --- a/src/input.c +++ b/src/input.c @@ -618,8 +618,8 @@ int Handle_key_release(SDL_KeyboardEvent event) // Joystick management -#if defined(USE_SDL) || defined(USE_SDL2) -int Handle_joystick_press(SDL_JoyButtonEvent event) +#if defined(USE_JOYSTICK) && (defined(USE_SDL) || defined(USE_SDL2)) +static int Handle_joystick_press(SDL_JoyButtonEvent event) { if (event.button == Joybutton_shift) { @@ -721,7 +721,7 @@ int Handle_joystick_press(SDL_JoyButtonEvent event) return Move_cursor_with_constraints(); } -int Handle_joystick_release(SDL_JoyButtonEvent event) +static int Handle_joystick_release(SDL_JoyButtonEvent event) { if (event.button == Joybutton_shift) { @@ -802,7 +802,7 @@ int Handle_joystick_release(SDL_JoyButtonEvent event) return Move_cursor_with_constraints(); } -void Handle_joystick_movement(SDL_JoyAxisEvent event) +static void Handle_joystick_movement(SDL_JoyAxisEvent event) { if (event.axis==JOYSTICK_AXIS_X) { diff --git a/src/main.c b/src/main.c index 8425b929..845f7be4 100644 --- a/src/main.c +++ b/src/main.c @@ -105,6 +105,11 @@ extern char Program_version[]; // generated in pversion.c static int setsize_width; static int setsize_height; +#if defined(USE_SDL) || defined(USE_SDL2) +/// Pointer to the current joystick controller. +static SDL_Joystick* Joystick; +#endif + //--- Affichage de la syntaxe, et de la liste des modes vidéos disponibles --- void Display_syntax(void) { @@ -651,9 +656,9 @@ int Init_program(int argc,char * argv[]) printf("Couldn't initialize SDL.\n"); return(0); } -#endif - //Joystick = SDL_JoystickOpen(0); + Joystick = SDL_JoystickOpen(0); +#endif #if defined(USE_SDL) SDL_EnableKeyRepeat(250, 32); SDL_EnableUNICODE(SDL_ENABLE);