#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "evdev.h"
#include <X11/keysym.h>
#include <X11/extensions/XI.h>
#include <linux/version.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <xf86.h>
#include <xf86Xinput.h>
#include <exevents.h>
#include <xorgVersion.h>
#include <xkbsrv.h>
#ifdef HAVE_PROPERTIES
#include <X11/Xatom.h>
#include <evdev-properties.h>
#include <xserver-properties.h>
#ifdef AXIS_LABEL_PROP
#define HAVE_LABELS
#else
#undef HAVE_LABELS
#endif
#endif
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
#define XI86_CONFIGURED 0x02
#define XI86_SEND_DRAG_EVENTS 0x08
#endif
#ifndef MAXDEVICES
#include <inputstr.h>
#define MAXDEVICES MAX_DEVICES
#endif
#define ArrayLength(a) (sizeof(a) / (sizeof((a)[0])))
#define MIN_KEYCODE 8
#define GLYPHS_PER_KEY 2
#define AltMask Mod1Mask
#define NumLockMask Mod2Mask
#define AltLangMask Mod3Mask
#define KanaMask Mod4Mask
#define ScrollLockMask Mod5Mask
#define CAPSFLAG 1
#define NUMFLAG 2
#define SCROLLFLAG 4
#define MODEFLAG 8
#define COMPOSEFLAG 16
static char *evdevDefaults[] = {
"XkbRules", "evdev",
"XkbModel", "evdev",
"XkbLayout", "us",
NULL
};
static int EvdevOn(DeviceIntPtr);
static int EvdevCacheCompare(InputInfoPtr pInfo, BOOL compare);
static void EvdevKbdCtrl(DeviceIntPtr device, KeybdCtrl *ctrl);
static int EvdevSwitchMode(ClientPtr client, DeviceIntPtr device, int mode);
static BOOL EvdevGrabDevice(InputInfoPtr pInfo, int grab, int ungrab);
static void EvdevSetCalibration(InputInfoPtr pInfo, int num_calibration, int calibration[4]);
static BOOL EvdevOpenDevice(InputInfoPtr pInfo);
#ifdef HAVE_PROPERTIES
static void EvdevInitAxesLabels(EvdevPtr pEvdev, int natoms, Atom *atoms);
static void EvdevInitButtonLabels(EvdevPtr pEvdev, int natoms, Atom *atoms);
static void EvdevInitProperty(DeviceIntPtr dev);
static int EvdevSetProperty(DeviceIntPtr dev, Atom atom,
XIPropertyValuePtr val, BOOL checkonly);
static Atom prop_invert = 0;
static Atom prop_calibration = 0;
static Atom prop_swap = 0;
static Atom prop_axis_label = 0;
static Atom prop_btn_label = 0;
#endif
static EvdevPtr evdev_devices[MAXDEVICES] = {NULL};
static int EvdevSwitchMode(ClientPtr client, DeviceIntPtr device, int mode)
{
InputInfoPtr pInfo;
EvdevPtr pEvdev;
pInfo = device->public.devicePrivate;
pEvdev = pInfo->private;
if (pEvdev->flags & EVDEV_RELATIVE_EVENTS)
{
if (mode == Relative)
return Success;
else
return XI_BadMode;
}
switch (mode) {
case Absolute:
pEvdev->flags &= ~EVDEV_RELATIVE_MODE;
break;
case Relative:
pEvdev->flags |= EVDEV_RELATIVE_MODE;
break;
default:
return XI_BadMode;
}
return Success;
}
static size_t CountBits(unsigned long *array, size_t nlongs)
{
unsigned int i;
size_t count = 0;
for (i = 0; i < nlongs; i++) {
unsigned long x = array[i];
while (x > 0)
{
count += (x & 0x1);
x >>= 1;
}
}
return count;
}
static int
EvdevGetMajorMinor(InputInfoPtr pInfo)
{
struct stat st;
if (fstat(pInfo->fd, &st) == -1)
{
xf86Msg(X_ERROR, "%s: stat failed (%s). cannot check for duplicates.\n",
pInfo->name, strerror(errno));
return 0;
}
return st.st_rdev;
}
static BOOL
EvdevIsDuplicate(InputInfoPtr pInfo)
{
EvdevPtr pEvdev = pInfo->private;
EvdevPtr* dev = evdev_devices;
if (pEvdev->min_maj)
{
while(*dev)
{
if ((*dev) != pEvdev &&
(*dev)->min_maj &&
(*dev)->min_maj == pEvdev->min_maj)
return TRUE;
dev++;
}
}
return FALSE;
}
static void
EvdevAddDevice(InputInfoPtr pInfo)
{
EvdevPtr pEvdev = pInfo->private;
EvdevPtr* dev = evdev_devices;
while(*dev)
dev++;
*dev = pEvdev;
}
static void
EvdevRemoveDevice(InputInfoPtr pInfo)
{
EvdevPtr pEvdev = pInfo->private;
EvdevPtr *dev = evdev_devices;
int count = 0;
while(*dev)
{
count++;
if (*dev == pEvdev)
{
memmove(dev, dev + 1,
sizeof(evdev_devices) - (count * sizeof(EvdevPtr)));
break;
}
dev++;
}
}
static void
SetXkbOption(InputInfoPtr pInfo, char *name, char **option)
{
char *s;
if ((s = xf86SetStrOption(pInfo->options, name, NULL))) {
if (!s[0]) {
free(s);
*option = NULL;
} else {
*option = s;
}
}
}
static int wheel_up_button = 4;
static int wheel_down_button = 5;
static int wheel_left_button = 6;
static int wheel_right_button = 7;
static EventQueuePtr
EvdevNextInQueue(InputInfoPtr pInfo)
{
EvdevPtr pEvdev = pInfo->private;
if (pEvdev->num_queue >= EVDEV_MAXQUEUE)
{
xf86Msg(X_NONE, "%s: dropping event due to full queue!\n", pInfo->name);
return NULL;
}
pEvdev->num_queue++;
return &pEvdev->queue[pEvdev->num_queue - 1];
}
void
EvdevQueueKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value)
{
int code = ev->code + MIN_KEYCODE;
EventQueuePtr pQueue;
if (value == 2
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) <= 2
&& (ev->code == KEY_LEFTCTRL || ev->code == KEY_RIGHTCTRL ||
ev->code == KEY_LEFTSHIFT || ev->code == KEY_RIGHTSHIFT ||
ev->code == KEY_LEFTALT || ev->code == KEY_RIGHTALT ||
ev->code == KEY_LEFTMETA || ev->code == KEY_RIGHTMETA ||
ev->code == KEY_CAPSLOCK || ev->code == KEY_NUMLOCK ||
ev->code == KEY_SCROLLLOCK)
#endif
)
return;
if ((pQueue = EvdevNextInQueue(pInfo)))
{
pQueue->type = EV_QUEUE_KEY;
pQueue->key = code;
pQueue->val = value;
}
}
void
EvdevQueueButtonEvent(InputInfoPtr pInfo, int button, int value)
{
EventQueuePtr pQueue;
if ((pQueue = EvdevNextInQueue(pInfo)))
{
pQueue->type = EV_QUEUE_BTN;
pQueue->key = button;
pQueue->val = value;
}
}
void
EvdevPostButtonEvent(InputInfoPtr pInfo, int button, int value)
{
xf86PostButtonEvent(pInfo->dev, 0, button, value, 0, 0);
}
void
EvdevQueueButtonClicks(InputInfoPtr pInfo, int button, int count)
{
int i;
for (i = 0; i < count; i++) {
EvdevQueueButtonEvent(pInfo, button, 1);
EvdevQueueButtonEvent(pInfo, button, 0);
}
}
#define ABS_X_VALUE 0x1
#define ABS_Y_VALUE 0x2
#define ABS_VALUE 0x4
static void
EvdevProcessValuators(InputInfoPtr pInfo, int v[MAX_VALUATORS], int *num_v,
int *first_v)
{
int tmp;
EvdevPtr pEvdev = pInfo->private;
*num_v = *first_v = 0;
if (pEvdev->abs && (pEvdev->flags & EVDEV_RELATIVE_MODE)) {
if (pEvdev->tool) {
if (pEvdev->old_vals[0] != -1)
pEvdev->delta[REL_X] = pEvdev->vals[0] - pEvdev->old_vals[0];
if (pEvdev->old_vals[1] != -1)
pEvdev->delta[REL_Y] = pEvdev->vals[1] - pEvdev->old_vals[1];
if (pEvdev->abs & ABS_X_VALUE)
pEvdev->old_vals[0] = pEvdev->vals[0];
if (pEvdev->abs & ABS_Y_VALUE)
pEvdev->old_vals[1] = pEvdev->vals[1];
} else {
pEvdev->old_vals[0] = pEvdev->old_vals[1] = -1;
}
pEvdev->abs = 0;
pEvdev->rel = 1;
}
if (pEvdev->rel) {
int first = REL_CNT, last = 0;
int i;
if (pEvdev->swap_axes) {
tmp = pEvdev->delta[REL_X];
pEvdev->delta[REL_X] = pEvdev->delta[REL_Y];
pEvdev->delta[REL_Y] = tmp;
}
if (pEvdev->invert_x)
pEvdev->delta[REL_X] *= -1;
if (pEvdev->invert_y)
pEvdev->delta[REL_Y] *= -1;
for (i = 0; i < REL_CNT; i++)
{
int map = pEvdev->axis_map[i];
if (pEvdev->delta[i] && map != -1)
{
v[map] = pEvdev->delta[i];
if (map < first)
first = map;
if (map > last)
last = map;
}
}
*num_v = (last - first + 1);
*first_v = first;
}
else if (pEvdev->abs && pEvdev->tool) {
memcpy(v, pEvdev->vals, sizeof(int) * pEvdev->num_vals);
if (pEvdev->swap_axes) {
int tmp = v[0];
v[0] = xf86ScaleAxis(v[1],
pEvdev->absinfo[ABS_X].maximum,
pEvdev->absinfo[ABS_X].minimum,
pEvdev->absinfo[ABS_Y].maximum,
pEvdev->absinfo[ABS_Y].minimum);
v[1] = xf86ScaleAxis(tmp,
pEvdev->absinfo[ABS_Y].maximum,
pEvdev->absinfo[ABS_Y].minimum,
pEvdev->absinfo[ABS_X].maximum,
pEvdev->absinfo[ABS_X].minimum);
}
if (pEvdev->flags & EVDEV_CALIBRATED)
{
v[0] = xf86ScaleAxis(v[0],
pEvdev->absinfo[ABS_X].maximum,
pEvdev->absinfo[ABS_X].minimum,
pEvdev->calibration.max_x, pEvdev->calibration.min_x);
v[1] = xf86ScaleAxis(v[1],
pEvdev->absinfo[ABS_Y].maximum,
pEvdev->absinfo[ABS_Y].minimum,
pEvdev->calibration.max_y, pEvdev->calibration.min_y);
}
if (pEvdev->invert_x)
v[0] = (pEvdev->absinfo[ABS_X].maximum - v[0] +
pEvdev->absinfo[ABS_X].minimum);
if (pEvdev->invert_y)
v[1] = (pEvdev->absinfo[ABS_Y].maximum - v[1] +
pEvdev->absinfo[ABS_Y].minimum);
*num_v = pEvdev->num_vals;
*first_v = 0;
}
}
static void
EvdevProcessButtonEvent(InputInfoPtr pInfo, struct input_event *ev)
{
unsigned int button;
int value;
EvdevPtr pEvdev = pInfo->private;
button = EvdevUtilButtonEventToButtonNumber(pEvdev, ev->code);
value = ev->value;
if (EvdevDragLockFilterEvent(pInfo, button, value))
return;
if (EvdevWheelEmuFilterButton(pInfo, button, value))
return;
if (EvdevMBEmuFilterEvent(pInfo, button, value))
return;
if (button)
EvdevQueueButtonEvent(pInfo, button, value);
else
EvdevQueueKbdEvent(pInfo, ev, value);
}
static void
EvdevProcessRelativeMotionEvent(InputInfoPtr pInfo, struct input_event *ev)
{
int value;
EvdevPtr pEvdev = pInfo->private;
value = ev->value;
switch (ev->code) {
case REL_WHEEL:
if (value > 0)
EvdevQueueButtonClicks(pInfo, wheel_up_button, value);
else if (value < 0)
EvdevQueueButtonClicks(pInfo, wheel_down_button, -value);
break;
case REL_DIAL:
case REL_HWHEEL:
if (value > 0)
EvdevQueueButtonClicks(pInfo, wheel_right_button, value);
else if (value < 0)
EvdevQueueButtonClicks(pInfo, wheel_left_button, -value);
break;
default:
if (!(pEvdev->flags & EVDEV_RELATIVE_EVENTS))
return;
if (EvdevWheelEmuFilterMotion(pInfo, ev))
return;
pEvdev->rel = 1;
pEvdev->delta[ev->code] += value;
break;
}
}
static void
EvdevProcessAbsoluteMotionEvent(InputInfoPtr pInfo, struct input_event *ev)
{
int value;
EvdevPtr pEvdev = pInfo->private;
value = ev->value;
if (!(pEvdev->flags & EVDEV_ABSOLUTE_EVENTS))
return;
if (ev->code > ABS_MAX)
return;
if (EvdevWheelEmuFilterMotion(pInfo, ev))
return;
pEvdev->vals[pEvdev->axis_map[ev->code]] = value;
if (ev->code == ABS_X)
pEvdev->abs |= ABS_X_VALUE;
else if (ev->code == ABS_Y)
pEvdev->abs |= ABS_Y_VALUE;
else
pEvdev->abs |= ABS_VALUE;
}
static void
EvdevProcessKeyEvent(InputInfoPtr pInfo, struct input_event *ev)
{
int value;
EvdevPtr pEvdev = pInfo->private;
value = ev->value;
if (ev->code >= BTN_MOUSE && ev->code < KEY_OK)
if (value == 2)
return;
switch (ev->code) {
case BTN_TOOL_PEN:
case BTN_TOOL_RUBBER:
case BTN_TOOL_BRUSH:
case BTN_TOOL_PENCIL:
case BTN_TOOL_AIRBRUSH:
case BTN_TOOL_FINGER:
case BTN_TOOL_MOUSE:
case BTN_TOOL_LENS:
pEvdev->tool = value ? ev->code : 0;
break;
case BTN_TOUCH:
if (!(pEvdev->flags & (EVDEV_TOUCHSCREEN | EVDEV_TABLET)))
break;
ev->code = BTN_LEFT;
default:
EvdevProcessButtonEvent(pInfo, ev);
break;
}
}
void
EvdevPostRelativeMotionEvents(InputInfoPtr pInfo, int num_v, int first_v,
int v[MAX_VALUATORS])
{
EvdevPtr pEvdev = pInfo->private;
if (pEvdev->rel) {
xf86PostMotionEventP(pInfo->dev, FALSE, first_v, num_v, v + first_v);
}
}
void
EvdevPostAbsoluteMotionEvents(InputInfoPtr pInfo, int num_v, int first_v,
int v[MAX_VALUATORS])
{
EvdevPtr pEvdev = pInfo->private;
if (pEvdev->abs && pEvdev->tool) {
xf86PostMotionEventP(pInfo->dev, TRUE, first_v, num_v, v + first_v);
}
}
static void EvdevPostQueuedEvents(InputInfoPtr pInfo, int num_v, int first_v,
int v[MAX_VALUATORS])
{
int i;
EvdevPtr pEvdev = pInfo->private;
for (i = 0; i < pEvdev->num_queue; i++) {
switch (pEvdev->queue[i].type) {
case EV_QUEUE_KEY:
xf86PostKeyboardEvent(pInfo->dev, pEvdev->queue[i].key,
pEvdev->queue[i].val);
break;
case EV_QUEUE_BTN:
xf86PostButtonEvent(pInfo->dev, 0, pEvdev->queue[i].key,
pEvdev->queue[i].val, 0, 0);
break;
}
}
}
static void
EvdevProcessSyncEvent(InputInfoPtr pInfo, struct input_event *ev)
{
int num_v = 0, first_v = 0;
int v[MAX_VALUATORS] = {};
EvdevPtr pEvdev = pInfo->private;
EvdevProcessValuators(pInfo, v, &num_v, &first_v);
EvdevPostRelativeMotionEvents(pInfo, num_v, first_v, v);
EvdevPostAbsoluteMotionEvents(pInfo, num_v, first_v, v);
EvdevPostQueuedEvents(pInfo, num_v, first_v, v);
memset(pEvdev->delta, 0, sizeof(pEvdev->delta));
memset(pEvdev->queue, 0, sizeof(pEvdev->queue));
pEvdev->num_queue = 0;
pEvdev->abs = 0;
pEvdev->rel = 0;
}
static void
EvdevProcessEvent(InputInfoPtr pInfo, struct input_event *ev)
{
switch (ev->type) {
case EV_REL:
EvdevProcessRelativeMotionEvent(pInfo, ev);
break;
case EV_ABS:
EvdevProcessAbsoluteMotionEvent(pInfo, ev);
break;
case EV_KEY:
EvdevProcessKeyEvent(pInfo, ev);
break;
case EV_SYN:
EvdevProcessSyncEvent(pInfo, ev);
break;
}
}
#undef ABS_X_VALUE
#undef ABS_Y_VALUE
#undef ABS_VALUE
#define NUM_EVENTS 16
static void
EvdevReadInput(InputInfoPtr pInfo)
{
struct input_event ev[NUM_EVENTS];
int i, len = sizeof(ev);
while (len == sizeof(ev))
{
len = read(pInfo->fd, &ev, sizeof(ev));
if (len <= 0)
{
if (errno == ENODEV)
{
EvdevMBEmuFinalize(pInfo);
xf86RemoveEnabledDevice(pInfo);
close(pInfo->fd);
pInfo->fd = -1;
} else if (errno != EAGAIN)
{
xf86MsgVerb(X_NONE, 0, "%s: Read error: %s\n", pInfo->name,
strerror(errno));
}
break;
}
if (len % sizeof(ev[0])) {
xf86MsgVerb(X_NONE, 0, "%s: Read error: %s\n", pInfo->name, strerror(errno));
break;
}
for (i = 0; i < len/sizeof(ev[0]); i++)
EvdevProcessEvent(pInfo, &ev[i]);
}
}
#define TestBit(bit, array) ((array[(bit) / LONG_BITS]) & (1L << ((bit) % LONG_BITS)))
static void
EvdevPtrCtrlProc(DeviceIntPtr device, PtrCtrl *ctrl)
{
}
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 5
static KeySym map[] = {
NoSymbol, NoSymbol,
XK_Escape, NoSymbol,
XK_1, XK_exclam,
XK_2, XK_at,
XK_3, XK_numbersign,
XK_4, XK_dollar,
XK_5, XK_percent,
XK_6, XK_asciicircum,
XK_7, XK_ampersand,
XK_8, XK_asterisk,
XK_9, XK_parenleft,
XK_0, XK_parenright,
XK_minus, XK_underscore,
XK_equal, XK_plus,
XK_BackSpace, NoSymbol,
XK_Tab, XK_ISO_Left_Tab,
XK_Q, NoSymbol,
XK_W, NoSymbol,
XK_E, NoSymbol,
XK_R, NoSymbol,
XK_T, NoSymbol,
XK_Y, NoSymbol,
XK_U, NoSymbol,
XK_I, NoSymbol,
XK_O, NoSymbol,
XK_P, NoSymbol,
XK_bracketleft, XK_braceleft,
XK_bracketright,XK_braceright,
XK_Return, NoSymbol,
XK_Control_L, NoSymbol,
XK_A, NoSymbol,
XK_S, NoSymbol,
XK_D, NoSymbol,
XK_F, NoSymbol,
XK_G, NoSymbol,
XK_H, NoSymbol,
XK_J, NoSymbol,
XK_K, NoSymbol,
XK_L, NoSymbol,
XK_semicolon, XK_colon,
XK_quoteright, XK_quotedbl,
XK_quoteleft, XK_asciitilde,
XK_Shift_L, NoSymbol,
XK_backslash, XK_bar,
XK_Z, NoSymbol,
XK_X, NoSymbol,
XK_C, NoSymbol,
XK_V, NoSymbol,
XK_B, NoSymbol,
XK_N, NoSymbol,
XK_M, NoSymbol,
XK_comma, XK_less,
XK_period, XK_greater,
XK_slash, XK_question,
XK_Shift_R, NoSymbol,
XK_KP_Multiply, NoSymbol,
XK_Alt_L, XK_Meta_L,
XK_space, NoSymbol,
XK_Caps_Lock, NoSymbol,
XK_F1, NoSymbol,
XK_F2, NoSymbol,
XK_F3, NoSymbol,
XK_F4, NoSymbol,
XK_F5, NoSymbol,
XK_F6, NoSymbol,
XK_F7, NoSymbol,
XK_F8, NoSymbol,
XK_F9, NoSymbol,
XK_F10, NoSymbol,
XK_Num_Lock, NoSymbol,
XK_Scroll_Lock, NoSymbol,
XK_KP_Home, XK_KP_7,
XK_KP_Up, XK_KP_8,
XK_KP_Prior, XK_KP_9,
XK_KP_Subtract, NoSymbol,
XK_KP_Left, XK_KP_4,
XK_KP_Begin, XK_KP_5,
XK_KP_Right, XK_KP_6,
XK_KP_Add, NoSymbol,
XK_KP_End, XK_KP_1,
XK_KP_Down, XK_KP_2,
XK_KP_Next, XK_KP_3,
XK_KP_Insert, XK_KP_0,
XK_KP_Delete, XK_KP_Decimal,
NoSymbol, NoSymbol,
XK_F13, NoSymbol,
XK_less, XK_greater,
XK_F11, NoSymbol,
XK_F12, NoSymbol,
XK_F14, NoSymbol,
XK_F15, NoSymbol,
XK_F16, NoSymbol,
XK_F17, NoSymbol,
XK_F18, NoSymbol,
XK_F19, NoSymbol,
XK_F20, NoSymbol,
XK_KP_Enter, NoSymbol,
XK_Control_R, NoSymbol,
XK_KP_Divide, NoSymbol,
XK_Print, XK_Sys_Req,
XK_Alt_R, XK_Meta_R,
NoSymbol, NoSymbol,
XK_Home, NoSymbol,
XK_Up, NoSymbol,
XK_Prior, NoSymbol,
XK_Left, NoSymbol,
XK_Right, NoSymbol,
XK_End, NoSymbol,
XK_Down, NoSymbol,
XK_Next, NoSymbol,
XK_Insert, NoSymbol,
XK_Delete, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
XK_KP_Equal, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
XK_F21, NoSymbol,
XK_F22, NoSymbol,
XK_F23, NoSymbol,
XK_F24, NoSymbol,
XK_KP_Separator, NoSymbol,
XK_Meta_L, NoSymbol,
XK_Meta_R, NoSymbol,
XK_Multi_key, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
NoSymbol, NoSymbol,
};
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_Meta_L, Mod4Mask },
{ XK_Meta_R, Mod4Mask },
{ XK_Num_Lock, NumLockMask },
{ XK_Scroll_Lock, ScrollLockMask },
{ XK_Mode_switch, AltLangMask }
};
static int
EvdevInitKeysyms(DeviceIntPtr device)
{
InputInfoPtr pInfo;
EvdevPtr pEvdev;
KeySymsRec keySyms;
CARD8 modMap[MAP_LENGTH];
KeySym sym;
int i, j;
pInfo = device->public.devicePrivate;
pEvdev = pInfo->private;
memset(modMap, 0, sizeof modMap);
for (i = 0; i < ArrayLength(map) / GLYPHS_PER_KEY; i++) {
sym = map[i * GLYPHS_PER_KEY];
for (j = 0; j < ArrayLength(modifiers); j++) {
if (modifiers[j].keysym == sym)
modMap[i + MIN_KEYCODE] = modifiers[j].mask;
}
}
keySyms.map = map;
keySyms.mapWidth = GLYPHS_PER_KEY;
keySyms.minKeyCode = MIN_KEYCODE;
keySyms.maxKeyCode = MIN_KEYCODE + ArrayLength(map) / GLYPHS_PER_KEY - 1;
XkbSetRulesDflts(pEvdev->rmlvo.rules, pEvdev->rmlvo.model,
pEvdev->rmlvo.layout, pEvdev->rmlvo.variant,
pEvdev->rmlvo.options);
if (!XkbInitKeyboardDeviceStruct(device, &pEvdev->xkbnames,
&keySyms, modMap, NULL,
EvdevKbdCtrl))
return 0;
return 1;
}
#endif
static void
EvdevKbdCtrl(DeviceIntPtr device, KeybdCtrl *ctrl)
{
static struct { int xbit, code; } bits[] = {
{ CAPSFLAG, LED_CAPSL },
{ NUMFLAG, LED_NUML },
{ SCROLLFLAG, LED_SCROLLL },
{ MODEFLAG, LED_KANA },
{ COMPOSEFLAG, LED_COMPOSE }
};
InputInfoPtr pInfo;
struct input_event ev[ArrayLength(bits)];
int i;
memset(ev, 0, sizeof(ev));
pInfo = device->public.devicePrivate;
for (i = 0; i < ArrayLength(bits); i++) {
ev[i].type = EV_LED;
ev[i].code = bits[i].code;
ev[i].value = (ctrl->leds & bits[i].xbit) > 0;
}
write(pInfo->fd, ev, sizeof ev);
}
static int
EvdevAddKeyClass(DeviceIntPtr device)
{
InputInfoPtr pInfo;
EvdevPtr pEvdev;
pInfo = device->public.devicePrivate;
pEvdev = pInfo->private;
xf86ReplaceStrOption(pInfo->options, "xkb_rules", "evdev");
SetXkbOption(pInfo, "xkb_rules", &pEvdev->rmlvo.rules);
SetXkbOption(pInfo, "xkb_model", &pEvdev->rmlvo.model);
if (!pEvdev->rmlvo.model)
SetXkbOption(pInfo, "XkbModel", &pEvdev->rmlvo.model);
SetXkbOption(pInfo, "xkb_layout", &pEvdev->rmlvo.layout);
if (!pEvdev->rmlvo.layout)
SetXkbOption(pInfo, "XkbLayout", &pEvdev->rmlvo.layout);
SetXkbOption(pInfo, "xkb_variant", &pEvdev->rmlvo.variant);
if (!pEvdev->rmlvo.variant)
SetXkbOption(pInfo, "XkbVariant", &pEvdev->rmlvo.variant);
SetXkbOption(pInfo, "xkb_options", &pEvdev->rmlvo.options);
if (!pEvdev->rmlvo.options)
SetXkbOption(pInfo, "XkbOptions", &pEvdev->rmlvo.options);
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 5
if (!InitKeyboardDeviceStruct(device, &pEvdev->rmlvo, NULL, EvdevKbdCtrl))
return !Success;
#else
if (!EvdevInitKeysyms(device))
return !Success;
#endif
return Success;
}
static int
EvdevAddAbsClass(DeviceIntPtr device)
{
InputInfoPtr pInfo;
EvdevPtr pEvdev;
int num_axes, axis, i = 0;
Atom *atoms;
pInfo = device->public.devicePrivate;
pEvdev = pInfo->private;
if (!TestBit(EV_ABS, pEvdev->bitmask))
return !Success;
num_axes = CountBits(pEvdev->abs_bitmask, NLONGS(ABS_MAX));
if (num_axes < 1)
return !Success;
if (num_axes > MAX_VALUATORS) {
xf86Msg(X_WARNING, "%s: found %d axes, limiting to %d.\n", device->name, num_axes, MAX_VALUATORS);
num_axes = MAX_VALUATORS;
}
pEvdev->num_vals = num_axes;
memset(pEvdev->vals, 0, num_axes * sizeof(int));
memset(pEvdev->old_vals, -1, num_axes * sizeof(int));
atoms = malloc(pEvdev->num_vals * sizeof(Atom));
for (axis = ABS_X; i < MAX_VALUATORS && axis <= ABS_MAX; axis++) {
pEvdev->axis_map[axis] = -1;
if (!TestBit(axis, pEvdev->abs_bitmask))
continue;
pEvdev->axis_map[axis] = i;
i++;
}
EvdevInitAxesLabels(pEvdev, pEvdev->num_vals, atoms);
if (!InitValuatorClassDeviceStruct(device, num_axes,
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
atoms,
#endif
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
GetMotionHistory,
#endif
GetMotionHistorySize(), Absolute))
return !Success;
for (axis = ABS_X; axis <= ABS_MAX; axis++) {
int axnum = pEvdev->axis_map[axis];
int resolution = 10000;
if (axnum == -1)
continue;
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 30)
if (pEvdev->absinfo[axis].resolution)
resolution = pEvdev->absinfo[axis].resolution * 1000;
#endif
xf86InitValuatorAxisStruct(device, axnum,
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
atoms[axnum],
#endif
pEvdev->absinfo[axis].minimum,
pEvdev->absinfo[axis].maximum,
resolution, 0, resolution);
xf86InitValuatorDefaults(device, axnum);
pEvdev->old_vals[axnum] = -1;
}
free(atoms);
if (!InitPtrFeedbackClassDeviceStruct(device, EvdevPtrCtrlProc))
return !Success;
if (pEvdev->flags & EVDEV_TOUCHPAD)
pEvdev->flags |= EVDEV_RELATIVE_MODE;
else
pEvdev->flags &= ~EVDEV_RELATIVE_MODE;
if (xf86FindOption(pInfo->options, "Mode"))
{
char *mode;
mode = xf86SetStrOption(pInfo->options, "Mode", NULL);
if (!strcasecmp("absolute", mode))
pEvdev->flags &= ~EVDEV_RELATIVE_MODE;
else if (!strcasecmp("relative", mode))
pEvdev->flags |= EVDEV_RELATIVE_MODE;
else
xf86Msg(X_INFO, "%s: unknown mode, use default\n", pInfo->name);
free(mode);
}
return Success;
}
static int
EvdevAddRelClass(DeviceIntPtr device)
{
InputInfoPtr pInfo;
EvdevPtr pEvdev;
int num_axes, axis, i = 0;
Atom *atoms;
pInfo = device->public.devicePrivate;
pEvdev = pInfo->private;
if (!TestBit(EV_REL, pEvdev->bitmask))
return !Success;
num_axes = CountBits(pEvdev->rel_bitmask, NLONGS(REL_MAX));
if (num_axes < 1)
return !Success;
if (TestBit(REL_WHEEL, pEvdev->rel_bitmask))
num_axes--;
if (TestBit(REL_HWHEEL, pEvdev->rel_bitmask))
num_axes--;
if (TestBit(REL_DIAL, pEvdev->rel_bitmask))
num_axes--;
if (num_axes <= 0)
return !Success;
if (num_axes > MAX_VALUATORS) {
xf86Msg(X_WARNING, "%s: found %d axes, limiting to %d.\n", device->name, num_axes, MAX_VALUATORS);
num_axes = MAX_VALUATORS;
}
pEvdev->num_vals = num_axes;
memset(pEvdev->vals, 0, num_axes * sizeof(int));
atoms = malloc(pEvdev->num_vals * sizeof(Atom));
for (axis = REL_X; i < MAX_VALUATORS && axis <= REL_MAX; axis++)
{
pEvdev->axis_map[axis] = -1;
if (axis == REL_WHEEL || axis == REL_HWHEEL || axis == REL_DIAL)
continue;
if (!TestBit(axis, pEvdev->rel_bitmask))
continue;
pEvdev->axis_map[axis] = i;
i++;
}
EvdevInitAxesLabels(pEvdev, pEvdev->num_vals, atoms);
if (!InitValuatorClassDeviceStruct(device, num_axes,
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
atoms,
#endif
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
GetMotionHistory,
#endif
GetMotionHistorySize(), Relative))
return !Success;
if (!InitPtrFeedbackClassDeviceStruct(device, EvdevPtrCtrlProc))
return !Success;
for (axis = REL_X; axis <= REL_MAX; axis++)
{
int axnum = pEvdev->axis_map[axis];
if (axnum == -1)
continue;
xf86InitValuatorAxisStruct(device, axnum,
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
atoms[axnum],
#endif
-1, -1, 1, 0, 1);
xf86InitValuatorDefaults(device, axnum);
}
free(atoms);
return Success;
}
static int
EvdevAddButtonClass(DeviceIntPtr device)
{
InputInfoPtr pInfo;
EvdevPtr pEvdev;
Atom *labels;
pInfo = device->public.devicePrivate;
pEvdev = pInfo->private;
labels = malloc(pEvdev->num_buttons * sizeof(Atom));
EvdevInitButtonLabels(pEvdev, pEvdev->num_buttons, labels);
if (!InitButtonClassDeviceStruct(device, pEvdev->num_buttons,
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
labels,
#endif
pEvdev->btnmap))
return !Success;
free(labels);
return Success;
}
static void
EvdevInitButtonMapping(InputInfoPtr pInfo)
{
int i, nbuttons = 1;
char *mapping = NULL;
EvdevPtr pEvdev = pInfo->private;
if ((mapping = xf86CheckStrOption(pInfo->options, "ButtonMapping", NULL)))
{
char *map, *s = " ";
int btn = 0;
xf86Msg(X_CONFIG, "%s: ButtonMapping '%s'\n", pInfo->name, mapping);
map = mapping;
while (s && *s != '\0' && nbuttons < EVDEV_MAXBUTTONS)
{
btn = strtol(map, &s, 10);
if (s == map || btn < 0 || btn > EVDEV_MAXBUTTONS)
{
xf86Msg(X_ERROR,
"%s: ... Invalid button mapping. Using defaults\n",
pInfo->name);
nbuttons = 1;
break;
}
pEvdev->btnmap[nbuttons++] = btn;
map = s;
}
free(mapping);
}
for (i = nbuttons; i < ArrayLength(pEvdev->btnmap); i++)
pEvdev->btnmap[i] = i;
}
static void
EvdevInitAnyClass(DeviceIntPtr device, EvdevPtr pEvdev)
{
if (pEvdev->flags & EVDEV_RELATIVE_EVENTS &&
EvdevAddRelClass(device) == Success)
xf86Msg(X_INFO, "%s: initialized for relative axes.\n", device->name);
if (pEvdev->flags & EVDEV_ABSOLUTE_EVENTS &&
EvdevAddAbsClass(device) == Success)
xf86Msg(X_INFO, "%s: initialized for absolute axes.\n", device->name);
}
static void
EvdevInitAbsClass(DeviceIntPtr device, EvdevPtr pEvdev)
{
if (EvdevAddAbsClass(device) == Success) {
xf86Msg(X_INFO,"%s: initialized for absolute axes.\n", device->name);
} else {
xf86Msg(X_ERROR,"%s: failed to initialize for absolute axes.\n",
device->name);
pEvdev->flags &= ~EVDEV_ABSOLUTE_EVENTS;
}
}
static void
EvdevInitRelClass(DeviceIntPtr device, EvdevPtr pEvdev)
{
int has_abs_axes = pEvdev->flags & EVDEV_ABSOLUTE_EVENTS;
if (EvdevAddRelClass(device) == Success) {
xf86Msg(X_INFO,"%s: initialized for relative axes.\n", device->name);
if (has_abs_axes) {
xf86Msg(X_WARNING,"%s: ignoring absolute axes.\n", device->name);
pEvdev->flags &= ~EVDEV_ABSOLUTE_EVENTS;
}
} else {
xf86Msg(X_ERROR,"%s: failed to initialize for relative axes.\n",
device->name);
pEvdev->flags &= ~EVDEV_RELATIVE_EVENTS;
if (has_abs_axes)
EvdevInitAbsClass(device, pEvdev);
}
}
static void
EvdevInitTouchDevice(DeviceIntPtr device, EvdevPtr pEvdev)
{
if (pEvdev->flags & EVDEV_RELATIVE_EVENTS) {
xf86Msg(X_WARNING,"%s: touchpads, tablets and touchscreens ignore "
"relative axes.\n", device->name);
pEvdev->flags &= ~EVDEV_RELATIVE_EVENTS;
}
EvdevInitAbsClass(device, pEvdev);
}
static int
EvdevInit(DeviceIntPtr device)
{
int i;
InputInfoPtr pInfo;
EvdevPtr pEvdev;
pInfo = device->public.devicePrivate;
pEvdev = pInfo->private;
for(i = 0; i < max(ABS_CNT,REL_CNT); i++)
pEvdev->axis_map[i]=-1;
if (pEvdev->flags & EVDEV_KEYBOARD_EVENTS)
EvdevAddKeyClass(device);
if (pEvdev->flags & EVDEV_BUTTON_EVENTS)
EvdevAddButtonClass(device);
if (pEvdev->flags & (EVDEV_UNIGNORE_RELATIVE | EVDEV_UNIGNORE_ABSOLUTE))
EvdevInitAnyClass(device, pEvdev);
else if (pEvdev->flags & (EVDEV_TOUCHPAD | EVDEV_TOUCHSCREEN | EVDEV_TABLET))
EvdevInitTouchDevice(device, pEvdev);
else if (pEvdev->flags & EVDEV_RELATIVE_EVENTS)
EvdevInitRelClass(device, pEvdev);
else if (pEvdev->flags & EVDEV_ABSOLUTE_EVENTS)
EvdevInitAbsClass(device, pEvdev);
#ifdef HAVE_PROPERTIES
EvdevInitProperty(device);
XIRegisterPropertyHandler(device, EvdevSetProperty, NULL, NULL);
EvdevMBEmuInitProperty(device);
EvdevWheelEmuInitProperty(device);
EvdevDragLockInitProperty(device);
#endif
return Success;
}
static int
EvdevOn(DeviceIntPtr device)
{
InputInfoPtr pInfo;
EvdevPtr pEvdev;
pInfo = device->public.devicePrivate;
pEvdev = pInfo->private;
if (!EvdevOpenDevice(pInfo))
return !Success;
EvdevGrabDevice(pInfo, 1, 0);
xf86FlushInput(pInfo->fd);
xf86AddEnabledDevice(pInfo);
EvdevMBEmuOn(pInfo);
pEvdev->flags |= EVDEV_INITIALIZED;
device->public.on = TRUE;
return Success;
}
static int
EvdevProc(DeviceIntPtr device, int what)
{
InputInfoPtr pInfo;
EvdevPtr pEvdev;
pInfo = device->public.devicePrivate;
pEvdev = pInfo->private;
switch (what)
{
case DEVICE_INIT:
return EvdevInit(device);
case DEVICE_ON:
return EvdevOn(device);
case DEVICE_OFF:
if (pEvdev->flags & EVDEV_INITIALIZED)
EvdevMBEmuFinalize(pInfo);
if (pInfo->fd != -1)
{
EvdevGrabDevice(pInfo, 0, 1);
xf86RemoveEnabledDevice(pInfo);
close(pInfo->fd);
pInfo->fd = -1;
}
pEvdev->min_maj = 0;
pEvdev->flags &= ~EVDEV_INITIALIZED;
device->public.on = FALSE;
break;
case DEVICE_CLOSE:
xf86Msg(X_INFO, "%s: Close\n", pInfo->name);
if (pInfo->fd != -1) {
close(pInfo->fd);
pInfo->fd = -1;
}
EvdevRemoveDevice(pInfo);
pEvdev->min_maj = 0;
break;
}
return Success;
}
static int
EvdevCacheCompare(InputInfoPtr pInfo, BOOL compare)
{
EvdevPtr pEvdev = pInfo->private;
int i, len;
char name[1024] = {0};
unsigned long bitmask[NLONGS(EV_CNT)] = {0};
unsigned long key_bitmask[NLONGS(KEY_CNT)] = {0};
unsigned long rel_bitmask[NLONGS(REL_CNT)] = {0};
unsigned long abs_bitmask[NLONGS(ABS_CNT)] = {0};
unsigned long led_bitmask[NLONGS(LED_CNT)] = {0};
if (ioctl(pInfo->fd, EVIOCGNAME(sizeof(name) - 1), name) < 0) {
xf86Msg(X_ERROR, "ioctl EVIOCGNAME failed: %s\n", strerror(errno));
goto error;
}
if (!compare) {
strcpy(pEvdev->name, name);
} else if (strcmp(pEvdev->name, name)) {
xf86Msg(X_ERROR, "%s: device name changed: %s != %s\n",
pInfo->name, pEvdev->name, name);
goto error;
}
len = ioctl(pInfo->fd, EVIOCGBIT(0, sizeof(bitmask)), bitmask);
if (len < 0) {
xf86Msg(X_ERROR, "%s: ioctl EVIOCGBIT failed: %s\n",
pInfo->name, strerror(errno));
goto error;
}
if (!compare) {
memcpy(pEvdev->bitmask, bitmask, len);
} else if (memcmp(pEvdev->bitmask, bitmask, len)) {
xf86Msg(X_ERROR, "%s: device bitmask has changed\n", pInfo->name);
goto error;
}
len = ioctl(pInfo->fd, EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask);
if (len < 0) {
xf86Msg(X_ERROR, "%s: ioctl EVIOCGBIT failed: %s\n",
pInfo->name, strerror(errno));
goto error;
}
if (!compare) {
memcpy(pEvdev->rel_bitmask, rel_bitmask, len);
} else if (memcmp(pEvdev->rel_bitmask, rel_bitmask, len)) {
xf86Msg(X_ERROR, "%s: device rel_bitmask has changed\n", pInfo->name);
goto error;
}
len = ioctl(pInfo->fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask);
if (len < 0) {
xf86Msg(X_ERROR, "%s: ioctl EVIOCGBIT failed: %s\n",
pInfo->name, strerror(errno));
goto error;
}
if (!compare) {
memcpy(pEvdev->abs_bitmask, abs_bitmask, len);
} else if (memcmp(pEvdev->abs_bitmask, abs_bitmask, len)) {
xf86Msg(X_ERROR, "%s: device abs_bitmask has changed\n", pInfo->name);
goto error;
}
len = ioctl(pInfo->fd, EVIOCGBIT(EV_LED, sizeof(led_bitmask)), led_bitmask);
if (len < 0) {
xf86Msg(X_ERROR, "%s: ioctl EVIOCGBIT failed: %s\n",
pInfo->name, strerror(errno));
goto error;
}
if (!compare) {
memcpy(pEvdev->led_bitmask, led_bitmask, len);
} else if (memcmp(pEvdev->led_bitmask, led_bitmask, len)) {
xf86Msg(X_ERROR, "%s: device led_bitmask has changed\n", pInfo->name);
goto error;
}
for (i = ABS_X; i <= ABS_MAX; i++) {
if (TestBit(i, abs_bitmask)) {
len = ioctl(pInfo->fd, EVIOCGABS(i), &pEvdev->absinfo[i]);
if (len < 0) {
xf86Msg(X_ERROR, "%s: ioctl EVIOCGABSi(%d) failed: %s\n",
pInfo->name, i, strerror(errno));
goto error;
}
}
}
len = ioctl(pInfo->fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask);
if (len < 0) {
xf86Msg(X_ERROR, "%s: ioctl EVIOCGBIT failed: %s\n",
pInfo->name, strerror(errno));
goto error;
}
if (compare) {
size_t start_word = BTN_MISC / LONG_BITS;
size_t start_byte = start_word * sizeof(unsigned long);
size_t end_word = KEY_OK / LONG_BITS;
size_t end_byte = end_word * sizeof(unsigned long);
if (len >= start_byte &&
memcmp(&pEvdev->key_bitmask[start_word], &key_bitmask[start_word],
min(len, end_byte) - start_byte + 1)) {
xf86Msg(X_ERROR, "%s: device key_bitmask has changed\n", pInfo->name);
goto error;
}
}
memcpy(pEvdev->key_bitmask, key_bitmask, len);
return Success;
error:
return !Success;
}
static BOOL
EvdevGrabDevice(InputInfoPtr pInfo, int grab, int ungrab)
{
EvdevPtr pEvdev = pInfo->private;
if (pEvdev->grabDevice)
{
if (grab && ioctl(pInfo->fd, EVIOCGRAB, (void *)1)) {
xf86Msg(X_WARNING, "%s: Grab failed (%s)\n", pInfo->name,
strerror(errno));
return FALSE;
} else if (ungrab && ioctl(pInfo->fd, EVIOCGRAB, (void *)0))
xf86Msg(X_WARNING, "%s: Release failed (%s)\n", pInfo->name,
strerror(errno));
}
return TRUE;
}
static int
EvdevProbe(InputInfoPtr pInfo)
{
int i, has_rel_axes, has_abs_axes, has_keys, num_buttons, has_scroll;
int has_lmr;
int ignore_abs = 0, ignore_rel = 0;
EvdevPtr pEvdev = pInfo->private;
if (xf86FindOption(pInfo->options, "IgnoreRelativeAxes"))
{
if (xf86SetBoolOption(pInfo->options, "IgnoreRelativeAxes", FALSE))
ignore_rel = TRUE;
else
pEvdev->flags |= EVDEV_UNIGNORE_RELATIVE;
}
if (xf86FindOption(pInfo->options, "IgnoreAbsoluteAxes"))
{
if (xf86SetBoolOption(pInfo->options, "IgnoreAbsoluteAxes", FALSE))
ignore_abs = TRUE;
else
pEvdev->flags |= EVDEV_UNIGNORE_ABSOLUTE;
}
has_rel_axes = FALSE;
has_abs_axes = FALSE;
has_keys = FALSE;
has_scroll = FALSE;
has_lmr = FALSE;
num_buttons = 0;
for (i = BTN_MISC; i < BTN_JOYSTICK; i++)
{
int mapping = 0;
if (TestBit(i, pEvdev->key_bitmask))
{
mapping = EvdevUtilButtonEventToButtonNumber(pEvdev, i);
if (mapping > num_buttons)
num_buttons = mapping;
}
}
has_lmr = TestBit(BTN_LEFT, pEvdev->key_bitmask) ||
TestBit(BTN_MIDDLE, pEvdev->key_bitmask) ||
TestBit(BTN_RIGHT, pEvdev->key_bitmask);
if (num_buttons)
{
pEvdev->flags |= EVDEV_BUTTON_EVENTS;
pEvdev->num_buttons = num_buttons;
xf86Msg(X_PROBED, "%s: Found %d mouse buttons\n", pInfo->name,
num_buttons);
}
for (i = 0; i < REL_MAX; i++) {
if (TestBit(i, pEvdev->rel_bitmask)) {
has_rel_axes = TRUE;
break;
}
}
if (has_rel_axes) {
if (TestBit(REL_WHEEL, pEvdev->rel_bitmask) ||
TestBit(REL_HWHEEL, pEvdev->rel_bitmask) ||
TestBit(REL_DIAL, pEvdev->rel_bitmask)) {
xf86Msg(X_PROBED, "%s: Found scroll wheel(s)\n", pInfo->name);
has_scroll = TRUE;
if (!num_buttons)
xf86Msg(X_INFO, "%s: Forcing buttons for scroll wheel(s)\n",
pInfo->name);
num_buttons = (num_buttons < 3) ? 7 : num_buttons + 4;
pEvdev->num_buttons = num_buttons;
}
if (!ignore_rel)
{
xf86Msg(X_PROBED, "%s: Found relative axes\n", pInfo->name);
pEvdev->flags |= EVDEV_RELATIVE_EVENTS;
if (TestBit(REL_X, pEvdev->rel_bitmask) &&
TestBit(REL_Y, pEvdev->rel_bitmask)) {
xf86Msg(X_PROBED, "%s: Found x and y relative axes\n", pInfo->name);
}
} else {
xf86Msg(X_INFO, "%s: Relative axes present but ignored.\n", pInfo->name);
has_rel_axes = FALSE;
}
}
for (i = 0; i < ABS_MAX; i++) {
if (TestBit(i, pEvdev->abs_bitmask)) {
has_abs_axes = TRUE;
break;
}
}
if (ignore_abs && has_abs_axes)
{
xf86Msg(X_INFO, "%s: Absolute axes present but ignored.\n", pInfo->name);
has_abs_axes = FALSE;
} else if (has_abs_axes) {
xf86Msg(X_PROBED, "%s: Found absolute axes\n", pInfo->name);
pEvdev->flags |= EVDEV_ABSOLUTE_EVENTS;
if ((TestBit(ABS_X, pEvdev->abs_bitmask) &&
TestBit(ABS_Y, pEvdev->abs_bitmask))) {
xf86Msg(X_PROBED, "%s: Found x and y absolute axes\n", pInfo->name);
if (TestBit(BTN_TOOL_PEN, pEvdev->key_bitmask) ||
TestBit(BTN_STYLUS, pEvdev->key_bitmask) ||
TestBit(BTN_STYLUS2, pEvdev->key_bitmask))
{
xf86Msg(X_PROBED, "%s: Found absolute tablet.\n", pInfo->name);
pEvdev->flags |= EVDEV_TABLET;
if (!pEvdev->num_buttons)
{
pEvdev->num_buttons = 7;
pEvdev->flags |= EVDEV_BUTTON_EVENTS;
}
} else if (TestBit(ABS_PRESSURE, pEvdev->abs_bitmask) ||
TestBit(BTN_TOUCH, pEvdev->key_bitmask)) {
if (has_lmr || TestBit(BTN_TOOL_FINGER, pEvdev->key_bitmask)) {
xf86Msg(X_PROBED, "%s: Found absolute touchpad.\n", pInfo->name);
pEvdev->flags |= EVDEV_TOUCHPAD;
memset(pEvdev->old_vals, -1, sizeof(int) * pEvdev->num_vals);
} else {
xf86Msg(X_PROBED, "%s: Found absolute touchscreen\n", pInfo->name);
pEvdev->flags |= EVDEV_TOUCHSCREEN;
pEvdev->flags |= EVDEV_BUTTON_EVENTS;
}
}
}
}
for (i = 0; i < BTN_MISC; i++) {
if (TestBit(i, pEvdev->key_bitmask)) {
xf86Msg(X_PROBED, "%s: Found keys\n", pInfo->name);
pEvdev->flags |= EVDEV_KEYBOARD_EVENTS;
has_keys = TRUE;
break;
}
}
if (has_rel_axes || has_abs_axes)
{
char *str;
int num_calibration = 0, calibration[4] = { 0, 0, 0, 0 };
pEvdev->invert_x = xf86SetBoolOption(pInfo->options, "InvertX", FALSE);
pEvdev->invert_y = xf86SetBoolOption(pInfo->options, "InvertY", FALSE);
pEvdev->swap_axes = xf86SetBoolOption(pInfo->options, "SwapAxes", FALSE);
str = xf86CheckStrOption(pInfo->options, "Calibration", NULL);
if (str) {
num_calibration = sscanf(str, "%d %d %d %d",
&calibration[0], &calibration[1],
&calibration[2], &calibration[3]);
free(str);
if (num_calibration == 4)
EvdevSetCalibration(pInfo, num_calibration, calibration);
else
xf86Msg(X_ERROR,
"%s: Insufficient calibration factors (%d). Ignoring calibration\n",
pInfo->name, num_calibration);
}
}
if (has_rel_axes || has_abs_axes || num_buttons) {
pInfo->flags |= XI86_SEND_DRAG_EVENTS | XI86_CONFIGURED;
if (pEvdev->flags & EVDEV_TOUCHPAD) {
xf86Msg(X_INFO, "%s: Configuring as touchpad\n", pInfo->name);
pInfo->type_name = XI_TOUCHPAD;
} else if (pEvdev->flags & EVDEV_TABLET) {
xf86Msg(X_INFO, "%s: Configuring as tablet\n", pInfo->name);
pInfo->type_name = XI_TABLET;
} else if (pEvdev->flags & EVDEV_TOUCHSCREEN) {
xf86Msg(X_INFO, "%s: Configuring as touchscreen\n", pInfo->name);
pInfo->type_name = XI_TOUCHSCREEN;
} else {
xf86Msg(X_INFO, "%s: Configuring as mouse\n", pInfo->name);
pInfo->type_name = XI_MOUSE;
}
}
if (has_keys) {
xf86Msg(X_INFO, "%s: Configuring as keyboard\n", pInfo->name);
pInfo->flags |= XI86_CONFIGURED;
pInfo->type_name = XI_KEYBOARD;
}
if (has_scroll && (pInfo->flags & XI86_CONFIGURED) &&
(has_rel_axes || has_abs_axes))
{
xf86Msg(X_INFO, "%s: Adding scrollwheel support\n", pInfo->name);
pEvdev->flags |= EVDEV_BUTTON_EVENTS;
pEvdev->flags |= EVDEV_RELATIVE_EVENTS;
}
if ((pInfo->flags & XI86_CONFIGURED) == 0) {
xf86Msg(X_WARNING, "%s: Don't know how to use device\n",
pInfo->name);
return 1;
}
return 0;
}
static void
EvdevSetCalibration(InputInfoPtr pInfo, int num_calibration, int calibration[4])
{
EvdevPtr pEvdev = pInfo->private;
if (num_calibration == 0) {
pEvdev->flags &= ~EVDEV_CALIBRATED;
pEvdev->calibration.min_x = 0;
pEvdev->calibration.max_x = 0;
pEvdev->calibration.min_y = 0;
pEvdev->calibration.max_y = 0;
} else if (num_calibration == 4) {
pEvdev->flags |= EVDEV_CALIBRATED;
pEvdev->calibration.min_x = calibration[0];
pEvdev->calibration.max_x = calibration[1];
pEvdev->calibration.min_y = calibration[2];
pEvdev->calibration.max_y = calibration[3];
}
}
static BOOL
EvdevOpenDevice(InputInfoPtr pInfo)
{
EvdevPtr pEvdev = pInfo->private;
char *device = (char*)pEvdev->device;
if (!device)
{
device = xf86CheckStrOption(pInfo->options, "Device", NULL);
if (!device) {
xf86Msg(X_ERROR, "%s: No device specified.\n", pInfo->name);
return FALSE;
}
pEvdev->device = device;
xf86Msg(X_CONFIG, "%s: Device: \"%s\"\n", pInfo->name, device);
}
if (pInfo->fd < 0)
{
do {
pInfo->fd = open(device, O_RDWR | O_NONBLOCK, 0);
} while (pInfo->fd < 0 && errno == EINTR);
if (pInfo->fd < 0) {
xf86Msg(X_ERROR, "Unable to open evdev device \"%s\".\n", device);
return FALSE;
}
}
pEvdev->min_maj = EvdevGetMajorMinor(pInfo);
if (EvdevIsDuplicate(pInfo))
{
xf86Msg(X_WARNING, "%s: device file is duplicate. Ignoring.\n",
pInfo->name);
close(pInfo->fd);
return FALSE;
}
return TRUE;
}
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
static int NewEvdevPreInit(InputDriverPtr, InputInfoPtr, int);
static InputInfoPtr
EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
{
InputInfoPtr pInfo;
if (!(pInfo = xf86AllocateInput(drv, 0)))
return NULL;
pInfo->fd = -1;
pInfo->name = dev->identifier;
pInfo->flags = 0;
pInfo->history_size = 0;
pInfo->control_proc = NULL;
pInfo->close_proc = NULL;
pInfo->conversion_proc = NULL;
pInfo->reverse_conversion_proc = NULL;
pInfo->dev = NULL;
pInfo->private_flags = 0;
pInfo->always_core_feedback = NULL;
pInfo->conf_idev = dev;
pInfo->private = NULL;
xf86CollectInputOptions(pInfo, (const char**)evdevDefaults, NULL);
xf86ProcessCommonOptions(pInfo, pInfo->options);
if (NewEvdevPreInit(drv, pInfo, flags) == Success)
return pInfo;
xf86DeleteInput(pInfo, 0);
return NULL;
}
static int
NewEvdevPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
#else
static int
EvdevPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
#endif
{
EvdevPtr pEvdev;
int rc = BadAlloc;
if (!(pEvdev = calloc(sizeof(EvdevRec), 1)))
goto error;
pInfo->private = pEvdev;
pInfo->type_name = "UNKNOWN";
pInfo->device_control = EvdevProc;
pInfo->read_input = EvdevReadInput;
pInfo->switch_mode = EvdevSwitchMode;
if (!EvdevOpenDevice(pInfo))
goto error;
pEvdev->tool = 1;
pEvdev->grabDevice = xf86CheckBoolOption(pInfo->options, "GrabDevice", 0);
if (!EvdevGrabDevice(pInfo, 1, 1))
{
xf86Msg(X_WARNING, "%s: Device may already be configured.\n",
pInfo->name);
rc = BadMatch;
goto error;
}
EvdevInitButtonMapping(pInfo);
if (EvdevCacheCompare(pInfo, FALSE) ||
EvdevProbe(pInfo)) {
rc = BadMatch;
goto error;
}
EvdevAddDevice(pInfo);
if (pEvdev->flags & EVDEV_BUTTON_EVENTS)
{
EvdevMBEmuPreInit(pInfo);
EvdevWheelEmuPreInit(pInfo);
EvdevDragLockPreInit(pInfo);
}
return Success;
error:
if (pInfo->fd >= 0)
close(pInfo->fd);
return rc;
}
_X_EXPORT InputDriverRec EVDEV = {
1,
"evdev",
NULL,
EvdevPreInit,
NULL,
NULL,
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
evdevDefaults
#endif
};
static void
EvdevUnplug(pointer p)
{
}
static pointer
EvdevPlug(pointer module,
pointer options,
int *errmaj,
int *errmin)
{
xf86AddInputDriver(&EVDEV, module, 0);
return module;
}
static XF86ModuleVersionInfo EvdevVersionRec =
{
"evdev",
MODULEVENDORSTRING,
MODINFOSTRING1,
MODINFOSTRING2,
XORG_VERSION_CURRENT,
PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
ABI_CLASS_XINPUT,
ABI_XINPUT_VERSION,
MOD_CLASS_XINPUT,
{0, 0, 0, 0}
};
_X_EXPORT XF86ModuleData evdevModuleData =
{
&EvdevVersionRec,
EvdevPlug,
EvdevUnplug
};
unsigned int
EvdevUtilButtonEventToButtonNumber(EvdevPtr pEvdev, int code)
{
switch (code)
{
case BTN_LEFT:
return 1;
case BTN_MIDDLE:
return 2;
case BTN_RIGHT:
return 3;
case BTN_SIDE ... BTN_TASK:
return 8 + code - BTN_SIDE;
case BTN_0 ... BTN_2:
return 1 + code - BTN_0;
case BTN_3 ... BTN_9:
return 8 + code - BTN_3;
case BTN_TOUCH ... BTN_STYLUS2:
return 1 + code - BTN_TOUCH;
default:
return 0;
}
}
#ifdef HAVE_PROPERTIES
#ifdef HAVE_LABELS
static char* abs_labels[] = {
AXIS_LABEL_PROP_ABS_X,
AXIS_LABEL_PROP_ABS_Y,
AXIS_LABEL_PROP_ABS_Z,
AXIS_LABEL_PROP_ABS_RX,
AXIS_LABEL_PROP_ABS_RY,
AXIS_LABEL_PROP_ABS_RZ,
AXIS_LABEL_PROP_ABS_THROTTLE,
AXIS_LABEL_PROP_ABS_RUDDER,
AXIS_LABEL_PROP_ABS_WHEEL,
AXIS_LABEL_PROP_ABS_GAS,
AXIS_LABEL_PROP_ABS_BRAKE,
AXIS_LABEL_PROP_ABS_MISC,
AXIS_LABEL_PROP_ABS_MISC,
AXIS_LABEL_PROP_ABS_MISC,
AXIS_LABEL_PROP_ABS_MISC,
AXIS_LABEL_PROP_ABS_MISC,
AXIS_LABEL_PROP_ABS_HAT0X,
AXIS_LABEL_PROP_ABS_HAT0Y,
AXIS_LABEL_PROP_ABS_HAT1X,
AXIS_LABEL_PROP_ABS_HAT1Y,
AXIS_LABEL_PROP_ABS_HAT2X,
AXIS_LABEL_PROP_ABS_HAT2Y,
AXIS_LABEL_PROP_ABS_HAT3X,
AXIS_LABEL_PROP_ABS_HAT3Y,
AXIS_LABEL_PROP_ABS_PRESSURE,
AXIS_LABEL_PROP_ABS_DISTANCE,
AXIS_LABEL_PROP_ABS_TILT_X,
AXIS_LABEL_PROP_ABS_TILT_Y,
AXIS_LABEL_PROP_ABS_TOOL_WIDTH,
AXIS_LABEL_PROP_ABS_MISC,
AXIS_LABEL_PROP_ABS_MISC,
AXIS_LABEL_PROP_ABS_MISC,
AXIS_LABEL_PROP_ABS_VOLUME
};
static char* rel_labels[] = {
AXIS_LABEL_PROP_REL_X,
AXIS_LABEL_PROP_REL_Y,
AXIS_LABEL_PROP_REL_Z,
AXIS_LABEL_PROP_REL_RX,
AXIS_LABEL_PROP_REL_RY,
AXIS_LABEL_PROP_REL_RZ,
AXIS_LABEL_PROP_REL_HWHEEL,
AXIS_LABEL_PROP_REL_DIAL,
AXIS_LABEL_PROP_REL_WHEEL,
AXIS_LABEL_PROP_REL_MISC
};
static char* btn_labels[][16] = {
{
BTN_LABEL_PROP_BTN_0,
BTN_LABEL_PROP_BTN_1,
BTN_LABEL_PROP_BTN_2,
BTN_LABEL_PROP_BTN_3,
BTN_LABEL_PROP_BTN_4,
BTN_LABEL_PROP_BTN_5,
BTN_LABEL_PROP_BTN_6,
BTN_LABEL_PROP_BTN_7,
BTN_LABEL_PROP_BTN_8,
BTN_LABEL_PROP_BTN_9
},
{
BTN_LABEL_PROP_BTN_LEFT,
BTN_LABEL_PROP_BTN_RIGHT,
BTN_LABEL_PROP_BTN_MIDDLE,
BTN_LABEL_PROP_BTN_SIDE,
BTN_LABEL_PROP_BTN_EXTRA,
BTN_LABEL_PROP_BTN_FORWARD,
BTN_LABEL_PROP_BTN_BACK,
BTN_LABEL_PROP_BTN_TASK
},
{
BTN_LABEL_PROP_BTN_TRIGGER,
BTN_LABEL_PROP_BTN_THUMB,
BTN_LABEL_PROP_BTN_THUMB2,
BTN_LABEL_PROP_BTN_TOP,
BTN_LABEL_PROP_BTN_TOP2,
BTN_LABEL_PROP_BTN_PINKIE,
BTN_LABEL_PROP_BTN_BASE,
BTN_LABEL_PROP_BTN_BASE2,
BTN_LABEL_PROP_BTN_BASE3,
BTN_LABEL_PROP_BTN_BASE4,
BTN_LABEL_PROP_BTN_BASE5,
BTN_LABEL_PROP_BTN_BASE6,
NULL,
NULL,
NULL,
BTN_LABEL_PROP_BTN_DEAD
},
{
BTN_LABEL_PROP_BTN_A,
BTN_LABEL_PROP_BTN_B,
BTN_LABEL_PROP_BTN_C,
BTN_LABEL_PROP_BTN_X,
BTN_LABEL_PROP_BTN_Y,
BTN_LABEL_PROP_BTN_Z,
BTN_LABEL_PROP_BTN_TL,
BTN_LABEL_PROP_BTN_TR,
BTN_LABEL_PROP_BTN_TL2,
BTN_LABEL_PROP_BTN_TR2,
BTN_LABEL_PROP_BTN_SELECT,
BTN_LABEL_PROP_BTN_START,
BTN_LABEL_PROP_BTN_MODE,
BTN_LABEL_PROP_BTN_THUMBL,
BTN_LABEL_PROP_BTN_THUMBR
},
{
BTN_LABEL_PROP_BTN_TOOL_PEN,
BTN_LABEL_PROP_BTN_TOOL_RUBBER,
BTN_LABEL_PROP_BTN_TOOL_BRUSH,
BTN_LABEL_PROP_BTN_TOOL_PENCIL,
BTN_LABEL_PROP_BTN_TOOL_AIRBRUSH,
BTN_LABEL_PROP_BTN_TOOL_FINGER,
BTN_LABEL_PROP_BTN_TOOL_MOUSE,
BTN_LABEL_PROP_BTN_TOOL_LENS,
NULL,
NULL,
BTN_LABEL_PROP_BTN_TOUCH,
BTN_LABEL_PROP_BTN_STYLUS,
BTN_LABEL_PROP_BTN_STYLUS2,
BTN_LABEL_PROP_BTN_TOOL_DOUBLETAP,
BTN_LABEL_PROP_BTN_TOOL_TRIPLETAP
},
{
BTN_LABEL_PROP_BTN_GEAR_DOWN,
BTN_LABEL_PROP_BTN_GEAR_UP
}
};
#endif
static void EvdevInitAxesLabels(EvdevPtr pEvdev, int natoms, Atom *atoms)
{
#ifdef HAVE_LABELS
Atom atom;
int axis;
char **labels;
int labels_len = 0;
char *misc_label;
if (pEvdev->flags & EVDEV_ABSOLUTE_EVENTS)
{
labels = abs_labels;
labels_len = ArrayLength(abs_labels);
misc_label = AXIS_LABEL_PROP_ABS_MISC;
} else if ((pEvdev->flags & EVDEV_RELATIVE_EVENTS))
{
labels = rel_labels;
labels_len = ArrayLength(rel_labels);
misc_label = AXIS_LABEL_PROP_REL_MISC;
}
memset(atoms, 0, natoms * sizeof(Atom));
for (axis = 0; axis < labels_len; axis++)
{
if (pEvdev->axis_map[axis] == -1)
continue;
atom = XIGetKnownProperty(labels[axis]);
if (!atom)
continue;
atoms[pEvdev->axis_map[axis]] = atom;
}
#endif
}
static void EvdevInitButtonLabels(EvdevPtr pEvdev, int natoms, Atom *atoms)
{
#ifdef HAVE_LABELS
Atom atom;
int button, bmap;
atom = XIGetKnownProperty(BTN_LABEL_PROP_BTN_UNKNOWN);
for (button = 0; button < natoms; button++)
atoms[button] = atom;
for (button = BTN_MISC; button < BTN_JOYSTICK; button++)
{
if (TestBit(button, pEvdev->key_bitmask))
{
int group = (button % 0x100)/16;
int idx = button - ((button/16) * 16);
if (!btn_labels[group][idx])
continue;
atom = XIGetKnownProperty(btn_labels[group][idx]);
if (!atom)
continue;
bmap = EvdevUtilButtonEventToButtonNumber(pEvdev, button) - 1;
atoms[bmap] = atom;
}
}
if (natoms > 3)
atoms[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
if (natoms > 4)
atoms[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
if (natoms > 5)
atoms[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
if (natoms > 6)
atoms[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
#endif
}
static void
EvdevInitProperty(DeviceIntPtr dev)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
int rc;
BOOL invert[2];
if (pEvdev->flags & (EVDEV_RELATIVE_EVENTS | EVDEV_ABSOLUTE_EVENTS))
{
invert[0] = pEvdev->invert_x;
invert[1] = pEvdev->invert_y;
prop_invert = MakeAtom(EVDEV_PROP_INVERT_AXES, strlen(EVDEV_PROP_INVERT_AXES), TRUE);
rc = XIChangeDeviceProperty(dev, prop_invert, XA_INTEGER, 8,
PropModeReplace, 2,
invert, FALSE);
if (rc != Success)
return;
XISetDevicePropertyDeletable(dev, prop_invert, FALSE);
prop_calibration = MakeAtom(EVDEV_PROP_CALIBRATION,
strlen(EVDEV_PROP_CALIBRATION), TRUE);
if (pEvdev->flags & EVDEV_CALIBRATED) {
int calibration[4];
calibration[0] = pEvdev->calibration.min_x;
calibration[1] = pEvdev->calibration.max_x;
calibration[2] = pEvdev->calibration.min_y;
calibration[3] = pEvdev->calibration.max_y;
rc = XIChangeDeviceProperty(dev, prop_calibration, XA_INTEGER,
32, PropModeReplace, 4, calibration,
FALSE);
} else if (pEvdev->flags & EVDEV_ABSOLUTE_EVENTS) {
rc = XIChangeDeviceProperty(dev, prop_calibration, XA_INTEGER,
32, PropModeReplace, 0, NULL,
FALSE);
}
if (rc != Success)
return;
XISetDevicePropertyDeletable(dev, prop_calibration, FALSE);
prop_swap = MakeAtom(EVDEV_PROP_SWAP_AXES,
strlen(EVDEV_PROP_SWAP_AXES), TRUE);
rc = XIChangeDeviceProperty(dev, prop_swap, XA_INTEGER, 8,
PropModeReplace, 1, &pEvdev->swap_axes, FALSE);
if (rc != Success)
return;
XISetDevicePropertyDeletable(dev, prop_swap, FALSE);
#ifdef HAVE_LABELS
if ((pEvdev->num_vals > 0) && (prop_axis_label = XIGetKnownProperty(AXIS_LABEL_PROP)))
{
Atom atoms[pEvdev->num_vals];
EvdevInitAxesLabels(pEvdev, pEvdev->num_vals, atoms);
XIChangeDeviceProperty(dev, prop_axis_label, XA_ATOM, 32,
PropModeReplace, pEvdev->num_vals, atoms, FALSE);
XISetDevicePropertyDeletable(dev, prop_axis_label, FALSE);
}
if ((pEvdev->num_buttons > 0) && (prop_btn_label = XIGetKnownProperty(BTN_LABEL_PROP)))
{
Atom atoms[EVDEV_MAXBUTTONS];
EvdevInitButtonLabels(pEvdev, EVDEV_MAXBUTTONS, atoms);
XIChangeDeviceProperty(dev, prop_btn_label, XA_ATOM, 32,
PropModeReplace, pEvdev->num_buttons, atoms, FALSE);
XISetDevicePropertyDeletable(dev, prop_btn_label, FALSE);
}
#endif
}
}
static int
EvdevSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
BOOL checkonly)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
if (atom == prop_invert)
{
BOOL* data;
if (val->format != 8 || val->size != 2 || val->type != XA_INTEGER)
return BadMatch;
if (!checkonly)
{
data = (BOOL*)val->data;
pEvdev->invert_x = data[0];
pEvdev->invert_y = data[1];
}
} else if (atom == prop_calibration)
{
if (val->format != 32 || val->type != XA_INTEGER)
return BadMatch;
if (val->size != 4 && val->size != 0)
return BadMatch;
if (!checkonly)
EvdevSetCalibration(pInfo, val->size, val->data);
} else if (atom == prop_swap)
{
if (val->format != 8 || val->type != XA_INTEGER || val->size != 1)
return BadMatch;
if (!checkonly)
pEvdev->swap_axes = *((BOOL*)val->data);
} else if (atom == prop_axis_label || atom == prop_btn_label)
return BadAccess;
return Success;
}
#endif