mirror of
https://github.com/X11Libre/xf86-input-joystick.git
synced 2026-04-14 11:54:23 +00:00
Prepared for proper usage of keymap for device
This commit is contained in:
@@ -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
|
||||
|
||||
24
src/jstk.c
24
src/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);
|
||||
|
||||
13
src/jstk.h
13
src/jstk.h
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
100
src/jstk_key.c
Normal file
100
src/jstk_key.c
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
31
src/jstk_key.h
Normal file
31
src/jstk_key.h
Normal file
@@ -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
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user