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.
This commit is contained in:
Ryan C. Gordon 2012-12-11 11:07:48 -05:00
parent 0dc1a837b5
commit d935bb9d4d
3 changed files with 18 additions and 215 deletions

View file

@ -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(NAS "Support the NAS audio API" ${UNIX_SYS})
set_option(RPATH "Use an rpath when linking SDL" ${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(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(INPUT_TSLIB "Use the Touchscreen library for input" ${UNIX_SYS})
set_option(VIDEO_X11 "Use X11 video driver" ${UNIX_SYS}) set_option(VIDEO_X11 "Use X11 video driver" ${UNIX_SYS})
dep_option(X11_SHARED "Dynamically load X11 support" ON "VIDEO_X11" OFF) dep_option(X11_SHARED "Dynamically load X11 support" ON "VIDEO_X11" OFF)
@ -632,7 +631,7 @@ if(UNIX AND NOT APPLE)
CheckOpenGLESX11() CheckOpenGLESX11()
endif(SDL_VIDEO) endif(SDL_VIDEO)
if(INPUT_EVENTS) if(LINUX)
check_c_source_compiles(" check_c_source_compiles("
#include <linux/input.h> #include <linux/input.h>
#ifndef EVIOCGNAME #ifndef EVIOCGNAME
@ -642,16 +641,14 @@ if(UNIX AND NOT APPLE)
if(HAVE_INPUT_EVENTS) if(HAVE_INPUT_EVENTS)
set(SDL_INPUT_LINUXEV 1) set(SDL_INPUT_LINUXEV 1)
endif(HAVE_INPUT_EVENTS) endif(HAVE_INPUT_EVENTS)
endif(INPUT_EVENTS)
if(SDL_HAPTIC AND HAVE_INPUT_EVENTS) if(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
if(LINUX)
set(SDL_HAPTIC_LINUX 1) set(SDL_HAPTIC_LINUX 1)
file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c) file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES}) set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
set(HAVE_SDL_HAPTIC TRUE) 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) if(INPUT_TSLIB)
check_c_source_compiles(" check_c_source_compiles("

View file

@ -1650,10 +1650,6 @@ dnl See if we can use the new unified event interface in Linux 2.4
CheckInputEvents() CheckInputEvents()
{ {
dnl Check for Linux 2.4 unified input event interface support 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) AC_MSG_CHECKING(for Linux 2.4 unified input interface)
use_input_events=no use_input_events=no
AC_TRY_COMPILE([ 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 if test x$use_input_events = xyes; then
AC_DEFINE(SDL_INPUT_LINUXEV, 1, [ ]) AC_DEFINE(SDL_INPUT_LINUXEV, 1, [ ])
fi fi
fi
} }
dnl See if we can use the Touchscreen input library dnl See if we can use the Touchscreen input library

View file

@ -22,6 +22,10 @@
#ifdef SDL_JOYSTICK_LINUX #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 */ /* This is the system specific header for the SDL joystick API */
#include <sys/stat.h> #include <sys/stat.h>
@ -36,29 +40,6 @@
#include "../SDL_joystick_c.h" #include "../SDL_joystick_c.h"
#include "SDL_sysjoystick_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 */ /* The maximum number of joysticks we'll detect */
#define MAX_JOYSTICKS 32 #define MAX_JOYSTICKS 32
@ -69,13 +50,12 @@ static struct
} SDL_joylist[MAX_JOYSTICKS]; } SDL_joylist[MAX_JOYSTICKS];
#if SDL_INPUT_LINUXEV
#define test_bit(nr, addr) \ #define test_bit(nr, addr) \
(((1UL << ((nr) % (sizeof(long) * 8))) & ((addr)[(nr) / (sizeof(long) * 8)])) != 0) (((1UL << ((nr) % (sizeof(long) * 8))) & ((addr)[(nr) / (sizeof(long) * 8)])) != 0)
#define NBITS(x) ((((x)-1)/(sizeof(long) * 8))+1) #define NBITS(x) ((((x)-1)/(sizeof(long) * 8))+1)
static int static int
EV_IsJoystick(int fd) IsJoystick(int fd)
{ {
unsigned long evbit[NBITS(EV_MAX)] = { 0 }; unsigned long evbit[NBITS(EV_MAX)] = { 0 };
unsigned long keybit[NBITS(KEY_MAX)] = { 0 }; unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
@ -94,7 +74,6 @@ EV_IsJoystick(int fd)
return (1); return (1);
} }
#endif /* SDL_INPUT_LINUXEV */
static int SDL_SYS_numjoysticks = 0; static int SDL_SYS_numjoysticks = 0;
@ -104,11 +83,7 @@ SDL_SYS_JoystickInit(void)
{ {
/* The base path of the joystick devices */ /* The base path of the joystick devices */
const char *joydev_pattern[] = { const char *joydev_pattern[] = {
#if SDL_INPUT_LINUXEV
"/dev/input/event%d", "/dev/input/event%d",
#endif
"/dev/input/js%d",
"/dev/js%d"
}; };
int numjoysticks; int numjoysticks;
int i, j; int i, j;
@ -173,15 +148,13 @@ SDL_SYS_JoystickInit(void)
if (fd < 0) { if (fd < 0) {
continue; continue;
} }
#if SDL_INPUT_LINUXEV
#ifdef DEBUG_INPUT_EVENTS #ifdef DEBUG_INPUT_EVENTS
printf("Checking %s\n", path); printf("Checking %s\n", path);
#endif #endif
if ((i == 0) && !EV_IsJoystick(fd)) { if ((i == 0) && !IsJoystick(fd)) {
close(fd); close(fd);
continue; continue;
} }
#endif
close(fd); close(fd);
/* We're fine, add this joystick */ /* We're fine, add this joystick */
@ -193,7 +166,6 @@ SDL_SYS_JoystickInit(void)
} }
} }
#if SDL_INPUT_LINUXEV
/* This is a special case... /* This is a special case...
If the event devices are valid then the joystick devices If the event devices are valid then the joystick devices
will be duplicates but without extra information about their will be duplicates but without extra information about their
@ -203,7 +175,6 @@ SDL_SYS_JoystickInit(void)
*/ */
if ((i == 0) && (numjoysticks > 0)) if ((i == 0) && (numjoysticks > 0))
break; break;
#endif
} }
SDL_SYS_numjoysticks = numjoysticks; SDL_SYS_numjoysticks = numjoysticks;
@ -235,11 +206,7 @@ SDL_SYS_JoystickNameForDeviceIndex(int device_index)
name = NULL; name = NULL;
fd = open(SDL_joylist[device_index].fname, O_RDONLY, 0); fd = open(SDL_joylist[device_index].fname, O_RDONLY, 0);
if (fd >= 0) { if (fd >= 0) {
if ( if (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) {
#if SDL_INPUT_LINUXEV
(ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) &&
#endif
(ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) <= 0)) {
name = SDL_joylist[device_index].fname; name = SDL_joylist[device_index].fname;
} else { } else {
name = namebuf; name = namebuf;
@ -291,100 +258,8 @@ allocate_balldata(SDL_Joystick * joystick)
return (0); return (0);
} }
static SDL_bool static void
JS_ConfigJoystick(SDL_Joystick * joystick, int fd) 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)
{ {
int i, t; int i, t;
unsigned long keybit[NBITS(KEY_MAX)] = { 0 }; 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) && if ((ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) &&
(ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) && (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) &&
(ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 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 */ /* Get the number of buttons, axes, and other thingamajigs */
for (i = BTN_JOYSTICK; i < KEY_MAX; ++i) { 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. /* Function to open a joystick for use.
The joystick to open is specified by the index field of the joystick. 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); fcntl(fd, F_SETFL, O_NONBLOCK);
/* Get the number of buttons and axes on the joystick */ /* Get the number of buttons and axes on the joystick */
#if SDL_INPUT_LINUXEV ConfigJoystick(joystick, fd);
if (!EV_ConfigJoystick(joystick, fd))
#endif
JS_ConfigJoystick(joystick, fd);
return (0); return (0);
} }
@ -564,60 +432,9 @@ HandleBall(SDL_Joystick * stick, Uint8 ball, int axis, int value)
stick->hwdata->balls[ball].axis[axis] += 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 static __inline__ int
EV_AxisCorrect(SDL_Joystick * joystick, int which, int value) AxisCorrect(SDL_Joystick * joystick, int which, int value)
{ {
struct axis_correct *correct; struct axis_correct *correct;
@ -645,7 +462,7 @@ EV_AxisCorrect(SDL_Joystick * joystick, int which, int value)
} }
static __inline__ void static __inline__ void
EV_HandleEvents(SDL_Joystick * joystick) HandleInputEvents(SDL_Joystick * joystick)
{ {
struct input_event events[32]; struct input_event events[32];
int i, len; int i, len;
@ -683,7 +500,7 @@ EV_HandleEvents(SDL_Joystick * joystick)
break; break;
default: default:
events[i].value = events[i].value =
EV_AxisCorrect(joystick, code, events[i].value); AxisCorrect(joystick, code, events[i].value);
SDL_PrivateJoystickAxis(joystick, SDL_PrivateJoystickAxis(joystick,
joystick->hwdata->abs_map[code], joystick->hwdata->abs_map[code],
events[i].value); events[i].value);
@ -707,19 +524,13 @@ EV_HandleEvents(SDL_Joystick * joystick)
} }
} }
} }
#endif /* SDL_INPUT_LINUXEV */
void void
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
{ {
int i; int i;
#if SDL_INPUT_LINUXEV HandleInputEvents(joystick);
if (joystick->hwdata->is_hid)
EV_HandleEvents(joystick);
else
#endif
JS_HandleEvents(joystick);
/* Deliver ball motion updates */ /* Deliver ball motion updates */
for (i = 0; i < joystick->nballs; ++i) { for (i = 0; i < joystick->nballs; ++i) {