aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2009-05-23 14:49:57 +0200
committerdakkar <dakkar@thenautilus.net>2010-04-25 13:41:25 +0100
commite32fe13c87d51eb929a4ff182abbda8656579136 (patch)
treedbfb18593219cc83bd8254d374922f8ca61ba5a4
parentstub for configuration (diff)
downloadxf86-input-evdev-e32fe13c87d51eb929a4ff182abbda8656579136.tar.gz
xf86-input-evdev-e32fe13c87d51eb929a4ff182abbda8656579136.tar.bz2
xf86-input-evdev-e32fe13c87d51eb929a4ff182abbda8656579136.zip
complies, may even work
-rw-r--r--src/evdev.c69
1 files changed, 48 insertions, 21 deletions
diff --git a/src/evdev.c b/src/evdev.c
index 8b49b01..1ce49d0 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -132,35 +132,43 @@ static Atom prop_axis_label = 0;
static Atom prop_btn_label = 0;
#endif
-#define remapKey(ev,x) (ev->keyremap && ev->keyremap->sl[(x)/256] ? ev->keyremap->sl[(x)/256]->cd[(x)%256] : (x))
+static uint16_t
+remapKey(EvdevPtr ev, uint16_t code)
+{
+ uint8_t slice=code/256;
+ uint8_t offs=code%256;
+
+ if (!ev->keyremap) return code;
+ if (!(ev->keyremap->sl[slice])) return code;
+ if (!(ev->keyremap->sl[slice]->cd[offs])) return code;
+ return ev->keyremap->sl[slice]->cd[offs];
+}
static void
addRemap(EvdevPtr ev,uint16_t code,uint8_t value)
{
uint8_t slice=code/256;
uint8_t offs=code%256;
- if (!ev->map) {
- ev->map=(EvdevKeyRemapPtr)malloc(sizeof(EvdevKeyRemap));
- memset(ev->map,0,sizeof(EvdevKeyRemap));
+ if (!ev->keyremap) {
+ ev->keyremap=(EvdevKeyRemapPtr)xcalloc(1,sizeof(EvdevKeyRemap));
}
- if (!ev->map->sl[slice]) {
- ev->map->sl[slice]=(EvdevKeyRemapSlice*)malloc(sizeof(EvdevKeyRemapSlice));
- memset(ev->map->sl[slice],0,sizeof(EvdevKeyRemapSlice));
+ if (!ev->keyremap->sl[slice]) {
+ ev->keyremap->sl[slice]=(EvdevKeyRemapSlice*)xcalloc(1,sizeof(EvdevKeyRemapSlice));
}
- ev->map->sl[slice]->cd[offs]=value;
+ ev->keyremap->sl[slice]->cd[offs]=value;
}
static void
freeRemap(EvdevPtr ev)
{
uint16_t slice;
- if (!ev->map) return;
+ if (!ev->keyremap) return;
for (slice=0;slice<256;++slice) {
- if (!ev->map->sl[slice]) continue;
- free(ev->map->sl[slice]);
+ if (!ev->keyremap->sl[slice]) continue;
+ xfree(ev->keyremap->sl[slice]);
}
- free(ev->map);
- ev->map=0;
+ xfree(ev->keyremap);
+ ev->keyremap=0;
}
/* All devices the evdev driver has allocated and knows about.
@@ -281,16 +289,35 @@ SetXkbOption(InputInfoPtr pInfo, char *name, char **option)
static void
SetRemapOption(InputInfoPtr pInfo,char* name,EvdevPtr ev)
{
- char *s;
+ char *s,*c;
+ unsigned long int code,value;
+ int consumed;
+
+ s = xf86SetStrOption(pInfo->options, name, NULL);
+ if (!s) return;
+ if (!s[0]) {
+ xfree(s);
+ return;
+ }
- s = xf86SetStrOption(pInfo->options, name, NULL);
- if (!s) return;
- if (!s[0]) {
- xfree(s);
- return;
+ c=s;
+ while (sscanf(c," %li = %li %n",&code,&value,&consumed)) {
+ if (code < 0 || code > 65535L) {
+ xf86Msg(X_ERROR,"%s: input code %ld out of range for option \"event_key_remap\", ignoring.\n",pInfo->name,code);
+ continue;
+ }
+ if (value < 1 || value > 255) {
+ xf86Msg(X_ERROR,"%s: output value %ld out of range for option \"event_key_remap\", ignoring.\n",pInfo->name,code);
+ continue;
}
+ addRemap(ev,code,value);
+ c+=consumed;
+ }
-
+ if (*c!='\0') {
+ xf86Msg(X_ERROR, "%s: invalid input for option \"event_key_remap\" starting at '%s', ignoring.\n",
+ pInfo->name, c);
+ }
}
static int wheel_up_button = 4;
@@ -320,7 +347,7 @@ EvdevQueueKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value)
)
return;
- code=remapKey((EvdevPtr)pInfo->private,code);
+ code=remapKey((EvdevPtr)(pInfo->private),code);
if (code > 255)
{
if (ev->code <= KEY_MAX && !warned[ev->code])