Cosmetic changes to structs, got rid of XFree86LOADER blocks

The XFree86LOADER is mandatory, without it it wouldn't compile anyway, so checks were deleted.
Named structs in jstk.h again
Added unions for mapping-relative data, given values more telling names
This commit is contained in:
Sascha Hlusiak
2007-04-15 22:51:35 -04:00
parent 886e418b89
commit 470acec6f4
8 changed files with 90 additions and 115 deletions

View File

@@ -22,7 +22,7 @@
AC_PREREQ(2.57)
AC_INIT([xf86-input-joystick],
1.2.0,
1.2.1,
[https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],
xf86-input-joystick)
@@ -44,24 +44,6 @@ AC_PROG_CC
AH_TOP([#include "xorg-server.h"])
#AC_DEFINE(XFree86LOADER,1,[Stub define for loadable drivers])
#
#AC_ARG_ENABLE(XINPUT, AS_HELP_STRING([--enable-xinput],
# [Build XInput support (default: yes)]),
# [XINPUT=$enableval],[XINPUT=yes])
#AM_CONDITIONAL(XINPUT, test "x$XINPUT" = "xyes")
#if test "x$XINPUT" = "xyes" ; then
# AC_DEFINE(XINPUT,1,[Enable XInput support])
#fi
#
#AC_ARG_ENABLE(XKB, AS_HELP_STRING([--enable-xkb],
# [Build XKB support (default: yes)]),
# [XKB=$enableval],[XKB=yes])
#AM_CONDITIONAL(XKB, test "x$XKB" = "xyes")
#if test "x$XKB" = "xyes" ; then
# AC_DEFINE(XKB,1,[Enable XKB support])
#fi
case $host_os in
linux*)
IS_LINUX="yes"
@@ -72,9 +54,9 @@ case $host_os in
;;
*)
AC_MSG_ERROR([Your operating system is not supported by the joystick driver.
Contact xorg@lists.freedesktop.org if you are interested in
porting it.])
AC_MSG_ERROR([Your operating system is not supported by the joystick
driver. Contact xorg@lists.freedesktop.org if you are
interested in porting it.])
;;
esac
AM_CONDITIONAL(LINUX, [test "x$IS_LINUX" = xyes])
@@ -82,7 +64,8 @@ AM_CONDITIONAL(BSD, [test "x$IS_BSD" = xyes])
AC_ARG_WITH(xorg-module-dir,
AC_HELP_STRING([--with-xorg-module-dir=DIR],
[Default xorg module directory [[default=$libdir/xorg/modules]]]),
[Default xorg module directory
[[default=$libdir/xorg/modules]]]),
[moduledir="$withval"],
[moduledir="$libdir/xorg/modules"])
inputdir=${moduledir}/input
@@ -93,7 +76,8 @@ XORG_DRIVER_CHECK_EXT(RANDR, randrproto)
XORG_DRIVER_CHECK_EXT(XINPUT, inputproto)
# Checks for pkg-config packages
PKG_CHECK_MODULES(XORG, [xorg-server >= 1.0.99.901] xproto $REQUIRED_MODULES)
PKG_CHECK_MODULES(XORG,
[xorg-server >= 1.0.99.901] xproto $REQUIRED_MODULES)
sdkdir=$(pkg-config --variable=sdkdir xorg-server)
CFLAGS="$CFLAGS $XORG_CFLAGS "' -I$(top_srcdir)/src'

View File

@@ -13,7 +13,8 @@ joystick \- Joystick input driver
.fi
.SH DESCRIPTION
.B joystick
is an __xservername__ input driver for Joysticks, using either Linux\'s joystick devices or *BSD\'s uhid devices.
is an __xservername__ input driver for Joysticks, using either Linux\'s
joystick devices or *BSD\'s uhid devices.
.SH SUPPORTED HARDWARE
In general, every by the kernel supported joystick should be supported through the

View File

@@ -32,7 +32,7 @@
jstk_axis.c jstk_axis.h \
jstk_options.c jstk_options.h
BSD_SRCS = bsd_jstk.c
BSD_SRCS = bsd_jstk.c
LINUX_SRCS = linux_jstk.c
if BSD

View File

@@ -35,10 +35,7 @@
#include <exevents.h> /* Needed for InitValuator/Proximity stuff */
#include <math.h>
#ifdef XFree86LOADER
#include <xf86Module.h>
#endif
#include "jstk.h"
@@ -123,7 +120,7 @@ jstkReadProc(LocalDevicePtr local)
switch (priv->button[number].mapping) {
case MAPPING_BUTTON:
if (priv->mouse_enabled == TRUE) {
xf86PostButtonEvent(local->dev, 0, priv->button[number].value,
xf86PostButtonEvent(local->dev, 0, priv->button[number].buttonnumber,
priv->button[number].pressed, 0, 0);
}
break;
@@ -133,7 +130,7 @@ jstkReadProc(LocalDevicePtr local)
case MAPPING_ZX:
case MAPPING_ZY:
if (priv->button[number].pressed == 0) /* If button was released */
priv->button[number].temp = 1.0; /* Reset speed counter */
priv->button[number].currentspeed = 1.0; /* Reset speed counter */
else if (priv->mouse_enabled == TRUE)
jstkStartButtonAxisTimer(local, number);
break;
@@ -160,7 +157,7 @@ jstkReadProc(LocalDevicePtr local)
for (i=0; i<MAXAXES; i++) {
if ((priv->button[i].pressed) &&
(priv->button[i].mapping == MAPPING_SPEED_MULTIPLY))
priv->amplify *= ((float)priv->button[i].value) / 1000.0f;
priv->amplify *= priv->button[i].amplify;
}
DBG(2, ErrorF("Global amplify is now %.3f\n", priv->amplify));
@@ -213,7 +210,7 @@ jstkReadProc(LocalDevicePtr local)
case TYPE_BYVALUE:
case TYPE_ACCELERATED:
if (priv->axis[number].value == 0) /* When axis was released */
priv->axis[number].temp = 1.0; /* Release speed counter */
priv->axis[number].currentspeed = 1.0; /* Release speed counter */
if (priv->mouse_enabled == TRUE)
jstkStartAxisTimer(local, number);
@@ -334,16 +331,6 @@ jstkDeviceControlProc(DeviceIntPtr pJstk,
/*
***************************************************************************
*
* Dynamic loading functions
*
***************************************************************************
*/
#ifdef XFree86LOADER
/*
***************************************************************************
*
@@ -406,27 +393,27 @@ jstkCorePreInit(InputDriverPtr drv, IDevPtr dev, int flags)
/* Initialize default mappings */
for (i=0; i<MAXAXES; i++) {
priv->axis[i].value = 0;
priv->axis[i].deadzone = 1000;
priv->axis[i].type = TYPE_BYVALUE;
priv->axis[i].mapping = MAPPING_NONE;
priv->axis[i].temp = 0.0f;
priv->axis[i].amplify = 1.0f;
priv->axis[i].value = 0;
priv->axis[i].deadzone = 1000;
priv->axis[i].type = TYPE_BYVALUE;
priv->axis[i].mapping = MAPPING_NONE;
priv->axis[i].currentspeed = 0.0f;
priv->axis[i].amplify = 1.0f;
}
for (i=0; i<MAXBUTTONS; i++) {
priv->button[i].pressed = 0;
priv->button[i].value = 0;
priv->button[i].mapping = MAPPING_NONE;
priv->button[i].temp = 1.0f;
priv->button[i].pressed = 0;
priv->button[i].buttonnumber = 0;
priv->button[i].mapping = MAPPING_NONE;
priv->button[i].currentspeed = 1.0f;
}
/* First three joystick buttons generate mouse clicks */
priv->button[0].mapping = MAPPING_BUTTON;
priv->button[0].value = 1;
priv->button[1].mapping = MAPPING_BUTTON;
priv->button[1].value = 2;
priv->button[2].mapping = MAPPING_BUTTON;
priv->button[2].value = 3;
priv->button[0].mapping = MAPPING_BUTTON;
priv->button[0].buttonnumber = 1;
priv->button[1].mapping = MAPPING_BUTTON;
priv->button[1].buttonnumber = 2;
priv->button[2].mapping = MAPPING_BUTTON;
priv->button[2].buttonnumber = 3;
/* Two axes by default */
priv->axis[0].type = TYPE_BYVALUE;
@@ -470,8 +457,8 @@ jstkCorePreInit(InputDriverPtr drv, IDevPtr dev, int flags)
if (s != NULL) {
jstkParseButtonOption(s, priv, i, local->name);
}
DBG(1, xf86Msg(X_CONFIG, "Button %d mapped to %d (value=%d)\n", i+1,
priv->button[i].mapping, priv->button[i].value));
DBG(1, xf86Msg(X_CONFIG, "Button %d mapped to %d\n", i+1,
priv->button[i].mapping));
}
/* Process button mapping options */
@@ -621,5 +608,3 @@ _X_EXPORT XF86ModuleData joystickModuleData = {
jstkDriverPlug,
jstkDriverUnplug
};
#endif /* XFree86LOADER */

View File

@@ -44,61 +44,67 @@
**/
#if DEBUG
extern int debug_level;
#define DBG(lvl, f) {if ((lvl) <= debug_level) f;}
extern int debug_level;
#define DBG(lvl, f) {if ((lvl) <= debug_level) f;}
#else
#define DBG(lvl, f)
#define DBG(lvl, f)
#endif
#define MAXBUTTONS 32
#define MAXAXES 32
#define MAXKEYSPERBUTTON 4
typedef enum {
TYPE_NONE,
typedef enum _JOYSTICKTYPE{
TYPE_NONE, /* Axis value is not relevant */
TYPE_BYVALUE, /* Speed of cursor is relative to amplitude */
TYPE_ACCELERATED, /* Speed is accelerated */
TYPE_ABSOLUTE /* The amplitude defines the cursor position */
} JOYSTICKTYPE;
typedef enum {
MAPPING_NONE=0,
MAPPING_X,
MAPPING_Y,
MAPPING_ZX,
MAPPING_ZY,
MAPPING_BUTTON,
MAPPING_KEY,
MAPPING_SPEED_MULTIPLY,
MAPPING_DISABLE,
MAPPING_DISABLE_MOUSE,
MAPPING_DISABLE_KEYS
} JOYSTICKMAPPING ;
typedef enum _JOYSTICKMAPPING{
MAPPING_NONE, /* Nothing */
MAPPING_X, /* X-Axis */
MAPPING_Y, /* Y-Axis */
MAPPING_ZX, /* Horizontal scrolling */
MAPPING_ZY, /* Vertical scrolling */
MAPPING_BUTTON, /* Mouse button */
MAPPING_KEY, /* Keyboard event */
MAPPING_SPEED_MULTIPLY, /* Will amplify all axis movement */
MAPPING_DISABLE, /* Disable mouse and key events */
MAPPING_DISABLE_MOUSE, /* Disable only mouse events */
MAPPING_DISABLE_KEYS /* Disable only key events */
} JOYSTICKMAPPING;
typedef struct
{
int value;
int deadzone;
float temp,amplify;
JOYSTICKTYPE type;
typedef struct _AXIS {
JOYSTICKTYPE type;
JOYSTICKMAPPING mapping;
int value;
int deadzone;
union {
float currentspeed;
float previousposition;
};
float amplify;
} AXIS;
typedef struct
{
char pressed;
int value;
unsigned int keys[MAXKEYSPERBUTTON];
float temp;
#define MAXKEYSPERBUTTON 4
typedef struct _BUTTON {
JOYSTICKMAPPING mapping;
char pressed;
union {
int buttonnumber; /* MAPPING_BUTTON */
struct {
float amplify; /* MAPPING_X/Y/ZX/ZY,
MAPPING_SPEED_MULTIPLY */
float currentspeed; /* MAPPING_X/Y/ZX/ZY */
};
unsigned int keys[MAXKEYSPERBUTTON]; /* MAPPING_KEY */
};
} BUTTON;
#define MAXBUTTONS 32
#define MAXAXES 32
typedef struct
{
typedef struct _JoystickDevRec {
int fd; /* Actual file descriptor */
void *devicedata; /* Extra platform device dependend data */
char *device; /* Name of the device */
@@ -115,5 +121,4 @@ typedef struct
unsigned char axes, buttons; /* Number of axes and buttons */
} JoystickDevRec, *JoystickDevPtr;
#endif

View File

@@ -89,9 +89,9 @@ jstkAxisTimer(OsTimerPtr timer,
} else if (axis->type == TYPE_ACCELERATED) {
/* Stop to accelerate at a certain speed */
if (axis->temp < 100.0f) axis->temp *= 1.15f;
if (axis->currentspeed < 100.0f) axis->currentspeed *= 1.15f;
p1 = (axis->temp - 0.1f) * (float)NEXTTIMER / 180.0f;
p1 = (axis->currentspeed - 0.1f) * (float)NEXTTIMER / 180.0f;
p2 = p1 / 8.0f;
}
if (axis->value < 0) {
@@ -124,9 +124,9 @@ jstkAxisTimer(OsTimerPtr timer,
float p1;
float p2;
if (priv->button[i].temp < 100.0f) priv->button[i].temp *= 1.15f;
p1 = (priv->button[i].temp - 0.1) * (float)NEXTTIMER / 180.0f *
((float)priv->button[i].value) / 1000.0f;
if (priv->button[i].currentspeed < 100.0f) priv->button[i].currentspeed *= 1.15f;
p1 = (priv->button[i].currentspeed - 0.1) * (float)NEXTTIMER / 180.0f *
priv->button[i].amplify;
p1 *= priv->amplify;
p2 = p1 / 8.0f;
@@ -263,7 +263,7 @@ jstkStartButtonAxisTimer(LocalDevicePtr device, int number)
priv->timerrunning = TRUE;
pixel = 1;
if (priv->button[number].value < 0) pixel = -1;
if (priv->button[number].amplify < 0) pixel = -1;
switch (priv->button[number].mapping) {
case MAPPING_X:
priv->x += pixel;
@@ -326,15 +326,15 @@ jstkHandleAbsoluteAxis(LocalDevicePtr device, int number)
DBG(5, ErrorF("Relative Position of axis %d: %.2f\n", i, rel));
/* Calculate difference to previous position on screen in pixels */
dif = (int)(rel - priv->axis[i].temp + 0.5f);
dif = (int)(rel - priv->axis[i].previousposition + 0.5f);
if ((dif >= 1)||(dif <= -1)) {
if (priv->axis[i].mapping == MAPPING_X) {
x += (dif);
priv->axis[i].temp += (float)dif;
priv->axis[i].previousposition += (float)dif;
}
if (priv->axis[i].mapping == MAPPING_Y) {
y += (int)(dif);
priv->axis[i].temp += (float)dif;
priv->axis[i].previousposition += (float)dif;
}
}
}

View File

@@ -24,7 +24,7 @@
#ifndef _LINUX_JSTK_H_INCLUDED_
#define _LINUX_JSTK_H_INCLUDED_
typedef enum {
typedef enum _JOYSTICKEVENT {
EVENT_NONE=0,
EVENT_BUTTON,
EVENT_AXIS

View File

@@ -95,17 +95,17 @@ jstkParseButtonOption(const char* org,
if (strcmp(param, "none") == 0) {
button->mapping = MAPPING_NONE;
} else if (sscanf(param, "button=%d", &value) == 1) {
button->mapping = MAPPING_BUTTON;
button->value = value;
button->mapping = MAPPING_BUTTON;
button->buttonnumber = value;
} else if (sscanf(param, "axis=%15s", p) == 1) {
button->mapping = jstkGetAxisMapping(&fvalue, p, name);
button->value = (int)(fvalue*1000.0);
button->amplify = fvalue;
if (button->mapping == MAPPING_NONE)
xf86Msg(X_WARNING, "%s: error parsing axis: %s.\n",
name, p);
} else if (sscanf(param, "amplify=%f", &fvalue) == 1) {
button->mapping = MAPPING_SPEED_MULTIPLY;
button->value = (int)(fvalue*1000.0);
button->amplify = fvalue;
} else if (sscanf(param, "key=%30s", p) == 1) {
char *current, *next;
current = p;