From dan@mvfx.com  Sat Apr 29 10:33:34 2000
Return-Path: <dan@mvfx.com>
Received: from mail.rdc1.sfba.home.com (ha1.rdc1.sfba.home.com [24.0.0.66])
	by hub.freebsd.org (Postfix) with ESMTP id E696637B74D
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 29 Apr 2000 10:33:32 -0700 (PDT)
	(envelope-from dan@mvfx.com)
Received: from mobiledan.mvfx.com ([24.7.201.244])
          by mail.rdc1.sfba.home.com (InterMail v4.01.01.00 201-229-111)
          with ESMTP
          id <20000429173331.SOOJ12856.mail.rdc1.sfba.home.com@mobiledan.mvfx.com>
          for <FreeBSD-gnats-submit@freebsd.org>;
          Sat, 29 Apr 2000 10:33:31 -0700
Received: (from dan@localhost)
	by mobiledan.mvfx.com (8.9.3/8.9.3) id KAA00791
	for FreeBSD-gnats-submit@freebsd.org; Sat, 29 Apr 2000 10:30:41 -0700 (PDT)
	(envelope-from dan)
Message-Id: <20000429103041.A768@mobiledan.mvfx.com>
Date: Sat, 29 Apr 2000 10:30:41 -0700
From: dan@tanelorn.demon.co.uk
Sender: dan@mvfx.com
Reply-To: dan@tanelorn.demon.co.uk
To: FreeBSD-gnats-submit@freebsd.org
Subject: Patch to allow z-axis events on versapad touchpad
X-Send-Pr-Version: 3.2

>Number:         18293
>Category:       kern
>Synopsis:       [psm] [patch] lack of versapad mouse wheel emulation
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 29 10:40:09 PDT 2000
>Closed-Date:    
>Last-Modified:  Sun Jun 17 09:46:54 GMT 2007
>Originator:     Dan Piponi
>Release:        FreeBSD 4.0-RELEASE i386
>Organization:
can be a good thing
>Environment:

FreeBSD-4.0 on i386

>Description:

Under Windows the versapad touchpad (found on Sony Vaio 505T[SRX]
laptops) drivers support 'wheel mouse' emulation when you drag your
finger up and down the far right hand side of the pad.  I have
written a patch to the mouse driver for the versapad device to
support this under FreeBSD.  Most people I know who run OSes that
don't support this emulation are pretty excited about this patch
so I think it'd be cool to get it into the main distribution.  I've
been using it for several weeks now with no problems.  Scrolls up
and down the right hand side now generate z-movement events.  It's
well behaved so it doesn't mistake slides right and then up as z.
Only moves that originate on the right hand side generate z events
and so there's no chance of accidentally causing unwanted z events.

This is ny first look at FreeBSD code so apologies if I've screwed
anything up.  But applying the patches works for me.  I haven't
figured out yet how to make this optiion nicely switchable from a
config file - or even better from rc.conf.

>How-To-Repeat:

N/A

>Fix:

Here are the patches:

*** /usr/src/sys/isa/psm.c	Wed Mar  1 11:30:36 2000
--- psm.c	Sat Apr 29 09:13:59 2000
***************
*** 168,173 ****
--- 168,174 ----
      int           button;	/* the latest button state */
      int		  xold;	/* previous absolute X position */
      int		  yold;	/* previous absolute Y position */
+     int		  scrolling;	/* emulating mouse wheel */
  };
  devclass_t psm_devclass;
  #define PSM_SOFTC(unit)	((struct psm_softc*)devclass_get_softc(psm_devclass, unit))
***************
*** 1951,1973 ****
  		if (y0 & 0x800)
  		    y0 -= 0x1000;
  		if (sc->flags & PSM_FLAGS_FINGERDOWN) {
! 		    x = sc->xold - x0;
! 		    y = y0 - sc->yold;
! 		    if (x < 0)	/* XXX */
! 			x++;
! 		    else if (x)
! 			x--;
! 		    if (y < 0)
! 			y++;
! 		    else if (y)
! 			y--;
  		} else {
  		    sc->flags |= PSM_FLAGS_FINGERDOWN;
  		}
  		sc->xold = x0;
  		sc->yold = y0;
  	    } else {
  		sc->flags &= ~PSM_FLAGS_FINGERDOWN;
  	    }
  	    c = ((x < 0) ? MOUSE_PS2_XNEG : 0)
  		| ((y < 0) ? MOUSE_PS2_YNEG : 0);
--- 1952,2002 ----
  		if (y0 & 0x800)
  		    y0 -= 0x1000;
  		if (sc->flags & PSM_FLAGS_FINGERDOWN) {
! #if defined(MOUSE_VERSA_SCROLL)
! 		    /*
! 		     * Support for mouse wheel emulation
! 		     */
! #define MOUSE_VERSA_SCROLL
! 		    if (sc->scrolling) {
! 			z = (sc->yold-y0)/MOUSE_VERSA_SCROLLSTEP;
! #if defined(MOUSE_VERSA_FRACTIONAL_SCROLL)
! 			/*
! 			 * We might not have 'consumed' all of the change
! 			 * in y because of the division by SCROLLSTEP 
! 			 * so save it for the next mouse movement.
! 			 */
! 			y0 = sc->yold-z*8;
! #endif /* defined(MOUSE_VERSA_FRACTIONAL_SCROLL) */
! 		    } else {
! #endif /* defined(MOUSE_VERSA_SCROLL) */
! 			x = sc->xold - x0;
! 			y = y0 - sc->yold;
! 			if (x < 0)	/* XXX */
! 			    x++;
! 			else if (x)
! 			    x--;
! 			if (y < 0)
! 			    y++;
! 			else if (y)
! 			    y--;
! #if defined(MOUSE_VERSA_SCROLL)
! 		    }
! #endif /* defined(MOUSE_VERSA_SCROLL) */
  		} else {
  		    sc->flags |= PSM_FLAGS_FINGERDOWN;
+ #if defined(MOUSE_VERSA_SCROLL)
+ 		    if (x0<MOUSE_VERSA_RIGHT_MARGIN) {
+ 			sc->scrolling = 1;
+ 		    }
+ #endif /* defined(MOUSE_VERSA_SCROLL) */
  		}
  		sc->xold = x0;
  		sc->yold = y0;
  	    } else {
  		sc->flags &= ~PSM_FLAGS_FINGERDOWN;
+ #if defined(MOUSE_VERSA_SCROLL)
+ 		sc->scrolling = 0;
+ #endif /* defined(MOUSE_VERSA_SCROLL) */
  	    }
  	    c = ((x < 0) ? MOUSE_PS2_XNEG : 0)
  		| ((y < 0) ? MOUSE_PS2_YNEG : 0);

*** /usr/src/sys/i386/include/mouse.h	Fri Aug 27 17:44:18 1999
--- mouse.h	Sat Apr 29 09:14:08 2000
***************
*** 239,244 ****
--- 239,249 ----
  #define MOUSE_PS2PLUS_SYNCMASK	0x48
  #define MOUSE_PS2PLUS_SYNC	0x48
  
+ #define MOUSE_VERSA_SCROLL
+ #define MOUSE_VERSA_SCROLLSTEP	32
+ #define MOUSE_VERSA_RIGHT_MARGIN	-180
+ #define MOUSE_VERSA_FRACTIONAL_SCROLL
+ 
  /* Interlink VersaPad (serial I/F) data packet */
  #define MOUSE_VERSA_PACKETSIZE	6
  #define MOUSE_VERSA_IN_USE	0x04


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->mikeh 
Responsible-Changed-By: mikeh 
Responsible-Changed-When: Tue Jul 1 09:26:35 PDT 2003 
Responsible-Changed-Why:  
I'll look at committing a variant of this patch. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=18293 
Responsible-Changed-From-To: mikeh->freebsd-bugs 
Responsible-Changed-By: mikeh 
Responsible-Changed-When: Thu Mar 11 06:27:53 PST 2004 
Responsible-Changed-Why:  
Release this back into the pool until I have more time to look at it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=18293 
>Unformatted:
