diff -ur xf86-input-synaptics-1.9.1/include/synaptics-properties.h xf86-input-synaptics-1.9.1_new/include/synaptics-properties.h --- xf86-input-synaptics-1.9.1/include/synaptics-properties.h +++ xf86-input-synaptics-1.9.1_new/include/synaptics-properties.h @@ -158,4 +158,13 @@ /* 32 Bit Integer, 2 values, horizontal hysteresis, vertical hysteresis */ #define SYNAPTICS_PROP_NOISE_CANCELLATION "Synaptics Noise Cancellation" +/* 8 bit (BOOL, read-only), has_led */ +#define SYNAPTICS_PROP_LED "Synaptics LED" + +/* 8 bit (BOOL), led_status (on/off) */ +#define SYNAPTICS_PROP_LED_STATUS "Synaptics LED Status" + +/* 8 bit (BOOL), double-tap action on LED corner (on/off) */ +#define SYNAPTICS_PROP_LED_DOUBLE_TAP "Synaptics LED Dobule Tap" + #endif /* _SYNAPTICS_PROPERTIES_H_ */ diff -ur xf86-input-synaptics-1.9.1/man/synaptics.man xf86-input-synaptics-1.9.1_new/man/synaptics.man --- xf86-input-synaptics-1.9.1/man/synaptics.man +++ xf86-input-synaptics-1.9.1_new/man/synaptics.man @@ -573,6 +573,19 @@ A "touch" event happens when the Z value goes above FingerHigh, and an "untouch" event happens when the Z value goes below FingerLow. . +.TP +.BI "Option \*qLEDDoubleTap\*q \*q" boolean \*q +. +Enables/disables the touchpad-control by double-tapping on the top-left +corner LED. +. +Some devices have an LED on the top-left corner to indicate the +touchpad state. User can double-tap on the LED to toggle the touchpad +state. This option controls whether this action is enabled or not. +The double-tap size is same as specified in MaxDoubleTapTime. +The default value is ON. +Property: "Synaptics LED Double Tap" +. .LP The MaxDoubleTapTime parameter has the same function as the MaxTapTime parameter, but for the second, third, etc tap in a tap sequence. @@ -918,6 +931,19 @@ .BI "Synaptics Pad Resolution" 32 bit unsigned, 2 values (read-only), vertical, horizontal in units/millimeter. +.TP 7 +.BI "Synaptics LED" +8 bit (BOOL, read-only), indicating whether the device has an embedded +LED support or not. + +.TP 7 +.BI "Synaptics LED Status" +8 bit (BOOL), the light status of the embedded LED. + +.TP 7 +.BI "Synaptics LED Double Tap" +8 bit (BOOL), enable/disable the double-tap on LED. + .SH "NOTES" Configuration through .I InputClass diff -ur xf86-input-synaptics-1.9.1/src/eventcomm.c xf86-input-synaptics-1.9.1_new/src/eventcomm.c --- xf86-input-synaptics-1.9.1/src/eventcomm.c +++ xf86-input-synaptics-1.9.1_new/src/eventcomm.c @@ -70,6 +70,10 @@ #define ABS_MT_MAX ABS_MT_TOOL_Y #define ABS_MT_CNT (ABS_MT_MAX - ABS_MT_MIN + 1) +/* file created by synaptics-led + by this file we control LED on touchpad */ +#define SYNAPTICS_LED_SYS_FILE "/sys/class/leds/psmouse::synaptics/brightness" + /** * Protocol-specific data. */ @@ -375,8 +379,12 @@ int vendor, product; struct model_lookup_t *model_lookup; + xf86IDrvMsg(NULL, X_INFO, + "led_debug: try detect: vendor and product\n"); vendor = libevdev_get_id_vendor(evdev); product = libevdev_get_id_product(evdev); + xf86IDrvMsg(NULL, X_INFO, + "led_debug: try detect: vendor and product - OK\n"); for (model_lookup = model_lookup_table; model_lookup->vendor; model_lookup++) { @@ -427,6 +435,47 @@ #endif return 0; +} + +static void +event_query_led(InputInfoPtr pInfo) +{ + SynapticsPrivate *priv = (SynapticsPrivate *)pInfo->private; + + xf86IDrvMsg(pInfo, X_INFO, + "led_debug: checking for access to %s\n", + SYNAPTICS_LED_SYS_FILE); + + priv->synpara.has_led = !access(SYNAPTICS_LED_SYS_FILE, W_OK); + if (priv->synpara.has_led) + xf86IDrvMsg(pInfo, X_INFO, "led_debug: access ok\n"); + else xf86IDrvMsg(pInfo, X_INFO, "led_debug: no access\n"); + +} + +static void EventUpdateLED(InputInfoPtr pInfo) +{ + SynapticsPrivate *priv = (SynapticsPrivate *)pInfo->private; + + if (priv->synpara.has_led) { + char *val = priv->synpara.led_status ? "255" : "0"; + xf86IDrvMsg(pInfo, X_INFO, + "led_debug: try to open SYNAPTICS_LED_SYS_FILE\n"); + int fd = open(SYNAPTICS_LED_SYS_FILE, O_WRONLY); + int err; + + if (fd < 0) return; + + xf86IDrvMsg(pInfo, X_INFO, + "led_debug: file opened, try to write to it for update status\n"); + err = write(fd, val, strlen(val)); + close(fd); + + if (err < 0) xf86IDrvMsg(pInfo, X_WARNING, + "led_debug: can't write LED value %s\n", val); + xf86IDrvMsg(pInfo, X_INFO, + "led_debug: write successful, LED status updated\n"); + } } /* Query device for axis ranges */ @@ -980,6 +1029,19 @@ event_query_model(proto_data->evdev, &priv->model, &priv->id_vendor, &priv->id_product); + int rc; + struct libevdev *evdev_fd; + + event_query_led(pInfo); + + rc = libevdev_new_from_fd(pInfo->fd, &evdev_fd); + if (rc >= 0) + { + event_query_model(evdev_fd, &priv->model, + &priv->id_vendor, &priv->id_product); + libevdev_free(evdev_fd); + } + xf86IDrvMsg(pInfo, X_PROBED, "Vendor %#hx Product %#hx\n", priv->id_vendor, priv->id_product); } @@ -1080,5 +1142,6 @@ EventQueryHardware, EventReadHwState, EventAutoDevProbe, - EventReadDevDimensions + EventReadDevDimensions, + EventUpdateLED }; diff -ur xf86-input-synaptics-1.9.1/src/properties.c xf86-input-synaptics-1.9.1_new/src/properties.c --- xf86-input-synaptics-1.9.1/src/properties.c +++ xf86-input-synaptics-1.9.1_new/src/properties.c @@ -95,6 +95,9 @@ Atom prop_noise_cancellation = 0; Atom prop_product_id = 0; Atom prop_device_node = 0; +Atom prop_led = 0; +Atom prop_led_status = 0; +Atom prop_led_double_tap = 0; static Atom InitTypedAtom(DeviceIntPtr dev, char *name, Atom type, int format, int nvalues, @@ -381,6 +384,12 @@ prop_noise_cancellation = InitAtom(pInfo->dev, SYNAPTICS_PROP_NOISE_CANCELLATION, 32, 2, values); + xf86IDrvMsg(pInfo, X_INFO, "led_debug: init device properties\n"); + prop_led = InitAtom(pInfo->dev, SYNAPTICS_PROP_LED, 8, 1, ¶->has_led); + prop_led_status = InitAtom(pInfo->dev, SYNAPTICS_PROP_LED_STATUS, 8, 1, ¶->led_status); + + prop_led_double_tap = InitAtom(pInfo->dev, SYNAPTICS_PROP_LED_DOUBLE_TAP, 8, 1, ¶->led_double_tap); + xf86IDrvMsg(pInfo, X_INFO, "led_debug: init device properties - OK\n"); /* only init product_id property if we actually know them */ if (priv->id_vendor || priv->id_product) { @@ -815,6 +824,26 @@ para->hyst_x = hyst[0]; para->hyst_y = hyst[1]; } + else if (property == prop_led_status) { + if (prop->size != 1 || prop->format != 8 || prop->type != XA_INTEGER) + return BadMatch; + + xf86IDrvMsg(pInfo, X_INFO, "led_debug: try to set property: prop_led_status \n"); + + if (para->has_led) { + para->led_status = *(BOOL*)prop->data; + if (priv->proto_ops && priv->proto_ops->UpdateLED) + priv->proto_ops->UpdateLED(pInfo); + } + } + else if (property == prop_led_double_tap) { + if (prop->size != 1 || prop->format != 8 || prop->type != XA_INTEGER) + return BadMatch; + + xf86IDrvMsg(pInfo, X_INFO, "led_debug: try to set property: prop_led_double_tap \n"); + + para->led_double_tap = *(CARD8*)prop->data; + } else if (property == prop_product_id || property == prop_device_node) return BadValue; /* read-only */ else { /* unknown property */ @@ -830,3 +859,14 @@ return Success; } + +void SynapticsToggleOffProperty(DeviceIntPtr dev, Bool off) +{ + uint8_t val; + + if (!prop_off) + return; + val = off; + XIChangeDeviceProperty(dev, prop_off, XA_INTEGER, 8, + PropModeReplace, 1, &val, FALSE); +} diff -ur xf86-input-synaptics-1.9.1/src/synaptics.c xf86-input-synaptics-1.9.1_new/src/synaptics.c --- xf86-input-synaptics-1.9.1/src/synaptics.c +++ xf86-input-synaptics-1.9.1_new/src/synaptics.c @@ -143,6 +143,7 @@ void InitDeviceProperties(InputInfoPtr pInfo); int SetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop, BOOL checkonly); +void SynapticsToggleOffProperty(DeviceIntPtr dev, Bool off); const static struct { const char *name; @@ -796,6 +797,9 @@ pars->maxDeltaMM = diag * 0.25; } + xf86IDrvMsg(pInfo, X_INFO, "led_debug: set default params for: led_double_tap\n"); + pars->led_double_tap = xf86SetBoolOption(opts, "LEDDoubleTap", TRUE); + xf86IDrvMsg(pInfo, X_INFO, "led_debug: set default params for: led_double_tap - OK\n"); /* Warn about (and fix) incorrectly configured TopEdge/BottomEdge parameters */ if (pars->top_edge > pars->bottom_edge) { @@ -1038,6 +1042,13 @@ xf86AddEnabledDevice(pInfo); dev->public.on = TRUE; + + /* update LED */ + if (priv->proto_ops && priv->proto_ops->UpdateLED) + { + xf86IDrvMsg(pInfo, X_INFO, "led_debug: UpdateLED\n"); + priv->proto_ops->UpdateLED(pInfo); + } return Success; @@ -1364,13 +1375,81 @@ return !Success; } +#define LED_TOGGLE_X_AREA 0.10 +#define LED_TOGGLE_Y_AREA 0.08 + +static int +in_led_toggle_area(InputInfoPtr pInfo, struct SynapticsHwState *hw) +{ + SynapticsPrivate *priv = (SynapticsPrivate *)pInfo->private; + int click_led_x, click_led_y; + + click_led_x = (priv->maxx - priv->minx) * LED_TOGGLE_X_AREA + priv->minx; + click_led_y = (priv->maxy - priv->miny) * LED_TOGGLE_Y_AREA + priv->miny; + return (hw->x < click_led_x && hw->y < click_led_y); +} + +/* clicpad button toggle point: + * some devices have a LED at the upper-left corner, and double-tapping it + * toggles the touchpad enable/disable + */ +static int +handle_toggle_led(InputInfoPtr pInfo, struct SynapticsHwState *hw, int finger) +{ + SynapticsPrivate *priv = (SynapticsPrivate *)pInfo->private; + SynapticsParameters *para = &priv->synpara; + int diff; + + if (finger) { + if (!in_led_toggle_area(pInfo, hw)) { + /* outside the toggle area */ + priv->led_touch_state = FALSE; + priv->led_tapped = FALSE; + return finger; + } + if (!priv->led_touch_state) { + /* touch start */ + priv->led_touch_millis = hw->millis; + priv->led_touch_state = TRUE; + } + return 0; /* already processed; ignore this finger event */ + } + + if (!priv->led_touch_state) + return finger; /* nothing happened */ + + /* touch-released */ + priv->led_touch_state = FALSE; + diff = TIME_DIFF(priv->led_touch_millis + para->tap_time, hw->millis); + if (diff < 0) { /* non-tap? */ + priv->led_tapped = FALSE; + return finger; + } + if (priv->led_tapped) { + /* double-tapped? */ + diff = TIME_DIFF(priv->led_tap_millis + para->tap_time_2, hw->millis); + if (diff >= 0) { + para->touchpad_off = !para->touchpad_off; + if (priv->proto_ops && priv->proto_ops->UpdateLED) { + para->led_status = para->touchpad_off; + priv->proto_ops->UpdateLED(pInfo); + } + priv->prop_change_pending = 1; + priv->led_tapped = FALSE; + } + } else + priv->led_tapped = TRUE; + priv->led_tap_millis = hw->millis; + return 0; /* already processed; ignore this finger event */ +} + /* * Convert from absolute X/Y coordinates to a coordinate system where * -1 corresponds to the left/upper edge and +1 corresponds to the * right/lower edge. */ static void -relative_coords(SynapticsPrivate * priv, int x, int y, +relative_coords(SynapticsPrivate *priv, int x, int y, double *relX, double *relY) { int minX = priv->synpara.left_edge; @@ -1599,6 +1678,7 @@ { InputInfoPtr pInfo = arg; SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private); + SynapticsParameters *para = &priv->synpara; struct SynapticsHwState *hw = priv->local_hw_state; int delay; #if !HAVE_THREADED_INPUT @@ -1611,6 +1691,13 @@ SynapticsCopyHwState(hw, priv->hwState); SynapticsResetTouchHwState(hw, FALSE); delay = HandleState(pInfo, hw, hw->millis, TRUE); + if (priv->prop_change_pending) + delay = MIN(10, delay); + + if (priv->prop_change_pending) { + SynapticsToggleOffProperty(pInfo->dev, para->touchpad_off); + priv->prop_change_pending = 0; + } priv->timer_time = now; priv->timer = TimerSet(priv->timer, 0, delay, timerFunc, pInfo); @@ -2791,7 +2878,7 @@ /* If this is a clickpad and the user clicks in a soft button area, press * the soft button instead. */ - if (para->clickpad) { + if (para->touchpad_off != 1 && para->clickpad) { /* hw->left is down, but no other buttons were already down */ if (!(priv->lastButtons & 7) && hw->left && !hw->right && !hw->middle) { /* If the finger down event is delayed, the x and y @@ -3009,6 +3096,12 @@ Bool using_cumulative_coords = FALSE; Bool ignore_motion; + /* If touchpad is switched off, we skip the whole thing and return delay */ + if (para->touchpad_off == TOUCHPAD_OFF && !(para->has_led && para->led_double_tap)) { + UpdateTouchState(pInfo, hw); + return delay; + } + /* We need both and x/y, the driver can't handle just one of the two * yet. But since it's possible to hit a phys button on non-clickpads * without ever getting motion data first, we must continue with 0/0 for @@ -3082,6 +3175,15 @@ finger = priv->finger_state; } + if (para->has_led && para->led_double_tap) { + if (inside_active_area) + finger = handle_toggle_led(pInfo, hw, finger); + if (para->touchpad_off == 1) { + priv->finger_state = finger; + return delay; + } + } + /* tap and drag detection. Needs to be performed even if the finger is in * the dead area to reset the state. */ timeleft = HandleTapProcessing(priv, hw, now, finger, inside_active_area); diff -ur xf86-input-synaptics-1.9.1/src/synapticsstr.h xf86-input-synaptics-1.9.1_new/src/synapticsstr.h --- xf86-input-synaptics-1.9.1/src/synapticsstr.h +++ xf86-input-synaptics-1.9.1_new/src/synapticsstr.h @@ -230,6 +230,10 @@ int softbutton_areas[4][4]; /* soft button area coordinates, 0 => right, 1 => middle , 2 => secondary right, 3 => secondary middle button */ int hyst_x, hyst_y; /* x and y width of hysteresis box */ + Bool has_led; /* has an embedded LED */ + Bool led_status; /* Current status of LED (1=on) */ + Bool led_double_tap; /* double-tap period in ms for touchpad LED control */ + int maxDeltaMM; /* maximum delta movement (vector length) in mm */ } SynapticsParameters; @@ -313,6 +317,11 @@ Bool has_scrollbuttons; /* device has physical scrollbuttons */ Bool has_semi_mt; /* device is only semi-multitouch capable */ Bool has_mt_palm_detect; /* device reports per finger width and pressure */ + int prop_change_pending; + Bool led_touch_state; + Bool led_tapped; + int led_touch_millis; + int led_tap_millis; enum TouchpadModel model; /* The detected model */ unsigned short id_vendor; /* vendor id */ diff -ur xf86-input-synaptics-1.9.1/src/synproto.h xf86-input-synaptics-1.9.1_new/src/synproto.h --- xf86-input-synaptics-1.9.1/src/synproto.h +++ xf86-input-synaptics-1.9.1_new/src/synproto.h @@ -109,6 +109,7 @@ struct SynapticsHwState * hwRet); Bool (*AutoDevProbe) (InputInfoPtr pInfo, const char *device); void (*ReadDevDimensions) (InputInfoPtr pInfo); + void (*UpdateLED)(InputInfoPtr pInfo); }; #ifdef BUILD_PS2COMM diff -ur xf86-input-synaptics-1.9.1/tools/synclient.c xf86-input-synaptics-1.9.1_new/tools/synclient.c --- xf86-input-synaptics-1.9.1/tools/synclient.c +++ xf86-input-synaptics-1.9.1_new/tools/synclient.c @@ -147,6 +147,8 @@ {"MiddleButtonAreaRight", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 5}, {"MiddleButtonAreaTop", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 6}, {"MiddleButtonAreaBottom", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 7}, + {"LEDStatus", PT_BOOL, 0, 1, SYNAPTICS_PROP_LED_STATUS, 8, 0}, + {"LEDDoubleTap", PT_BOOL, 0, 1, SYNAPTICS_PROP_LED_DOUBLE_TAP, 8, 0}, { NULL, 0, 0, 0, 0 } };