[Gpm] patch for ALPS Glidepoint.

Bill Allombert Bill.Allombert@math.u-bordeaux.fr
Fri, 20 Oct 2000 21:09:55 +0200 (MET DST)


Hello, 

this is a patch for gpm 1.19.3. to handle ALPS GlidePoint in absolute
mode. It maps tap as left button and left button as middle
button. Drags finished because the finger is on the edge of the
touchpad are locked until the drag restart.

The patch for gpm.c allows the glidepoint to revert to absolute mode
automatically, for example after a suspend.

Best regards,

Bill Allombert.

allomber@math.u-bordaeux.fr

-------------

diff -u gpm-1.19.3.orig/gpm.c gpm-1.19.3/gpm.c
--- gpm-1.19.3.orig/gpm.c	Tue Jul 18 14:06:06 2000
+++ gpm-1.19.3/gpm.c	Thu Oct 19 22:36:31 2000
@@ -341,12 +341,24 @@
 
     if ((data[0]&(m_type->proto)[0]) != (m_type->proto)[1])
       {
-      if (m_type->getextra)
+      if (m_type->getextra==1)
 	{
 	data[1]=GPM_EXTRA_MAGIC_1; data[2]=GPM_EXTRA_MAGIC_2;
         gpm_debug_log(LOG_DEBUG,"Extra %02x",data[0]);
 	return data;
 	}
+      /* Bill Allombert Thu Oct 19 20:25:12 UTC 2000 */
+      /* allow touchpads to revert automatically to absolute mode */
+      	if (m_type->getextra==2 && (data[0]&0xc8)==0x08)
+        {
+	  /*TouchPad has returned to relative mode...*/
+  	  /*read the packet...*/
+	  read(fd,data,2);
+  	  /*revert to absolute mode*/
+	  m_type=(m_type->init)(fd, m_type->flags, m_type,-1,NULL);
+	  gpm_debug_log(LOG_DEBUG,"gpm: touchpad returned to absolute.\n");
+	  return NULL;
+	}/*end*/
       gpm_debug_log(LOG_DEBUG,"Error in protocol");
       return NULL;
       }
diff -u gpm-1.19.3.orig/mice.c gpm-1.19.3/mice.c
--- gpm-1.19.3.orig/mice.c	Tue Mar  7 15:10:00 2000
+++ gpm-1.19.3/mice.c	Thu Oct 19 22:46:43 2000
@@ -1280,6 +1280,65 @@
 	return 0;
 }
 
+/* ALPS touchpad, ps2 version: Bill Allombert Thu Oct 19 20:19:54 UTC 2000 */
+static int M_alps2(Gpm_Event *state,  unsigned char *data)
+{
+  /*driver for PS2 ALPS TouchPad in Advanced mode 
+    (i.e. absolute x/y/z)
+    bit    | 7 | 6 | 5 | 4 | 3 |   2    |   1    |    0    |
+    byte 0:| 1 | 1 | 1 | 1 | 1 |   1    |   1    |    1    |
+    byte 1:| 0 |               X 6..0                      |
+    byte 2:| 0 |    X 10..7    |   0    | Finger | Gesture |
+    byte 3:| 0 |   Y 9..7  | 1 |(Middle)| Right  | Left    |
+    byte 4:| 0 |                  Y 6..0                   |      
+    byte 5:| 0 |                  Z 6..0                   |
+  */
+  static int ox, oy, draglock=0, enter=0;
+  
+  long x = data[1] | ((data[2]&0x78)<<4);
+  long y = data[4] | ((data[3]&0x70)<<3);
+  long z = data[5];
+  long tap =  data[2]&1,finger=data[2]&2;
+
+  if (!finger)/*leave touchpad*/
+  {
+    state->dx =  state->dy = 0;
+    /* if we are in the edges*/
+    if (x<150  || y<150 || x>950 || y>700 )
+    {
+      if (tap && ox==x && oy==y) 
+        draglock=1;
+    }
+    else if (draglock)
+    {
+      draglock=0;
+    }
+    enter=0;
+  }
+  else if ( !enter )  /* enter touchpad */
+  {
+    state->dx =  state->dy = 0;
+    ox=x; oy=y;
+    enter=1;
+  }
+  else
+  {
+    /*resolution in 240 counts per inch*/
+    /*geometry is normaly 47x31 mm */
+    /*synaptic use roughly 6144 X counts ad reports 11%=676*/
+    /*there is 47/25.4*240=444 counts here*/
+    state->dx = (x-ox)/2;
+    state->dy = (y-oy)/2;
+    ox=x; oy=y;
+  }
+  if (draglock) tap=1;
+  state->buttons=
+    tap * GPM_B_LEFT +
+    ((data[3]&1)?GPM_B_MIDDLE:0) + 
+    ((data[3]&2)?GPM_B_RIGHT:0);
+  return 0;
+}
+
 /*========================================================================*/
 /* Then, mice should be initialized */
 
@@ -1913,6 +1972,26 @@
   return type;
 }
 
+/* ALPS touchpad, ps2 version: Bill Allombert Thu Oct 19 20:19:54 UTC 2000 */
+static Gpm_Type *I_alps2(int fd, unsigned short flags,
+		      struct Gpm_Type *type, int argc, char **argv)
+{
+  int i;
+  unsigned char c = 0;
+  unsigned char magic[] = {0xf5, 0xf5, 0xf5, 0xf5, 0xf4};
+  /* Switch to Advanced mode*/
+  for (i=0; i<sizeof(magic); i++) {
+    write( fd, magic+i, 1 );
+    read( fd, &c, 1 );
+    if (c != 0xfa) 
+    {
+      fprintf( stderr, "alps2: Error switching mode %d :<%x>\n",i,c);
+      return NULL;
+    }
+  }
+  return type;
+}
+
 /*========================================================================*/
 /* Finally, the table */
 #define STD_FLG (CREAD|CLOCAL|HUPCL)
@@ -2043,6 +2122,9 @@
            "wizardpad", M_wp, I_wp, STD_FLG,
                                 {0xFA, 0x42, 0x00, 0x00}, 10, 1, 0, 1, 0},
 
+  {"alps2", "ALPS PS2 GlidePoint",
+           "glidepoint_ps2", M_alps2, I_alps2, STD_FLG,
+                                {0xff, 0xff, 0x00, 0x00}, 6, 1, 2, 0, 0},
   {"",     "",
            "", NULL, NULL, 0,
                                 {0x00, 0x00, 0x00, 0x00}, 0, 0, 0, 0, 0}