diff options
author | Sascha Hlusiak <saschahlusiak@arcor.de> | 2007-04-30 00:37:27 -0400 |
---|---|---|
committer | Sascha Hlusiak <saschahlusiak@arcor.de> | 2007-04-30 00:37:27 -0400 |
commit | a24a5eeb30b224abf2bb512619fe5ab7284fa252 (patch) | |
tree | 2da271274355279187452eab573f5391115587fe /src | |
parent | f0ab39f9d200cdf1387bf3ffa1583bfdddd1d427 (diff) |
Prepared for proper usage of keymap for device
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/jstk.c | 24 | ||||
-rw-r--r-- | src/jstk.h | 13 | ||||
-rw-r--r-- | src/jstk_axis.c | 16 | ||||
-rw-r--r-- | src/jstk_key.c | 100 | ||||
-rw-r--r-- | src/jstk_key.h | 31 | ||||
-rw-r--r-- | src/jstk_options.c | 15 |
7 files changed, 174 insertions, 26 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 2987e21..147c537 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,6 +30,7 @@ @DRIVER_NAME@_drv_la_SOURCES = jstk.c jstk.h jstk_hw.h \ jstk_axis.c jstk_axis.h \ + jstk_key.c jstk_key.h \ jstk_options.c jstk_options.h BSD_SRCS = bsd_jstk.c @@ -41,6 +41,7 @@ #include "jstk.h" #include "jstk_hw.h" #include "jstk_axis.h" +#include "jstk_key.h" #include "jstk_options.h" @@ -259,9 +260,9 @@ jstkDeviceControlProc(DeviceIntPtr pJstk, int m; DBG(1, ErrorF("jstkDeviceControlProc what=INIT\n")); /* We want the first 7 button numbers fixed */ - if (priv->buttonmap_size != 0) { - if (InitButtonClassDeviceStruct(pJstk, priv->buttonmap_size, - priv->buttonmap) == FALSE) { + if (priv->buttonmap.size != 0) { + if (InitButtonClassDeviceStruct(pJstk, priv->buttonmap.size, + priv->buttonmap.map) == FALSE) { ErrorF("unable to allocate Button class device\n"); return !Success; } @@ -270,6 +271,8 @@ jstkDeviceControlProc(DeviceIntPtr pJstk, return !Success; } } + jstkInitKeys(pJstk, priv); + m = 2; for (i=0; i<MAXAXES; i++) if (priv->axis[i].type != TYPE_NONE) @@ -309,8 +312,6 @@ jstkDeviceControlProc(DeviceIntPtr pJstk, 0, /* min_res */ 1); /* max_res */ } - - /* allocate the motion history buffer if needed */ xf86MotionHistoryAllocate(local); } @@ -412,7 +413,8 @@ jstkCorePreInit(InputDriverPtr drv, IDevPtr dev, int flags) priv->mouse_enabled = TRUE; priv->keys_enabled = TRUE; priv->amplify = 1.0f; - priv->buttonmap_size = 0; + priv->buttonmap.size = 0; + priv->keymap.size = 0; /* Initialize default mappings */ for (i=0; i<MAXAXES; i++) { @@ -445,10 +447,12 @@ jstkCorePreInit(InputDriverPtr drv, IDevPtr dev, int flags) priv->axis[1].type = TYPE_BYVALUE; priv->axis[1].mapping = MAPPING_Y; - priv->scrollbuttonmap[0] = jstkGetButtonNumberInMap(priv, 4); - priv->scrollbuttonmap[1] = jstkGetButtonNumberInMap(priv, 5); - priv->scrollbuttonmap[2] = jstkGetButtonNumberInMap(priv, 6); - priv->scrollbuttonmap[3] = jstkGetButtonNumberInMap(priv, 7); + priv->buttonmap.scrollbutton[0] = jstkGetButtonNumberInMap(priv, 4); + priv->buttonmap.scrollbutton[1] = jstkGetButtonNumberInMap(priv, 5); + priv->buttonmap.scrollbutton[2] = jstkGetButtonNumberInMap(priv, 6); + priv->buttonmap.scrollbutton[3] = jstkGetButtonNumberInMap(priv, 7); + priv->buttonmap.map[0] = 0; + xf86CollectInputOptions(local, NULL, NULL); xf86OptionListReport(local->options); @@ -111,9 +111,16 @@ typedef struct _JoystickDevRec { Bool mouse_enabled, keys_enabled; float amplify; /* Global amplifier of axis movement */ - int buttonmap_size; - CARD8 scrollbuttonmap[4]; /* Logical button numbers for scrollwheel */ - CARD8 buttonmap[MAXBUTTONS+1]; + struct _BUTTONMAP { + int size; + CARD8 scrollbutton[4]; /* Logical button numbers for scrollwheel */ + CARD8 map[MAXBUTTONS+1]; + } buttonmap; + struct _KEYMAP { + int size; + KeySym map[MAXBUTTONS+1]; + } keymap; + AXIS axis[MAXAXES]; /* Configuration per axis */ BUTTON button[MAXBUTTONS]; /* Configuration per button */ } JoystickDevRec, *JoystickDevPtr; diff --git a/src/jstk_axis.c b/src/jstk_axis.c index ce4cd56..8eb28a9 100644 --- a/src/jstk_axis.c +++ b/src/jstk_axis.c @@ -163,24 +163,24 @@ jstkAxisTimer(OsTimerPtr timer, /* Generate scrolling events */ while (priv->zy >= 1.0) { /* down */ - xf86PostButtonEvent(device, 0, priv->scrollbuttonmap[1], 1, 0, 0); - xf86PostButtonEvent(device, 0, priv->scrollbuttonmap[1], 0, 0, 0); + xf86PostButtonEvent(device, 0, priv->buttonmap.scrollbutton[1], 1, 0, 0); + xf86PostButtonEvent(device, 0, priv->buttonmap.scrollbutton[1], 0, 0, 0); priv->zy-=1.0; } while (priv->zy <= -1.0) { /* up */ - xf86PostButtonEvent(device, 0, priv->scrollbuttonmap[0], 1, 0, 0); - xf86PostButtonEvent(device, 0, priv->scrollbuttonmap[0], 0, 0, 0); + xf86PostButtonEvent(device, 0, priv->buttonmap.scrollbutton[0], 1, 0, 0); + xf86PostButtonEvent(device, 0, priv->buttonmap.scrollbutton[0], 0, 0, 0); priv->zy+=1.0; } while (priv->zx >= 1.0) { /* right */ - xf86PostButtonEvent(device, 0, priv->scrollbuttonmap[3], 1, 0, 0); - xf86PostButtonEvent(device, 0, priv->scrollbuttonmap[3], 0, 0, 0); + xf86PostButtonEvent(device, 0, priv->buttonmap.scrollbutton[3], 1, 0, 0); + xf86PostButtonEvent(device, 0, priv->buttonmap.scrollbutton[3], 0, 0, 0); priv->zx-=1.0; } while (priv->zx <= -1.0) { /* left */ - xf86PostButtonEvent(device, 0, priv->scrollbuttonmap[2], 1, 0, 0); - xf86PostButtonEvent(device, 0, priv->scrollbuttonmap[2], 0, 0, 0); + xf86PostButtonEvent(device, 0, priv->buttonmap.scrollbutton[2], 1, 0, 0); + xf86PostButtonEvent(device, 0, priv->buttonmap.scrollbutton[2], 0, 0, 0); priv->zx+=1.0; } diff --git a/src/jstk_key.c b/src/jstk_key.c new file mode 100644 index 0000000..3c3cd38 --- /dev/null +++ b/src/jstk_key.c @@ -0,0 +1,100 @@ +/* + * Copyright 2007 by Sascha Hlusiak. <saschahlusiak@freedesktop.org> + * Copyright 1995-1999 by Frederic Lepied, France. <Lepied@XFree86.org> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of copyright holders not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The copyright holders make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + +#include <xf86.h> +#include <X11/extensions/XKB.h> +#include <X11/extensions/XKBstr.h> +#include <X11/extensions/XKBsrv.h> +#include <X11/keysym.h> +#include <X11/XF86keysym.h> +// #include <xf86Xinput.h> +#include "jstk.h" +#include "jstk_key.h" + +#define MIN_KEYCODE 8 + +int +jstkInitKeys(DeviceIntPtr pJstk, JoystickDevPtr priv) +{ +/* KeySymsRec keySyms; + CARD8 modMap[MAP_LENGTH]; + KeySym sym; + int i, j; + XkbComponentNamesRec xkbnames; + + static struct { KeySym keysym; CARD8 mask; } modifiers[] = { + { XK_Shift_L, ShiftMask }, + { XK_Shift_R, ShiftMask }, + { XK_Control_L, ControlMask }, + { XK_Control_R, ControlMask }, + { XK_Caps_Lock, LockMask } + { XK_Alt_L, AltMask }, + { XK_Alt_R, AltMask }, + { XK_Num_Lock, NumLockMask }, + { XK_Scroll_Lock, ScrollLockMask }, + { XK_Mode_switch, AltLangMask } + }; + + priv->keymap.size = 20; + for (i = 0; i < 20; i++) + priv->keymap.map[i] = XK_at; + + memset(modMap, 0, sizeof modMap); + + for (i = 0; i < priv->keymap.size; i++) { + sym = priv->keymap.map[i]; + for (j = 0; j < sizeof(modifiers)/sizeof(modifiers[0]); j++) { + if (modifiers[j].keysym == sym) + modMap[i + MIN_KEYCODE] = modifiers[j].mask; + } + } + + keySyms.map = priv->keymap.map; + keySyms.mapWidth = 1; + keySyms.minKeyCode = MIN_KEYCODE; + keySyms.maxKeyCode = MIN_KEYCODE + priv->keymap.size - 1; + + XkbSetRulesDflts(__XKBDEFRULES__, "pc105", "de", "nodeadkeys", NULL); + + XkbInitKeyboardDeviceStruct (pJstk, &xkbnames, &keySyms, modMap, + NULL, NULL); +*/ + + return Success; +} + + + + + + + + + diff --git a/src/jstk_key.h b/src/jstk_key.h new file mode 100644 index 0000000..bbc3b59 --- /dev/null +++ b/src/jstk_key.h @@ -0,0 +1,31 @@ +/* + * Copyright 2007 by Sascha Hlusiak. <saschahlusiak@freedesktop.org> + * Copyright 1995-1999 by Frederic Lepied, France. <Lepied@XFree86.org> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of copyright holders not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The copyright holders make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + + +#ifndef __JSTK_KEY_H_INCLUDED__ +#define __JSTK_KEY_H_INCLUDED__ + +int jstkInitKeys(DeviceIntPtr pJstk, JoystickDevPtr priv); + + +#endif diff --git a/src/jstk_options.c b/src/jstk_options.c index 07044f9..e07445c 100644 --- a/src/jstk_options.c +++ b/src/jstk_options.c @@ -21,6 +21,11 @@ * */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -45,12 +50,12 @@ jstkGetButtonNumberInMap(JoystickDevPtr priv, int buttonnumber) { int j; - for (j=1; j<=priv->buttonmap_size; j++) - if (priv->buttonmap[j] == buttonnumber) + for (j=1; j<=priv->buttonmap.size; j++) + if (priv->buttonmap.map[j] == buttonnumber) break; if (j > MAXBUTTONS+1) return 0; - priv->buttonmap[j] = buttonnumber; - if (j > priv->buttonmap_size) priv->buttonmap_size = j; + priv->buttonmap.map[j] = buttonnumber; + if (j > priv->buttonmap.size) priv->buttonmap.size = j; return j; } @@ -139,7 +144,7 @@ jstkParseButtonOption(const char* org, for (value = 0; value < MAXKEYSPERBUTTON; value++) if (current != NULL) { next = strchr(current, ','); if (next) *(next++) = '\0'; - button->keys[value] = atoi(current); + button->keys[value] = atoi(current); if (button->keys[value] == 0) xf86Msg(X_WARNING, "%s: error parsing key value: %s.\n", name, current); |