From 1d4d895b4cd74cc50874d26f21b0fedf2a3d5b5d Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 11 Dec 2012 11:07:48 -0500 Subject: [PATCH] Removed old Linux joystick API (/dev/js*). The newer API (/dev/input/event/*) is 12+ years old at this point, and has been available since Linux 2.4. --- CMakeLists.txt | 11 +- configure.in | 5 - src/joystick/linux/SDL_sysjoystick.c | 217 ++------------------------- 3 files changed, 18 insertions(+), 215 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c31f52f7..80389d100 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,7 +205,6 @@ dep_option(ARTS_SHARED "Dynamically load aRts audio support" ON "ARTS" O set_option(NAS "Support the NAS audio API" ${UNIX_SYS}) set_option(RPATH "Use an rpath when linking SDL" ${UNIX_SYS}) set_option(CLOCK_GETTIME "Use clock_gettime() instead of gettimeofday()" OFF) -set_option(INPUT_EVENTS "Use Linux 2.4 unified input interface" ${LINUX}) set_option(INPUT_TSLIB "Use the Touchscreen library for input" ${UNIX_SYS}) set_option(VIDEO_X11 "Use X11 video driver" ${UNIX_SYS}) dep_option(X11_SHARED "Dynamically load X11 support" ON "VIDEO_X11" OFF) @@ -632,7 +631,7 @@ if(UNIX AND NOT APPLE) CheckOpenGLESX11() endif(SDL_VIDEO) - if(INPUT_EVENTS) + if(LINUX) check_c_source_compiles(" #include #ifndef EVIOCGNAME @@ -642,16 +641,14 @@ if(UNIX AND NOT APPLE) if(HAVE_INPUT_EVENTS) set(SDL_INPUT_LINUXEV 1) endif(HAVE_INPUT_EVENTS) - endif(INPUT_EVENTS) - if(SDL_HAPTIC AND HAVE_INPUT_EVENTS) - if(LINUX) + if(SDL_HAPTIC AND HAVE_INPUT_EVENTS) set(SDL_HAPTIC_LINUX 1) file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c) set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES}) set(HAVE_SDL_HAPTIC TRUE) - endif(LINUX) - endif(SDL_HAPTIC AND HAVE_INPUT_EVENTS) + endif(SDL_HAPTIC AND HAVE_INPUT_EVENTS) + endif(LINUX if(INPUT_TSLIB) check_c_source_compiles(" diff --git a/configure.in b/configure.in index 39da8624a..b7f974df5 100644 --- a/configure.in +++ b/configure.in @@ -1650,10 +1650,6 @@ dnl See if we can use the new unified event interface in Linux 2.4 CheckInputEvents() { dnl Check for Linux 2.4 unified input event interface support - AC_ARG_ENABLE(input-events, -AC_HELP_STRING([--enable-input-events], [use Linux 2.4 unified input interface [[default=yes]]]), - , enable_input_events=yes) - if test x$enable_input_events = xyes; then AC_MSG_CHECKING(for Linux 2.4 unified input interface) use_input_events=no AC_TRY_COMPILE([ @@ -1669,7 +1665,6 @@ AC_HELP_STRING([--enable-input-events], [use Linux 2.4 unified input interface [ if test x$use_input_events = xyes; then AC_DEFINE(SDL_INPUT_LINUXEV, 1, [ ]) fi - fi } dnl See if we can use the Touchscreen input library diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index b4ba68658..938d1d6d7 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -22,6 +22,10 @@ #ifdef SDL_JOYSTICK_LINUX +#ifndef SDL_INPUT_LINUXEV +#error SDL now requires a Linux 2.4+ kernel with /dev/input/event support. +#endif + /* This is the system specific header for the SDL joystick API */ #include @@ -36,29 +40,6 @@ #include "../SDL_joystick_c.h" #include "SDL_sysjoystick_c.h" -/* Special joystick configurations */ -static struct -{ - const char *name; - int naxes; - int nhats; - int nballs; -} special_joysticks[] = { - { - "MadCatz Panther XL", 3, 2, 1}, /* We don't handle rudder (axis 8) */ - { - "SideWinder Precision Pro", 4, 1, 0}, { - "SideWinder 3D Pro", 4, 1, 0}, { - "Microsoft SideWinder 3D Pro", 4, 1, 0}, { - "Microsoft SideWinder Precision Pro", 4, 1, 0}, { - "Microsoft SideWinder Dual Strike USB version 1.0", 2, 1, 0}, { - "WingMan Interceptor", 3, 3, 0}, { - "WingMan Extreme Digital 3D", 4, 1, 0}, { - "Microsoft SideWinder Precision 2 Joystick", 4, 1, 0}, { - "Logitech Inc. WingMan Extreme Digital 3D", 4, 1, 0}, { - "Saitek Saitek X45", 6, 1, 0} -}; - /* The maximum number of joysticks we'll detect */ #define MAX_JOYSTICKS 32 @@ -69,13 +50,12 @@ static struct } SDL_joylist[MAX_JOYSTICKS]; -#if SDL_INPUT_LINUXEV #define test_bit(nr, addr) \ (((1UL << ((nr) % (sizeof(long) * 8))) & ((addr)[(nr) / (sizeof(long) * 8)])) != 0) #define NBITS(x) ((((x)-1)/(sizeof(long) * 8))+1) static int -EV_IsJoystick(int fd) +IsJoystick(int fd) { unsigned long evbit[NBITS(EV_MAX)] = { 0 }; unsigned long keybit[NBITS(KEY_MAX)] = { 0 }; @@ -94,7 +74,6 @@ EV_IsJoystick(int fd) return (1); } -#endif /* SDL_INPUT_LINUXEV */ static int SDL_SYS_numjoysticks = 0; @@ -104,11 +83,7 @@ SDL_SYS_JoystickInit(void) { /* The base path of the joystick devices */ const char *joydev_pattern[] = { -#if SDL_INPUT_LINUXEV "/dev/input/event%d", -#endif - "/dev/input/js%d", - "/dev/js%d" }; int numjoysticks; int i, j; @@ -173,15 +148,13 @@ SDL_SYS_JoystickInit(void) if (fd < 0) { continue; } -#if SDL_INPUT_LINUXEV #ifdef DEBUG_INPUT_EVENTS printf("Checking %s\n", path); #endif - if ((i == 0) && !EV_IsJoystick(fd)) { + if ((i == 0) && !IsJoystick(fd)) { close(fd); continue; } -#endif close(fd); /* We're fine, add this joystick */ @@ -193,7 +166,6 @@ SDL_SYS_JoystickInit(void) } } -#if SDL_INPUT_LINUXEV /* This is a special case... If the event devices are valid then the joystick devices will be duplicates but without extra information about their @@ -203,7 +175,6 @@ SDL_SYS_JoystickInit(void) */ if ((i == 0) && (numjoysticks > 0)) break; -#endif } SDL_SYS_numjoysticks = numjoysticks; @@ -235,11 +206,7 @@ SDL_SYS_JoystickNameForDeviceIndex(int device_index) name = NULL; fd = open(SDL_joylist[device_index].fname, O_RDONLY, 0); if (fd >= 0) { - if ( -#if SDL_INPUT_LINUXEV - (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) && -#endif - (ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) <= 0)) { + if (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) { name = SDL_joylist[device_index].fname; } else { name = namebuf; @@ -291,100 +258,8 @@ allocate_balldata(SDL_Joystick * joystick) return (0); } -static SDL_bool -JS_ConfigJoystick(SDL_Joystick * joystick, int fd) -{ - SDL_bool handled; - unsigned char n; - int tmp_naxes, tmp_nhats, tmp_nballs; - const char *name; - char *env, env_name[128]; - int i; - - handled = SDL_FALSE; - - /* Default joystick device settings */ - if (ioctl(fd, JSIOCGAXES, &n) < 0) { - joystick->naxes = 2; - } else { - joystick->naxes = n; - } - if (ioctl(fd, JSIOCGBUTTONS, &n) < 0) { - joystick->nbuttons = 2; - } else { - joystick->nbuttons = n; - } - - name = SDL_SYS_JoystickNameForDeviceIndex(joystick->instance_id); - - /* Generic analog joystick support */ - if (SDL_strstr(name, "Analog") == name && SDL_strstr(name, "-hat")) { - if (SDL_sscanf(name, "Analog %d-axis %*d-button %d-hat", - &tmp_naxes, &tmp_nhats) == 2) { - - joystick->naxes = tmp_naxes; - joystick->nhats = tmp_nhats; - - handled = SDL_TRUE; - } - } - - /* Special joystick support */ - for (i = 0; i < SDL_arraysize(special_joysticks); ++i) { - if (SDL_strcmp(name, special_joysticks[i].name) == 0) { - - joystick->naxes = special_joysticks[i].naxes; - joystick->nhats = special_joysticks[i].nhats; - joystick->nballs = special_joysticks[i].nballs; - - handled = SDL_TRUE; - break; - } - } - - /* User environment joystick support */ - if ((env = SDL_getenv("SDL_LINUX_JOYSTICK"))) { - *env_name = '\0'; - if (*env == '\'' && SDL_sscanf(env, "'%[^']s'", env_name) == 1) - env += SDL_strlen(env_name) + 2; - else if (SDL_sscanf(env, "%s", env_name) == 1) - env += SDL_strlen(env_name); - - if (SDL_strcmp(name, env_name) == 0) { - - if (SDL_sscanf(env, "%d %d %d", &tmp_naxes, &tmp_nhats, - &tmp_nballs) == 3) { - - joystick->naxes = tmp_naxes; - joystick->nhats = tmp_nhats; - joystick->nballs = tmp_nballs; - - handled = SDL_TRUE; - } - } - } - - /* Remap hats and balls */ - if (handled) { - if (joystick->nhats > 0) { - if (allocate_hatdata(joystick) < 0) { - joystick->nhats = 0; - } - } - if (joystick->nballs > 0) { - if (allocate_balldata(joystick) < 0) { - joystick->nballs = 0; - } - } - } - - return (handled); -} - -#if SDL_INPUT_LINUXEV - -static SDL_bool -EV_ConfigJoystick(SDL_Joystick * joystick, int fd) +static void +ConfigJoystick(SDL_Joystick * joystick, int fd) { int i, t; unsigned long keybit[NBITS(KEY_MAX)] = { 0 }; @@ -395,7 +270,6 @@ EV_ConfigJoystick(SDL_Joystick * joystick, int fd) if ((ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) && (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) && (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 0)) { - joystick->hwdata->is_hid = SDL_TRUE; /* Get the number of buttons, axes, and other thingamajigs */ for (i = BTN_JOYSTICK; i < KEY_MAX; ++i) { @@ -477,11 +351,8 @@ EV_ConfigJoystick(SDL_Joystick * joystick, int fd) } } } - return (joystick->hwdata->is_hid); } -#endif /* SDL_INPUT_LINUXEV */ - /* Function to open a joystick for use. The joystick to open is specified by the index field of the joystick. @@ -518,10 +389,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) fcntl(fd, F_SETFL, O_NONBLOCK); /* Get the number of buttons and axes on the joystick */ -#if SDL_INPUT_LINUXEV - if (!EV_ConfigJoystick(joystick, fd)) -#endif - JS_ConfigJoystick(joystick, fd); + ConfigJoystick(joystick, fd); return (0); } @@ -564,60 +432,9 @@ HandleBall(SDL_Joystick * stick, Uint8 ball, int axis, int value) stick->hwdata->balls[ball].axis[axis] += value; } -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ -static __inline__ void -JS_HandleEvents(SDL_Joystick * joystick) -{ - struct js_event events[32]; - int i, len; - Uint8 other_axis; - - while ((len = read(joystick->hwdata->fd, events, (sizeof events))) > 0) { - len /= sizeof(events[0]); - for (i = 0; i < len; ++i) { - switch (events[i].type & ~JS_EVENT_INIT) { - case JS_EVENT_AXIS: - if (events[i].number < joystick->naxes) { - SDL_PrivateJoystickAxis(joystick, - events[i].number, - events[i].value); - break; - } - events[i].number -= joystick->naxes; - other_axis = (events[i].number / 2); - if (other_axis < joystick->nhats) { - HandleHat(joystick, other_axis, - events[i].number % 2, events[i].value); - break; - } - events[i].number -= joystick->nhats * 2; - other_axis = (events[i].number / 2); - if (other_axis < joystick->nballs) { - HandleBall(joystick, other_axis, - events[i].number % 2, events[i].value); - break; - } - break; - case JS_EVENT_BUTTON: - SDL_PrivateJoystickButton(joystick, - events[i].number, - events[i].value); - break; - default: - /* ?? */ - break; - } - } - } -} -#if SDL_INPUT_LINUXEV static __inline__ int -EV_AxisCorrect(SDL_Joystick * joystick, int which, int value) +AxisCorrect(SDL_Joystick * joystick, int which, int value) { struct axis_correct *correct; @@ -645,7 +462,7 @@ EV_AxisCorrect(SDL_Joystick * joystick, int which, int value) } static __inline__ void -EV_HandleEvents(SDL_Joystick * joystick) +HandleInputEvents(SDL_Joystick * joystick) { struct input_event events[32]; int i, len; @@ -683,7 +500,7 @@ EV_HandleEvents(SDL_Joystick * joystick) break; default: events[i].value = - EV_AxisCorrect(joystick, code, events[i].value); + AxisCorrect(joystick, code, events[i].value); SDL_PrivateJoystickAxis(joystick, joystick->hwdata->abs_map[code], events[i].value); @@ -707,19 +524,13 @@ EV_HandleEvents(SDL_Joystick * joystick) } } } -#endif /* SDL_INPUT_LINUXEV */ void SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) { int i; -#if SDL_INPUT_LINUXEV - if (joystick->hwdata->is_hid) - EV_HandleEvents(joystick); - else -#endif - JS_HandleEvents(joystick); + HandleInputEvents(joystick); /* Deliver ball motion updates */ for (i = 0; i < joystick->nballs; ++i) {