patch-2.3.41 linux/drivers/usb/mousedev.c

Next file: linux/drivers/usb/ohci-hcd.c
Previous file: linux/drivers/usb/keybdev.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.40/linux/drivers/usb/mousedev.c linux/drivers/usb/mousedev.c
@@ -38,6 +38,13 @@
 #include <linux/input.h>
 #include <linux/config.h>
 
+#ifndef CONFIG_MOUSEDEV_SCREEN_X
+#define CONFIG_MOUSEDEV_SCREEN_X	1024
+#endif
+#ifndef CONFIG_MOUSEDEV_SCREEN_Y
+#define CONFIG_MOUSEDEV_SCREEN_Y	768
+#endif
+
 struct mousedev {
 	char name[32];
 	int used;
@@ -51,8 +58,8 @@
 	struct fasync_struct *fasync;
 	struct mousedev *mousedev;
 	struct mousedev_list *next;
-	int dx, dy, dz;
-	unsigned char ps2[6];
+	int dx, dy, dz, oldx, oldy;
+	char ps2[6];
 	unsigned long buttons;
 	unsigned char ready, buffer, bufsiz;
 	unsigned char mode, genseq, impseq;
@@ -75,10 +82,26 @@
 {
 	struct mousedev *mousedev = handle->private;
 	struct mousedev_list *list = mousedev->list;
-	int index;
+	int index, size;
 
 	while (list) {
 		switch (type) {
+			case EV_ABS:
+				if (test_bit(EV_REL, handle->dev->evbit) && test_bit(REL_X, handle->dev->relbit))
+					return;
+				switch (code) {
+					case ABS_X:	
+						size = handle->dev->absmax[ABS_X] - handle->dev->absmin[ABS_X];
+						list->dx += (value * CONFIG_MOUSEDEV_SCREEN_X - list->oldx) / size;
+						list->oldx += list->dx * size;
+						break;
+					case ABS_Y:
+						size = handle->dev->absmax[ABS_Y] - handle->dev->absmin[ABS_Y];
+						list->dy += (value * CONFIG_MOUSEDEV_SCREEN_Y - list->oldy) / size;
+						list->oldy += list->dy * size;
+						break;
+				}
+				break;
 			case EV_REL:
 				switch (code) {
 					case REL_X:	list->dx += value; break;
@@ -89,12 +112,20 @@
 
 			case EV_KEY:
 				switch (code) {
+					case BTN_0:
+					case BTN_TOUCH:
 					case BTN_LEFT:   index = 0; break;
+					case BTN_4:
 					case BTN_EXTRA:  if (list->mode > 1) { index = 4; break; }
+					case BTN_STYLUS:
+					case BTN_1:
 					case BTN_RIGHT:  index = 1; break;
+					case BTN_3:
 					case BTN_SIDE:   if (list->mode > 1) { index = 3; break; }
+					case BTN_2:
+					case BTN_STYLUS2:
 					case BTN_MIDDLE: index = 2; break;	
-					default: index = 0;
+					default: return;
 				}
 				switch (value) {
 					case 0: clear_bit(index, &list->buttons); break;
@@ -186,7 +217,8 @@
 	list->ps2[off] = 0x08 | ((list->dx < 0) << 4) | ((list->dy < 0) << 5) | (list->buttons & 0x07);
 	list->ps2[off + 1] = (list->dx > 127 ? 127 : (list->dx < -127 ? -127 : list->dx));
 	list->ps2[off + 2] = (list->dy > 127 ? 127 : (list->dy < -127 ? -127 : list->dy));
-	list->dx = list->dy = 0;
+	list->dx -= list->ps2[off + 1];
+	list->dy -= list->ps2[off + 2];
 	list->bufsiz = off + 3;
 
 	if (list->mode > 1)
@@ -195,9 +227,9 @@
 	if (list->mode) {
 		list->ps2[off + 3] = (list->dz > 127 ? 127 : (list->dz < -127 ? -127 : list->dz));
 		list->bufsiz++;
-		list->dz = 0;
+		list->dz -= list->ps2[off + 3];
 	}
-	list->ready = 0;
+	if (!list->dx && !list->dy && (!list->mode || !list->dz)) list->ready = 0;
 	list->buffer = list->bufsiz;
 }
 
@@ -330,15 +362,14 @@
 static int mousedev_connect(struct input_handler *handler, struct input_dev *dev)
 {
 
-	if (!(test_bit(EV_KEY, dev->evbit) && test_bit(EV_REL, dev->evbit)))	/* The device must have both rels and keys */
+	if (!test_bit(EV_KEY, dev->evbit) ||
+	   (!test_bit(BTN_LEFT, dev->keybit) && !test_bit(BTN_TOUCH, dev->keybit)))
 		return -1;
 
-	if (!(test_bit(REL_X, dev->relbit) && test_bit(REL_Y, dev->relbit)))	/* It must be a pointer device */
+	if ((!test_bit(EV_REL, dev->evbit) || !test_bit(REL_X, dev->relbit)) &&
+	    (!test_bit(EV_ABS, dev->evbit) || !test_bit(ABS_X, dev->absbit)))
 		return -1;
 	
-	if (!test_bit(BTN_LEFT, dev->keybit))				/* And have at least one mousebutton */
-		return -1;
-
 #ifdef CONFIG_INPUT_MOUSEDEV_MIX
 	{
 		struct input_handle *handle;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)