[RFC 0/2] Add EVIOC mechanism to extract the MT slot state

3 messages, 1 author, 2011-01-27 · open the first message on its own page

[RFC 0/2] Add EVIOC mechanism to extract the MT slot state

From: Benjamin Tissoires <hidden>
Date: 2011-01-27 10:35:57

Hi guys,

This patchset is a rework of Henrik's original work.
Henrik, I kept your signed-off-by, please tell me if it's ok with you.
I just changed the method call (and signature) for it to be compliant with the new EVIOC handling.

I'm not very happy with it (for instance, there is a call of an mt stuff in generic input), but it's a start.

Cheers,
Benjamin


[RFC 1/2] input: mt: Add method to extract the MT slot state

From: Benjamin Tissoires <hidden>
Date: 2011-01-27 10:35:57

This patch adds the function input_mt_get_abs_value(), which may be
used to extract the current state of the MT slots.

Signed-off-by: Henrik Rydberg <redacted>
Signed-off-by: Benjamin Tissoires <redacted>
---
 drivers/input/input-mt.c |   32 ++++++++++++++++++++++++++++++++
 include/linux/input/mt.h |    1 +
 2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c
index c48c81f..5b95e38 100644
--- a/drivers/input/input-mt.c
+++ b/drivers/input/input-mt.c
@@ -168,3 +168,35 @@ void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count)
 	}
 }
 EXPORT_SYMBOL(input_mt_report_pointer_emulation);
+
+/**
+ * input_mt_get_absinfo - retrieve MT state variables from a device slot
+ * @dev: input device which state is being queried
+ * @code: ABS code to retrieve
+ * @slot: slot to retrieve from
+ *
+ * Return the ABS state of the given MT slot. If code is not an MT
+ * event, the corresponding ABS event is returned.
+ *
+ * This function may be called by anyone interested in extracting the
+ * current MT state. Used by evdev handlers.
+ */
+struct input_absinfo input_mt_get_absinfo(struct input_dev *dev, unsigned int code, int slot)
+{
+	unsigned int mtmap = code > ABS_MT_FIRST ? code - ABS_MT_FIRST : 0;
+	unsigned long flags;
+	struct input_absinfo retval;
+
+	spin_lock_irqsave(&dev->event_lock, flags);
+	if (!mtmap)
+		retval = dev->absinfo[code];
+	else if (slot >= 0 && slot < dev->mtsize) {
+		retval = dev->absinfo[code];
+		retval.value = dev->mt[slot].abs[mtmap];
+	} else
+		retval.value = 0;
+	spin_unlock_irqrestore(&dev->event_lock, flags);
+
+	return retval;
+}
+EXPORT_SYMBOL(input_mt_get_absinfo);
diff --git a/include/linux/input/mt.h b/include/linux/input/mt.h
index b3ac06a..a71a27f 100644
--- a/include/linux/input/mt.h
+++ b/include/linux/input/mt.h
@@ -54,4 +54,5 @@ void input_mt_report_slot_state(struct input_dev *dev,
 void input_mt_report_finger_count(struct input_dev *dev, int count);
 void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count);
 
+struct input_absinfo input_mt_get_absinfo(struct input_dev *dev, unsigned int code, int slot);
 #endif
-- 
1.7.3.4

[RFC 2/2] input: evdev: Add EVIOC mechanism to extract the MT slot state

From: Benjamin Tissoires <hidden>
Date: 2011-01-27 10:36:01

This patch adds the ability to extract the MT slot state sequentially
via EVIOCGABS. The slot parameter is first selected by calling
EVIOCSABS with ABS_MT_SLOT as argument, followed by a set of EVIOCGABS
calls. The slot selection is local to the evdev client handler, and
does not affect the actual input state.

Signed-off-by: Henrik Rydberg <redacted>
Signed-off-by: Benjamin Tissoires <redacted>
---
 drivers/input/evdev.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index c8471a2..a689079 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -23,6 +23,7 @@
 #include <linux/input.h>
 #include <linux/major.h>
 #include <linux/device.h>
+#include <linux/input/mt.h>
 #include "input-compat.h"
 
 struct evdev {
@@ -45,6 +46,7 @@ struct evdev_client {
 	struct fasync_struct *fasync;
 	struct evdev *evdev;
 	struct list_head node;
+	int slot; /* used to extract MT events via EVIOC */
 	int bufsize;
 	struct input_event buffer[];
 };
@@ -741,7 +743,7 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
 				return -EINVAL;
 
 			t = _IOC_NR(cmd) & ABS_MAX;
-			abs = dev->absinfo[t];
+			abs = input_mt_get_absinfo(dev, t, client->slot);
 
 			if (copy_to_user(p, &abs, min_t(size_t,
 					size, sizeof(struct input_absinfo))))
@@ -767,9 +769,10 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
 			if (size < sizeof(struct input_absinfo))
 				abs.resolution = 0;
 
-			/* We can't change number of reserved MT slots */
-			if (t == ABS_MT_SLOT)
-				return -EINVAL;
+			if (t == ABS_MT_SLOT) {
+				client->slot = abs.value;
+				return 0;
+			}
 
 			/*
 			 * Take event lock to ensure that we are not
-- 
1.7.3.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help