aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/dmx/input/usb-common.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/hw/dmx/input/usb-common.c')
-rw-r--r--xorg-server/hw/dmx/input/usb-common.c331
1 files changed, 221 insertions, 110 deletions
diff --git a/xorg-server/hw/dmx/input/usb-common.c b/xorg-server/hw/dmx/input/usb-common.c
index 944033eba..c7c166cce 100644
--- a/xorg-server/hw/dmx/input/usb-common.c
+++ b/xorg-server/hw/dmx/input/usb-common.c
@@ -74,7 +74,6 @@
/* End of interface definitions. */
/*****************************************************************************/
-
/** Read an event from the \a pDev device. If the event is a motion
* event, enqueue it with the \a motion function. Otherwise, enqueue
* the event with the \a enqueue function. The \a block type is passed
@@ -84,16 +83,14 @@
* Since USB devices return EV_KEY events for buttons and keys, \a
* minButton is used to decide if a Button or Key event should be
* queued.*/
-void usbRead(DevicePtr pDev,
- MOTIONPROC motion,
- ENQUEUEPROC enqueue,
- int minButton,
- BLOCK block)
+void
+usbRead(DevicePtr pDev,
+ MOTIONPROC motion, ENQUEUEPROC enqueue, int minButton, BLOCK block)
{
GETPRIV;
struct input_event raw;
- int v[DMX_MAX_AXES];
- int axis;
+ int v[DMX_MAX_AXES];
+ int axis;
#define PRESS(b) \
do { \
@@ -112,11 +109,14 @@ void usbRead(DevicePtr pDev,
#endif
switch (raw.type) {
case EV_KEY:
- /* raw.value = 1 for first, 2 for repeat */
+ /* raw.value = 1 for first, 2 for repeat */
if (raw.code > minButton) {
- if (raw.value) PRESS((raw.code & 0x0f) + 1);
- else RELEASE((raw.code & 0x0f) + 1);
- } else {
+ if (raw.value)
+ PRESS((raw.code & 0x0f) + 1);
+ else
+ RELEASE((raw.code & 0x0f) + 1);
+ }
+ else {
enqueue(pDev, raw.value ? KeyPress : KeyRelease,
0, 0, NULL, block);
}
@@ -134,10 +134,11 @@ void usbRead(DevicePtr pDev,
motion(pDev, v, 0, 2, DMX_RELATIVE, block);
break;
case REL_WHEEL:
- if ((int)raw.value > 0) {
+ if ((int) raw.value > 0) {
PRESS(4);
RELEASE(4);
- } else if ((int)raw.value < 0) {
+ }
+ else if ((int) raw.value < 0) {
PRESS(5);
RELEASE(5);
}
@@ -162,126 +163,228 @@ void usbRead(DevicePtr pDev,
#define test_bit(bit) (priv->mask[(bit)/8] & (1 << ((bit)%8)))
#define test_bits(bit) (bits[(bit)/8] & (1 << ((bit)%8)))
-static void usbPrint(myPrivate *priv,
- const char *filename, const char *devname, int fd)
+static void
+usbPrint(myPrivate * priv, const char *filename, const char *devname, int fd)
{
- int j, k;
- DeviceIntPtr pDevice = priv->pDevice;
- unsigned char bits[KEY_MAX/8 + 1]; /* RATS: Use ok assuming that
- * KEY_MAX is greater than
- * REL_MAX, ABS_MAX, SND_MAX, and
- * LED_MAX. */
+ int j, k;
+ DeviceIntPtr pDevice = priv->pDevice;
+ unsigned char bits[KEY_MAX / 8 + 1]; /* RATS: Use ok assuming that
+ * KEY_MAX is greater than
+ * REL_MAX, ABS_MAX, SND_MAX, and
+ * LED_MAX. */
LOG3INPUT(priv, "%s (%s) using %s\n", pDevice->name, GETNAME, filename);
LOG1INPUT(priv, " %s\n", devname);
for (j = 0; j < EV_MAX; j++) {
if (test_bit(j)) {
- const char *type = "unknown";
- char extra[256]; /* FIXME: may cause buffer overflow */
+ const char *type = "unknown";
+ char extra[256]; /* FIXME: may cause buffer overflow */
+
extra[0] = '\0';
- switch(j) {
- case EV_KEY: type = "keys/buttons"; break;
- case EV_REL: type = "relative";
+ switch (j) {
+ case EV_KEY:
+ type = "keys/buttons";
+ break;
+ case EV_REL:
+ type = "relative";
memset(bits, 0, sizeof(bits));
ioctl(priv->fd, EVIOCGBIT(EV_REL, sizeof(bits)), bits);
for (k = 0; k < REL_MAX; k++) {
- if (test_bits(k)) switch (k) {
- case REL_X: strcat(extra, " X"); break;
- case REL_Y: strcat(extra, " Y"); break;
- case REL_Z: strcat(extra, " Z"); break;
- case REL_HWHEEL: strcat(extra, " HWheel"); break;
- case REL_DIAL: strcat(extra, " Dial"); break;
- case REL_WHEEL: strcat(extra, " Wheel"); break;
- case REL_MISC: strcat(extra, " Misc"); break;
- }
+ if (test_bits(k))
+ switch (k) {
+ case REL_X:
+ strcat(extra, " X");
+ break;
+ case REL_Y:
+ strcat(extra, " Y");
+ break;
+ case REL_Z:
+ strcat(extra, " Z");
+ break;
+ case REL_HWHEEL:
+ strcat(extra, " HWheel");
+ break;
+ case REL_DIAL:
+ strcat(extra, " Dial");
+ break;
+ case REL_WHEEL:
+ strcat(extra, " Wheel");
+ break;
+ case REL_MISC:
+ strcat(extra, " Misc");
+ break;
+ }
}
break;
- case EV_ABS: type = "absolute";
+ case EV_ABS:
+ type = "absolute";
memset(bits, 0, sizeof(bits));
ioctl(priv->fd, EVIOCGBIT(EV_ABS, sizeof(bits)), bits);
for (k = 0; k < ABS_MAX; k++) {
- if (test_bits(k)) switch (k) {
- case ABS_X: strcat(extra," X"); break;
- case ABS_Y: strcat(extra," Y"); break;
- case ABS_Z: strcat(extra," Z"); break;
- case ABS_RX: strcat(extra," RX"); break;
- case ABS_RY: strcat(extra," RY"); break;
- case ABS_RZ: strcat(extra," RZ"); break;
- case ABS_THROTTLE: strcat(extra," Throttle");break;
- case ABS_RUDDER: strcat(extra," Rudder"); break;
- case ABS_WHEEL: strcat(extra," Wheel"); break;
- case ABS_GAS: strcat(extra," Gas"); break;
- case ABS_BRAKE: strcat(extra," Break"); break;
- case ABS_HAT0X: strcat(extra," Hat0X"); break;
- case ABS_HAT0Y: strcat(extra," Hat0Y"); break;
- case ABS_HAT1X: strcat(extra," Hat1X"); break;
- case ABS_HAT1Y: strcat(extra," Hat1Y"); break;
- case ABS_HAT2X: strcat(extra," Hat2X"); break;
- case ABS_HAT2Y: strcat(extra," Hat2Y"); break;
- case ABS_HAT3X: strcat(extra," Hat3X"); break;
- case ABS_HAT3Y: strcat(extra," Hat3Y"); break;
- case ABS_PRESSURE: strcat(extra," Pressure");break;
- case ABS_DISTANCE: strcat(extra," Distance");break;
- case ABS_TILT_X: strcat(extra," TiltX"); break;
- case ABS_TILT_Y: strcat(extra," TiltY"); break;
- case ABS_MISC: strcat(extra," Misc"); break;
- }
+ if (test_bits(k))
+ switch (k) {
+ case ABS_X:
+ strcat(extra, " X");
+ break;
+ case ABS_Y:
+ strcat(extra, " Y");
+ break;
+ case ABS_Z:
+ strcat(extra, " Z");
+ break;
+ case ABS_RX:
+ strcat(extra, " RX");
+ break;
+ case ABS_RY:
+ strcat(extra, " RY");
+ break;
+ case ABS_RZ:
+ strcat(extra, " RZ");
+ break;
+ case ABS_THROTTLE:
+ strcat(extra, " Throttle");
+ break;
+ case ABS_RUDDER:
+ strcat(extra, " Rudder");
+ break;
+ case ABS_WHEEL:
+ strcat(extra, " Wheel");
+ break;
+ case ABS_GAS:
+ strcat(extra, " Gas");
+ break;
+ case ABS_BRAKE:
+ strcat(extra, " Break");
+ break;
+ case ABS_HAT0X:
+ strcat(extra, " Hat0X");
+ break;
+ case ABS_HAT0Y:
+ strcat(extra, " Hat0Y");
+ break;
+ case ABS_HAT1X:
+ strcat(extra, " Hat1X");
+ break;
+ case ABS_HAT1Y:
+ strcat(extra, " Hat1Y");
+ break;
+ case ABS_HAT2X:
+ strcat(extra, " Hat2X");
+ break;
+ case ABS_HAT2Y:
+ strcat(extra, " Hat2Y");
+ break;
+ case ABS_HAT3X:
+ strcat(extra, " Hat3X");
+ break;
+ case ABS_HAT3Y:
+ strcat(extra, " Hat3Y");
+ break;
+ case ABS_PRESSURE:
+ strcat(extra, " Pressure");
+ break;
+ case ABS_DISTANCE:
+ strcat(extra, " Distance");
+ break;
+ case ABS_TILT_X:
+ strcat(extra, " TiltX");
+ break;
+ case ABS_TILT_Y:
+ strcat(extra, " TiltY");
+ break;
+ case ABS_MISC:
+ strcat(extra, " Misc");
+ break;
+ }
}
break;
- case EV_MSC: type = "reserved"; break;
- case EV_LED: type = "leds";
+ case EV_MSC:
+ type = "reserved";
+ break;
+ case EV_LED:
+ type = "leds";
memset(bits, 0, sizeof(bits));
ioctl(priv->fd, EVIOCGBIT(EV_LED, sizeof(bits)), bits);
for (k = 0; k < LED_MAX; k++) {
- if (test_bits(k)) switch (k) {
- case LED_NUML: strcat(extra," NumLock"); break;
- case LED_CAPSL: strcat(extra," CapsLock"); break;
- case LED_SCROLLL: strcat(extra," ScrlLock"); break;
- case LED_COMPOSE: strcat(extra," Compose"); break;
- case LED_KANA: strcat(extra," Kana"); break;
- case LED_SLEEP: strcat(extra," Sleep"); break;
- case LED_SUSPEND: strcat(extra," Suspend"); break;
- case LED_MUTE: strcat(extra," Mute"); break;
- case LED_MISC: strcat(extra," Misc"); break;
- }
+ if (test_bits(k))
+ switch (k) {
+ case LED_NUML:
+ strcat(extra, " NumLock");
+ break;
+ case LED_CAPSL:
+ strcat(extra, " CapsLock");
+ break;
+ case LED_SCROLLL:
+ strcat(extra, " ScrlLock");
+ break;
+ case LED_COMPOSE:
+ strcat(extra, " Compose");
+ break;
+ case LED_KANA:
+ strcat(extra, " Kana");
+ break;
+ case LED_SLEEP:
+ strcat(extra, " Sleep");
+ break;
+ case LED_SUSPEND:
+ strcat(extra, " Suspend");
+ break;
+ case LED_MUTE:
+ strcat(extra, " Mute");
+ break;
+ case LED_MISC:
+ strcat(extra, " Misc");
+ break;
+ }
}
break;
- case EV_SND: type = "sound";
+ case EV_SND:
+ type = "sound";
memset(bits, 0, sizeof(bits));
ioctl(priv->fd, EVIOCGBIT(EV_SND, sizeof(bits)), bits);
for (k = 0; k < SND_MAX; k++) {
- if (test_bits(k)) switch (k) {
- case SND_CLICK: strcat(extra," Click"); break;
- case SND_BELL: strcat(extra," Bell"); break;
- }
+ if (test_bits(k))
+ switch (k) {
+ case SND_CLICK:
+ strcat(extra, " Click");
+ break;
+ case SND_BELL:
+ strcat(extra, " Bell");
+ break;
+ }
}
break;
- case EV_REP: type = "repeat"; break;
- case EV_FF: type = "feedback"; break;
+ case EV_REP:
+ type = "repeat";
+ break;
+ case EV_FF:
+ type = "feedback";
+ break;
}
LOG5INPUT(priv, " Feature 0x%02x = %s%s%s%s\n", j, type,
extra[0] ? " [" : "",
- extra[0] ? extra+1 : "",
- extra[0] ? "]" : "");
+ extra[0] ? extra + 1 : "", extra[0] ? "]" : "");
}
}
}
/** Initialized \a pDev as a \a usbMouse, \a usbKeyboard, or \a usbOther
-device. */
-void usbInit(DevicePtr pDev, usbType type)
+device. */
+void
+usbInit(DevicePtr pDev, usbType type)
{
GETPRIV;
- char name[64]; /* RATS: Only used in snprintf */
- int i, j, k;
- char buf[256] = { 0, }; /* RATS: Use ok */
- int version;
- unsigned char bits[KEY_MAX/8 + 1]; /* RATS: Use ok assuming that
- * KEY_MAX is greater than
- * REL_MAX, ABS_MAX, SND_MAX, and
- * LED_MAX. */
+ char name[64]; /* RATS: Only used in snprintf */
+ int i, j, k;
+ char buf[256] = { 0, }; /* RATS: Use ok */
+ int version;
+ unsigned char bits[KEY_MAX / 8 + 1]; /* RATS: Use ok assuming that
+ * KEY_MAX is greater than
+ * REL_MAX, ABS_MAX, SND_MAX, and
+ * LED_MAX. */
- if (priv->fd >=0) return;
+ if (priv->fd >= 0)
+ return;
for (i = 0; i < 32; i++) {
snprintf(name, sizeof(name), "/dev/input/event%d", i);
@@ -293,15 +396,18 @@ void usbInit(DevicePtr pDev, usbType type)
for (j = 0; j < EV_MAX; j++) {
if (test_bit(j)) {
- switch(j) {
+ switch (j) {
case EV_REL:
memset(bits, 0, sizeof(bits));
ioctl(priv->fd, EVIOCGBIT(EV_REL, sizeof(bits)), bits);
for (k = 0; k < REL_MAX; k++) {
if (test_bits(k)) {
- if (k == REL_X) priv->relmap[k] = 0;
- else if (k == REL_Y) priv->relmap[k] = 1;
- else priv->relmap[k] = 2 + priv->numAbs;
+ if (k == REL_X)
+ priv->relmap[k] = 0;
+ else if (k == REL_Y)
+ priv->relmap[k] = 1;
+ else
+ priv->relmap[k] = 2 + priv->numAbs;
++priv->numRel;
}
}
@@ -320,7 +426,8 @@ void usbInit(DevicePtr pDev, usbType type)
memset(bits, 0, sizeof(bits));
ioctl(priv->fd, EVIOCGBIT(EV_LED, sizeof(bits)), bits);
for (k = 0; k < LED_MAX; k++) {
- if (test_bits(k)) ++priv->numLeds;
+ if (test_bits(k))
+ ++priv->numLeds;
}
break;
}
@@ -350,32 +457,36 @@ void usbInit(DevicePtr pDev, usbType type)
FATAL1("usbInit: Cannot open /dev/input/event* port (%s)\n"
" If you have not done so, you may need to:\n"
" rmmod mousedev; rmmod keybdev\n"
- " modprobe evdev\n",
- strerror(errno));
- found:
+ " modprobe evdev\n", strerror(errno));
+ found:
usbPrint(priv, name, buf, priv->fd);
}
/** Turn \a pDev off (i.e., stop taking input from \a pDev). */
-void usbOff(DevicePtr pDev)
+void
+usbOff(DevicePtr pDev)
{
GETPRIV;
- if (priv->fd >= 0) close(priv->fd);
+ if (priv->fd >= 0)
+ close(priv->fd);
priv->fd = -1;
}
/** Create a private structure for use within this file. */
-pointer usbCreatePrivate(DeviceIntPtr pDevice)
+pointer
+usbCreatePrivate(DeviceIntPtr pDevice)
{
myPrivate *priv = calloc(1, sizeof(*priv));
- priv->fd = -1;
- priv->pDevice = pDevice;
+
+ priv->fd = -1;
+ priv->pDevice = pDevice;
return priv;
}
/** Destroy a private structure. */
-void usbDestroyPrivate(pointer priv)
+void
+usbDestroyPrivate(pointer priv)
{
free(priv);
}