On Wed, Apr 14, 2010 at 09:45:48PM -0700, Ping Cheng wrote: > From: Ping Cheng <[email protected]> > Date: Wed, 14 Apr 2010 21:38:28 -0700 > Subject: [PATCH] Normalize pressure sensitivity > > Instead of reporting the raw pressure, the normalized pressure from > 0 to FILTER_PRESSURE_RES (which is 2048) is reported. This is mainly > to deal with the case where heavily used stylus may have a "pre-loaded" > initial pressure. This patch checks the in-prox pressure and subtract > it from the raw pressure to prevent a potential left-click before the > pen touches the tablet. > > Left click threshold and pressure curve are updated accordingly. > > Signed-off-by: Ping Cheng <[email protected]> > --- > src/wcmCommon.c | 69 +++++++++++++++++++++++++++++++++----------------- > src/wcmXCommand.c | 2 +- > src/xf86Wacom.c | 4 +- > src/xf86WacomDefs.h | 1 + > tools/xsetwacom.c | 4 +- > 5 files changed, 51 insertions(+), 29 deletions(-) > > diff --git a/src/wcmCommon.c b/src/wcmCommon.c > index f5a91d4..778d08a 100644 > --- a/src/wcmCommon.c > +++ b/src/wcmCommon.c > @@ -26,6 +26,10 @@ > #include <xkbsrv.h> > #include <xf86_OSproc.h> > > +/* Tested result for setting the pressure threshold to a reasonable value */ > +#define THRESHOLD_TOLERANCE (FILTER_PRESSURE_RES / 125) > +#define DEFAULT_THRESHOLD (FILTER_PRESSURE_RES / 75) > + > > /***************************************************************************** > * Static functions > > ****************************************************************************/ > @@ -1445,18 +1449,45 @@ static void commonDispatchDevice(WacomCommonPtr > common, unsigned int channel, > > if (IsStylus(priv) || IsEraser(priv)) > { > - /* set button1 (left click) on/off */ > - if (filtered.pressure >= common->wcmThreshold) > - filtered.buttons |= button; > + /* Instead of reporting the raw pressure, we normalize > + * the pressure from 0 to FILTER_PRESSURE_RES. This is > + * mainly to deal with the case where heavily used > + * stylus may have a "pre-loaded" initial pressure. To > + * do so, we keep the in-prox pressure and subtract it > + * from the raw pressure to prevent a potential > + * left-click before the pen touches the tablet. > + */ > + double tmpP; > + > + /* set the minimum pressure when in prox */ > + if (!priv->oldProximity) > + priv->minPressure = filtered.pressure; > else > + priv->minPressure = min(priv->minPressure, > filtered.pressure); > + > + /* normalize pressure to FILTER_PRESSURE_RES */ > + tmpP = (filtered.pressure - priv->minPressure) > + * FILTER_PRESSURE_RES; > + tmpP /= (common->wcmMaxZ - priv->minPressure); > + filtered.pressure = (int)tmpP; > + > + /* set button1 (left click) on/off */ > + if (filtered.pressure < common->wcmThreshold) > { > - /* threshold tolerance */ > - int tol = common->wcmMaxZ / 250; > - if (strstr(common->wcmModel->name, "Intuos4")) > - tol = common->wcmMaxZ / 125; > - if (filtered.pressure < common->wcmThreshold - > tol) > - filtered.buttons &= ~button; > + filtered.buttons &= ~button; > + if (priv->oldButtons & button) /* left click > was on */ > + { > + /* don't set it off if it is within the > tolerance > + and threshold is larger than the > tolerance */ > + if ((common->wcmThreshold > > THRESHOLD_TOLERANCE) && > + (filtered.pressure > > common->wcmThreshold - > + THRESHOLD_TOLERANCE)) > + filtered.buttons |= button; > + } > } > + else > + filtered.buttons |= button; > + > /* transform pressure */ > transPressureCurve(priv,&filtered); > } > @@ -1601,10 +1632,8 @@ int wcmInitTablet(LocalDevicePtr local, const char* > id, float version) > if (common->wcmThreshold <= 0) > { > /* Threshold for counting pressure as a button */ > - if (strstr(common->wcmModel->name, "Intuos4")) > - common->wcmThreshold = common->wcmMaxZ * 3 / 25; > - else > - common->wcmThreshold = common->wcmMaxZ * 3 / 50; > + common->wcmThreshold = DEFAULT_THRESHOLD; > + > xf86Msg(X_PROBED, "%s: using pressure threshold of %d for > button 1\n", > local->name, common->wcmThreshold); > } > @@ -1645,21 +1674,13 @@ static void transPressureCurve(WacomDevicePtr pDev, > WacomDeviceStatePtr pState) > { > if (pDev->pPressCurve) > { > - int p = pState->pressure; > + /* clip the pressure */ > + int p = max(0, pState->pressure); > > - /* clip */ > - p = (p < 0) ? 0 : (p > pDev->common->wcmMaxZ) ? > - pDev->common->wcmMaxZ : p; > - > - /* rescale pressure to FILTER_PRESSURE_RES */ > - p = (p * FILTER_PRESSURE_RES) / pDev->common->wcmMaxZ; > + p = min(FILTER_PRESSURE_RES, p); > > /* apply pressure curve function */ > p = pDev->pPressCurve[p]; > - > - /* scale back to wcmMaxZ */ > - pState->pressure = (p * pDev->common->wcmMaxZ) / > - FILTER_PRESSURE_RES; > } > } > > diff --git a/src/wcmXCommand.c b/src/wcmXCommand.c > index c8e4f5f..40207a3 100644 > --- a/src/wcmXCommand.c > +++ b/src/wcmXCommand.c > @@ -636,7 +636,7 @@ int wcmSetProperty(DeviceIntPtr dev, Atom property, > XIPropertyValuePtr prop, > > value = *(CARD32*)prop->data; > > - if ((value < 1) || (value > common->wcmMaxZ)) > + if ((value < 1) || (value > FILTER_PRESSURE_RES)) > return BadValue; > > if (!checkonly) > diff --git a/src/xf86Wacom.c b/src/xf86Wacom.c > index efca491..3f951df 100644 > --- a/src/xf86Wacom.c > +++ b/src/xf86Wacom.c > @@ -767,12 +767,12 @@ static int wcmRegisterX11Devices (LocalDevicePtr local) > /* Rotation rotates the Max X and Y */ > wcmRotateTablet(local, common->wcmRotate); > > - /* pressure */ > + /* pressure normalized to FILTER_PRESSURE_RES */ > InitValuatorAxisStruct(local->dev, 2, > #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7 > XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE), > #endif > - 0, common->wcmMaxZ, 1, 1, 1); > + 0, FILTER_PRESSURE_RES, 1, 1, 1); > > if (IsCursor(priv)) > { > diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h > index 2f9e827..da5e2cf 100644 > --- a/src/xf86WacomDefs.h > +++ b/src/xf86WacomDefs.h > @@ -242,6 +242,7 @@ struct _WacomDeviceRec > /* JEJ - filters */ > int* pPressCurve; /* pressure curve */ > int nPressCtrl[4]; /* control points for curve */ > + int minPressure; /* the minimum pressure a pen may hold */ > > WacomToolPtr tool; /* The common tool-structure for this device > */ > WacomToolAreaPtr toolarea; /* The area defined for this device */ > diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c > index 03a820a..59602b4 100644 > --- a/tools/xsetwacom.c > +++ b/tools/xsetwacom.c > @@ -495,8 +495,8 @@ static param_t parameters[] = > }, > { > .name = "ClickForce", > - .desc = "Sets tip/eraser pressure threshold = > ClickForce*MaxZ/100 " > - "(default is 6)", > + .desc = "Sets tip/eraser pressure threshold " > + "(default is 409)", > .prop_name = WACOM_PROP_PRESSURE_THRESHOLD, > .prop_format = 32, > .prop_offset = 0, > -- > 1.6.6.1
merged, thanks. Cheers, Peter ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Linuxwacom-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel
