diff --git a/man/synaptics.man b/man/synaptics.man index 8f7812c..5b98082 100644 --- a/man/synaptics.man +++ b/man/synaptics.man @@ -99,9 +99,7 @@ option is not needed with synaptics 1.0 or later. See section X coordinate for left edge. Property: "Synaptics Edges" .TP 7 .BI "Option \*qRightEdge\*q \*q" integer \*q -X coordinate for right edge. If this option is set, -.BI SpecialScrollAreaRight -is ignored. Property: "Synaptics Edges" +X coordinate for right edge. Property: "Synaptics Edges" .TP 7 .BI "Option \*qTopEdge\*q \*q" integer \*q Y coordinate for top edge. Property: "Synaptics Edges" @@ -109,10 +107,6 @@ Y coordinate for top edge. Property: "Synaptics Edges" .BI "Option \*qBottomEdge\*q \*q" integer \*q Y coordinate for bottom edge. Property: "Synaptics Edges" .TP 7 -.BI "Option \*qSpecialScrollAreaRight\*q \*q" boolean \*q -Some touchpads have a scroll region on the right edge. Disable this option if -you have one but don't want use it as scroll wheel region. -.TP 7 .BI "Option \*qFingerLow\*q \*q" integer \*q When finger pressure drops below this value, the driver counts it as a release. Property: "Synaptics Finger" @@ -842,6 +836,11 @@ Tapping is disabled by default for touchpads with one or more physical buttons. To enable it you need to map tap actions to buttons. See the "TapButton1", "TapButton2" and "TapButton3" options. .LP +Some devices report min/max values but provide values outside this range. +In this case, the driver auto-adjusts the edge values. Acceleration and +speed values are not affected. User-specified edges are not +auto-adjusted. +.LP Button mapping for physical buttons is handled in the server. If the device is switched to left-handed (an in-server mapping of physical buttons 1, 2, 3 to the logical buttons 3, 2, 1, respectively), both physical @@ -854,6 +853,10 @@ The following options are no longer part of the driver configuration: .BI "Option \*qRepeater\*q \*q" string \*q .TP .BI "Option \*qHistorySize\*q \*q" integer \*q +.TP 7 +.BI "Option \*qSpecialScrollAreaRight\*q \*q" boolean \*q +Some touchpads have a scroll region on the right edge. Disable this option if +you have one but don't want use it as scroll wheel region. .SH "AUTHORS" .LP diff --git a/src/properties.c b/src/properties.c index 70b59e0..4a2daf7 100644 --- a/src/properties.c +++ b/src/properties.c @@ -151,10 +151,10 @@ InitDeviceProperties(LocalDevicePtr local) } } - values[0] = para->left_edge; - values[1] = para->right_edge; - values[2] = para->top_edge; - values[3] = para->bottom_edge; + values[0] = para->edges[LEFT_EDGE]; + values[1] = para->edges[RIGHT_EDGE]; + values[2] = para->edges[TOP_EDGE]; + values[3] = para->edges[BOTTOM_EDGE]; prop_edges = InitAtom(local->dev, SYNAPTICS_PROP_EDGES, 32, 4, values); @@ -291,10 +291,10 @@ SetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop, if (edges[0] > edges[1] || edges[2] > edges[3]) return BadValue; - para->left_edge = edges[0]; - para->right_edge = edges[1]; - para->top_edge = edges[2]; - para->bottom_edge = edges[3]; + para->edges[LEFT_EDGE] = edges[0]; + para->edges[RIGHT_EDGE] = edges[1]; + para->edges[TOP_EDGE] = edges[2]; + para->edges[BOTTOM_EDGE] = edges[3]; } else if (property == prop_finger) { @@ -617,5 +617,22 @@ SetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop, return Success; } +void +SetEdgeProperty(LocalDevicePtr local) +{ + SynapticsPrivate *priv = (SynapticsPrivate*) (local->private); + SynapticsParameters *para = &priv->synpara; + uint32_t values[4]; + + values[0] = para->edges[LEFT_EDGE]; + values[1] = para->edges[RIGHT_EDGE]; + values[2] = para->edges[TOP_EDGE]; + values[3] = para->edges[BOTTOM_EDGE]; + + XIChangeDeviceProperty(local->dev, prop_edges, XA_INTEGER, 32, + PropModeReplace, 4, values, FALSE); +} + + #endif diff --git a/src/synaptics.c b/src/synaptics.c index e1e3646..10baf8b 100644 --- a/src/synaptics.c +++ b/src/synaptics.c @@ -82,17 +82,6 @@ #include #endif -typedef enum { - BOTTOM_EDGE = 1, - TOP_EDGE = 2, - LEFT_EDGE = 4, - RIGHT_EDGE = 8, - LEFT_BOTTOM_EDGE = BOTTOM_EDGE | LEFT_EDGE, - RIGHT_BOTTOM_EDGE = BOTTOM_EDGE | RIGHT_EDGE, - RIGHT_TOP_EDGE = TOP_EDGE | RIGHT_EDGE, - LEFT_TOP_EDGE = TOP_EDGE | LEFT_EDGE -} edge_type; - #define MAX(a, b) (((a)>(b))?(a):(b)) #define MIN(a, b) (((a)<(b))?(a):(b)) #define TIME_DIFF(a, b) ((int)((a)-(b))) @@ -107,6 +96,9 @@ typedef enum { #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ #endif +#define PROPERTY_TIMER_SET 0x1 +#define PROPERTY_NOTIFY_NEEDED 0x2 + #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 1 #define DBG(a,b) #endif @@ -134,6 +126,7 @@ static void ReadDevDimensions(LocalDevicePtr); void InitDeviceProperties(LocalDevicePtr local); int SetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop, BOOL checkonly); +int SetEdgeProperty(LocalDevicePtr local); #endif InputDriverRec SYNAPTICS = { @@ -293,6 +286,40 @@ free_param_data(SynapticsPrivate *priv) priv->synshm = NULL; } +static void +calculate_edge_widths(SynapticsPrivate *priv, int *l, int *r, int *t, int *b) +{ + int width, height; + int ewidth, eheight; /* edge width/height */ + + width = abs(priv->maxx - priv->minx); + height = abs(priv->maxy - priv->miny); + + if (priv->model == MODEL_SYNAPTICS) + { + ewidth = width * .07; + eheight = height * .07; + } else if (priv->model == MODEL_ALPS) + { + ewidth = width * .15; + eheight = height * .15; + } else if (priv->model == MODEL_APPLETOUCH) + { + ewidth = width * .085; + eheight = height * .085; + } else + { + ewidth = width * .04; + eheight = height * .054; + } + + *l = priv->minx + ewidth; + *r = priv->maxx - ewidth; + *t = priv->miny + eheight; + *b = priv->maxy - eheight; +} + + static void set_default_parameters(LocalDevicePtr local) { SynapticsPrivate *priv = local->private; /* read-only */ @@ -332,33 +359,12 @@ static void set_default_parameters(LocalDevicePtr local) if (priv->minx < priv->maxx && priv->miny < priv->maxy) { int width, height, diag; - int ewidth, eheight; /* edge width/height */ width = abs(priv->maxx - priv->minx); height = abs(priv->maxy - priv->miny); diag = sqrt(width * width + height * height); - if (priv->model == MODEL_SYNAPTICS) - { - ewidth = width * .07; - eheight = height * .07; - } else if (priv->model == MODEL_ALPS) - { - ewidth = width * .15; - eheight = height * .15; - } else if (priv->model == MODEL_APPLETOUCH) - { - ewidth = width * .085; - eheight = height * .085; - } else - { - ewidth = width * .04; - eheight = height * .054; - } - l = priv->minx + ewidth; - r = priv->maxx - ewidth; - t = priv->miny + eheight; - b = priv->maxy - eheight; + calculate_edge_widths(priv, &l, &r, &t, &b); /* Again, based on typical x/y range and defaults */ horizScrollDelta = diag * .020; @@ -437,10 +443,14 @@ static void set_default_parameters(LocalDevicePtr local) horizTwoFingerScroll = FALSE; /* set the parameters */ - pars->left_edge = xf86SetIntOption(opts, "LeftEdge", l); - pars->right_edge = xf86SetIntOption(opts, "RightEdge", r); - pars->top_edge = xf86SetIntOption(opts, "TopEdge", t); - pars->bottom_edge = xf86SetIntOption(opts, "BottomEdge", b); + pars->edges_forced[LEFT_EDGE] = xf86CheckIfOptionUsedByName(opts, "LeftEdge"); + pars->edges_forced[RIGHT_EDGE] = xf86CheckIfOptionUsedByName(opts, "RightEdge"); + pars->edges_forced[TOP_EDGE] = xf86CheckIfOptionUsedByName(opts, "TopEdge"); + pars->edges_forced[BOTTOM_EDGE] = xf86CheckIfOptionUsedByName(opts, "BottomEdge"); + pars->edges[LEFT_EDGE] = xf86SetIntOption(opts, "LeftEdge", l); + pars->edges[RIGHT_EDGE] = xf86SetIntOption(opts, "RightEdge", r); + pars->edges[TOP_EDGE] = xf86SetIntOption(opts, "TopEdge", t); + pars->edges[BOTTOM_EDGE] = xf86SetIntOption(opts, "BottomEdge", b); pars->finger_low = xf86SetIntOption(opts, "FingerLow", fingerLow); pars->finger_high = xf86SetIntOption(opts, "FingerHigh", fingerHigh); @@ -456,11 +466,6 @@ static void set_default_parameters(LocalDevicePtr local) pars->scroll_dist_vert = xf86SetIntOption(opts, "VertScrollDelta", horizScrollDelta); pars->scroll_dist_horiz = xf86SetIntOption(opts, "HorizScrollDelta", vertScrollDelta); pars->scroll_edge_vert = xf86SetBoolOption(opts, "VertEdgeScroll", vertEdgeScroll); - if (xf86CheckIfOptionUsedByName(opts, "RightEdge")) { - pars->special_scroll_area_right = FALSE; - } else { - pars->special_scroll_area_right = xf86SetBoolOption(opts, "SpecialScrollAreaRight", TRUE); - } pars->scroll_edge_horiz = xf86SetBoolOption(opts, "HorizEdgeScroll", horizEdgeScroll); pars->scroll_edge_corner = xf86SetBoolOption(opts, "CornerCoasting", FALSE); pars->scroll_twofinger_vert = xf86SetBoolOption(opts, "VertTwoFingerScroll", vertTwoFingerScroll); @@ -511,10 +516,10 @@ static void set_default_parameters(LocalDevicePtr local) pars->tap_and_drag_gesture = xf86SetBoolOption(opts, "TapAndDragGesture", TRUE); /* Warn about (and fix) incorrectly configured TopEdge/BottomEdge parameters */ - if (pars->top_edge > pars->bottom_edge) { - int tmp = pars->top_edge; - pars->top_edge = pars->bottom_edge; - pars->bottom_edge = tmp; + if (pars->edges[TOP_EDGE] > pars->edges[BOTTOM_EDGE]) { + int tmp = pars->edges[TOP_EDGE]; + pars->edges[TOP_EDGE]= pars->edges[BOTTOM_EDGE]; + pars->edges[BOTTOM_EDGE] = tmp; xf86Msg(X_WARNING, "%s: TopEdge is bigger than BottomEdge. Fixing.\n", local->name); } @@ -541,6 +546,12 @@ SynapticsPreInit(InputDriverPtr drv, IDevPtr dev, int flags) return NULL; } + priv->property_notify_timer = TimerSet(NULL, 0, 0, NULL, NULL); + if (!priv->property_notify_timer) { + xfree(priv); + return NULL; + } + /* Allocate a new InputInfoRec and add it to the head xf86InputDevs. */ local = xf86AllocateInput(drv, 0); if (!local) { @@ -605,8 +616,6 @@ SynapticsPreInit(InputDriverPtr drv, IDevPtr dev, int flags) set_default_parameters(local); - priv->largest_valid_x = MIN(priv->synpara.right_edge, XMAX_NOMINAL); - if (!alloc_param_data(local)) goto SetupProc_fail; @@ -767,7 +776,9 @@ DeviceOff(DeviceIntPtr dev) if (local->fd != -1) { TimerFree(priv->timer); + TimerFree(priv->property_notify_timer); priv->timer = NULL; + priv->property_notify_timer = NULL; xf86RemoveEnabledDevice(local); if (priv->proto_ops->DeviceOffHook) priv->proto_ops->DeviceOffHook(local); @@ -942,10 +953,10 @@ static void relative_coords(SynapticsPrivate *priv, int x, int y, double *relX, double *relY) { - int minX = priv->synpara.left_edge; - int maxX = priv->synpara.right_edge; - int minY = priv->synpara.top_edge; - int maxY = priv->synpara.bottom_edge; + int minX = priv->synpara.edges[LEFT_EDGE]; + int maxX = priv->synpara.edges[RIGHT_EDGE]; + int minY = priv->synpara.edges[TOP_EDGE]; + int maxY = priv->synpara.edges[BOTTOM_EDGE]; double xCenter = (minX + maxX) / 2.0; double yCenter = (minY + maxY) / 2.0; @@ -962,8 +973,8 @@ relative_coords(SynapticsPrivate *priv, int x, int y, static double angle(SynapticsPrivate *priv, int x, int y) { - double xCenter = (priv->synpara.left_edge + priv->synpara.right_edge) / 2.0; - double yCenter = (priv->synpara.top_edge + priv->synpara.bottom_edge) / 2.0; + double xCenter = (priv->synpara.edges[LEFT_EDGE] + priv->synpara.edges[RIGHT_EDGE]) / 2.0; + double yCenter = (priv->synpara.edges[TOP_EDGE] + priv->synpara.edges[BOTTOM_EDGE]) / 2.0; return atan2(-(y - yCenter), x - xCenter); } @@ -1013,19 +1024,40 @@ edge_detection(SynapticsPrivate *priv, int x, int y) if (priv->synpara.circular_pad) return circular_edge_detection(priv, x, y); - if (x > priv->synpara.right_edge) + if (x > priv->synpara.edges[RIGHT_EDGE]) edge |= RIGHT_EDGE; - else if (x < priv->synpara.left_edge) + else if (x < priv->synpara.edges[LEFT_EDGE]) edge |= LEFT_EDGE; - if (y < priv->synpara.top_edge) + if (y < priv->synpara.edges[TOP_EDGE]) edge |= TOP_EDGE; - else if (y > priv->synpara.bottom_edge) + else if (y > priv->synpara.edges[BOTTOM_EDGE]) edge |= BOTTOM_EDGE; return edge; } +#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3 +static CARD32 +propertyTimerFunc(OsTimerPtr timer, CARD32 now, pointer arg) +{ + LocalDevicePtr local = (LocalDevicePtr) (arg); + SynapticsPrivate *priv = (SynapticsPrivate *) (local->private); + int sigstate; + + if (!priv->had_edge_change) + return 0; + + sigstate = xf86BlockSIGIO(); + + SetEdgeProperty(local); + + priv->had_edge_change = 0; + xf86UnblockSIGIO(sigstate); + return 0; +} +#endif + static CARD32 timerFunc(OsTimerPtr timer, CARD32 now, pointer arg) { @@ -1098,6 +1130,14 @@ ReadInput(LocalDevicePtr local) if (newDelay) priv->timer = TimerSet(priv->timer, 0, delay, timerFunc, local); + +#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3 + if (!(priv->had_edge_change & PROPERTY_TIMER_SET)) { + priv->property_notify_timer = + TimerSet(priv->property_notify_timer, 0, 100, propertyTimerFunc, local); + priv->had_edge_change |= PROPERTY_TIMER_SET; + } +#endif } static int @@ -2106,22 +2146,48 @@ HandleState(LocalDevicePtr local, struct SynapticsHwState *hw) hw->multi[2] = hw->multi[3] = FALSE; } - /* - * Some touchpads have a scroll wheel region where a very large X - * coordinate is reported. In this case for eliminate discontinuity, - * we adjust X and simulate new zone which adjacent to right edge. - */ - if (hw->x <= XMAX_VALID) { - if (priv->largest_valid_x < hw->x) - priv->largest_valid_x = hw->x; - } else { - hw->x = priv->largest_valid_x + 1; - /* - * If user didn't set right_edge manualy, auto-adjust to bounds of - * hardware scroll area. - */ - if (para->special_scroll_area_right) - priv->synpara.right_edge = priv->largest_valid_x; + /* The kernel doesn't clip into min/max, so auto-adjust the edges if we + * go beyond min/max */ + if (hw->x > priv->maxx || hw->x < priv->minx || + hw->y > priv->maxy || hw->y < priv->miny) + { + int l, r, t, b; + Bool changed = FALSE; + + if (hw->x > priv->maxx && !para->edges_forced[RIGHT_EDGE]) + { + priv->maxx = hw->x; + changed = TRUE; + } else if (hw->x < priv->minx && !para->edges_forced[LEFT_EDGE]) + { + priv->minx = hw->x; + changed = TRUE; + } + + if (hw->y > priv->maxy && !para->edges_forced[BOTTOM_EDGE]) + { + priv->maxy = hw->y; + changed = TRUE; + } else if (hw->y < priv->miny && !para->edges_forced[TOP_EDGE]) + { + priv->miny = hw->y; + changed = TRUE; + } + + if (changed) + { + calculate_edge_widths(priv, &l, &r, &t, &b); + if (!para->edges_forced[LEFT_EDGE]) + para->edges[LEFT_EDGE] = l; + if (!para->edges_forced[RIGHT_EDGE]) + para->edges[RIGHT_EDGE] = r; + if (!para->edges_forced[TOP_EDGE]) + para->edges[TOP_EDGE] = t; + if (!para->edges_forced[BOTTOM_EDGE]) + para->edges[BOTTOM_EDGE] = b; + + priv->had_edge_change |= PROPERTY_NOTIFY_NEEDED; + } } edge = edge_detection(priv, hw->x, hw->y); diff --git a/src/synapticsstr.h b/src/synapticsstr.h index d2ff57c..9668736 100644 --- a/src/synapticsstr.h +++ b/src/synapticsstr.h @@ -86,10 +86,23 @@ enum TouchpadModel { MODEL_APPLETOUCH }; +typedef enum { + BOTTOM_EDGE = 1, + TOP_EDGE = 2, + LEFT_EDGE = 4, + RIGHT_EDGE = 8, + LEFT_BOTTOM_EDGE = BOTTOM_EDGE | LEFT_EDGE, + RIGHT_BOTTOM_EDGE = BOTTOM_EDGE | RIGHT_EDGE, + RIGHT_TOP_EDGE = TOP_EDGE | RIGHT_EDGE, + LEFT_TOP_EDGE = TOP_EDGE | LEFT_EDGE +} edge_type; + + typedef struct _SynapticsParameters { /* Parameter data */ - int left_edge, right_edge, top_edge, bottom_edge; /* edge coordinates absolute */ + int edges[RIGHT_EDGE]; /* edge coordinates absolute */ + Bool edges_forced[RIGHT_EDGE]; /* edges set manually? */ int finger_low, finger_high, finger_press; /* finger detection values in Z-values */ int tap_time; int tap_move; /* max. tapping time and movement in packets and coord. */ @@ -169,7 +182,6 @@ typedef struct _SynapticsPrivateRec SynapticsMoveHistRec move_hist[SYNAPTICS_MOVE_HISTORY]; /* movement history */ int hist_index; /* Last added entry in move_hist[] */ - int largest_valid_x; /* Largest valid X coordinate seen so far */ int scroll_y; /* last y-scroll position */ int scroll_x; /* last x-scroll position */ double scroll_a; /* last angle-scroll position */ @@ -219,6 +231,9 @@ typedef struct _SynapticsPrivateRec Bool has_pressure; /* device reports pressure */ enum TouchpadModel model; /* The detected model */ + + int had_edge_change; /* Non-zero if the edges have changed */ + OsTimerPtr property_notify_timer; /* For sending off property notify events */ } SynapticsPrivate; #endif /* _SYNAPTICSSTR_H_ */