/* * Copyright 2004 Peter Osterlund * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include "eventcomm.h" #include "synproto.h" #include #define SYNAPTICS_PRIVATE #include "synaptics.h" #include #define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) /***************************************************************************** * Function Definitions ****************************************************************************/ static void EventDeviceOnHook(LocalDevicePtr local) { /* Try to grab the event device so that data don't leak to /dev/input/mice */ int ret; SYSCALL(ret = ioctl(local->fd, EVIOCGRAB, (pointer)1)); if (ret < 0) { xf86Msg(X_WARNING, "%s can't grab event device\n", local->name, errno); } } static void EventDeviceOffHook(LocalDevicePtr local) { } static Bool EventQueryHardware(LocalDevicePtr local, struct synapticshw *synhw, Bool *hasGuest) { return TRUE; } static Bool SynapticsReadEvent(SynapticsPrivate *priv, struct input_event *ev) { int i, c; unsigned char *pBuf, u; for (i = 0; i < sizeof(struct input_event); i++) { if ((c = XisbRead(priv->buffer)) < 0) return FALSE; u = (unsigned char)c; pBuf = (unsigned char *)ev; pBuf[i] = u; } return TRUE; } static Bool EventReadHwState(LocalDevicePtr local, SynapticsPrivate *priv, struct SynapticsHwState *hwRet) { struct input_event ev; Bool v; struct SynapticsHwState *hw = &(priv->hwState); while (SynapticsReadEvent(priv, &ev)) { switch (ev.type) { case EV_SYN: switch (ev.code) { case SYN_REPORT: if (priv->oneFinger) hw->numFingers = 1; else if (priv->twoFingers) hw->numFingers = 2; else if (priv->threeFingers) hw->numFingers = 3; else hw->numFingers = 0; *hwRet = *hw; return TRUE; } case EV_KEY: v = (ev.value ? TRUE : FALSE); switch (ev.code) { case BTN_LEFT: hw->left = v; break; case BTN_RIGHT: hw->right = v; break; case BTN_MIDDLE: hw->middle = v; break; case BTN_FORWARD: hw->up = v; break; case BTN_BACK: hw->down = v; break; case BTN_0: hw->multi[0] = v; break; case BTN_1: hw->multi[1] = v; break; case BTN_2: hw->multi[2] = v; break; case BTN_3: hw->multi[3] = v; break; case BTN_4: hw->multi[4] = v; break; case BTN_5: hw->multi[5] = v; break; case BTN_6: hw->multi[6] = v; break; case BTN_7: hw->multi[7] = v; break; case BTN_TOOL_FINGER: priv->oneFinger = v; break; case BTN_TOOL_DOUBLETAP: priv->twoFingers = v; break; case BTN_TOOL_TRIPLETAP: priv->threeFingers = v; break; } break; case EV_ABS: switch (ev.code) { case ABS_X: hw->x = ev.value; break; case ABS_Y: hw->y = ev.value; break; case ABS_PRESSURE: hw->z = ev.value; break; case ABS_TOOL_WIDTH: hw->fingerWidth = ev.value; break; } break; } } return FALSE; } struct SynapticsProtocolOperations event_proto_operations = { EventDeviceOnHook, EventDeviceOffHook, EventQueryHardware, EventReadHwState };