From 005c5dcce308ce624d950738f71a2a855dfcb080 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 5 Feb 2011 12:53:25 +0000 Subject: code-remap for 2.6.0 --- src/evdev.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) (limited to 'src/evdev.c') diff --git a/src/evdev.c b/src/evdev.c index 45873c1..617df6c 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -127,6 +127,46 @@ static Atom prop_axis_label = 0; static Atom prop_btn_label = 0; #endif +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->keyremap) { + ev->keyremap=(EvdevKeyRemapPtr)calloc(sizeof(EvdevKeyRemap),1); + } + if (!ev->keyremap->sl[slice]) { + ev->keyremap->sl[slice]=(EvdevKeyRemapSlice*)calloc(sizeof(EvdevKeyRemapSlice),1); + } + ev->keyremap->sl[slice]->cd[offs]=value; +} + +static void +freeRemap(EvdevPtr ev) +{ + uint16_t slice; + if (!ev->keyremap) return; + for (slice=0;slice<256;++slice) { + if (!ev->keyremap->sl[slice]) continue; + free(ev->keyremap->sl[slice]); + } + free(ev->keyremap); + ev->keyremap=0; +} + /* All devices the evdev driver has allocated and knows about. * MAXDEVICES is safe as null-terminated array, as two devices (VCP and VCK) * cannot be used by evdev, leaving us with a space of 2 at the end. */ @@ -274,6 +314,41 @@ SetXkbOption(InputInfoPtr pInfo, char *name, char **option) } } +static void +SetRemapOption(InputInfoPtr pInfo,const char* name,EvdevPtr ev) +{ + char *s,*c; + unsigned long int code,value; + int consumed; + + s = xf86SetStrOption(pInfo->options, name, NULL); + if (!s) return; + if (!s[0]) { + free(s); + return; + } + + c=s; + while (sscanf(c," %li = %li %n",&code,&value,&consumed) > 1) { + 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 < MIN_KEYCODE || value > 255) { + xf86Msg(X_ERROR,"%s: output value %ld out of range for option \"event_key_remap\", ignoring.\n",pInfo->name,code); + continue; + } + xf86Msg(X_INFO,"%s: remapping %ld into %ld.\n",pInfo->name,code,value); + addRemap(ev,code,value-MIN_KEYCODE); + 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; static int wheel_down_button = 5; static int wheel_left_button = 6; @@ -297,7 +372,7 @@ EvdevNextInQueue(InputInfoPtr pInfo) void EvdevQueueKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value) { - int code = ev->code + MIN_KEYCODE; + int code = remapKey((EvdevPtr)(pInfo->private),ev->code) + MIN_KEYCODE; EventQueuePtr pQueue; /* Filter all repeated events from device. @@ -1263,6 +1338,8 @@ EvdevAddKeyClass(DeviceIntPtr device) if (!pEvdev->rmlvo.options) SetXkbOption(pInfo, "XkbOptions", &pEvdev->rmlvo.options); + SetRemapOption(pInfo,"event_key_remap",pEvdev); + #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 5 if (!InitKeyboardDeviceStruct(device, &pEvdev->rmlvo, NULL, EvdevKbdCtrl)) return !Success; @@ -1760,6 +1837,7 @@ EvdevProc(DeviceIntPtr device, int what) pInfo->fd = -1; } EvdevRemoveDevice(pInfo); + freeRemap(pEvdev); pEvdev->min_maj = 0; break; } -- cgit v1.2.3