Re: wsmouse(4): Apple-like multi-touch buttons

2023-02-09 Thread Ulf Brosziewski
If we consider it as a work in progress, is it a good idea then to "publish"
it via wsconsctl immediately?  Shouldn't we leave wsconsctl as it is until
we have figured out what to do, or at least hide that new field?  And, speaking
of hiding, it is for a feature that's only useful for a subset of touchpads:
MT-clickpads with MT-support in our kernel.  How do you want to handle the cases
where it is useless?  And MT-clickpads without MT-support?  It may raise wrong
expectations.  Without MT-data reasonable filtering won't be possible.


On 2/8/23 00:48, Patrick Wildt wrote:
> On Tue, Feb 07, 2023 at 10:07:56PM +0100, Ulf Brosziewski wrote:
>> I wouldn't mind seeing such a feature in the driver, but I think there's more
>> to do than counting contacts. The start of a click-and-drag gesture may 
>> involve
>> two contacts and a button-press event, or people who place a thumb in the 
>> lower
>> clickpad area and use it for pressing the clickpad button might leave the 
>> index
>> finger in the main area. In both cases you probably shouldn't generate a 
>> middle-
>> button event, and I guess it doesn't happen on MacOS, or does it?
>>
>> There may be various means to distinguish the gestures. The driver might 
>> check
>> the positions and the distance of the contacts, or identify their duration,
>> their initial position or the current direction and speed of movement, etc.
>>
>> I don't know which strategies work well and can be implemented with 
>> reasonable
>> effort, it might not be easy to figure that out. It seems that libinput uses
>> distances (see
>>   
>> https://wayland.freedesktop.org/libinput/doc/1.22.0/clickpad-softbuttons.html
>> ) as well as additional means for identifying "thumbs", but I'm not familiar
>> with the details.
> 
> Sounds like this good be something one could improve upon in-tree?  The
> diff already feels much better than the current default.
> 
> Cheers,
> Patrick
> 



Re: wsmouse(4): Apple-like multi-touch buttons

2023-02-08 Thread Mark Jamsek
On 23-02-07 02:12PM, Tobias Heider wrote:
> On Mon, Sep 19, 2022 at 11:16:51AM +0200, Ulf Brosziewski wrote:
> > Is there enough interest in this feature among OpenBSD users?  I haven't
> > seen many requests for it, if any.  Moreover, is it a good idea to configure
> > different input methods on this or that hardware just because another OS
> > has different defaults?
> > 
> > Just in case the answer to these questions turns out to be "yes", here are
> > some remarks on the diff.
> 
> I do still believe that there is interest in this feature based on the 
> feedback
> I got from other devs. Having it available as a non-default option as 
> kettenis@
> said would be good enough.
> Below is a revised version of the diff that adds a new mouse.tp.mtbuttons 
> config
> option. It can either be enabled via wsconsctl mouse.tp.mtbuttons=1 or by
> adding mouse.tp.mtbuttons=1 to your /etc/wsconsctl.conf.
> 

I'm definitely interested and would like to see this option made
available. Thanks for working on it, tobhe! I'd be happy to test any
further diffs too


-- 
Mark Jamsek 
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68


Re: wsmouse(4): Apple-like multi-touch buttons

2023-02-07 Thread Patrick Wildt
On Tue, Feb 07, 2023 at 10:07:56PM +0100, Ulf Brosziewski wrote:
> I wouldn't mind seeing such a feature in the driver, but I think there's more
> to do than counting contacts. The start of a click-and-drag gesture may 
> involve
> two contacts and a button-press event, or people who place a thumb in the 
> lower
> clickpad area and use it for pressing the clickpad button might leave the 
> index
> finger in the main area. In both cases you probably shouldn't generate a 
> middle-
> button event, and I guess it doesn't happen on MacOS, or does it?
> 
> There may be various means to distinguish the gestures. The driver might check
> the positions and the distance of the contacts, or identify their duration,
> their initial position or the current direction and speed of movement, etc.
> 
> I don't know which strategies work well and can be implemented with reasonable
> effort, it might not be easy to figure that out. It seems that libinput uses
> distances (see
>   
> https://wayland.freedesktop.org/libinput/doc/1.22.0/clickpad-softbuttons.html
> ) as well as additional means for identifying "thumbs", but I'm not familiar
> with the details.

Sounds like this good be something one could improve upon in-tree?  The
diff already feels much better than the current default.

Cheers,
Patrick



Re: wsmouse(4): Apple-like multi-touch buttons

2023-02-07 Thread Ulf Brosziewski
I wouldn't mind seeing such a feature in the driver, but I think there's more
to do than counting contacts. The start of a click-and-drag gesture may involve
two contacts and a button-press event, or people who place a thumb in the lower
clickpad area and use it for pressing the clickpad button might leave the index
finger in the main area. In both cases you probably shouldn't generate a middle-
button event, and I guess it doesn't happen on MacOS, or does it?

There may be various means to distinguish the gestures. The driver might check
the positions and the distance of the contacts, or identify their duration,
their initial position or the current direction and speed of movement, etc.

I don't know which strategies work well and can be implemented with reasonable
effort, it might not be easy to figure that out. It seems that libinput uses
distances (see
  https://wayland.freedesktop.org/libinput/doc/1.22.0/clickpad-softbuttons.html
) as well as additional means for identifying "thumbs", but I'm not familiar
with the details.


On 2/7/23 14:12, Tobias Heider wrote:
> On Mon, Sep 19, 2022 at 11:16:51AM +0200, Ulf Brosziewski wrote:
>> Is there enough interest in this feature among OpenBSD users?  I haven't
>> seen many requests for it, if any.  Moreover, is it a good idea to configure
>> different input methods on this or that hardware just because another OS
>> has different defaults?
>>
>> Just in case the answer to these questions turns out to be "yes", here are
>> some remarks on the diff.
> 
> I do still believe that there is interest in this feature based on the 
> feedback
> I got from other devs. Having it available as a non-default option as 
> kettenis@
> said would be good enough.
> 
> Below is a revised version of the diff that adds a new mouse.tp.mtbuttons 
> config
> option. It can either be enabled via wsconsctl mouse.tp.mtbuttons=1 or by
> adding mouse.tp.mtbuttons=1 to your /etc/wsconsctl.conf.
> 
> ok?
> 
> Index: sys/dev/wscons/wsconsio.h
> ===
> RCS file: /cvs/src/sys/dev/wscons/wsconsio.h,v
> retrieving revision 1.98
> diff -u -p -r1.98 wsconsio.h
> --- sys/dev/wscons/wsconsio.h 15 Jul 2022 17:57:27 -  1.98
> +++ sys/dev/wscons/wsconsio.h 5 Feb 2023 15:35:39 -
> @@ -319,6 +319,7 @@ enum wsmousecfg {
>   WSMOUSECFG_SWAPSIDES,   /* invert soft-button/scroll areas */
>   WSMOUSECFG_DISABLE, /* disable all output except for
>  clicks in the top-button area */
> + WSMOUSECFG_MTBUTTONS,   /* multi-touch buttons */
>  
>   /*
>* Touchpad options
> Index: sys/dev/wscons/wstpad.c
> ===
> RCS file: /cvs/src/sys/dev/wscons/wstpad.c,v
> retrieving revision 1.31
> diff -u -p -r1.31 wstpad.c
> --- sys/dev/wscons/wstpad.c   9 Jun 2022 22:17:18 -   1.31
> +++ sys/dev/wscons/wstpad.c   5 Feb 2023 15:35:39 -
> @@ -72,6 +72,7 @@
>  enum tpad_handlers {
>   SOFTBUTTON_HDLR,
>   TOPBUTTON_HDLR,
> + MTBUTTON_HDLR,
>   TAP_HDLR,
>   F2SCROLL_HDLR,
>   EDGESCROLL_HDLR,
> @@ -149,6 +150,7 @@ struct tpad_touch {
>  #define WSTPAD_HORIZSCROLL   (1 << 5)
>  #define WSTPAD_SWAPSIDES (1 << 6)
>  #define WSTPAD_DISABLE   (1 << 7)
> +#define WSTPAD_MTBUTTONS (1 << 8)
>  
>  #define WSTPAD_MT(1 << 31)
>  
> @@ -646,7 +648,17 @@ wstpad_softbuttons(struct wsmouseinput *
>   }
>  
>   if (tp->softbutton == 0 && PRIMARYBTN_CLICKED(tp)) {
> - tp->softbutton = wstpad_get_sbtn(input, top);
> + if (hdlr == MTBUTTON_HDLR) {
> + switch (tp->contacts) {
> + case 2:
> + tp->softbutton = RIGHTBTN;
> + break;
> + case 3:
> + tp->softbutton = MIDDLEBTN;
> + break;
> + }
> + } else
> + tp->softbutton = wstpad_get_sbtn(input, top);
>   if (tp->softbutton)
>   *cmds |= 1 << SOFTBUTTON_DOWN;
>   }
> @@ -1237,12 +1249,14 @@ wstpad_process_input(struct wsmouseinput
>   cmds = 0;
>   handlers = tp->handlers;
>   if (DISABLE(tp))
> - handlers &= ((1 << TOPBUTTON_HDLR) | (1 << SOFTBUTTON_HDLR));
> + handlers &= ((1 << TOPBUTTON_HDLR) | (1 << SOFTBUTTON_HDLR) |
> + (1 << MTBUTTON_HDLR));
>  
>   FOREACHBIT(handlers, hdlr) {
>   switch (hdlr) {
>   case SOFTBUTTON_HDLR:
>   case TOPBUTTON_HDLR:
> + case MTBUTTON_HDLR:
>   wstpad_softbuttons(input, , hdlr);
>   continue;
>   case TAP_HDLR:
> @@ -1621,6 +1635,8 @@ wstpad_configure(struct wsmouseinput *in
>  
>   tp->handlers = 0;
>  
> + if 

Re: wsmouse(4): Apple-like multi-touch buttons

2023-02-07 Thread Patrick Wildt
On Tue, Feb 07, 2023 at 02:12:57PM +0100, Tobias Heider wrote:
> On Mon, Sep 19, 2022 at 11:16:51AM +0200, Ulf Brosziewski wrote:
> > Is there enough interest in this feature among OpenBSD users?  I haven't
> > seen many requests for it, if any.  Moreover, is it a good idea to configure
> > different input methods on this or that hardware just because another OS
> > has different defaults?
> > 
> > Just in case the answer to these questions turns out to be "yes", here are
> > some remarks on the diff.
> 
> I do still believe that there is interest in this feature based on the 
> feedback
> I got from other devs. Having it available as a non-default option as 
> kettenis@
> said would be good enough.
> 
> Below is a revised version of the diff that adds a new mouse.tp.mtbuttons 
> config
> option. It can either be enabled via wsconsctl mouse.tp.mtbuttons=1 or by
> adding mouse.tp.mtbuttons=1 to your /etc/wsconsctl.conf.
> 
> ok?

I am very supportive of this idea/diff.  Not sure if it's my area to ok.

> Index: sys/dev/wscons/wsconsio.h
> ===
> RCS file: /cvs/src/sys/dev/wscons/wsconsio.h,v
> retrieving revision 1.98
> diff -u -p -r1.98 wsconsio.h
> --- sys/dev/wscons/wsconsio.h 15 Jul 2022 17:57:27 -  1.98
> +++ sys/dev/wscons/wsconsio.h 5 Feb 2023 15:35:39 -
> @@ -319,6 +319,7 @@ enum wsmousecfg {
>   WSMOUSECFG_SWAPSIDES,   /* invert soft-button/scroll areas */
>   WSMOUSECFG_DISABLE, /* disable all output except for
>  clicks in the top-button area */
> + WSMOUSECFG_MTBUTTONS,   /* multi-touch buttons */
>  
>   /*
>* Touchpad options
> Index: sys/dev/wscons/wstpad.c
> ===
> RCS file: /cvs/src/sys/dev/wscons/wstpad.c,v
> retrieving revision 1.31
> diff -u -p -r1.31 wstpad.c
> --- sys/dev/wscons/wstpad.c   9 Jun 2022 22:17:18 -   1.31
> +++ sys/dev/wscons/wstpad.c   5 Feb 2023 15:35:39 -
> @@ -72,6 +72,7 @@
>  enum tpad_handlers {
>   SOFTBUTTON_HDLR,
>   TOPBUTTON_HDLR,
> + MTBUTTON_HDLR,
>   TAP_HDLR,
>   F2SCROLL_HDLR,
>   EDGESCROLL_HDLR,
> @@ -149,6 +150,7 @@ struct tpad_touch {
>  #define WSTPAD_HORIZSCROLL   (1 << 5)
>  #define WSTPAD_SWAPSIDES (1 << 6)
>  #define WSTPAD_DISABLE   (1 << 7)
> +#define WSTPAD_MTBUTTONS (1 << 8)
>  
>  #define WSTPAD_MT(1 << 31)
>  
> @@ -646,7 +648,17 @@ wstpad_softbuttons(struct wsmouseinput *
>   }
>  
>   if (tp->softbutton == 0 && PRIMARYBTN_CLICKED(tp)) {
> - tp->softbutton = wstpad_get_sbtn(input, top);
> + if (hdlr == MTBUTTON_HDLR) {
> + switch (tp->contacts) {
> + case 2:
> + tp->softbutton = RIGHTBTN;
> + break;
> + case 3:
> + tp->softbutton = MIDDLEBTN;
> + break;
> + }
> + } else
> + tp->softbutton = wstpad_get_sbtn(input, top);
>   if (tp->softbutton)
>   *cmds |= 1 << SOFTBUTTON_DOWN;
>   }
> @@ -1237,12 +1249,14 @@ wstpad_process_input(struct wsmouseinput
>   cmds = 0;
>   handlers = tp->handlers;
>   if (DISABLE(tp))
> - handlers &= ((1 << TOPBUTTON_HDLR) | (1 << SOFTBUTTON_HDLR));
> + handlers &= ((1 << TOPBUTTON_HDLR) | (1 << SOFTBUTTON_HDLR) |
> + (1 << MTBUTTON_HDLR));
>  
>   FOREACHBIT(handlers, hdlr) {
>   switch (hdlr) {
>   case SOFTBUTTON_HDLR:
>   case TOPBUTTON_HDLR:
> + case MTBUTTON_HDLR:
>   wstpad_softbuttons(input, , hdlr);
>   continue;
>   case TAP_HDLR:
> @@ -1621,6 +1635,8 @@ wstpad_configure(struct wsmouseinput *in
>  
>   tp->handlers = 0;
>  
> + if (tp->features & WSTPAD_MTBUTTONS)
> + tp->handlers |= 1 << MTBUTTON_HDLR;
>   if (tp->features & WSTPAD_SOFTBUTTONS)
>   tp->handlers |= 1 << SOFTBUTTON_HDLR;
>   if (tp->features & WSTPAD_TOPBUTTONS)
> @@ -1691,7 +1707,7 @@ wstpad_set_param(struct wsmouseinput *in
>   return (EINVAL);
>  
>   switch (key) {
> - case WSMOUSECFG_SOFTBUTTONS ... WSMOUSECFG_DISABLE:
> + case WSMOUSECFG_SOFTBUTTONS ... WSMOUSECFG_MTBUTTONS:
>   switch (key) {
>   case WSMOUSECFG_SOFTBUTTONS:
>   flag = WSTPAD_SOFTBUTTONS;
> @@ -1717,6 +1733,9 @@ wstpad_set_param(struct wsmouseinput *in
>   case WSMOUSECFG_DISABLE:
>   flag = WSTPAD_DISABLE;
>   break;
> + case WSMOUSECFG_MTBUTTONS:
> + flag = WSTPAD_MTBUTTONS;
> + break;
>   }
>   if 

Re: wsmouse(4): Apple-like multi-touch buttons

2023-02-07 Thread Tobias Heider
On Mon, Sep 19, 2022 at 11:16:51AM +0200, Ulf Brosziewski wrote:
> Is there enough interest in this feature among OpenBSD users?  I haven't
> seen many requests for it, if any.  Moreover, is it a good idea to configure
> different input methods on this or that hardware just because another OS
> has different defaults?
> 
> Just in case the answer to these questions turns out to be "yes", here are
> some remarks on the diff.

I do still believe that there is interest in this feature based on the feedback
I got from other devs. Having it available as a non-default option as kettenis@
said would be good enough.

Below is a revised version of the diff that adds a new mouse.tp.mtbuttons config
option. It can either be enabled via wsconsctl mouse.tp.mtbuttons=1 or by
adding mouse.tp.mtbuttons=1 to your /etc/wsconsctl.conf.

ok?

Index: sys/dev/wscons/wsconsio.h
===
RCS file: /cvs/src/sys/dev/wscons/wsconsio.h,v
retrieving revision 1.98
diff -u -p -r1.98 wsconsio.h
--- sys/dev/wscons/wsconsio.h   15 Jul 2022 17:57:27 -  1.98
+++ sys/dev/wscons/wsconsio.h   5 Feb 2023 15:35:39 -
@@ -319,6 +319,7 @@ enum wsmousecfg {
WSMOUSECFG_SWAPSIDES,   /* invert soft-button/scroll areas */
WSMOUSECFG_DISABLE, /* disable all output except for
   clicks in the top-button area */
+   WSMOUSECFG_MTBUTTONS,   /* multi-touch buttons */
 
/*
 * Touchpad options
Index: sys/dev/wscons/wstpad.c
===
RCS file: /cvs/src/sys/dev/wscons/wstpad.c,v
retrieving revision 1.31
diff -u -p -r1.31 wstpad.c
--- sys/dev/wscons/wstpad.c 9 Jun 2022 22:17:18 -   1.31
+++ sys/dev/wscons/wstpad.c 5 Feb 2023 15:35:39 -
@@ -72,6 +72,7 @@
 enum tpad_handlers {
SOFTBUTTON_HDLR,
TOPBUTTON_HDLR,
+   MTBUTTON_HDLR,
TAP_HDLR,
F2SCROLL_HDLR,
EDGESCROLL_HDLR,
@@ -149,6 +150,7 @@ struct tpad_touch {
 #define WSTPAD_HORIZSCROLL (1 << 5)
 #define WSTPAD_SWAPSIDES   (1 << 6)
 #define WSTPAD_DISABLE (1 << 7)
+#define WSTPAD_MTBUTTONS   (1 << 8)
 
 #define WSTPAD_MT  (1 << 31)
 
@@ -646,7 +648,17 @@ wstpad_softbuttons(struct wsmouseinput *
}
 
if (tp->softbutton == 0 && PRIMARYBTN_CLICKED(tp)) {
-   tp->softbutton = wstpad_get_sbtn(input, top);
+   if (hdlr == MTBUTTON_HDLR) {
+   switch (tp->contacts) {
+   case 2:
+   tp->softbutton = RIGHTBTN;
+   break;
+   case 3:
+   tp->softbutton = MIDDLEBTN;
+   break;
+   }
+   } else
+   tp->softbutton = wstpad_get_sbtn(input, top);
if (tp->softbutton)
*cmds |= 1 << SOFTBUTTON_DOWN;
}
@@ -1237,12 +1249,14 @@ wstpad_process_input(struct wsmouseinput
cmds = 0;
handlers = tp->handlers;
if (DISABLE(tp))
-   handlers &= ((1 << TOPBUTTON_HDLR) | (1 << SOFTBUTTON_HDLR));
+   handlers &= ((1 << TOPBUTTON_HDLR) | (1 << SOFTBUTTON_HDLR) |
+   (1 << MTBUTTON_HDLR));
 
FOREACHBIT(handlers, hdlr) {
switch (hdlr) {
case SOFTBUTTON_HDLR:
case TOPBUTTON_HDLR:
+   case MTBUTTON_HDLR:
wstpad_softbuttons(input, , hdlr);
continue;
case TAP_HDLR:
@@ -1621,6 +1635,8 @@ wstpad_configure(struct wsmouseinput *in
 
tp->handlers = 0;
 
+   if (tp->features & WSTPAD_MTBUTTONS)
+   tp->handlers |= 1 << MTBUTTON_HDLR;
if (tp->features & WSTPAD_SOFTBUTTONS)
tp->handlers |= 1 << SOFTBUTTON_HDLR;
if (tp->features & WSTPAD_TOPBUTTONS)
@@ -1691,7 +1707,7 @@ wstpad_set_param(struct wsmouseinput *in
return (EINVAL);
 
switch (key) {
-   case WSMOUSECFG_SOFTBUTTONS ... WSMOUSECFG_DISABLE:
+   case WSMOUSECFG_SOFTBUTTONS ... WSMOUSECFG_MTBUTTONS:
switch (key) {
case WSMOUSECFG_SOFTBUTTONS:
flag = WSTPAD_SOFTBUTTONS;
@@ -1717,6 +1733,9 @@ wstpad_set_param(struct wsmouseinput *in
case WSMOUSECFG_DISABLE:
flag = WSTPAD_DISABLE;
break;
+   case WSMOUSECFG_MTBUTTONS:
+   flag = WSTPAD_MTBUTTONS;
+   break;
}
if (val)
tp->features |= flag;
@@ -1785,7 +1804,7 @@ wstpad_get_param(struct wsmouseinput *in
return (EINVAL);
 
switch (key) {
-   case WSMOUSECFG_SOFTBUTTONS ... WSMOUSECFG_DISABLE:
+   case 

Re: wsmouse(4): Apple-like multi-touch buttons

2022-09-24 Thread Mark Kettenis
> Date: Sun, 18 Sep 2022 14:21:06 +0200
> From: Tobias Heider 
> 
> Hi,
> 
> the diff below adds a new mouse type WSMOUSE_TYPE_APPLE which emulates Apples
> touchpad behaviour.  Instead of mapping soft-buttons to an area on the pad,
> the different mouse buttons are mapped to single-finger, two-finger and
> three-finger clicks as is the default in macos.
> 
> The diff enables the new mode on apldcms(4) and aplms(4) which are the drivers
> used by Apple silicon laptops.
> 
> Tested on an m2 air by me and an m1 by robert@.
> 
> ok?

I don't think OpenBSD should behave differently just because it is
running on Apple hardware.  Maybe it makes sense to add this mode as a
user configurale option?

> diff --git sys/arch/arm64/dev/apldc.c sys/arch/arm64/dev/apldc.c
> index 09a03c734da..f261c19b13b 100644
> --- sys/arch/arm64/dev/apldc.c
> +++ sys/arch/arm64/dev/apldc.c
> @@ -1363,7 +1363,7 @@ apldcms_configure(struct apldcms_softc *sc)
>   struct wsmousehw *hw = wsmouse_get_hw(sc->sc_wsmousedev);
>  
>   /* The values below are for the MacBookPro17,1 */
> - hw->type = WSMOUSE_TYPE_TOUCHPAD;
> + hw->type = WSMOUSE_TYPE_APPLE;
>   hw->hw_type = WSMOUSEHW_CLICKPAD;
>   hw->x_min = -6046;
>   hw->x_max = 6536;
> diff --git sys/arch/arm64/dev/aplhidev.c sys/arch/arm64/dev/aplhidev.c
> index 2b00f7e217d..290520e85cb 100644
> --- sys/arch/arm64/dev/aplhidev.c
> +++ sys/arch/arm64/dev/aplhidev.c
> @@ -654,7 +654,7 @@ aplms_configure(struct aplms_softc *sc)
>   struct wsmousehw *hw = wsmouse_get_hw(sc->sc_wsmousedev);
>  
>   /* The values below are for the MacBookPro17,1 */
> - hw->type = WSMOUSE_TYPE_TOUCHPAD;
> + hw->type = WSMOUSE_TYPE_APPLE;
>   hw->hw_type = WSMOUSEHW_CLICKPAD;
>   hw->x_min = -6046;
>   hw->x_max = 6536;
> diff --git sys/dev/wscons/wsconsio.h sys/dev/wscons/wsconsio.h
> index de483493360..67b46da8d1f 100644
> --- sys/dev/wscons/wsconsio.h
> +++ sys/dev/wscons/wsconsio.h
> @@ -245,6 +245,7 @@ struct wskbd_encoding_data {
>  #define  WSMOUSE_TYPE_ELANTECH   18  /* Elantech touchpad */
>  #define  WSMOUSE_TYPE_SYNAP_SBTN 19  /* Synaptics soft 
> buttons */
>  #define  WSMOUSE_TYPE_TOUCHPAD   20  /* Generic touchpad */
> +#define  WSMOUSE_TYPE_APPLE  21  /* Apple touchpad */
>  
>  /* Set resolution.  Not applicable to all mouse types. */
>  #define  WSMOUSEIO_SRES  _IOW('W', 33, u_int)
> @@ -313,6 +314,7 @@ enum wsmousecfg {
>   WSMOUSECFG_SOFTBUTTONS = 64,/* 2 soft-buttons at the bottom edge */
>   WSMOUSECFG_SOFTMBTN,/* add a middle-button area */
>   WSMOUSECFG_TOPBUTTONS,  /* 3 soft-buttons at the top edge */
> + WSMOUSECFG_MTBUTTONS,   /* multi-finger buttons */
>   WSMOUSECFG_TWOFINGERSCROLL, /* enable two-finger scrolling */
>   WSMOUSECFG_EDGESCROLL,  /* enable edge scrolling */
>   WSMOUSECFG_HORIZSCROLL, /* enable horizontal edge scrolling */
> diff --git sys/dev/wscons/wstpad.c sys/dev/wscons/wstpad.c
> index be074b89fb8..9a74fa65908 100644
> --- sys/dev/wscons/wstpad.c
> +++ sys/dev/wscons/wstpad.c
> @@ -72,6 +72,7 @@
>  enum tpad_handlers {
>   SOFTBUTTON_HDLR,
>   TOPBUTTON_HDLR,
> + MTBUTTON_HDLR,
>   TAP_HDLR,
>   F2SCROLL_HDLR,
>   EDGESCROLL_HDLR,
> @@ -149,6 +150,7 @@ struct tpad_touch {
>  #define WSTPAD_HORIZSCROLL   (1 << 5)
>  #define WSTPAD_SWAPSIDES (1 << 6)
>  #define WSTPAD_DISABLE   (1 << 7)
> +#define WSTPAD_MTBUTTONS (1 << 8)
>  
>  #define WSTPAD_MT(1 << 31)
>  
> @@ -646,7 +648,23 @@ wstpad_softbuttons(struct wsmouseinput *input, u_int 
> *cmds, int hdlr)
>   }
>  
>   if (tp->softbutton == 0 && PRIMARYBTN_CLICKED(tp)) {
> - tp->softbutton = wstpad_get_sbtn(input, top);
> + if (hdlr == MTBUTTON_HDLR) {
> + switch (tp->contacts) {
> + case 2:
> + tp->softbutton = RIGHTBTN;
> + break;
> + case 3:
> + tp->softbutton = MIDDLEBTN;
> + break;
> + case 1:
> + tp->softbutton = LEFTBTN;
> + break;
> + default:
> + tp->softbutton = 0;
> + break;
> + }
> + } else
> + tp->softbutton = wstpad_get_sbtn(input, top);
>   if (tp->softbutton)
>   *cmds |= 1 << SOFTBUTTON_DOWN;
>   }
> @@ -1237,12 +1255,14 @@ wstpad_process_input(struct wsmouseinput *input, 
> struct evq_access *evq)
>   cmds = 0;
>   handlers = tp->handlers;
>   if (DISABLE(tp))
> - handlers &= ((1 << TOPBUTTON_HDLR) | (1 << SOFTBUTTON_HDLR));
> + handlers &= ((1 << TOPBUTTON_HDLR) | 

Re: wsmouse(4): Apple-like multi-touch buttons

2022-09-19 Thread Ulf Brosziewski
Is there enough interest in this feature among OpenBSD users?  I haven't
seen many requests for it, if any.  Moreover, is it a good idea to configure
different input methods on this or that hardware just because another OS
has different defaults?

Just in case the answer to these questions turns out to be "yes", here are
some remarks on the diff.

First, I think the initialization bug should be fixed at its origin.
Currently, passing parameters to wsmouse_configure() only works with the
general wsmouse parameters (WSMOUSECFG_DX_SCALE .. WSMOUSECFG_REVERSE_
SCROLLING), and a subset of the touchpad-specific ones.  Changing
wsmouse.c as follows will make it work with all of them:

diff --git a/sys/dev/wscons/wsmouse.c b/sys/dev/wscons/wsmouse.c
index c786af18208..0feae6824bb 100644
--- a/sys/dev/wscons/wsmouse.c
+++ b/sys/dev/wscons/wsmouse.c
@@ -1662,11 +1662,11 @@ wsmouse_configure(struct device *sc,
"Initialization failed.\n");
return (-1);
}
+   input->flags |= CONFIGURED;
if (params != NULL) {
if ((error = wsmouse_set_params(sc, params, nparams)))
return (error);
}
-   input->flags |= CONFIGURED;
}
if (IS_TOUCHPAD(input))
wsmouse_set_mode(sc, WSMOUSE_COMPAT);


(We might as well remove the 'params' arguments from wsmouse_configure, and
leave the call to wsmouse_set_params() to the hardware drivers;  up to now,
only pms changes default configurations.)

Two more remarks are inline.


On 9/18/22 16:42, Tobias Heider wrote:
> On Sun, Sep 18, 2022 at 02:21:06PM +0200, Tobias Heider wrote:
>> Hi,
>>
>> the diff below adds a new mouse type WSMOUSE_TYPE_APPLE which emulates Apples
>> touchpad behaviour.  Instead of mapping soft-buttons to an area on the pad,
>> the different mouse buttons are mapped to single-finger, two-finger and
>> three-finger clicks as is the default in macos.
>>
>> The diff enables the new mode on apldcms(4) and aplms(4) which are the 
>> drivers
>> used by Apple silicon laptops.
>>
>> Tested on an m2 air by me and an m1 by robert@.
>>
>> ok?
> 
> Here's an updated version that does not add a new WSMOUSE_TYPE and as such 
> does
> not require any changes in X.  Instead I just pass the button configuration 
> via
> params in wsmouse_configure().
> 
> To make this work I had to fix a bug in wstpad where the CONFIGURE flag is not
> set after initial configuration, which causes all values to be overwritten 
> with
> the defaults on each reconfigure triggered from wsmouse_set_params().
> 
> diff --git sys/arch/arm64/dev/apldc.c sys/arch/arm64/dev/apldc.c
> index 09a03c734da..7962a3c645a 100644
> --- sys/arch/arm64/dev/apldc.c
> +++ sys/arch/arm64/dev/apldc.c
> @@ -1317,6 +1317,11 @@ const struct wsmouse_accessops apldcms_accessops = {
>   .ioctl = apldcms_ioctl,
>  };
>  
> +static struct wsmouse_param apldcms_params[] = {
> + { WSMOUSECFG_SOFTBUTTONS, 0 },
> + { WSMOUSECFG_MTBUTTONS, 1 },
> +};
> +
>  int   apldcms_match(struct device *, void *, void *);
>  void  apldcms_attach(struct device *, struct device *, void *);
>  
> @@ -1372,7 +1377,7 @@ apldcms_configure(struct apldcms_softc *sc)
>   hw->mt_slots = UBCMTP_MAX_FINGERS;
>   hw->flags = WSMOUSEHW_MT_TRACKING;
>  
> - return wsmouse_configure(sc->sc_wsmousedev, NULL, 0);
> + return wsmouse_configure(sc->sc_wsmousedev, apldcms_params, 2);
>  }
>  
>  void
> diff --git sys/arch/arm64/dev/aplhidev.c sys/arch/arm64/dev/aplhidev.c
> index 2b00f7e217d..ecfb5b8f4eb 100644
> --- sys/arch/arm64/dev/aplhidev.c
> +++ sys/arch/arm64/dev/aplhidev.c
> @@ -608,6 +608,11 @@ const struct wsmouse_accessops aplms_accessops = {
>   .ioctl = aplms_ioctl,
>  };
>  
> +static struct wsmouse_param aplms_params[] = {
> + { WSMOUSECFG_SOFTBUTTONS, 0 },
> + { WSMOUSECFG_MTBUTTONS, 1 },
> +};
> +
>  int   aplms_match(struct device *, void *, void *);
>  void  aplms_attach(struct device *, struct device *, void *);
>  
> @@ -663,7 +668,7 @@ aplms_configure(struct aplms_softc *sc)
>   hw->mt_slots = UBCMTP_MAX_FINGERS;
>   hw->flags = WSMOUSEHW_MT_TRACKING;
>  
> - return wsmouse_configure(sc->sc_wsmousedev, NULL, 0);
> + return wsmouse_configure(sc->sc_wsmousedev, aplms_params, 2);
>  }
>  
>  void
> diff --git sys/dev/wscons/wsconsio.h sys/dev/wscons/wsconsio.h
> index de483493360..497e9a32db7 100644
> --- sys/dev/wscons/wsconsio.h
> +++ sys/dev/wscons/wsconsio.h
> @@ -313,6 +313,7 @@ enum wsmousecfg {
>   WSMOUSECFG_SOFTBUTTONS = 64,/* 2 soft-buttons at the bottom edge */
>   WSMOUSECFG_SOFTMBTN,/* add a middle-button area */
>   WSMOUSECFG_TOPBUTTONS,  /* 3 soft-buttons at the top edge */
> + WSMOUSECFG_MTBUTTONS,   /* multi-finger buttons */

Even though it requires updating a line of wsconsctl code, I think the
MTBUTTONS entry should be placed at 

Re: wsmouse(4): Apple-like multi-touch buttons

2022-09-18 Thread Tobias Heider
On Sun, Sep 18, 2022 at 02:21:06PM +0200, Tobias Heider wrote:
> Hi,
> 
> the diff below adds a new mouse type WSMOUSE_TYPE_APPLE which emulates Apples
> touchpad behaviour.  Instead of mapping soft-buttons to an area on the pad,
> the different mouse buttons are mapped to single-finger, two-finger and
> three-finger clicks as is the default in macos.
> 
> The diff enables the new mode on apldcms(4) and aplms(4) which are the drivers
> used by Apple silicon laptops.
> 
> Tested on an m2 air by me and an m1 by robert@.
> 
> ok?

Here's an updated version that does not add a new WSMOUSE_TYPE and as such does
not require any changes in X.  Instead I just pass the button configuration via
params in wsmouse_configure().

To make this work I had to fix a bug in wstpad where the CONFIGURE flag is not
set after initial configuration, which causes all values to be overwritten with
the defaults on each reconfigure triggered from wsmouse_set_params().

diff --git sys/arch/arm64/dev/apldc.c sys/arch/arm64/dev/apldc.c
index 09a03c734da..7962a3c645a 100644
--- sys/arch/arm64/dev/apldc.c
+++ sys/arch/arm64/dev/apldc.c
@@ -1317,6 +1317,11 @@ const struct wsmouse_accessops apldcms_accessops = {
.ioctl = apldcms_ioctl,
 };
 
+static struct wsmouse_param apldcms_params[] = {
+   { WSMOUSECFG_SOFTBUTTONS, 0 },
+   { WSMOUSECFG_MTBUTTONS, 1 },
+};
+
 int apldcms_match(struct device *, void *, void *);
 voidapldcms_attach(struct device *, struct device *, void *);
 
@@ -1372,7 +1377,7 @@ apldcms_configure(struct apldcms_softc *sc)
hw->mt_slots = UBCMTP_MAX_FINGERS;
hw->flags = WSMOUSEHW_MT_TRACKING;
 
-   return wsmouse_configure(sc->sc_wsmousedev, NULL, 0);
+   return wsmouse_configure(sc->sc_wsmousedev, apldcms_params, 2);
 }
 
 void
diff --git sys/arch/arm64/dev/aplhidev.c sys/arch/arm64/dev/aplhidev.c
index 2b00f7e217d..ecfb5b8f4eb 100644
--- sys/arch/arm64/dev/aplhidev.c
+++ sys/arch/arm64/dev/aplhidev.c
@@ -608,6 +608,11 @@ const struct wsmouse_accessops aplms_accessops = {
.ioctl = aplms_ioctl,
 };
 
+static struct wsmouse_param aplms_params[] = {
+   { WSMOUSECFG_SOFTBUTTONS, 0 },
+   { WSMOUSECFG_MTBUTTONS, 1 },
+};
+
 int aplms_match(struct device *, void *, void *);
 voidaplms_attach(struct device *, struct device *, void *);
 
@@ -663,7 +668,7 @@ aplms_configure(struct aplms_softc *sc)
hw->mt_slots = UBCMTP_MAX_FINGERS;
hw->flags = WSMOUSEHW_MT_TRACKING;
 
-   return wsmouse_configure(sc->sc_wsmousedev, NULL, 0);
+   return wsmouse_configure(sc->sc_wsmousedev, aplms_params, 2);
 }
 
 void
diff --git sys/dev/wscons/wsconsio.h sys/dev/wscons/wsconsio.h
index de483493360..497e9a32db7 100644
--- sys/dev/wscons/wsconsio.h
+++ sys/dev/wscons/wsconsio.h
@@ -313,6 +313,7 @@ enum wsmousecfg {
WSMOUSECFG_SOFTBUTTONS = 64,/* 2 soft-buttons at the bottom edge */
WSMOUSECFG_SOFTMBTN,/* add a middle-button area */
WSMOUSECFG_TOPBUTTONS,  /* 3 soft-buttons at the top edge */
+   WSMOUSECFG_MTBUTTONS,   /* multi-finger buttons */
WSMOUSECFG_TWOFINGERSCROLL, /* enable two-finger scrolling */
WSMOUSECFG_EDGESCROLL,  /* enable edge scrolling */
WSMOUSECFG_HORIZSCROLL, /* enable horizontal edge scrolling */
diff --git sys/dev/wscons/wstpad.c sys/dev/wscons/wstpad.c
index be074b89fb8..4384370545e 100644
--- sys/dev/wscons/wstpad.c
+++ sys/dev/wscons/wstpad.c
@@ -72,6 +72,7 @@
 enum tpad_handlers {
SOFTBUTTON_HDLR,
TOPBUTTON_HDLR,
+   MTBUTTON_HDLR,
TAP_HDLR,
F2SCROLL_HDLR,
EDGESCROLL_HDLR,
@@ -149,6 +150,7 @@ struct tpad_touch {
 #define WSTPAD_HORIZSCROLL (1 << 5)
 #define WSTPAD_SWAPSIDES   (1 << 6)
 #define WSTPAD_DISABLE (1 << 7)
+#define WSTPAD_MTBUTTONS   (1 << 8)
 
 #define WSTPAD_MT  (1 << 31)
 
@@ -646,7 +648,23 @@ wstpad_softbuttons(struct wsmouseinput *input, u_int 
*cmds, int hdlr)
}
 
if (tp->softbutton == 0 && PRIMARYBTN_CLICKED(tp)) {
-   tp->softbutton = wstpad_get_sbtn(input, top);
+   if (hdlr == MTBUTTON_HDLR) {
+   switch (tp->contacts) {
+   case 2:
+   tp->softbutton = RIGHTBTN;
+   break;
+   case 3:
+   tp->softbutton = MIDDLEBTN;
+   break;
+   case 1:
+   tp->softbutton = LEFTBTN;
+   break;
+   default:
+   tp->softbutton = 0;
+   break;
+   }
+   } else
+   tp->softbutton = wstpad_get_sbtn(input, top);
if (tp->softbutton)
*cmds |= 1 << SOFTBUTTON_DOWN;
}
@@ -1237,12 +1255,14 @@ 

wsmouse(4): Apple-like multi-touch buttons

2022-09-18 Thread Tobias Heider
Hi,

the diff below adds a new mouse type WSMOUSE_TYPE_APPLE which emulates Apples
touchpad behaviour.  Instead of mapping soft-buttons to an area on the pad,
the different mouse buttons are mapped to single-finger, two-finger and
three-finger clicks as is the default in macos.

The diff enables the new mode on apldcms(4) and aplms(4) which are the drivers
used by Apple silicon laptops.

Tested on an m2 air by me and an m1 by robert@.

ok?

diff --git sys/arch/arm64/dev/apldc.c sys/arch/arm64/dev/apldc.c
index 09a03c734da..f261c19b13b 100644
--- sys/arch/arm64/dev/apldc.c
+++ sys/arch/arm64/dev/apldc.c
@@ -1363,7 +1363,7 @@ apldcms_configure(struct apldcms_softc *sc)
struct wsmousehw *hw = wsmouse_get_hw(sc->sc_wsmousedev);
 
/* The values below are for the MacBookPro17,1 */
-   hw->type = WSMOUSE_TYPE_TOUCHPAD;
+   hw->type = WSMOUSE_TYPE_APPLE;
hw->hw_type = WSMOUSEHW_CLICKPAD;
hw->x_min = -6046;
hw->x_max = 6536;
diff --git sys/arch/arm64/dev/aplhidev.c sys/arch/arm64/dev/aplhidev.c
index 2b00f7e217d..290520e85cb 100644
--- sys/arch/arm64/dev/aplhidev.c
+++ sys/arch/arm64/dev/aplhidev.c
@@ -654,7 +654,7 @@ aplms_configure(struct aplms_softc *sc)
struct wsmousehw *hw = wsmouse_get_hw(sc->sc_wsmousedev);
 
/* The values below are for the MacBookPro17,1 */
-   hw->type = WSMOUSE_TYPE_TOUCHPAD;
+   hw->type = WSMOUSE_TYPE_APPLE;
hw->hw_type = WSMOUSEHW_CLICKPAD;
hw->x_min = -6046;
hw->x_max = 6536;
diff --git sys/dev/wscons/wsconsio.h sys/dev/wscons/wsconsio.h
index de483493360..67b46da8d1f 100644
--- sys/dev/wscons/wsconsio.h
+++ sys/dev/wscons/wsconsio.h
@@ -245,6 +245,7 @@ struct wskbd_encoding_data {
 #defineWSMOUSE_TYPE_ELANTECH   18  /* Elantech touchpad */
 #defineWSMOUSE_TYPE_SYNAP_SBTN 19  /* Synaptics soft 
buttons */
 #defineWSMOUSE_TYPE_TOUCHPAD   20  /* Generic touchpad */
+#defineWSMOUSE_TYPE_APPLE  21  /* Apple touchpad */
 
 /* Set resolution.  Not applicable to all mouse types. */
 #defineWSMOUSEIO_SRES  _IOW('W', 33, u_int)
@@ -313,6 +314,7 @@ enum wsmousecfg {
WSMOUSECFG_SOFTBUTTONS = 64,/* 2 soft-buttons at the bottom edge */
WSMOUSECFG_SOFTMBTN,/* add a middle-button area */
WSMOUSECFG_TOPBUTTONS,  /* 3 soft-buttons at the top edge */
+   WSMOUSECFG_MTBUTTONS,   /* multi-finger buttons */
WSMOUSECFG_TWOFINGERSCROLL, /* enable two-finger scrolling */
WSMOUSECFG_EDGESCROLL,  /* enable edge scrolling */
WSMOUSECFG_HORIZSCROLL, /* enable horizontal edge scrolling */
diff --git sys/dev/wscons/wstpad.c sys/dev/wscons/wstpad.c
index be074b89fb8..9a74fa65908 100644
--- sys/dev/wscons/wstpad.c
+++ sys/dev/wscons/wstpad.c
@@ -72,6 +72,7 @@
 enum tpad_handlers {
SOFTBUTTON_HDLR,
TOPBUTTON_HDLR,
+   MTBUTTON_HDLR,
TAP_HDLR,
F2SCROLL_HDLR,
EDGESCROLL_HDLR,
@@ -149,6 +150,7 @@ struct tpad_touch {
 #define WSTPAD_HORIZSCROLL (1 << 5)
 #define WSTPAD_SWAPSIDES   (1 << 6)
 #define WSTPAD_DISABLE (1 << 7)
+#define WSTPAD_MTBUTTONS   (1 << 8)
 
 #define WSTPAD_MT  (1 << 31)
 
@@ -646,7 +648,23 @@ wstpad_softbuttons(struct wsmouseinput *input, u_int 
*cmds, int hdlr)
}
 
if (tp->softbutton == 0 && PRIMARYBTN_CLICKED(tp)) {
-   tp->softbutton = wstpad_get_sbtn(input, top);
+   if (hdlr == MTBUTTON_HDLR) {
+   switch (tp->contacts) {
+   case 2:
+   tp->softbutton = RIGHTBTN;
+   break;
+   case 3:
+   tp->softbutton = MIDDLEBTN;
+   break;
+   case 1:
+   tp->softbutton = LEFTBTN;
+   break;
+   default:
+   tp->softbutton = 0;
+   break;
+   }
+   } else
+   tp->softbutton = wstpad_get_sbtn(input, top);
if (tp->softbutton)
*cmds |= 1 << SOFTBUTTON_DOWN;
}
@@ -1237,12 +1255,14 @@ wstpad_process_input(struct wsmouseinput *input, struct 
evq_access *evq)
cmds = 0;
handlers = tp->handlers;
if (DISABLE(tp))
-   handlers &= ((1 << TOPBUTTON_HDLR) | (1 << SOFTBUTTON_HDLR));
+   handlers &= ((1 << TOPBUTTON_HDLR) | (1 << SOFTBUTTON_HDLR) |
+   (1 << MTBUTTON_HDLR));
 
FOREACHBIT(handlers, hdlr) {
switch (hdlr) {
case SOFTBUTTON_HDLR:
case TOPBUTTON_HDLR:
+   case MTBUTTON_HDLR:
wstpad_softbuttons(input, , hdlr);