Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
synapticstouchpad [2009/07/30 08:55] – Fix: use moused_enable="YES" instead of enable_moused="YES" JeanSébastienPédronsynapticstouchpad [2022/08/18 05:58] (current) – Indent command/file/code lines for readability KubilayKocak
Line 1: Line 1:
-====== Synaptics Touchpad ======+===== Synaptics Touchpad =====
  
-The Synaptics Touchpad is a pointing device, found on many laptops for instance. First, we discuss the problems with the current driver. Then we talk about a replacement driver to improve the quality and extend features.+===== Introduction =====
  
-===== Current driver in RELENG_7 =====+The Synaptics Touchpad is a pointing device found on many laptops and supported since %%FreeBSD%% 8.
  
-Support for this device is already included in %%FreeBSD%% and can be enabled with the ''%%hw.psm.synaptics_support%%'' tunable. Without this, the touchpad is recognized as a standard 3-buttons mouse.+By default, it is recognized and configured as a 3-buttons mouse. Additional features can be enabled with the ''%%hw.psm.synaptics_support%%'' sysctl tunable.
  
-The current implementation provides the following features: +Also check out [[https://docs.freebsd.org/en/books/faq/#x-and-synaptic|FreeBSD FAQ: My laptop has a Synaptics Touchpad. Can I use it in X?]]
-  * movement smoothing +
-  * tap detection with one finger +
-  * palm detection +
-  * support for extra buttons +
-  * support for guest devices+
  
-However it lacks several useful features: +===== Features =====
-  * precision with slow movements +
-  * tap detection with two or three fingers +
-  * tap-hold (to simulate a button kept pressed) +
-  * virtual scrolling (to simulate a wheel) +
-  * movement continuation (to continue a movement when the finger reaches a border)+
  
-An [[http://www.freshports.org/x11-drivers/synaptics/|X.Org driver]] providing some of the missing features is available in the Ports tree but it requires further setup and its features are obviously unavailable for the console.+  * Improved movement smoothing. It's comparable to the Microsoft Windows driver from Synaptics, except when the finger reaches touchpad borders where the movement becomes chaotic. 
 +  * Tap detection with one (left click), two (right click), or three (middle click) finger tap support. 
 +  * Tap-hold detection with one, two, or three fingers. 
 +  * Virtual scrolling. For now, an area must be dedicated to virtual scrolling; typically, one on the right (vertical scrolling) and one at the bottom (horizontal scrolling). Also, a patch must be applied to xf86-input-mouse to handle horizontal scrolling from sysmouse. Later, virtual scrolling with two fingers will be re-added, as found on Apple %%MacBook%%.
  
-===== New driver =====+===== Setup =====
  
-The development of the new driver will go through two phases: +To enable psm(4) Synaptics support, add the following line to ''%%/boot/loader.conf%%''
-  - Bring the **quality** of the movement smoothing and tap-hold support on par with what is done internaly by the touchpad, when ''%%hw.psm.synaptics_support%%'' is not set. +
-  - Add **more features** such as virtual scrolling. +
- +
-==== Patch ==== +
- +
-The latest patch was committed to 8-CURRENT as revision r183888 on 10/14/2008. If you're using CVS or CVSup, check that src/sys/dev/atkbdc/psm.c as revision 1.100. +
- +
-To be able **to use horizontal scrolling** with this new driver under X.Org (through sysmouse), you'll need a [[http://people.freebsd.org/~dumbbell/synaptics/xf86-input-mouse-sysmouse-horizontal-scrolling.patch|patch against xf86-input-mouse]]. +
- +
-To apply it: +
- +
-<code> +
-# cd /usr/ports/x11-drivers/xf86-input-mouse +
-# make patch +
-# cd work +
-# patch -p1 < xf86-input-mouse-sysmouse-horizontal-scrolling.patch +
-# cd .. +
-# make +
-</code> +
- +
-==== Current features ==== +
- +
-  * better movement smoothing. It's comparable to the Microsoft Windows driver from Synaptics, except when the finger reaches touchpad borders where the movement becomes chaotic. +
-  * tap detection with one (left click), two (right click) or three (middle click) fingers. +
-  * tap-hold detection with one, two or three fingers. +
-  * virtual scrolling. For now, an area must be dedicated to virtual scrolling; typically, one on the right (vertical scrolling) and one at the bottom (horizontal scrolling). Also, a patch must be applied to xf86-input-mouse to handle horizontal scrolling from sysmouse. Later, virtual scrolling with two fingers will be re-added, as found on Apple MacBook. +
- +
-==== How to use it ==== +
- +
-You must add the following line in ''%%/boot/loader.conf%%'' to enable the psm(4) Synaptics support.+
  
 <code> <code>
Line 61: Line 24:
 </code> </code>
  
-You'll need moused(8) too. Add this to ''%%/etc/rc.conf%%'':+Enable moused(8). Add the following to ''%%/etc/rc.conf%%''
  
 <code> <code>
Line 67: Line 30:
 </code> </code>
  
-To use it with X.Org, you'll have to disable Synaptics X.Org specific driver and configure a sysmouse mouse. Here's an example to add to ''%%/etc/X11/xorg.conf%%'':+To use it within X.Org, disable the X.Org-specific Synaptics driver, and configure a sysmouse mouse. Here's an example section for ''%%/etc/X11/xorg.conf%%''
  
 <code> <code>
Line 79: Line 42:
 </code> </code>
  
-Horizontal scrolling is disabled by default. To enable it, you need to set a sysctl (in your ''%%/etc/sysctl.conf%%''):+Horizontal scrolling is disabled by default. To enable it, add the following to ''%%/etc/sysctl.conf%%''
  
 <code> <code>
Line 85: Line 48:
 </code> </code>
  
-==== sysctl documentation ====+===== Touchpad Configuration =====
  
-=== Palm detection ===+==== Palm Detection ====
  
-== Finger pressure ==+=== Finger Pressure ===
  
 <code> <code>
Line 96: Line 59:
 </code> </code>
  
-If the pressure is less than ''%%min_pressure%%'' of above ''%%max_pressure%%'', the packet is ignored but the current action isn't terminated. The pressure is comprised between 0 and 255. Here are some meaningful values, as stated by Synaptics specifications:+If the pressure is less than ''%%min_pressure%%'' or above ''%%max_pressure%%'', the packet is ignored but the current action isn't terminated. The pressure is comprised between 0 and 255. Here are some meaningful values, as stated by Synaptics specifications:
   * z = 0: no finger contact   * z = 0: no finger contact
   * z = 10: finger hovering near the pad   * z = 10: finger hovering near the pad
Line 105: Line 68:
   * z = 255: maximum reportable Z   * z = 255: maximum reportable Z
  
-== Finger width ==+=== Finger Width ===
  
 <code> <code>
Line 116: Line 79:
   * w = 15: maximum reportable width (capPalmDetect needed   * w = 15: maximum reportable width (capPalmDetect needed
  
-=== Movement smoothing ===+==== Movement Smoothing ====
  
-To smooth the movement, we use a weighted average then a division where both the weight and the divisor vary, depending on the movement speed. See "How it works".+For movement smoothing, we use a weighted average then a division where both the weight and the divisor vary, depending on the movement speed. See "How it works".
  
 <code> <code>
Line 148: Line 111:
 This multiplicator is used during averages and divisions to increase the precision. This multiplicator is used during averages and divisions to increase the precision.
  
-=== Touchpad borders ===+=== How Movement Smoothing Works ===
  
-The touchpad borders generate a lot of noise in the reported coordinates. There are two sets of sysctl to control this area.+The smoothing is based on a weighted average: 
 + 
 +<code cpp> 
 +average = (weight_current * delta + weight_previous * average) / (weight_current + weight_preivous) 
 +</code> 
 + 
 +where : 
 +  * ''%%average%%'' is the previous average, which is kept between each packet. 
 +  * ''%%delta%%'' is the relative movement. 
 +  * ''%%weight_current%%'' and ''%%weight_previous%%'' are configurable weights. 
 + 
 +This average is calculated for each axis (x & y) separately. 
 + 
 +The problem with a simple weighted average as above is that the user has to choose between a smooth but laggy movement (''%%weight_previous%%'' greater then ''%%weight_current%%'') or a sharp but imprecise movement at slow speed (''%%weight_previous%%'' smaller or equal to ''%%weight_current%%''). 
 + 
 +The idea is then to change ''%%weight_previous%%'' based on the last packets: 
 +  * If the movement is slow, we keep ''%%weight_previous%%'' at its original value. 
 +  * If the movement is fast, ''%%weight_previous%%'' decreases and may reach 0 for the fastest movements. 
 + 
 +Internaly, the driver keeps the last 10 packets. Here is the simplified algorithm: 
 + 
 +<code cpp> 
 +dx = abs(new_x - older_x) + 1; /* +1: to avoid a division by zero below. */ 
 +dy = abs(new_y - older_y) + 1; 
 + 
 +/* "len" is really the length squared. */ 
 +len = (dx * dx) + (dy * dy); 
 + 
 +/* "sysctl_weight_len_squared" is the length squared at which the 
 + * "weight_previous" will start to decrease. */ 
 +weight_previous = sysctl_weight_len_squared * weight_previous / len; 
 +weight_previous = imin(weight_previous, sysctl_weight_previous); 
 +</code> 
 + 
 +The driver will do almost the same with the divisor to calculate the acceleration. The rest of the division is also kept between each packet; otherwise, with slow movements, the pointer doesn't reproduce well what the finger is doing. 
 + 
 +==== Touchpad Borders (Margins) ==== 
 + 
 +Touchpad edges (borders) can generate a lot of noise in reported coordinates. There are two sets of sysctl tunables that control this area:
  
 <code> <code>
Line 168: Line 169:
 </code> </code>
  
-''%%na%%'' stands for noisy area. Movements inside these larger margins will be smoothed using different max weight and divisor. See "Movement smoothing".+''%%na%%'' stands for noisy area. Movements inside these larger margins will be smoothed using different max weight and divisor. See "Movement Smoothing".
  
-=== Points history ===+==== Points History ====
  
 <code> <code>
Line 179: Line 180:
 ''%%window_min%%'' indicates the minimum number of packets to receive before an action is considered to be real and wanted. ''%%window_max%%'' is the maximum number of packets to use in calculations. ''%%window_min%%'' indicates the minimum number of packets to receive before an action is considered to be real and wanted. ''%%window_max%%'' is the maximum number of packets to use in calculations.
  
-=== Tap and tap-hold ===+==== Tap and Tap-hold ====
  
 <code> <code>
Line 194: Line 195:
 ''%%taphold_timeout%%'' is the time (in microseconds) between two taps to consider a tap-hols action. ''%%taphold_timeout%%'' is the time (in microseconds) between two taps to consider a tap-hols action.
  
-=== Virtual scrolling ===+==== Virtual Scrolling ====
  
 <code> <code>
Line 206: Line 207:
 An area must be dedicated to virtual scrolling for now. This area is defined by ''%%vscroll_hor_area%%'' (positive for an area at the bottom, negative for an area at the top) for horizontal scrolling and ''%%vscroll_ver_area%%'' (positive for an area on the left, negative for an area on the right) for vertical scrolling. ''%%vscroll_min_delta%%'' is the minimum delta between points to consider a scrolling action. This is to prevent unwanted scrolling when tapping for instance. ''%%vscroll_div_min%%'' and ''%%vscroll_div_max%%'' are the divisors used instead of ''%%div_min%%'' and ''%%div_max%%'' respectively. An area must be dedicated to virtual scrolling for now. This area is defined by ''%%vscroll_hor_area%%'' (positive for an area at the bottom, negative for an area at the top) for horizontal scrolling and ''%%vscroll_ver_area%%'' (positive for an area on the left, negative for an area on the right) for vertical scrolling. ''%%vscroll_min_delta%%'' is the minimum delta between points to consider a scrolling action. This is to prevent unwanted scrolling when tapping for instance. ''%%vscroll_div_min%%'' and ''%%vscroll_div_max%%'' are the divisors used instead of ''%%div_min%%'' and ''%%div_max%%'' respectively.
  
-==== How it works ====+===== Toggling Synaptics Touchpad with devd =====
  
-=== Movement smoothing and tap-hold support ===+Although touchpads can support palm detection, it is sometimes desirable to disable them if a USB mouse is plugged in.
  
-The smoothing is based on a weighted average:+These instructions assume a USB wired or wireless mouse. For a mouse that connects via Bluetooth, you will also need to identify your mouse ''%%device-name%%''.
  
-<code cpp> +==== Setup ==== 
-average = (weight_current * delta + weight_previous * average) / (weight_current + weight_preivous)+ 
 +We will be triggering a script from devd in order to toggle synaptics. 
 + 
 +Create a new script in /usr/local/bin named "synaptics-hotplug". 
 + 
 +In this script, paste the following: 
 + 
 +<code> 
 +#!/bin/sh 
 + 
 +trackpad_disable(){ 
 +        /sbin/sysctl hw.psm.synaptics.min_pressure=220 
 +} 
 + 
 +trackpad_enable(){ 
 +        /sbin/kldunload ums 
 +        /sbin/sysctl hw.psm.synaptics.min_pressure=32 
 +} 
 + 
 +synaptics_$1
 </code> </code>
  
-where : +Then you will want to make the script executable.
-  * ''%%average%%'' is the previous average, which is kept between each packet. +
-  * ''%%delta%%'' is the relative movement. +
-  * ''%%weight_current%%'' and ''%%weight_previous%%'' are configurable weights.+
  
-This average is calculated for each axis (x & y) separately.+<code> 
 +chmod +x synaptics-hotplug 
 +</code>
  
-The problem with a simple weighted average as above is that the user has to choose between a smooth but laggy movement (''%%weight_previous%%'' greater then ''%%weight_current%%'') or a sharp but imprecise movement at slow speed (''%%weight_previous%%'' smaller or equal to ''%%weight_current%%'').+Next you will want to open /etc/devd/usb.conf and navigate to line 5686, it should look like the following:
  
-The idea is then to change ''%%weight_previous%%'' based on the last packets: +<code> 
-  * If the movement is slow, we keep ''%%weight_previous%%'' at its original value. +nomatch 32 { 
-  * If the movement is fast, ''%%weight_previous%%'' decreases and may reach 0 for the fastest movements.+        match "bus" "uhub[0-9]+"; 
 +        match "mode" "host"; 
 +        match "intclass" "0x03"; 
 +        match "intsubclass" "0x01"; 
 +        match "intprotocol" "0x02"; 
 +        action "kldload -n ums"; 
 +}; 
 +</code>
  
-Internaly, the driver keeps the last 10 packets. Here is the simplified algorithm:+That last line in the block, 'action' is what runs everytime we plug in our USB mouse, edit it so it runs our script:
  
-<code cpp> +<code> 
-dx = abs(new_x - older_x) + 1; /* +1: to avoid a division by zero below. */ +action "kldload -n ums && /usr/local/bin/synaptics-hotplug disable"; 
-dy = abs(new_y - older_y) + 1;+</code>
  
-/* "len" is really the length squared. */ +Now everytime we plug in our USB mouse, it will run our script with the "disable" argument variable which runs our script's "synaptics_disable" function, this changes our synaptics trackpad minimal pressure to 220, disabling it.
-len = (dx * dx) + (dy * dy);+
  
-/* "sysctl_weight_len_squared" is the length squared at which the +Next open /etc/devd.conf as root and put the following at the end of the file(or anywhere): 
- * "weight_previous" will start to decrease. */ + 
-weight_previous = sysctl_weight_len_squared * weight_previous / len; +<code> 
-weight_previous = imin(weight_previous, sysctl_weight_previous);+detach 100 { 
 +        device-name "ums[0-9]+"; 
 +        action "/usr/local/bin/synaptics-hotplug enable"; 
 +};
 </code> </code>
  
-The driver will do almost the same with the divisor to calculate the acceleration. The rest of the division is also kept between each packet; otherwise, with slow movements, the pointer doesn't reproduce well what the finger is doing.+With this done, the only thing you'll need to do is restart devd 
 + 
 +<code> 
 +service devd restart 
 +</code> 
 + 
 +Once devd is restarted, the synaptics trackpad should turn off and on depending whether your USB mouse is plugged in. 
 + 
 +Credit for scripted synpatics toggle via devd goes to SamuelGogarty. 
 + 
 +===== Other Resources ===== 
 + 
 +  * [[https://www.freshports.org/sysutils/iichid/|FreeBSD Port: sysutils/iichid -- Generic FreeBSD HID layer for I2C and USB devices]] 
 + 
 +---- 
 + 
 +{{tag>HowTo}} 
 +{{tag>Laptop}}
  
  • synapticstouchpad.1248944104.txt.gz
  • Last modified: 2009/07/30 08:55
  • by JeanSébastienPédron