Reducing clutter. Signed-off-by: Jason Gerecke <killert...@gmail.com> --- src/wcmCommon.c | 154 +++++++++++++++++++++++++-------------------------- src/wcmConfig.c | 2 +- src/wcmTouchFilter.c | 2 +- src/wcmXCommand.c | 10 ++-- src/xf86WacomDefs.h | 71 ++++++++++-------------- test/wacom-tests.c | 4 +- 6 files changed, 114 insertions(+), 129 deletions(-)
diff --git a/src/wcmCommon.c b/src/wcmCommon.c index eae1ad6..f9650f9 100644 --- a/src/wcmCommon.c +++ b/src/wcmCommon.c @@ -118,10 +118,10 @@ static void wcmSendButtons(InputInfoPtr pInfo, int buttons, if ((buttons & 1) == 0) buttons = 0; /* tip pressed? send all other button presses */ - else if ((buttons & 1) != (priv->oldButtons & 1)) - priv->oldButtons = 0; + else if ((buttons & 1) != (priv->oldState.buttons & 1)) + priv->oldState.buttons = 0; /* other button changed while tip is still down? release tip */ - else if ((buttons & 1) && (buttons != priv->oldButtons)) + else if ((buttons & 1) && (buttons != priv->oldState.buttons)) { buttons &= ~1; first_button = 0; @@ -131,7 +131,7 @@ static void wcmSendButtons(InputInfoPtr pInfo, int buttons, for (button = first_button; button < WCM_MAX_BUTTONS; button++) { mask = 1 << button; - if ((mask & priv->oldButtons) != (mask & buttons)) + if ((mask & priv->oldState.buttons) != (mask & buttons)) sendAButton(pInfo, button, (mask & buttons), first_val, num_vals, valuators); } @@ -362,9 +362,9 @@ static void sendWheelStripEvents(InputInfoPtr pInfo, const WacomDeviceState* ds, DBG(10, priv, "\n"); /* emulate events for left strip */ - delta = getScrollDelta(ds->stripx, priv->oldStripX, 0, AXIS_INVERT | AXIS_BITWISE); + delta = getScrollDelta(ds->stripx, priv->oldState.stripx, 0, AXIS_INVERT | AXIS_BITWISE); idx = getWheelButton(delta, STRIP_LEFT_UP, STRIP_LEFT_DN); - if (idx >= 0 && IsPad(priv) && priv->oldProximity == ds->proximity) + if (idx >= 0 && IsPad(priv) && priv->oldState.proximity == ds->proximity) { DBG(10, priv, "Left touch strip scroll delta = %d\n", delta); sendWheelStripEvent(priv->strip_keys[idx], ARRAY_SIZE(priv->strip_keys[idx]), @@ -372,9 +372,9 @@ static void sendWheelStripEvents(InputInfoPtr pInfo, const WacomDeviceState* ds, } /* emulate events for right strip */ - delta = getScrollDelta(ds->stripy, priv->oldStripY, 0, AXIS_INVERT | AXIS_BITWISE); + delta = getScrollDelta(ds->stripy, priv->oldState.stripy, 0, AXIS_INVERT | AXIS_BITWISE); idx = getWheelButton(delta, STRIP_RIGHT_UP, STRIP_RIGHT_DN); - if (idx >= 0 && IsPad(priv) && priv->oldProximity == ds->proximity) + if (idx >= 0 && IsPad(priv) && priv->oldState.proximity == ds->proximity) { DBG(10, priv, "Right touch strip scroll delta = %d\n", delta); sendWheelStripEvent(priv->strip_keys[idx], ARRAY_SIZE(priv->strip_keys[idx]), @@ -384,7 +384,7 @@ static void sendWheelStripEvents(InputInfoPtr pInfo, const WacomDeviceState* ds, /* emulate events for relative wheel */ delta = getScrollDelta(ds->relwheel, 0, 0, 0); idx = getWheelButton(delta, WHEEL_REL_UP, WHEEL_REL_DN); - if (idx >= 0 && (IsCursor(priv) || IsPad(priv)) && priv->oldProximity == ds->proximity) + if (idx >= 0 && (IsCursor(priv) || IsPad(priv)) && priv->oldState.proximity == ds->proximity) { DBG(10, priv, "Relative wheel scroll delta = %d\n", delta); sendWheelStripEvent(priv->wheel_keys[idx], ARRAY_SIZE(priv->wheel_keys[idx]), @@ -392,9 +392,9 @@ static void sendWheelStripEvents(InputInfoPtr pInfo, const WacomDeviceState* ds, } /* emulate events for left touch ring */ - delta = getScrollDelta(ds->abswheel, priv->oldWheel, MAX_PAD_RING, AXIS_INVERT); + delta = getScrollDelta(ds->abswheel, priv->oldState.abswheel, MAX_PAD_RING, AXIS_INVERT); idx = getWheelButton(delta, WHEEL_ABS_UP, WHEEL_ABS_DN); - if (idx >= 0 && IsPad(priv) && priv->oldProximity == ds->proximity) + if (idx >= 0 && IsPad(priv) && priv->oldState.proximity == ds->proximity) { DBG(10, priv, "Left touch wheel scroll delta = %d\n", delta); sendWheelStripEvent(priv->wheel_keys[idx], ARRAY_SIZE(priv->wheel_keys[idx]), @@ -402,9 +402,9 @@ static void sendWheelStripEvents(InputInfoPtr pInfo, const WacomDeviceState* ds, } /* emulate events for right touch ring */ - delta = getScrollDelta(ds->abswheel2, priv->oldWheel2, MAX_PAD_RING, AXIS_INVERT); + delta = getScrollDelta(ds->abswheel2, priv->oldState.abswheel2, MAX_PAD_RING, AXIS_INVERT); idx = getWheelButton(delta, WHEEL2_ABS_UP, WHEEL2_ABS_DN); - if (idx >= 0 && IsPad(priv) && priv->oldProximity == ds->proximity) + if (idx >= 0 && IsPad(priv) && priv->oldState.proximity == ds->proximity) { DBG(10, priv, "Right touch wheel scroll delta = %d\n", delta); sendWheelStripEvent(priv->wheel_keys[idx], ARRAY_SIZE(priv->wheel_keys[idx]), @@ -424,13 +424,13 @@ static void sendCommonEvents(InputInfoPtr pInfo, const WacomDeviceState* ds, int buttons = ds->buttons; /* send button events when state changed or first time in prox and button unpresses */ - if (priv->oldButtons != buttons || (!priv->oldProximity && !buttons)) + if (priv->oldState.buttons != buttons || (!priv->oldState.proximity && !buttons)) wcmSendButtons(pInfo,buttons, first_val, num_vals, valuators); /* emulate wheel/strip events when defined */ - if ( ds->relwheel || (ds->abswheel != priv->oldWheel) || (ds->abswheel2 != priv->oldWheel2) || - ( (ds->stripx - priv->oldStripX) && ds->stripx && priv->oldStripX) || - ((ds->stripy - priv->oldStripY) && ds->stripy && priv->oldStripY) ) + if ( ds->relwheel || (ds->abswheel != priv->oldState.abswheel) || (ds->abswheel2 != priv->oldState.abswheel2) || + ( (ds->stripx - priv->oldState.stripx) && ds->stripx && priv->oldState.stripx) || + ((ds->stripy - priv->oldState.stripy) && ds->stripy && priv->oldState.stripy) ) sendWheelStripEvents(pInfo, ds, first_val, num_vals, valuators); } @@ -489,18 +489,18 @@ static void wcmUpdateOldState(const InputInfoPtr pInfo, { const WacomDevicePtr priv = (WacomDevicePtr) pInfo->private; - priv->oldWheel = ds->abswheel; - priv->oldWheel2 = ds->abswheel2; - priv->oldButtons = ds->buttons; - priv->oldX = currentX; - priv->oldY = currentY; - priv->oldZ = ds->pressure; - priv->oldTiltX = ds->tiltx; - priv->oldTiltY = ds->tilty; - priv->oldStripX = ds->stripx; - priv->oldStripY = ds->stripy; - priv->oldRot = ds->rotation; - priv->oldThrottle = ds->throttle; + priv->oldState.abswheel = ds->abswheel; + priv->oldState.abswheel2 = ds->abswheel2; + priv->oldState.buttons = ds->buttons; + priv->oldState.x = currentX; + priv->oldState.y = currentY; + priv->oldState.pressure = ds->pressure; + priv->oldState.tiltx = ds->tilty; + priv->oldState.tilty = ds->tiltx; + priv->oldState.stripx = ds->stripx; + priv->oldState.stripy = ds->stripy; + priv->oldState.rotation = ds->rotation; + priv->oldState.throttle = ds->throttle; } static void @@ -510,14 +510,14 @@ wcmSendPadEvents(InputInfoPtr pInfo, const WacomDeviceState* ds, int i; WacomDevicePtr priv = (WacomDevicePtr) pInfo->private; - if (!priv->oldProximity && ds->proximity) + if (!priv->oldState.proximity && ds->proximity) xf86PostProximityEventP(pInfo->dev, 1, first_val, num_vals, VCOPY(valuators, num_vals)); for (i = 0; i < num_vals; i++) if (valuators[i]) break; if (i < num_vals || ds->buttons || ds->relwheel || - (ds->abswheel != priv->oldWheel) || (ds->abswheel2 != priv->oldWheel2)) + (ds->abswheel != priv->oldState.abswheel) || (ds->abswheel2 != priv->oldState.abswheel2)) { sendCommonEvents(pInfo, ds, first_val, num_vals, valuators); @@ -529,11 +529,11 @@ wcmSendPadEvents(InputInfoPtr pInfo, const WacomDeviceState* ds, } else { - if (priv->oldButtons) + if (priv->oldState.buttons) wcmSendButtons(pInfo, ds->buttons, first_val, num_vals, valuators); } - if (priv->oldProximity && !ds->proximity) + if (priv->oldState.proximity && !ds->proximity) xf86PostProximityEventP(pInfo->dev, 0, first_val, num_vals, VCOPY(valuators, num_vals)); } @@ -547,27 +547,27 @@ wcmSendNonPadEvents(InputInfoPtr pInfo, const WacomDeviceState *ds, if (!is_absolute(pInfo)) { - valuators[0] -= priv->oldX; - valuators[1] -= priv->oldY; - valuators[2] -= priv->oldZ; + valuators[0] -= priv->oldState.x; + valuators[1] -= priv->oldState.y; + valuators[2] -= priv->oldState.pressure; if (IsCursor(priv)) { - valuators[3] -= priv->oldRot; - valuators[4] -= priv->oldThrottle; + valuators[3] -= priv->oldState.rotation; + valuators[4] -= priv->oldState.throttle; } else { - valuators[3] -= priv->oldTiltX; - valuators[4] -= priv->oldTiltY; + valuators[3] -= priv->oldState.tiltx; + valuators[4] -= priv->oldState.tilty; } - valuators[5] -= priv->oldWheel; - valuators[6] -= priv->oldWheel2; + valuators[5] -= priv->oldState.abswheel; + valuators[6] -= priv->oldState.abswheel2; } /* coordinates are ready we can send events */ if (ds->proximity) { /* don't emit proximity events if device does not support proximity */ - if ((pInfo->dev->proximity && !priv->oldProximity)) + if ((pInfo->dev->proximity && !priv->oldState.proximity)) xf86PostProximityEventP(pInfo->dev, 1, first_val, num_vals, VCOPY(valuators, num_vals)); @@ -597,10 +597,10 @@ wcmSendNonPadEvents(InputInfoPtr pInfo, const WacomDeviceState *ds, /* reports button up when the device has been * down and becomes out of proximity */ - if (priv->oldButtons) + if (priv->oldState.buttons) wcmSendButtons(pInfo, buttons, first_val, num_vals, valuators); - if (priv->oldProximity) + if (priv->oldState.proximity) xf86PostProximityEventP(pInfo->dev, 0, first_val, num_vals, VCOPY(valuators, num_vals)); } /* not in proximity */ @@ -643,8 +643,8 @@ void wcmSendEvents(InputInfoPtr pInfo, const WacomDeviceState* ds) /* don't move the cursor when going out-prox */ if (!ds->proximity) { - x = priv->oldX; - y = priv->oldY; + x = priv->oldState.x; + y = priv->oldState.x; } /* use tx and ty to report stripx and stripy */ @@ -657,7 +657,7 @@ void wcmSendEvents(InputInfoPtr pInfo, const WacomDeviceState* ds) DBG(7, priv, "[%s] o_prox=%s x=%d y=%d z=%d " "b=%s b=%d tx=%d ty=%d wl=%d wl2=%d rot=%d th=%d\n", pInfo->type_name, - priv->oldProximity ? "true" : "false", + priv->oldState.proximity ? "true" : "false", x, y, z, is_button ? "true" : "false", ds->buttons, tx, ty, ds->abswheel, ds->abswheel2, ds->rotation, ds->throttle); @@ -695,10 +695,10 @@ void wcmSendEvents(InputInfoPtr pInfo, const WacomDeviceState* ds) is_button ? "true" : "false", ds->buttons); /* update the old records */ - if(!priv->oldProximity) + if(!priv->oldState.proximity) { wcmUpdateOldState(pInfo, ds, x, y); - priv->oldButtons = 0; + priv->oldState.buttons = 0; } valuators[0] = x; @@ -717,25 +717,25 @@ void wcmSendEvents(InputInfoPtr pInfo, const WacomDeviceState* ds) wcmSendNonPadEvents(pInfo, ds, 0, priv->naxes, valuators); } - priv->oldProximity = ds->proximity; + priv->oldState.proximity = ds->proximity; if (ds->proximity) wcmUpdateOldState(pInfo, ds, x, y); else { - priv->oldButtons = 0; - priv->oldWheel = MAX_PAD_RING + 1; - priv->oldWheel2 = MAX_PAD_RING + 1; - priv->oldX = 0; - priv->oldY = 0; - priv->oldZ = 0; - priv->oldTiltX = 0; - priv->oldTiltY = 0; - priv->oldStripX = 0; - priv->oldStripY = 0; - priv->oldRot = 0; - priv->oldThrottle = 0; - priv->old_serial = serial; - priv->old_device_id = id; + priv->oldState.buttons = 0; + priv->oldState.abswheel = MAX_PAD_RING + 1; + priv->oldState.abswheel2 = MAX_PAD_RING + 1; + priv->oldState.x = 0; + priv->oldState.y = 0; + priv->oldState.pressure = 0; + priv->oldState.tiltx = 0; + priv->oldState.tilty = 0; + priv->oldState.stripx = 0; + priv->oldState.stripy = 0; + priv->oldState.rotation = 0; + priv->oldState.throttle = 0; + priv->oldState.serial_num = serial; + priv->oldState.device_id = id; wcmUpdateSerial(pInfo, 0, 0); } } @@ -981,7 +981,7 @@ rebasePressure(const WacomDevicePtr priv, const WacomDeviceState *ds) int min_pressure; /* set the minimum pressure when in prox */ - if (!priv->oldProximity) + if (!priv->oldState.proximity) min_pressure = ds->pressure; else min_pressure = min(priv->minPressure, ds->pressure); @@ -1048,7 +1048,7 @@ setPressureButton(const WacomDevicePtr priv, int buttons, const int pressure) if (pressure < common->wcmThreshold) { buttons &= ~button; - if (priv->oldButtons & button) /* left click was on */ + if (priv->oldState.buttons & button) /* left click was on */ { /* don't set it off if it is within the tolerance and threshold is larger than the tolerance */ @@ -1081,7 +1081,7 @@ static void detectPressureIssue(WacomDevicePtr priv, WacomDeviceStatePtr ds) { /* pen is just going out of proximity */ - if (priv->oldProximity && !ds->proximity) { + if (priv->oldState.proximity && !ds->proximity) { int pressureThreshold = common->wcmMaxZ * LIMIT_LOW_PRESSURE / 100; /* check if minPressure has persisted all the time @@ -1095,7 +1095,7 @@ static void detectPressureIssue(WacomDevicePtr priv, "\tThis indicates a worn out pen, it is time to change your tool. Also see:\n" "\thttp://sourceforge.net/apps/mediawiki/linuxwacom/index.php?title=Pen_Wear.\n", priv->pInfo->name, priv->serial, priv->minPressure, LIMIT_LOW_PRESSURE, common->wcmMaxZ); - } else if (!priv->oldProximity) + } else if (!priv->oldState.proximity) priv->eventCnt = 0; priv->oldMinPressure = priv->minPressure; @@ -1171,7 +1171,7 @@ static void commonDispatchDevice(WacomCommonPtr common, unsigned int channel, * devices that provide both pen/puck and touch events * so system cursor won't jump between tools. */ - if (common->wcmTouchDevice->oldProximity) + if (common->wcmTouchDevice->oldState.proximity) { common->wcmGestureMode = 0; wcmSoftOutEvent(common->wcmTouchDevice->pInfo); @@ -1185,12 +1185,12 @@ static void commonDispatchDevice(WacomCommonPtr common, unsigned int channel, if ((IsPen(priv) || IsTouch(priv)) && common->wcmMaxZ) { - int prev_min_pressure = priv->oldProximity ? priv->minPressure : 0; + int prev_min_pressure = priv->oldState.proximity ? priv->minPressure : 0; detectPressureIssue(priv, common, &filtered); raw_pressure = filtered.pressure; - if (!priv->oldProximity) + if (!priv->oldState.proximity) priv->maxRawPressure = raw_pressure; priv->minPressure = rebasePressure(priv, &filtered); @@ -1255,8 +1255,8 @@ static void commonDispatchDevice(WacomCommonPtr common, unsigned int channel, /* To improve the accuracy of relative x/y, * don't send motion event when there is no movement. */ - double deltx = filtered.x - priv->oldX; - double delty = filtered.y - priv->oldY; + double deltx = filtered.x - priv->oldState.x; + double delty = filtered.y - priv->oldState.y; /* less than one device coordinate movement? */ if (abs(deltx)<1 && abs(delty)<1) @@ -1269,8 +1269,8 @@ static void commonDispatchDevice(WacomCommonPtr common, unsigned int channel, } /* send other events, such as button/wheel */ - filtered.x = priv->oldX; - filtered.y = priv->oldY; + filtered.x = priv->oldState.x; + filtered.y = priv->oldState.y; } } @@ -1299,7 +1299,7 @@ static void commonDispatchDevice(WacomCommonPtr common, unsigned int channel, common->wcmMaxCursorDist, ds->proximity); - if (priv->oldProximity) + if (priv->oldState.proximity) { if (abs(filtered.distance - common->wcmMaxCursorDist) > common->wcmCursorProxoutDist) diff --git a/src/wcmConfig.c b/src/wcmConfig.c index d5652e9..138a769 100644 --- a/src/wcmConfig.c +++ b/src/wcmConfig.c @@ -170,7 +170,7 @@ wcmSetType(InputInfoPtr pInfo, const char *type) goto invalid; /* Set the device id of the "last seen" device on this tool */ - priv->old_device_id = wcmGetPhyDeviceID(priv); + priv->oldState.device_id = wcmGetPhyDeviceID(priv); if (!priv->tool) return 0; diff --git a/src/wcmTouchFilter.c b/src/wcmTouchFilter.c index bfd19de..166d2a0 100644 --- a/src/wcmTouchFilter.c +++ b/src/wcmTouchFilter.c @@ -198,7 +198,7 @@ static void wcmSendButtonClick(WacomDevicePtr priv, int button, int state) /* We have changed the button state (from down to up) for the device * so we need to update the record */ if (button == 1) - priv->oldButtons = 0; + priv->oldState.buttons = 0; } /***************************************************************************** diff --git a/src/wcmXCommand.c b/src/wcmXCommand.c index 0ec8737..6bba996 100644 --- a/src/wcmXCommand.c +++ b/src/wcmXCommand.c @@ -242,8 +242,8 @@ void InitWcmDeviceProperties(InputInfoPtr pInfo) } values[0] = common->tablet_id; - values[1] = priv->old_serial; - values[2] = priv->old_device_id; + values[1] = priv->oldState.serial_num; + values[2] = priv->oldState.device_id; values[3] = priv->cur_serial; values[4] = priv->cur_device_id; prop_serials = InitWcmAtom(pInfo->dev, WACOM_PROP_SERIALIDS, XA_INTEGER, 32, 5, values); @@ -965,12 +965,12 @@ int wcmGetProperty (DeviceIntPtr dev, Atom property) uint32_t values[5]; values[0] = common->tablet_id; - values[1] = priv->old_serial; - values[2] = priv->old_device_id; + values[1] = priv->oldState.serial_num; + values[2] = priv->oldState.device_id; values[3] = priv->cur_serial; values[4] = priv->cur_device_id; - DBG(10, priv, "Update to serial: %d\n", priv->old_serial); + DBG(10, priv, "Update to serial: %d\n", priv->oldState.serial_num); return XIChangeDeviceProperty(dev, property, XA_INTEGER, 32, PropModeReplace, 5, diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h index f40f654..01ae655 100644 --- a/src/xf86WacomDefs.h +++ b/src/xf86WacomDefs.h @@ -206,6 +206,33 @@ struct _WacomModel #define STRIP_RIGHT_UP 2 #define STRIP_RIGHT_DN 3 +/****************************************************************************** + * WacomDeviceState + *****************************************************************************/ +struct _WacomDeviceState +{ + InputInfoPtr pInfo; + int device_id; /* tool id reported from the physical device */ + int device_type; + unsigned int serial_num; + int x; + int y; + int buttons; + int pressure; + int tiltx; + int tilty; + int stripx; + int stripy; + int rotation; + int abswheel; + int abswheel2; + int relwheel; + int distance; + int throttle; + int proximity; + int sample; /* wraps every 24 days */ +}; + struct _WacomDeviceRec { char *name; /* Do not move, same offset as common->device_path. Used by DBG macro */ @@ -250,22 +277,8 @@ struct _WacomDeviceRec WacomCommonPtr common; /* common info pointer */ /* state fields in device coordinates */ - int oldX; /* previous X position */ - int oldY; /* previous Y position */ - int oldZ; /* previous pressure */ - int oldTiltX; /* previous tilt in x direction */ - int oldTiltY; /* previous tilt in y direction */ - int oldWheel; /* previous wheel value */ - int oldWheel2; /* previous wheel2 value */ - int oldRot; /* previous rotation value */ - int oldStripX; /* previous left strip value */ - int oldStripY; /* previous right strip value */ - int oldThrottle; /* previous throttle value */ - int oldButtons; /* previous buttons state */ - int oldProximity; /* previous proximity */ + struct _WacomDeviceState oldState; /* previous state information */ int oldCursorHwProx; /* previous cursor hardware proximity */ - int old_device_id; /* last in prox device id */ - unsigned int old_serial;/* last in prox tool serial number */ /* JEJ - filters */ int pPressCurve[FILTER_PRESSURE_RES + 1]; /* pressure curve */ @@ -283,37 +296,9 @@ struct _WacomDeviceRec OsTimerPtr touch_timer; /* timer used for touch switch property update */ }; -/****************************************************************************** - * WacomDeviceState - *****************************************************************************/ - #define MAX_SAMPLES 20 #define DEFAULT_SAMPLES 4 -struct _WacomDeviceState -{ - InputInfoPtr pInfo; - int device_id; /* tool id reported from the physical device */ - int device_type; - unsigned int serial_num; - int x; - int y; - int buttons; - int pressure; - int tiltx; - int tilty; - int stripx; - int stripy; - int rotation; - int abswheel; - int abswheel2; - int relwheel; - int distance; - int throttle; - int proximity; - int sample; /* wraps every 24 days */ -}; - struct _WacomFilterState { int npoints; diff --git a/test/wacom-tests.c b/test/wacom-tests.c index 8c74a72..486454d 100644 --- a/test/wacom-tests.c +++ b/test/wacom-tests.c @@ -152,7 +152,7 @@ test_rebase_pressure(void) ds.pressure = 10; /* Pressure in out-of-proximity means get new preloaded pressure */ - priv.oldProximity = 0; + priv.oldState.proximity = 0; /* make sure we don't touch priv, not really needed, the compiler should * honor the consts but... */ @@ -164,7 +164,7 @@ test_rebase_pressure(void) assert(memcmp(&priv, &base, sizeof(priv)) == 0); /* Pressure in-proximity means rebase to new minimum */ - priv.oldProximity = 1; + priv.oldState.proximity = 1; base = priv; -- 1.9.2 ------------------------------------------------------------------------------ Is your legacy SCM system holding you back? Join Perforce May 7 to find out: • 3 signs your SCM is hindering your productivity • Requirements for releasing software faster • Expert tips and advice for migrating your SCM now http://p.sf.net/sfu/perforce _______________________________________________ Linuxwacom-devel mailing list Linuxwacom-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel