Did I included my patch (MIT licenced) ?

Mildred
-- 
Mildred Ki'Lya
╭───────── mildred593@online.fr ──────────
│ Jabber, GoogleTalk: <[EMAIL PROTECTED]>
│ Site: <http://ki.lya.online.fr>              GPG ID: 9A7D 2E2B
│ Fingerprint: 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 9A7D 2E2B
diff --git a/include/synaptics.h b/include/synaptics.h
index 7e55293..d10e0de 100644
--- a/include/synaptics.h
+++ b/include/synaptics.h
@@ -133,6 +133,7 @@ typedef struct _SynapticsSHM
     double press_motion_min_factor;	    /* factor applied on speed when finger pressure is at minimum */
     double press_motion_max_factor; 	    /* factor applied on speed when finger pressure is at minimum */
     Bool grab_event_device;		    /* grab event device for exclusive use? */
+    int orientation;			    /* orientation of the trackpad */
 } SynapticsSHM;
 
 /*
diff --git a/man/synaptics.man b/man/synaptics.man
index 79958e7..34733f2 100644
--- a/man/synaptics.man
+++ b/man/synaptics.man
@@ -384,6 +384,15 @@ reenabled.
 .
 This can be achieved by switching to a text console and then switching
 back to X.
+.TP
+.BI "Option \*qOrientation\*q \*q" integer \*q
+This option can be used to change the orientation of the trackpad and can
+takes values from 0 to 3. The default value 0 implies a normal orientation,
+other values can be used to have respectively an orientation set to the
+left, an inverted orientation, and an orientation set to the right.
+This may be useful in combinaison with the orientation option of the xrandr
+extension. You may notice that the values used are the same to the values
+used by xrandr.
 .
 .
 .LP
diff --git a/src/synaptics.c b/src/synaptics.c
index df29358..7fce724 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -475,6 +475,7 @@ static void set_default_parameters(LocalDevicePtr local)
     pars->single_tap_timeout = xf86SetIntOption(opts, "SingleTapTimeout", 180);
     pars->press_motion_min_z = xf86SetIntOption(opts, "PressureMotionMinZ", pressureMotionMinZ);
     pars->press_motion_max_z = xf86SetIntOption(opts, "PressureMotionMaxZ", pressureMotionMaxZ);
+    pars->orientation        = xf86SetIntOption(opts, "Orientation", 0);
 
     pars->min_speed = synSetFloatOption(opts, "MinSpeed", 0.4);
     pars->max_speed = synSetFloatOption(opts, "MaxSpeed", 0.7);
@@ -1397,6 +1398,54 @@ estimate_delta(double x0, double x1, double x2, double x3)
     return x0 * 0.3 + x1 * 0.1 - x2 * 0.1 - x3 * 0.3;
 }
 
+static void
+HandleOrientation_double(int orientation, double *dx, double *dy) {
+    double tmp;
+    switch(orientation) {
+	default:
+	case 0:
+	    break;
+	case 1: /* left */
+	    tmp =  *dx;
+	    *dx = -*dy;
+	    *dy =  tmp;
+	    break;
+	case 2: /* inverted */
+	    *dx = -*dx;
+	    *dy = -*dy;
+	    break;
+	case 3: /* right */
+	    tmp =  *dx;
+	    *dx =  *dy;
+	    *dy = -tmp;
+	    break;
+    }
+}
+
+static void
+HandleOrientation_int(int orientation, int *dx, int *dy) {
+    int tmp;
+    switch(orientation) {
+	default:
+	case 0:
+	    break;
+	case 1: /* left */
+	    tmp =  *dx;
+	    *dx = -*dy;
+	    *dy =  tmp;
+	    break;
+	case 2: /* inverted */
+	    *dx = -*dx;
+	    *dy = -*dy;
+	    break;
+	case 3: /* right */
+	    tmp =  *dx;
+	    *dx =  *dy;
+	    *dy = -tmp;
+	    break;
+    }
+}
+
 static int
 ComputeDeltas(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 	      edge_type edge, int *dxP, int *dyP)
@@ -1442,12 +1491,16 @@ ComputeDeltas(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 		dx = (hw->x - priv->trackstick_neutral_x);
 		dy = (hw->y - priv->trackstick_neutral_y);
 
+		HandleOrientation_double(para->orientation, &dx, &dy);
+
 		dx = dx * dtime * para->trackstick_speed;
 		dy = dy * dtime * para->trackstick_speed;
 	    } else if (moving_state == MS_TOUCHPAD_RELATIVE) {
 		dx = estimate_delta(hw->x, HIST(0).x, HIST(1).x, HIST(2).x);
 		dy = estimate_delta(hw->y, HIST(0).y, HIST(1).y, HIST(2).y);
 
+		HandleOrientation_double(para->orientation, &dx, &dy);
+
 		if ((priv->tap_state == TS_DRAG) || para->edge_motion_use_always) {
 		    int minZ = para->edge_motion_min_z;
 		    int maxZ = para->edge_motion_max_z;
@@ -1462,7 +1515,7 @@ ComputeDeltas(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 		    } else {
 			edge_speed = minSpd + (hw->z - minZ) * (maxSpd - minSpd) / (maxZ - minZ);
 		    }
-		    if (!priv->synpara->circular_pad) {
+		    if (!para->circular_pad) {
 			/* on rectangular pad */
 			if (edge & RIGHT_EDGE) {
 			    x_edge_speed = edge_speed;
@@ -1481,6 +1534,9 @@ ComputeDeltas(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 			relative_coords(priv, hw->x, hw->y, &relX, &relY);
 			x_edge_speed = (int)(edge_speed * relX);
 			y_edge_speed = (int)(edge_speed * relY);
+
+			HandleOrientation_int(para->orientation,
+			    &x_edge_speed, &y_edge_speed);
 		    }
 		}
 	    }
@@ -1544,7 +1600,7 @@ struct ScrollData {
 };
 
 static void
-start_coasting(SynapticsPrivate *priv, struct SynapticsHwState *hw, edge_type edge,
+start_coasting(SynapticsPrivate *priv, int x, int y, edge_type edge,
 	       Bool vertical)
 {
     SynapticsSHM *para = priv->synpara;
@@ -1561,7 +1617,7 @@ start_coasting(SynapticsPrivate *priv, struct SynapticsHwState *hw, edge_type ed
 		double scrolls_per_sec = dy / pkt_time / sdelta;
 		if (fabs(scrolls_per_sec) >= para->coasting_speed) {
 		    priv->autoscroll_yspd = scrolls_per_sec;
-		    priv->autoscroll_y = (hw->y - priv->scroll_y) / (double)sdelta;
+		    priv->autoscroll_y = (y - priv->scroll_y) / (double)sdelta;
 		}
 	    }
 	} else {
@@ -1571,7 +1627,7 @@ start_coasting(SynapticsPrivate *priv, struct SynapticsHwState *hw, edge_type ed
 		double scrolls_per_sec = dx / pkt_time / sdelta;
 		if (fabs(scrolls_per_sec) >= para->coasting_speed) {
 		    priv->autoscroll_xspd = scrolls_per_sec;
-		    priv->autoscroll_x = (hw->x - priv->scroll_x) / (double)sdelta;
+		    priv->autoscroll_x = (x - priv->scroll_x) / (double)sdelta;
 		}
 	    }
 	}
@@ -1593,6 +1649,9 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 {
     SynapticsSHM *para = priv->synpara;
     int delay = 1000000000;
+    int oriented_x = hw->x, oriented_y = hw->y;
+
+    HandleOrientation_int(priv->synpara->orientation, &oriented_x, &oriented_y);
 
     sd->left = sd->right = sd->up = sd->down = 0;
 
@@ -1633,14 +1692,14 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 		    (para->scroll_twofinger_vert) && (para->scroll_dist_vert != 0)) {
 		    priv->vert_scroll_twofinger_on = TRUE;
 		    priv->vert_scroll_edge_on = FALSE;
-		    priv->scroll_y = hw->y;
+		    priv->scroll_y = oriented_y;
 		    DBG(7, ErrorF("vert two-finger scroll detected\n"));
 		}
 		if (!priv->horiz_scroll_twofinger_on &&
 		    (para->scroll_twofinger_horiz) && (para->scroll_dist_horiz != 0)) {
 		    priv->horiz_scroll_twofinger_on = TRUE;
 		    priv->horiz_scroll_edge_on = FALSE;
-		    priv->scroll_x = hw->x;
+		    priv->scroll_x = oriented_x;
 		    DBG(7, ErrorF("horiz two-finger scroll detected\n"));
 		}
 	    }
@@ -1650,13 +1709,13 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 		if ((para->scroll_edge_vert) && (para->scroll_dist_vert != 0) &&
 		    (edge & RIGHT_EDGE)) {
 		    priv->vert_scroll_edge_on = TRUE;
-		    priv->scroll_y = hw->y;
+		    priv->scroll_y = oriented_y;
 		    DBG(7, ErrorF("vert edge scroll detected on right edge\n"));
 		}
 		if ((para->scroll_edge_horiz) && (para->scroll_dist_horiz != 0) &&
 		    (edge & BOTTOM_EDGE)) {
 		    priv->horiz_scroll_edge_on = TRUE;
-		    priv->scroll_x = hw->x;
+		    priv->scroll_x = oriented_x;
 		    DBG(7, ErrorF("horiz edge scroll detected on bottom edge\n"));
 		}
 	    }
@@ -1706,7 +1765,7 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 	if ((oldv || oldh) && !para->scroll_edge_corner &&
 	    !(priv->circ_scroll_on || priv->vert_scroll_edge_on ||
 	      priv->horiz_scroll_edge_on)) {
-	    start_coasting(priv, hw, edge, oldv);
+	    start_coasting(priv, oriented_x, oriented_y, edge, oldv);
 	}
     }
 
@@ -1721,7 +1780,7 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 		 * we're in the corner, but we were moving so slowly when we
 		 * got here that we didn't actually start coasting. */
 		DBG(7, ErrorF("corner edge scroll on\n"));
-		start_coasting(priv, hw, edge, TRUE);
+		start_coasting(priv, oriented_x, oriented_y, edge, TRUE);
 	    }
 	} else if (para->circular_scrolling) {
 	    priv->vert_scroll_edge_on = FALSE;
@@ -1740,7 +1799,7 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 		 * we're in the corner, but we were moving so slowly when we
 		 * got here that we didn't actually start coasting. */
 		DBG(7, ErrorF("corner edge scroll on\n"));
-		start_coasting(priv, hw, edge, FALSE);
+		start_coasting(priv, oriented_x, oriented_y, edge, FALSE);
 	    }
 	} else if (para->circular_scrolling) {
 	    priv->horiz_scroll_edge_on = FALSE;
@@ -1870,6 +1929,46 @@ HandleClickWithFingers(SynapticsSHM *para, struct SynapticsHwState *hw)
     }
 }
 
+static edge_type
+HandleEdgeOrientation(int orientation, edge_type edge) {
+    int new_edge = 0;
+    if(edge & BOTTOM_EDGE) {
+      switch(orientation) {
+	  default:
+	  case 0:  new_edge |= BOTTOM_EDGE;	break;
+	  case 1:  new_edge |= LEFT_EDGE;	break;
+	  case 2:  new_edge |= TOP_EDGE;	break;
+	  case 3:  new_edge |= RIGHT_EDGE;	break;
+      }
+    } else if(edge & TOP_EDGE) {
+      switch(orientation) {
+	  default:
+	  case 0:  new_edge |= TOP_EDGE;	break;
+	  case 1:  new_edge |= RIGHT_EDGE;	break;
+	  case 2:  new_edge |= BOTTOM_EDGE;	break;
+	  case 3:  new_edge |= LEFT_EDGE;	break;
+      }
+    }
+    if(edge & LEFT_EDGE) {
+      switch(orientation) {
+	  default:
+	  case 0:  new_edge |= LEFT_EDGE;	break;
+	  case 1:  new_edge |= TOP_EDGE;	break;
+	  case 2:  new_edge |= RIGHT_EDGE;	break;
+	  case 3:  new_edge |= BOTTOM_EDGE;	break;
+      }
+    } else if(edge & RIGHT_EDGE) {
+      switch(orientation) {
+	  default:
+	  case 0:  new_edge |= RIGHT_EDGE;	break;
+	  case 1:  new_edge |= BOTTOM_EDGE;	break;
+	  case 2:  new_edge |= LEFT_EDGE;	break;
+	  case 3:  new_edge |= TOP_EDGE;	break;
+      }
+    }
+    return new_edge;
+}
+
 
 /*
  * React on changes in the hardware state. This function is called every time
@@ -1928,16 +2027,16 @@ HandleState(LocalDevicePtr local, struct SynapticsHwState *hw)
     /* 3rd button emulation */
     hw->middle |= HandleMidButtonEmulation(priv, hw, &delay);
 
-    /* Fingers emulate other buttons */
-    if(hw->left && hw->numFingers >= 1){
-        HandleClickWithFingers(para, hw);
-    }
-
     /* Two finger emulation */
     if (hw->z >= para->emulate_twofinger_z && hw->numFingers == 1) {
 	hw->numFingers = 2;
     }
 
+    /* Fingers emulate other buttons */
+    if(hw->left && hw->numFingers >= 1){
+        HandleClickWithFingers(para, hw);
+    }
+
     /* Up/Down button scrolling or middle/double click */
     double_click = FALSE;
     if (!para->updown_button_scrolling) {
@@ -1995,6 +2094,7 @@ HandleState(LocalDevicePtr local, struct SynapticsHwState *hw)
     }
 
     edge = edge_detection(priv, hw->x, hw->y);
+    edge = HandleEdgeOrientation(para->orientation, edge);
 
     finger = SynapticsDetectFinger(priv, hw);
 
@@ -2035,8 +2135,10 @@ HandleState(LocalDevicePtr local, struct SynapticsHwState *hw)
     }
 
     /* Post events */
-    if (dx || dy)
+    if (dx || dy) {
+	ErrorF("DBG: Orientation=%d dx=%d dy=%d\n", para->orientation, dx, dy);
 	xf86PostMotionEvent(local->dev, 0, 0, 2, dx, dy);
+    }
 
     if (priv->mid_emu_state == MBE_LEFT_CLICK)
     {
diff --git a/tools/synclient.c b/tools/synclient.c
index 2677d63..0d03fe8 100644
--- a/tools/synclient.c
+++ b/tools/synclient.c
@@ -123,6 +123,7 @@ static struct Parameter params[] = {
     DEFINE_PAR("PressureMotionMinFactor", press_motion_min_factor, PT_DOUBLE, 0, 10.0),
     DEFINE_PAR("PressureMotionMaxFactor", press_motion_max_factor, PT_DOUBLE, 0, 10.0),
     DEFINE_PAR("GrabEventDevice",      grab_event_device,       PT_BOOL,   0, 1),
+    DEFINE_PAR("Orientation",          orientation,             PT_INT,   0, 3),
     { NULL, 0, 0, 0, 0 }
 };
 
_______________________________________________
xorg mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/xorg

Reply via email to