mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] trackpoint: enable selection of press-to-select button
@ 2009-06-25 16:10 Tom Weissmann
  2009-06-30  6:34 ` Pavel Machek
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Weissmann @ 2009-06-25 16:10 UTC (permalink / raw)
  To: rubini; +Cc: linux-kernel

Currently the trackpoint driver supports press-to-select but only left
button clicks can be generated, although the trackpoint itself can
generate 3 different button clicks when pressed: left, middle, or
right.

With this patch the trackpoint sysfs variable press-to-select can be
set not only to 0 (off), 1 (left button), but also to 2 (middle
button) and 3 (right button). This makes the feature more useful for
left-handed users with no visible changes to the right-handed default
behaviour.

Signed-off by: Tom Weissmann <tom.weissmann@gmail.com>
---

--- linux-2.6.30/drivers/input/mouse/trackpoint.h.orig	2009-06-19
12:16:54.814029216 +0200
+++ linux-2.6.30/drivers/input/mouse/trackpoint.h	2009-06-19
12:38:31.151280333 +0200
@@ -102,6 +102,13 @@
 #define TP_MASK_EXT_TAG			0x04


+/* Press-to-select button maps */
+
+#define TP_BUTTON1_MAP          0x41
+#define TP_BUTTON2_MAP          0x43
+#define TP_BUTTON3_MAP          0x42
+
+
 /* Power on Self Test Results */
 #define TP_POR_SUCCESS		0x3B

@@ -121,6 +128,8 @@
 #define TP_DEF_Z_TIME		0x26
 #define TP_DEF_JENKS_CURV	0x87

+#define TP_DEF_PTS		0x00
+
 /* Toggles */
 #define TP_DEF_MB		0x00
 #define TP_DEF_PTSON		0x00
--- linux-2.6.30/drivers/input/mouse/trackpoint.c.orig	2009-06-19
12:18:57.430029371 +0200
+++ linux-2.6.30/drivers/input/mouse/trackpoint.c	2009-06-20
00:13:54.299571377 +0200
@@ -131,17 +131,69 @@ static ssize_t trackpoint_set_bit_attr(s
 }


-#define TRACKPOINT_BIT_ATTR(_name, _command, _mask, _inv)				\
-	static struct trackpoint_attr_data trackpoint_attr_##_name = {		\
-		.field_offset	= offsetof(struct trackpoint_data, _name),	\
-		.command	= _command,					\
-		.mask		= _mask,					\
-		.inverted	= _inv,						\
-	};									\
-	PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO,				\
-			    &trackpoint_attr_##_name,				\
+#define TRACKPOINT_BIT_ATTR(_name, _command, _mask, _inv)		      \
+	static struct trackpoint_attr_data trackpoint_attr_##_name = {	      \
+		.field_offset	= offsetof(struct trackpoint_data, _name),    \
+		.command	= _command,				      \
+		.mask		= _mask,				      \
+		.inverted	= _inv,					      \
+	};								      \
+	PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO,			      \
+			    &trackpoint_attr_##_name,			      \
 			    trackpoint_show_int_attr, trackpoint_set_bit_attr)

+
+#define TRACKPOINT_CUSTOM_WRITE_ATTR(_name, _command, _mask, _inv, _writefn)  \
+	static struct trackpoint_attr_data trackpoint_attr_##_name = {	      \
+		.field_offset	= offsetof(struct trackpoint_data, _name),    \
+		.command	= _command,				      \
+		.mask		= _mask,				      \
+		.inverted	= _inv,					      \
+	};								      \
+	PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO,			      \
+			    &trackpoint_attr_##_name,			      \
+			    trackpoint_show_int_attr, _writefn)
+
+
+#define TRACKPOINT_SET_PTS_BUTTON(_ps2dev, _value)			      \
+ do {									      \
+	trackpoint_write(_ps2dev, TP_BUTTON1_MAP, ((1 == _value) ? 255 : 0)); \
+	trackpoint_write(_ps2dev, TP_BUTTON2_MAP, ((2 == _value) ? 255 : 0)); \
+	trackpoint_write(_ps2dev, TP_BUTTON3_MAP, ((3 == _value) ? 255 : 0)); \
+  } while (0)								      \
+
+static ssize_t trackpoint_set_press_to_select(struct psmouse *psmouse,
+					      void *data,
+					      const char *buf,
+					      size_t count)
+{
+	struct trackpoint_data *tp = psmouse->private;
+	struct trackpoint_attr_data *attr = data;
+	unsigned char *field = (unsigned char *) ((char *)tp +
+						  attr->field_offset);
+	unsigned long value;
+	char *rest;
+
+	value = strict_strtoul(buf, &rest, 10);
+	if (*rest || value > 3)
+		return -EINVAL;
+
+	if (*field != value) {
+
+		if (*field == 0 || value == 0)
+			trackpoint_toggle_bit(&psmouse->ps2dev, attr->command,
+					      attr->mask);
+
+		if (0 < value)
+			TRACKPOINT_SET_PTS_BUTTON(&psmouse->ps2dev, value);
+
+	  *field = value;
+	}
+
+	return count;
+}
+
+
 TRACKPOINT_INT_ATTR(sensitivity, TP_SENS);
 TRACKPOINT_INT_ATTR(speed, TP_SPEED);
 TRACKPOINT_INT_ATTR(inertia, TP_INERTIA);
@@ -153,10 +205,12 @@ TRACKPOINT_INT_ATTR(upthresh, TP_UP_THRE
 TRACKPOINT_INT_ATTR(ztime, TP_Z_TIME);
 TRACKPOINT_INT_ATTR(jenks, TP_JENKS_CURV);

-TRACKPOINT_BIT_ATTR(press_to_select, TP_TOGGLE_PTSON, TP_MASK_PTSON, 0);
 TRACKPOINT_BIT_ATTR(skipback, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK, 0);
 TRACKPOINT_BIT_ATTR(ext_dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV, 1);

+TRACKPOINT_CUSTOM_WRITE_ATTR(press_to_select, TP_TOGGLE_PTSON,
TP_MASK_PTSON, 0,
+				   trackpoint_set_press_to_select);
+
 static struct attribute *trackpoint_attrs[] = {
 	&psmouse_attr_sensitivity.dattr.attr,
 	&psmouse_attr_speed.dattr.attr,
@@ -228,8 +282,16 @@ static int trackpoint_sync(struct psmous
 	trackpoint_write(&psmouse->ps2dev, TP_JENKS_CURV, tp->jenks);

 	trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_PTSON, &toggle);
-	if (((toggle & TP_MASK_PTSON) == TP_MASK_PTSON) != tp->press_to_select)
-		 trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_PTSON, TP_MASK_PTSON);
+
+	if (((toggle & TP_MASK_PTSON) == TP_MASK_PTSON) !=
+	    (0 < tp->press_to_select))
+		trackpoint_toggle_bit(&psmouse->ps2dev,
+				      TP_TOGGLE_PTSON,
+				      TP_MASK_PTSON);
+	}
+	if (0 < tp->press_to_select)
+		TRACKPOINT_SET_PTS_BUTTON(&psmouse->ps2dev, tp->press_to_select)
+

 	trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_SKIPBACK, &toggle);
 	if (((toggle & TP_MASK_SKIPBACK) == TP_MASK_SKIPBACK) != tp->skipback)
@@ -244,7 +306,8 @@ static int trackpoint_sync(struct psmous

 static void trackpoint_defaults(struct trackpoint_data *tp)
 {
-	tp->press_to_select = TP_DEF_PTSON;
+	tp->press_to_select = TP_DEF_PTS;
+
 	tp->sensitivity = TP_DEF_SENS;
 	tp->speed = TP_DEF_SPEED;
 	tp->reach = TP_DEF_REACH;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] trackpoint: enable selection of press-to-select button
  2009-06-25 16:10 [PATCH] trackpoint: enable selection of press-to-select button Tom Weissmann
@ 2009-06-30  6:34 ` Pavel Machek
  2009-07-01 10:44   ` Tom Weissmann
  0 siblings, 1 reply; 4+ messages in thread
From: Pavel Machek @ 2009-06-30  6:34 UTC (permalink / raw)
  To: Tom Weissmann; +Cc: rubini, linux-kernel, jikos


On Thu 2009-06-25 18:10:41, Tom Weissmann wrote:
> Currently the trackpoint driver supports press-to-select but only left
> button clicks can be generated, although the trackpoint itself can
> generate 3 different button clicks when pressed: left, middle, or
> right.
> 
> With this patch the trackpoint sysfs variable press-to-select can be
> set not only to 0 (off), 1 (left button), but also to 2 (middle
> button) and 3 (right button). This makes the feature more useful for
> left-handed users with no visible changes to the right-handed default
> behaviour.

Uhuh. Ugly as night. Could we instead convert press to button 4, and
let userland map it?

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] trackpoint: enable selection of press-to-select button
  2009-06-30  6:34 ` Pavel Machek
@ 2009-07-01 10:44   ` Tom Weissmann
  2009-07-03 10:40     ` Tom Weissmann
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Weissmann @ 2009-07-01 10:44 UTC (permalink / raw)
  To: Pavel Machek; +Cc: rubini, linux-kernel, jikos

2009/6/30 Pavel Machek <pavel@ucw.cz>:

>> With this patch the trackpoint sysfs variable press-to-select can be
>> set not only to 0 (off), 1 (left button), but also to 2 (middle
>> button) and 3 (right button). This makes the feature more useful for
>> left-handed users with no visible changes to the right-handed default
>> behaviour.
>
> Uhuh. Ugly as night. Could we instead convert press to button 4, and
> let userland map it?

This would be much better.

However, as far as I know it is not possible to distinguish a "real"
button click from a PTS one.
The PTS button is determined by 3 masks (button 1, 2, 3). I believe
that if more than one mask is set, PTS will still only generate one
click, not two simultaneous ones.

Regards,
Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] trackpoint: enable selection of press-to-select button
  2009-07-01 10:44   ` Tom Weissmann
@ 2009-07-03 10:40     ` Tom Weissmann
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Weissmann @ 2009-07-03 10:40 UTC (permalink / raw)
  To: Pavel Machek; +Cc: rubini, linux-kernel, jikos

2009/7/1 Tom Weissmann <tom.weissmann@gmail.com>:
> 2009/6/30 Pavel Machek <pavel@ucw.cz>:

> The PTS button is determined by 3 masks (button 1, 2, 3). I believe
> that if more than one mask is set, PTS will still only generate one
> click, not two simultaneous ones.

In fact it is possible set the masks to generate any combination of
button 1, 2, and 3 events (but not to distinguish events generated by
PTS from real button events).

With this in mind press-to-select could remain a boolean and the 3
button marks could be exposed as sysfs variables. Would this be
preferable?

Regards,
Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-07-03 10:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-25 16:10 [PATCH] trackpoint: enable selection of press-to-select button Tom Weissmann
2009-06-30  6:34 ` Pavel Machek
2009-07-01 10:44   ` Tom Weissmann
2009-07-03 10:40     ` Tom Weissmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®