From 7d3941e47bfe52d0519ef5cc1da8254bfac8f65e Mon Sep 17 00:00:00 2001 From: Sascha Hlusiak Date: Sun, 25 Mar 2007 20:10:10 -0400 Subject: [PATCH] Added "amplify", "disable-mouse", "disable-keys", "disable-all" options to code and manpage --- man/joystick.man | 14 ++++++++++++ src/jstk.c | 53 +++++++++++++++++++++++++++++++++++++--------- src/jstk.h | 3 +++ src/jstk_axis.c | 18 ++++++++++------ src/jstk_options.c | 43 +++++++++++++++++++++++++++---------- 5 files changed, 103 insertions(+), 28 deletions(-) diff --git a/man/joystick.man b/man/joystick.man index ed78b96..30fab40 100644 --- a/man/joystick.man +++ b/man/joystick.man @@ -60,6 +60,20 @@ and is an optional amplifier of the axis, like .B -, +, -5, 0.4, 1.3, ... Use positive and negative values to control the direction. Default: 1.0 +.TP 7 +.BI "\*qamplify=" \*q +Amplifies the movement of all axes by the given factor when pressed. Different +factors can be combined. +.TP 7 +.B "\*qdisable-mouse\*q" +.TP 7 +.B "\*qdisable-keys\*q" +.TP 7 +.B "\*qdisable-all\*q" +Disables either the generation of mouse events, key events or the generation of +all X events by the driver. Press button again to allow the driver to generate +events again. + .RE .PP .TP 7 diff --git a/src/jstk.c b/src/jstk.c index 2fad667..760ac37 100644 --- a/src/jstk.c +++ b/src/jstk.c @@ -102,6 +102,7 @@ xf86JstkRead(LocalDevicePtr local) { enum JOYSTICKEVENT event; int number; + int i; JoystickDevPtr priv = local->private; @@ -117,8 +118,10 @@ xf86JstkRead(LocalDevicePtr local) if (event == EVENT_BUTTON) { switch (priv->button[number].mapping) { case MAPPING_BUTTON: - xf86PostButtonEvent(local->dev, 0, priv->button[number].value, - priv->button[number].pressed, 0, 0); + if (priv->mouse_enabled == TRUE) { + xf86PostButtonEvent(local->dev, 0, priv->button[number].value, + priv->button[number].pressed, 0, 0); + } break; case MAPPING_X: @@ -127,18 +130,42 @@ xf86JstkRead(LocalDevicePtr local) case MAPPING_ZY: if (priv->button[number].pressed == 0) priv->button[number].temp = 1.0; - jstkStartButtonAxisTimer(local, number); + if (priv->mouse_enabled == TRUE) + jstkStartButtonAxisTimer(local, number); break; case MAPPING_KEY: /* FIXME */ break; - case MAPPING_SPEED_MULTIPLY: /* FIXME */ + case MAPPING_SPEED_MULTIPLY: + priv->amplify = 1.0; + for (i=0; ibutton[i].pressed) && + (priv->button[i].mapping == MAPPING_SPEED_MULTIPLY)) + priv->amplify *= ((float)(priv->button[i].value)) / 1000.0; + } break; - case MAPPING_DISABLE: /* FIXME */ + case MAPPING_DISABLE: + if (priv->button[number].pressed == 1) { + if ((priv->mouse_enabled == TRUE) || (priv->keys_enabled == TRUE)) { + priv->mouse_enabled = FALSE; + priv->keys_enabled = FALSE; + } else { + priv->mouse_enabled = TRUE; + priv->keys_enabled = TRUE; + } + } break; - case MAPPING_DISABLE_MOUSE: /* FIXME */ + case MAPPING_DISABLE_MOUSE: + if (priv->button[number].pressed == 1) { + if (priv->mouse_enabled == TRUE) priv->mouse_enabled = FALSE; + else priv->mouse_enabled = TRUE; + } break; - case MAPPING_DISABLE_KEYS: /* FIXME */ + case MAPPING_DISABLE_KEYS: + if (priv->button[number].pressed == 1) { + if (priv->keys_enabled == TRUE) priv->keys_enabled = FALSE; + else priv->keys_enabled = TRUE; + } break; default: @@ -147,16 +174,19 @@ xf86JstkRead(LocalDevicePtr local) } /* An axis was moved */ - if ((event == EVENT_AXIS) && (priv->axis[number].mapping != MAPPING_NONE)) { + if ((event == EVENT_AXIS) && + (priv->axis[number].mapping != MAPPING_NONE)) { switch (priv->axis[number].type) { case TYPE_BYVALUE: case TYPE_ACCELERATED: if (priv->axis[number].value == 0) priv->axis[number].temp = 1.0; - jstkStartAxisTimer(local, number); + if (priv->mouse_enabled == TRUE) + jstkStartAxisTimer(local, number); break; case TYPE_ABSOLUTE: /* FIXME */ - jstkHandleAbsoluteAxis(local, number); + if (priv->mouse_enabled == TRUE) + jstkHandleAbsoluteAxis(local, number); break; default: @@ -356,6 +386,9 @@ xf86JstkCorePreInit(InputDriverPtr drv, IDevPtr dev, int flags) priv->zy = 0.0; priv->timer = NULL; priv->timerrunning = FALSE; + priv->mouse_enabled = TRUE; + priv->keys_enabled = TRUE; + priv->amplify = 1.0; /* Initialize default mappings */ for (i=0; iaxis[i].value)-(float)priv->axis[i].deadzone)* scale/1700.0, 3.5))+100.0)* - ((float)NEXTTIMER/40000.0) * priv->axis[i].amplify; + ((float)NEXTTIMER/40000.0); p2 = ((pow((abs((float)priv->axis[i].value)-(float)priv->axis[i].deadzone)* scale/1000.0, 2.5))+200.0)* - ((float)NEXTTIMER/200000.0) * priv->axis[i].amplify; + ((float)NEXTTIMER/200000.0); } else if (priv->axis[i].type == TYPE_ACCELERATED) { - if (priv->axis[i].temp < 120.0) priv->axis[i].temp *= 1.2; + if (priv->axis[i].temp < 120.0) priv->axis[i].temp *= 1.15; - p1 = (priv->axis[i].temp - 0.1) * (float)NEXTTIMER / 180.0 * priv->axis[i].amplify; + p1 = (priv->axis[i].temp - 0.1) * (float)NEXTTIMER / 180.0; p2 = p1 / 8.0; } if (priv->axis[i].value < 0) { p1 *= -1.0; p2 *= -1.0; } + p1 *= priv->axis[i].amplify * priv->amplify; + p2 *= priv->axis[i].amplify * priv->amplify; switch (priv->axis[i].mapping) { case MAPPING_X: @@ -103,8 +105,9 @@ jstkAxisTimer(OsTimerPtr timer, float p1; float p2; - if (priv->button[i].temp < 120.0) priv->button[i].temp *= 1.2; + if (priv->button[i].temp < 120.0) priv->button[i].temp *= 1.15; p1 = (priv->button[i].temp - 0.1) * (float)NEXTTIMER / 180.0 * ((float)priv->button[i].value)/1000.0; + p1 *= priv->amplify; p2 = p1 / 8.0; switch (priv->button[i].mapping) { @@ -157,13 +160,14 @@ jstkAxisTimer(OsTimerPtr timer, priv->zx+=1.0; } + if (priv->mouse_enabled == FALSE) nexttimer = 0; if (nexttimer == 0) { priv->timerrunning = FALSE; priv->x = 0.0; priv->y = 0.0; priv->zx = 0.0; priv->zy = 0.0; - DBG(2, ErrorF("Stopping Timer\n")); +// DBG(2, ErrorF("Stopping Timer\n")); } xf86UnblockSIGIO (sigstate); return nexttimer; @@ -195,7 +199,7 @@ jstkStartAxisTimer(LocalDevicePtr device, int number) { break; } - DBG(2, ErrorF("Starting Timer\n")); +// DBG(2, ErrorF("Starting Timer\n")); priv->timer = TimerSet( priv->timer, 0, /* Relative */ diff --git a/src/jstk_options.c b/src/jstk_options.c index 7875ce7..73ae443 100644 --- a/src/jstk_options.c +++ b/src/jstk_options.c @@ -26,15 +26,15 @@ #include "jstk_options.h" +/** + * Parses strings like: + * x, +y, -zx, 3x, 3.5zy, -8x + * And returns the mapping and stores the optional factor + * In the float referenced by 'value' + **/ + static enum JOYSTICKMAPPING -jstkGetAxisMapping(float *value, char* param, const char* name) { - /* param can be like: - x - +y - -zx - 3x - 3.5zy - -8x */ +jstkGetAxisMapping(float *value, const char* param, const char* name) { if (sscanf(param, "%f", value)==0) { *value = 1.0; if (param[0]=='-') @@ -52,6 +52,12 @@ jstkGetAxisMapping(float *value, char* param, const char* name) { return MAPPING_NONE; } +/** + * Interpretes one ButtonMappingX option, given in 'org' + * stores the result in *button + * name is the name of the InputDevice + **/ + void jstkParseButtonOption(const char* org, struct BUTTON *button, @@ -59,6 +65,7 @@ jstkParseButtonOption(const char* org, char *param; char *tmp; int value; + float fvalue; char p[64]; param = xstrdup(org); @@ -70,12 +77,20 @@ jstkParseButtonOption(const char* org, button->mapping = MAPPING_BUTTON; button->value = value; } else if (sscanf(param, "axis=%15s", p) == 1) { - float value; - button->mapping = jstkGetAxisMapping(&value, p, name); - button->value = (int)(value*1000.0); + button->mapping = jstkGetAxisMapping(&fvalue, p, name); + button->value = (int)(fvalue*1000.0); 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); + } else if (strcmp(param, "disable-all") == 0) { + button->mapping = MAPPING_DISABLE; + } else if (strcmp(param, "disable-mouse") == 0) { + button->mapping = MAPPING_DISABLE_MOUSE; + } else if (strcmp(param, "disable-keys") == 0) { + button->mapping = MAPPING_DISABLE_KEYS; } else { xf86Msg(X_WARNING, "%s: error parsing button parameter.\n", name); @@ -84,6 +99,12 @@ jstkParseButtonOption(const char* org, } +/** + * Interpretes one AxisMappingX option, given in 'org' + * stores the result in *axis + * name is the name of the InputDevice + **/ + void jstkParseAxisOption(const char* org, struct AXIS *axis, const char *name) { char *param;