[PATCH 20/47] mousedev - implement tapping for touchpads

Vojtech Pavlik
2004-07-29T14:51:16Z

ChangeSet@1.1612.25.4, 2004-06-06 11:37:05-05:00, dtor_core@ameritech.net
Input: mousedev - implement tapping for touchpads working in absolute
mode, such as Synaptics

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

Documentation/kernel-parameters.txt | 6 +++++
drivers/input/mouse/Kconfig | 2 -
drivers/input/mousedev.c | 38 +++++++++++++++++++++++++++++-------
3 files changed, 37 insertions(+), 9 deletions(-)

===================================================================

diff -Nru a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
--- a/Documentation/kernel-parameters.txt Thu Jul 29 14:40:47 2004
+++ b/Documentation/kernel-parameters.txt Thu Jul 29 14:40:47 2004
@@ -652,6 +652,12 @@

mga= [HW,DRM]

+ mousedev.tap_time=
+ [MOUSE] Maximum time between finger touching and
+ leaving touchpad surface for touch to be considered
+ a tap and be reported as a left button click (for
+ touchpads working in absolute mode only).
+ Format: <msecs>
mousedev.xres= [MOUSE] Horizontal screen resolution, used for devices
reporting absolute coordinates, such as tablets
mousedev.yres= [MOUSE] Vertical screen resolution, used for devices
diff -Nru a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
--- a/drivers/input/mouse/Kconfig Thu Jul 29 14:40:47 2004
+++ b/drivers/input/mouse/Kconfig Thu Jul 29 14:40:47 2004
@@ -30,8 +30,6 @@
and a new verion of GPM at:
http://www.geocities.com/dt_or/gpm/gpm.html
to take advantage of the advanced features of the touchpad.
- If you do not want install specialized drivers but want tapping
- working please use option psmouse.proto=imps.

If unsure, say Y.

diff -Nru a/drivers/input/mousedev.c b/drivers/input/mousedev.c
--- a/drivers/input/mousedev.c Thu Jul 29 14:40:47 2004
+++ b/drivers/input/mousedev.c Thu Jul 29 14:40:47 2004
@@ -48,6 +48,10 @@
module_param(yres, uint, 0);
MODULE_PARM_DESC(yres, "Vertical screen resolution");

+static unsigned tap_time = 200;
+module_param(tap_time, uint, 0);
+MODULE_PARM_DESC(tap_time, "Tap time for touchpads in absolute mode (msecs)");
+
struct mousedev_motion {
int dx, dy, dz;
unsigned long buttons;
@@ -65,7 +69,7 @@
struct mousedev_motion packet;
unsigned int pkt_count;
int old_x[4], old_y[4];
- unsigned int touch;
+ unsigned long touch;
};

enum mousedev_emul {
@@ -216,6 +220,30 @@
wake_up_interruptible(&mousedev->wait);
}

+static void mousedev_touchpad_touch(struct mousedev *mousedev, int value)
+{
+ if (!value) {
+ if (mousedev->touch &&
+ !time_after(jiffies, mousedev->touch + msecs_to_jiffies(tap_time))) {
+ /*
+ * Toggle left button to emulate tap.
+ * We rely on the fact that mousedev_mix always has 0
+ * motion packet so we won't mess current position.
+ */
+ set_bit(0, &mousedev->packet.buttons);
+ set_bit(0, &mousedev_mix.packet.buttons);
+ mousedev_notify_readers(mousedev, &mousedev_mix.packet);
+ mousedev_notify_readers(&mousedev_mix, &mousedev_mix.packet);
+ clear_bit(0, &mousedev->packet.buttons);
+ clear_bit(0, &mousedev_mix.packet.buttons);
+ }
+ mousedev->touch = mousedev->pkt_count = 0;
+ }
+ else
+ if (!mousedev->touch)
+ mousedev->touch = jiffies;
+}
+
static void mousedev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
{
struct mousedev *mousedev = handle->private;
@@ -239,12 +267,8 @@

case EV_KEY:
if (value != 2) {
- if (code == BTN_TOUCH && test_bit(BTN_TOOL_FINGER, handle->dev->keybit)) {
- /* Handle touchpad data */
- mousedev->touch = value;
- if (!mousedev->touch)
- mousedev->pkt_count = 0;
- }
+ if (code == BTN_TOUCH && test_bit(BTN_TOOL_FINGER, handle->dev->keybit))
+ mousedev_touchpad_touch(mousedev, value);
else
mousedev_key_event(mousedev, code, value);
}