Removed old Linux joystick API (/dev/js*).
authorRyan C. Gordon <icculus@icculus.org>
Tue, 11 Dec 2012 11:07:48 -0500
changeset 6729fdaeea9e7567
parent 6728 0f8336c1f6d9
child 6730 36158e4061f4
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
configure.in
src/joystick/linux/SDL_sysjoystick.c
     1.1 --- a/CMakeLists.txt	Mon Dec 10 15:50:42 2012 -0500
     1.2 +++ b/CMakeLists.txt	Tue Dec 11 11:07:48 2012 -0500
     1.3 @@ -205,7 +205,6 @@
     1.4  set_option(NAS                 "Support the NAS audio API" ${UNIX_SYS})
     1.5  set_option(RPATH               "Use an rpath when linking SDL" ${UNIX_SYS})
     1.6  set_option(CLOCK_GETTIME       "Use clock_gettime() instead of gettimeofday()" OFF)
     1.7 -set_option(INPUT_EVENTS        "Use Linux 2.4 unified input interface" ${LINUX})
     1.8  set_option(INPUT_TSLIB         "Use the Touchscreen library for input" ${UNIX_SYS})
     1.9  set_option(VIDEO_X11           "Use X11 video driver" ${UNIX_SYS})
    1.10  dep_option(X11_SHARED          "Dynamically load X11 support" ON "VIDEO_X11" OFF)
    1.11 @@ -632,7 +631,7 @@
    1.12      CheckOpenGLESX11()
    1.13    endif(SDL_VIDEO)
    1.14  
    1.15 -  if(INPUT_EVENTS)
    1.16 +  if(LINUX)
    1.17      check_c_source_compiles("
    1.18          #include <linux/input.h>
    1.19          #ifndef EVIOCGNAME
    1.20 @@ -642,16 +641,14 @@
    1.21      if(HAVE_INPUT_EVENTS)
    1.22        set(SDL_INPUT_LINUXEV 1)
    1.23      endif(HAVE_INPUT_EVENTS)
    1.24 -  endif(INPUT_EVENTS)
    1.25  
    1.26 -  if(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
    1.27 -    if(LINUX)
    1.28 +    if(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
    1.29        set(SDL_HAPTIC_LINUX 1)
    1.30        file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c)
    1.31        set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
    1.32        set(HAVE_SDL_HAPTIC TRUE)
    1.33 -    endif(LINUX)
    1.34 -  endif(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
    1.35 +    endif(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
    1.36 +  endif(LINUX
    1.37  
    1.38    if(INPUT_TSLIB)
    1.39      check_c_source_compiles("
     2.1 --- a/configure.in	Mon Dec 10 15:50:42 2012 -0500
     2.2 +++ b/configure.in	Tue Dec 11 11:07:48 2012 -0500
     2.3 @@ -1650,10 +1650,6 @@
     2.4  CheckInputEvents()
     2.5  {
     2.6      dnl Check for Linux 2.4 unified input event interface support
     2.7 -    AC_ARG_ENABLE(input-events,
     2.8 -AC_HELP_STRING([--enable-input-events], [use Linux 2.4 unified input interface [[default=yes]]]),
     2.9 -                  , enable_input_events=yes)
    2.10 -    if test x$enable_input_events = xyes; then
    2.11          AC_MSG_CHECKING(for Linux 2.4 unified input interface)
    2.12          use_input_events=no
    2.13          AC_TRY_COMPILE([
    2.14 @@ -1669,7 +1665,6 @@
    2.15          if test x$use_input_events = xyes; then
    2.16              AC_DEFINE(SDL_INPUT_LINUXEV, 1, [ ])
    2.17          fi
    2.18 -    fi
    2.19  }
    2.20  
    2.21  dnl See if we can use the Touchscreen input library
     3.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Mon Dec 10 15:50:42 2012 -0500
     3.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Tue Dec 11 11:07:48 2012 -0500
     3.3 @@ -22,6 +22,10 @@
     3.4  
     3.5  #ifdef SDL_JOYSTICK_LINUX
     3.6  
     3.7 +#ifndef SDL_INPUT_LINUXEV
     3.8 +#error SDL now requires a Linux 2.4+ kernel with /dev/input/event support.
     3.9 +#endif
    3.10 +
    3.11  /* This is the system specific header for the SDL joystick API */
    3.12  
    3.13  #include <sys/stat.h>
    3.14 @@ -36,29 +40,6 @@
    3.15  #include "../SDL_joystick_c.h"
    3.16  #include "SDL_sysjoystick_c.h"
    3.17  
    3.18 -/* Special joystick configurations */
    3.19 -static struct
    3.20 -{
    3.21 -    const char *name;
    3.22 -    int naxes;
    3.23 -    int nhats;
    3.24 -    int nballs;
    3.25 -} special_joysticks[] = {
    3.26 -    {
    3.27 -    "MadCatz Panther XL", 3, 2, 1},     /* We don't handle rudder (axis 8) */
    3.28 -    {
    3.29 -    "SideWinder Precision Pro", 4, 1, 0}, {
    3.30 -    "SideWinder 3D Pro", 4, 1, 0}, {
    3.31 -    "Microsoft SideWinder 3D Pro", 4, 1, 0}, {
    3.32 -    "Microsoft SideWinder Precision Pro", 4, 1, 0}, {
    3.33 -    "Microsoft SideWinder Dual Strike USB version 1.0", 2, 1, 0}, {
    3.34 -    "WingMan Interceptor", 3, 3, 0}, {
    3.35 -    "WingMan Extreme Digital 3D", 4, 1, 0}, {
    3.36 -    "Microsoft SideWinder Precision 2 Joystick", 4, 1, 0}, {
    3.37 -    "Logitech Inc. WingMan Extreme Digital 3D", 4, 1, 0}, {
    3.38 -    "Saitek Saitek X45", 6, 1, 0}
    3.39 -};
    3.40 -
    3.41  /* The maximum number of joysticks we'll detect */
    3.42  #define MAX_JOYSTICKS	32
    3.43  
    3.44 @@ -69,13 +50,12 @@
    3.45  } SDL_joylist[MAX_JOYSTICKS];
    3.46  
    3.47  
    3.48 -#if SDL_INPUT_LINUXEV
    3.49  #define test_bit(nr, addr) \
    3.50  	(((1UL << ((nr) % (sizeof(long) * 8))) & ((addr)[(nr) / (sizeof(long) * 8)])) != 0)
    3.51  #define NBITS(x) ((((x)-1)/(sizeof(long) * 8))+1)
    3.52  
    3.53  static int
    3.54 -EV_IsJoystick(int fd)
    3.55 +IsJoystick(int fd)
    3.56  {
    3.57      unsigned long evbit[NBITS(EV_MAX)] = { 0 };
    3.58      unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
    3.59 @@ -94,7 +74,6 @@
    3.60      return (1);
    3.61  }
    3.62  
    3.63 -#endif /* SDL_INPUT_LINUXEV */
    3.64  
    3.65  static int SDL_SYS_numjoysticks = 0;
    3.66  
    3.67 @@ -104,11 +83,7 @@
    3.68  {
    3.69      /* The base path of the joystick devices */
    3.70      const char *joydev_pattern[] = {
    3.71 -#if SDL_INPUT_LINUXEV
    3.72          "/dev/input/event%d",
    3.73 -#endif
    3.74 -        "/dev/input/js%d",
    3.75 -        "/dev/js%d"
    3.76      };
    3.77      int numjoysticks;
    3.78      int i, j;
    3.79 @@ -173,15 +148,13 @@
    3.80                  if (fd < 0) {
    3.81                      continue;
    3.82                  }
    3.83 -#if SDL_INPUT_LINUXEV
    3.84  #ifdef DEBUG_INPUT_EVENTS
    3.85                  printf("Checking %s\n", path);
    3.86  #endif
    3.87 -                if ((i == 0) && !EV_IsJoystick(fd)) {
    3.88 +                if ((i == 0) && !IsJoystick(fd)) {
    3.89                      close(fd);
    3.90                      continue;
    3.91                  }
    3.92 -#endif
    3.93                  close(fd);
    3.94  
    3.95                  /* We're fine, add this joystick */
    3.96 @@ -193,7 +166,6 @@
    3.97              }
    3.98          }
    3.99  
   3.100 -#if SDL_INPUT_LINUXEV
   3.101          /* This is a special case...
   3.102             If the event devices are valid then the joystick devices
   3.103             will be duplicates but without extra information about their
   3.104 @@ -203,7 +175,6 @@
   3.105           */
   3.106          if ((i == 0) && (numjoysticks > 0))
   3.107              break;
   3.108 -#endif
   3.109      }
   3.110  
   3.111      SDL_SYS_numjoysticks = numjoysticks;
   3.112 @@ -235,11 +206,7 @@
   3.113      name = NULL;
   3.114      fd = open(SDL_joylist[device_index].fname, O_RDONLY, 0);
   3.115      if (fd >= 0) {
   3.116 -        if (
   3.117 -#if SDL_INPUT_LINUXEV
   3.118 -               (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) &&
   3.119 -#endif
   3.120 -               (ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) <= 0)) {
   3.121 +        if (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) {
   3.122              name = SDL_joylist[device_index].fname;
   3.123          } else {
   3.124              name = namebuf;
   3.125 @@ -291,100 +258,8 @@
   3.126      return (0);
   3.127  }
   3.128  
   3.129 -static SDL_bool
   3.130 -JS_ConfigJoystick(SDL_Joystick * joystick, int fd)
   3.131 -{
   3.132 -    SDL_bool handled;
   3.133 -    unsigned char n;
   3.134 -    int tmp_naxes, tmp_nhats, tmp_nballs;
   3.135 -    const char *name;
   3.136 -    char *env, env_name[128];
   3.137 -    int i;
   3.138 -
   3.139 -    handled = SDL_FALSE;
   3.140 -
   3.141 -    /* Default joystick device settings */
   3.142 -    if (ioctl(fd, JSIOCGAXES, &n) < 0) {
   3.143 -        joystick->naxes = 2;
   3.144 -    } else {
   3.145 -        joystick->naxes = n;
   3.146 -    }
   3.147 -    if (ioctl(fd, JSIOCGBUTTONS, &n) < 0) {
   3.148 -        joystick->nbuttons = 2;
   3.149 -    } else {
   3.150 -        joystick->nbuttons = n;
   3.151 -    }
   3.152 -
   3.153 -    name = SDL_SYS_JoystickNameForDeviceIndex(joystick->instance_id);
   3.154 -
   3.155 -    /* Generic analog joystick support */
   3.156 -    if (SDL_strstr(name, "Analog") == name && SDL_strstr(name, "-hat")) {
   3.157 -        if (SDL_sscanf(name, "Analog %d-axis %*d-button %d-hat",
   3.158 -                       &tmp_naxes, &tmp_nhats) == 2) {
   3.159 -
   3.160 -            joystick->naxes = tmp_naxes;
   3.161 -            joystick->nhats = tmp_nhats;
   3.162 -
   3.163 -            handled = SDL_TRUE;
   3.164 -        }
   3.165 -    }
   3.166 -
   3.167 -    /* Special joystick support */
   3.168 -    for (i = 0; i < SDL_arraysize(special_joysticks); ++i) {
   3.169 -        if (SDL_strcmp(name, special_joysticks[i].name) == 0) {
   3.170 -
   3.171 -            joystick->naxes = special_joysticks[i].naxes;
   3.172 -            joystick->nhats = special_joysticks[i].nhats;
   3.173 -            joystick->nballs = special_joysticks[i].nballs;
   3.174 -
   3.175 -            handled = SDL_TRUE;
   3.176 -            break;
   3.177 -        }
   3.178 -    }
   3.179 -
   3.180 -    /* User environment joystick support */
   3.181 -    if ((env = SDL_getenv("SDL_LINUX_JOYSTICK"))) {
   3.182 -        *env_name = '\0';
   3.183 -        if (*env == '\'' && SDL_sscanf(env, "'%[^']s'", env_name) == 1)
   3.184 -            env += SDL_strlen(env_name) + 2;
   3.185 -        else if (SDL_sscanf(env, "%s", env_name) == 1)
   3.186 -            env += SDL_strlen(env_name);
   3.187 -
   3.188 -        if (SDL_strcmp(name, env_name) == 0) {
   3.189 -
   3.190 -            if (SDL_sscanf(env, "%d %d %d", &tmp_naxes, &tmp_nhats,
   3.191 -                           &tmp_nballs) == 3) {
   3.192 -
   3.193 -                joystick->naxes = tmp_naxes;
   3.194 -                joystick->nhats = tmp_nhats;
   3.195 -                joystick->nballs = tmp_nballs;
   3.196 -
   3.197 -                handled = SDL_TRUE;
   3.198 -            }
   3.199 -        }
   3.200 -    }
   3.201 -
   3.202 -    /* Remap hats and balls */
   3.203 -    if (handled) {
   3.204 -        if (joystick->nhats > 0) {
   3.205 -            if (allocate_hatdata(joystick) < 0) {
   3.206 -                joystick->nhats = 0;
   3.207 -            }
   3.208 -        }
   3.209 -        if (joystick->nballs > 0) {
   3.210 -            if (allocate_balldata(joystick) < 0) {
   3.211 -                joystick->nballs = 0;
   3.212 -            }
   3.213 -        }
   3.214 -    }
   3.215 -
   3.216 -    return (handled);
   3.217 -}
   3.218 -
   3.219 -#if SDL_INPUT_LINUXEV
   3.220 -
   3.221 -static SDL_bool
   3.222 -EV_ConfigJoystick(SDL_Joystick * joystick, int fd)
   3.223 +static void
   3.224 +ConfigJoystick(SDL_Joystick * joystick, int fd)
   3.225  {
   3.226      int i, t;
   3.227      unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
   3.228 @@ -395,7 +270,6 @@
   3.229      if ((ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) &&
   3.230          (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) &&
   3.231          (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 0)) {
   3.232 -        joystick->hwdata->is_hid = SDL_TRUE;
   3.233  
   3.234          /* Get the number of buttons, axes, and other thingamajigs */
   3.235          for (i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
   3.236 @@ -477,11 +351,8 @@
   3.237              }
   3.238          }
   3.239      }
   3.240 -    return (joystick->hwdata->is_hid);
   3.241  }
   3.242  
   3.243 -#endif /* SDL_INPUT_LINUXEV */
   3.244 -
   3.245  
   3.246  /* Function to open a joystick for use.
   3.247     The joystick to open is specified by the index field of the joystick.
   3.248 @@ -518,10 +389,7 @@
   3.249      fcntl(fd, F_SETFL, O_NONBLOCK);
   3.250  
   3.251      /* Get the number of buttons and axes on the joystick */
   3.252 -#if SDL_INPUT_LINUXEV
   3.253 -    if (!EV_ConfigJoystick(joystick, fd))
   3.254 -#endif
   3.255 -        JS_ConfigJoystick(joystick, fd);
   3.256 +    ConfigJoystick(joystick, fd);
   3.257  
   3.258      return (0);
   3.259  }
   3.260 @@ -564,60 +432,9 @@
   3.261      stick->hwdata->balls[ball].axis[axis] += value;
   3.262  }
   3.263  
   3.264 -/* Function to update the state of a joystick - called as a device poll.
   3.265 - * This function shouldn't update the joystick structure directly,
   3.266 - * but instead should call SDL_PrivateJoystick*() to deliver events
   3.267 - * and update joystick device state.
   3.268 - */
   3.269 -static __inline__ void
   3.270 -JS_HandleEvents(SDL_Joystick * joystick)
   3.271 -{
   3.272 -    struct js_event events[32];
   3.273 -    int i, len;
   3.274 -    Uint8 other_axis;
   3.275  
   3.276 -    while ((len = read(joystick->hwdata->fd, events, (sizeof events))) > 0) {
   3.277 -        len /= sizeof(events[0]);
   3.278 -        for (i = 0; i < len; ++i) {
   3.279 -            switch (events[i].type & ~JS_EVENT_INIT) {
   3.280 -            case JS_EVENT_AXIS:
   3.281 -                if (events[i].number < joystick->naxes) {
   3.282 -                    SDL_PrivateJoystickAxis(joystick,
   3.283 -                                            events[i].number,
   3.284 -                                            events[i].value);
   3.285 -                    break;
   3.286 -                }
   3.287 -                events[i].number -= joystick->naxes;
   3.288 -                other_axis = (events[i].number / 2);
   3.289 -                if (other_axis < joystick->nhats) {
   3.290 -                    HandleHat(joystick, other_axis,
   3.291 -                              events[i].number % 2, events[i].value);
   3.292 -                    break;
   3.293 -                }
   3.294 -                events[i].number -= joystick->nhats * 2;
   3.295 -                other_axis = (events[i].number / 2);
   3.296 -                if (other_axis < joystick->nballs) {
   3.297 -                    HandleBall(joystick, other_axis,
   3.298 -                               events[i].number % 2, events[i].value);
   3.299 -                    break;
   3.300 -                }
   3.301 -                break;
   3.302 -            case JS_EVENT_BUTTON:
   3.303 -                SDL_PrivateJoystickButton(joystick,
   3.304 -                                          events[i].number,
   3.305 -                                          events[i].value);
   3.306 -                break;
   3.307 -            default:
   3.308 -                /* ?? */
   3.309 -                break;
   3.310 -            }
   3.311 -        }
   3.312 -    }
   3.313 -}
   3.314 -
   3.315 -#if SDL_INPUT_LINUXEV
   3.316  static __inline__ int
   3.317 -EV_AxisCorrect(SDL_Joystick * joystick, int which, int value)
   3.318 +AxisCorrect(SDL_Joystick * joystick, int which, int value)
   3.319  {
   3.320      struct axis_correct *correct;
   3.321  
   3.322 @@ -645,7 +462,7 @@
   3.323  }
   3.324  
   3.325  static __inline__ void
   3.326 -EV_HandleEvents(SDL_Joystick * joystick)
   3.327 +HandleInputEvents(SDL_Joystick * joystick)
   3.328  {
   3.329      struct input_event events[32];
   3.330      int i, len;
   3.331 @@ -683,7 +500,7 @@
   3.332                      break;
   3.333                  default:
   3.334                      events[i].value =
   3.335 -                        EV_AxisCorrect(joystick, code, events[i].value);
   3.336 +                        AxisCorrect(joystick, code, events[i].value);
   3.337                      SDL_PrivateJoystickAxis(joystick,
   3.338                                              joystick->hwdata->abs_map[code],
   3.339                                              events[i].value);
   3.340 @@ -707,19 +524,13 @@
   3.341          }
   3.342      }
   3.343  }
   3.344 -#endif /* SDL_INPUT_LINUXEV */
   3.345  
   3.346  void
   3.347  SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
   3.348  {
   3.349      int i;
   3.350  
   3.351 -#if SDL_INPUT_LINUXEV
   3.352 -    if (joystick->hwdata->is_hid)
   3.353 -        EV_HandleEvents(joystick);
   3.354 -    else
   3.355 -#endif
   3.356 -        JS_HandleEvents(joystick);
   3.357 +    HandleInputEvents(joystick);
   3.358  
   3.359      /* Deliver ball motion updates */
   3.360      for (i = 0; i < joystick->nballs; ++i) {