diff --git a/allegro5.cfg b/allegro5.cfg index f87bd92f1..233a39ffb 100644 --- a/allegro5.cfg +++ b/allegro5.cfg @@ -252,3 +252,7 @@ automatic_menu_display_resize = true # to a graphical application. This may be undesirable for console applications. Set # this to false to disable this behavior. osx_tell_dock_outside_bundle = true + +# To restore behavior of older code versions, specify this number to the +# Allegro version that had the old behavior. +# joystick_version = 5.2.9 diff --git a/include/allegro5/internal/aintern_system.h b/include/allegro5/internal/aintern_system.h index 01d6a36f4..90f4756d6 100644 --- a/include/allegro5/internal/aintern_system.h +++ b/include/allegro5/internal/aintern_system.h @@ -72,6 +72,7 @@ AL_VAR(_AL_DTOR_LIST *, _al_dtor_list); AL_FUNC(void *, _al_open_library, (const char *filename)); AL_FUNC(void *, _al_import_symbol, (void *library, const char *symbol)); AL_FUNC(void, _al_close_library, (void *library)); +AL_FUNC(uint32_t, _al_get_joystick_compat_version, (void)); #ifdef __cplusplus } diff --git a/src/joynu.c b/src/joynu.c index ef3ced8db..5c95d8c4c 100644 --- a/src/joynu.c +++ b/src/joynu.c @@ -299,6 +299,23 @@ void al_get_joystick_state(ALLEGRO_JOYSTICK *joy, ALLEGRO_JOYSTICK_STATE *ret_st new_joystick_driver->get_joystick_state(joy, ret_state); } +#include +uint32_t _al_get_joystick_compat_version(void) +{ + ALLEGRO_CONFIG *system_config = al_get_system_config(); + const char* compat_version = al_get_config_value(system_config, "compatibility", "joystick_version"); + if (!compat_version) + return al_get_allegro_version(); + /* 4 2 digit numbers + 3 dot separators */ + if (strlen(compat_version) > 4 * 2 + 3) + return al_get_allegro_version(); + int version = 0; + int sub_version = 0; + int wip_version = 0; + /* Ignore the release number, we don't expect that to make a difference */ + sscanf(compat_version, "%d.%d.%d", &version, &sub_version, &wip_version); + return AL_ID(version, sub_version, wip_version, 0); +} /* * Local Variables: diff --git a/src/macosx/hidjoy.m b/src/macosx/hidjoy.m index 3b7eeafe1..d14737ca3 100644 --- a/src/macosx/hidjoy.m +++ b/src/macosx/hidjoy.m @@ -189,6 +189,7 @@ static void add_elements(CFArrayRef elements, ALLEGRO_JOYSTICK_OSX *joy) char default_name[100]; int stick_class = -1; int axis_index = 0; + bool old_style = _al_get_joystick_compat_version() < AL_ID(5, 2, 10, 0); joy_null(joy); @@ -199,15 +200,25 @@ static void add_elements(CFArrayRef elements, ALLEGRO_JOYSTICK_OSX *joy) ); int usage = IOHIDElementGetUsage(elem); + int usage_page = IOHIDElementGetUsagePage(elem); if (IOHIDElementGetType(elem) == kIOHIDElementTypeInput_Button) { - if (usage >= 0 && usage < _AL_MAX_JOYSTICK_BUTTONS && - !joy->buttons[usage-1]) { - joy->buttons[usage-1] = elem; - sprintf(default_name, "Button %d", usage-1); + int idx; + if (old_style) + idx = usage - 1; + else { + idx = joy->parent.info.num_buttons; + // 0x09 is the Button Page. + if (usage_page != 0x09) + continue; + } + if (idx >= 0 && idx < _AL_MAX_JOYSTICK_BUTTONS && + !joy->buttons[idx]) { + joy->buttons[idx] = elem; + sprintf(default_name, "Button %d", idx); const char *name = get_element_name(elem, default_name); char *str = al_malloc(strlen(name)+1); strcpy(str, name); - joy->parent.info.button[usage-1].name = str; + joy->parent.info.button[idx].name = str; joy->parent.info.num_buttons++; } }