Αναζήτηση αυτού του ιστολογίου

ELAN Touchscreen Right Click and Kernel Configuration

Trying to make Elan Touch Screen to work correctly on linux.
Target is to have a long press on the touch screen to be treated as a right click.
This fails in most DE. It is partially supported under Gnome and Unity.

Gnome Bug: Touchscreen right click works only if Dekstop Icons are hidden (=no desktop). If you enable the icons (classic desktop use) then right click fails to work.

This guy, tries to make ELAN to work correctly on an old kernel:
http://superuser.com/questions/729894/linux-kernel-getting-elan-touchscreen-to-work-usb-debug-related

As a solution he found this kernel configuration about config options
http://www.everfall.com/paste/id.php?pmj1v6mwhaly

Relevant Bugs: https://bugs.launchpad.net/ubuntu/+source/xorg-server/+bug/1212736

Users suggest also to try mousetweaks (also available in Debian, but it is for Gnome)

Also there is this nice python script that is built for ELAN touchscreen and it might work:
https://github.com/Zyell/Python-Touchscreen-RightClick



Tip: Install Xserver auxiliary files like x11-xserver-utils, etc. You can apt-cache search x11*

Usefull Xserver packages for testing : https://packages.debian.org/sid/x11/
All xserver-xorg-input packages worth to be checked: i.e -input-all, -input-evdev, -input-libinput, -input-mutouch, -input-mtrack, -input-multitouch)

PS: I don't know what are the differences. but since bellow we have examples of using libinput and evdev as "drivers" maybe we could try to use "mutouch" to see what happens.


Modifying xorg settings.
I installed and used xinput-calibrator.
Giving xinput-calibrator gives an error (file not found).
To locate the correct file to launch you have to run dpkg -L xinput-calibrator.
PS: Some times , the correct info comes from dpkg -S.
Once located, run it using /path/to/xinput-calibrator.

Once calibrator runs, i got a prompt to make a file 99-calibration.conf in location /etc/X11/xorg.conf.d/99-calibration.conf
 or
/usr/share/X11/xorg.conf.d/99-calibration.conf.

In my system my xorg.conf.d folder was in /usr/share.

PS: also a "master" file xorg.conf (advised by a lot of people in the web) is not present in my system. which is normal for xorg versions 7.xx

xinpur-calibrator output:
Section "InputClass"
    Identifier    "calibration"
    MatchProduct    "ELAN Touchscreen"
    Option    "MinX"    "-88"
    Option    "MaxX"    "65575"
    Option    "MinY"    "270"
    Option    "MaxY"    "65350"
    Option    "SwapXY"    "0" # unless it was already set to 1
    Option    "InvertX"    "0"  # unless it was already set
    Option    "InvertY"    "0"  # unless it was already set
EndSection

Following the recommendation of this post i add some more lines before EndSection
(http://forums.bodhilinux.com/index.php?/topic/6375-solvedright-click-using-touchscreen/)

Option "EmulateThirdButton" "1"
Option "EmulateThirdButtonTimeout" "750"
Option "EmulateThirdButtonThreshold" "30"
(PS: Most Probably the correct option EmulateThirdButtionMoveTreshold).


Alternative configuration: Option  "Calibration"   "234 1962 164 1861"

PS: In any case using xinput list-props and set-props you will be able to dynamically list and change above values to see immediatelly if the change of this values have any effect in your system.
Use of xinput : xinput list-props id and xinput set-props id parameter value.
Parameter can be given as "text" or by it's numeric value.

I saved the file, reboot ,but touch screen right click still not working, either on desktop of XFCE or inside file managers (i.e nautilus)

Tip : Using #xev or #evtest you can see the real touchscreen events. It is obvious that while click is recorder by xserver as "ButtonPress" event, the long duration click is reported either as movement (due to the high screen resolution) or again as a button press (code 330) and in any case this clicks are not recorded as EV_KEY type events (code 272 (BTN_MOUSE) or 273 (BTN_RIGHT).

In xorg manual you can see all the options that above InputClass conf file can accept .
ftp://www.x.org/pub/X11R7.7/doc/man/man5/xorg.conf.5.xhtml

PS: Noitce the X11 correct version manual. You can quickly find your version by apt list xserver-xorg or apt policy xserver

Another work around according to this post http://unix.stackexchange.com/questions/224257/how-to-disable-xorg-right-click-emulation-at-runtime is to run #xinput list-props 10 (10=ELAN id number of xinput in my pc).

If the "enable third button" settings are present are listed by xinput props like this:
$ xinput list-props 8

    Evdev Third Button Emulation (280):     0
    Evdev Third Button Emulation Timeout (281):     1000
    Evdev Third Button Emulation Button (282):      3
    Evdev Third Button Emulation Threshold (283):   20
.....

Libinput
In my case these evdev settings do not appear in list-props, but libinput settings appear instead of evdev.
This means that my touch screen is using libinput as driver , instead of evdev, obviously due to the installation / existence of xserver-xorg-input-libinput and as a result all the above options (xinput list-props) differs.

According to apt list, this libinput package is installed automatically and not manually, meaning installed by Debian.
Also package xserver-xorg-input-evdev is installed automatically (!)

This yeld to have two different conf files inside /usr/share/X11/xorg.conf.d folder:

10-evdev.conf file with a lot of entries to catch all input devices using evdev as a driver

60-libinput.conf file with similar catches for touchscreen but using libinput as a driver.

It seems that for somereason, it is the libinput settings that are finally kept by xserver and not the evdev ones (i.e maybe the starting number declares a kind of priority and thus 60 is higher priority than 10, so libinput conf stays).

I manually edited 60-libinput.conf file and commented (#) the touchscreen entries (i left the other devices entries untouched).

After a log out / log in , i could now see the relevant evdev entries in xinput list-props 10.

I also noticed that there is one parameter never mentioned before in the web, and is called "EmulateThirdButtonButton" with value 3.

According to this advanced evdev manual (https://www.mankier.com/4/evdev) this parameter defines which mouse buttion the emulation will triger (in our case button 3).

PS: It is still unclear why right click is considered to be button 3. I changed this value also to 2 for testing.

Moreover, the same post above which talks about xorg.conf (i do not have one) with these settings:
Section "InputClass"
    Identifier "Touchscreen"
    Option "EmulateThirdButton" "1"
    Option "EmulateThirdButtonTimeout" "750"
    Option "EmulateThirdButtonThreshold" "30"
EndSection

I deleted my previous 99-calibration.conf file and i made a new file with above lines plus the following lines :
MatchIsTouchscreen "on"
MatchProduct "ELAN Touchscreen"
MatchDevicePath "/dev/input/event*"
Driver "evdev"

File stored in /usr/share/X11/xorg.conf.d/90-tourchscreen.config.

PS: Driver entry could be neglected since this is included in the 10-evdev.conf, but in any case i rewrote it on my new .conf file.

After a reboot I could verify that now all evdev parameters appear in xinput list-props
(although i noticed a difference in Treshold , value reported to be 20 instead of 30 that i had enter).

The result is that touchscreen right click is still not functional.

I tried to adjust dynamically some more parameters by xinput like this :
xinput set-prop 8 280 1 (8= device id, 280 = parameter id , 1 = parameter value = true)
(alternative way: xinput set-prop 8 'Evdev Third Button Emulation' 1)

Tip : xinput --set-prop manual: https://www.x.org/releases/current/doc/man/man1/xinput.1.xhtml

PS: Obviously to adjust evdev parameters with xinput, you must see the corresponding parameters with xinput list-props. If Paramaters values are not set within any conf file, xinput still list this parameters with the default values applied by evdev driver (i.e EmulateThirdButton=0)

In any case still right click does not work .

This evdev manual ftp://www.x.org/pub/X11R7.5/doc/man/man4/evdev.4.html#toc  and also the advanced evdev manual (https://www.mankier.com/4/evdev) describes some more parameters like Emulate3Buttons that seems to be of a different use.

Tip: Could be interesting to play with GrabDevice parameter which kills all other input devices (like mouse) and isolates the selected device (touchscreen). I have to check it out.

Tip : I install in VBox the package xserver-xorg-input-evdev-dev. 
Under /usr/include/xorg , a file was created with name evdev-properties.h
Reading this header file i found a lot of interesting lines about third button emulation, like this one:
#define EVDEV_PROP_THIRDBUTTON "Evdev Third Button Emulation"

I don't know if this evdev-dev header file is required for corg configs to run correctly since the description of the options are provided / defined, or is is just a dev header / tool for supporting languages like Python that want to make evdev apps.


Tip: Create the missing xorg.conf in Xserver 7.XX
https://ubuntuforums.org/showthread.php?t=1336863
http://askubuntu.com/questions/4662/where-is-the-x-org-config-file-how-do-i-configure-x-there

You can create such a file by switching to tty1 login as user and give:
$sudo service lightdm stop && sudo Xorg -configure
A new file will be generated (xorg.conf.new) hopefully without errors.

You can then copy this new file to /etc/X11 and rename it as xorg.conf.
#cp /root/xorg.conf.new /etc/X11/xorg.conf

PS1: This Xorg -configure worked in VBox, but not in my home debian (display errors - no display found , etc).

PS2 : xorg.conf (if present) get's higher priority than xorg.conf.d folder.
If other config files exist then xorg.conf is the No1 priority (highest).
If xorg.conf.d/config files describe different settings from xorg.conf, the xorg.conf settings are used (higher priority) according to this post : http://askubuntu.com/questions/26290/50-synaptics-conf-options-not-working/27017#27017

It is though not clear if i can make manually a small xorg.conf by applying only touchscreen parameters and left all the rest to be autodetected by X or to be loaded by xorg.conf.d folder.
I didn't tried since the new file under xorg.conf.d file seems to be loaded correctly.

PS3: It is possible different calibration files to exist for different users (root / user) and maybe in different paths. As a general idea it seems that user files go to /usr directory, while global files seems to go at /etc directory. This is why some sources refer /etc/X11/xorg.conf.d/99-calibration.conf.
Or it could be just old Xserver versions, used to keep the conf files in different location.

The latest version manual of xorg is here:
https://www.x.org/releases/current/doc/man/man5/xorg.conf.5.xhtml
https://www.x.org/releases/current/doc/man/
PS: Mind the releases/current in the address....


Tip : For detailed xinput list, use #xinput --list --long . This extended infor gives information about buttons, etc.

Give a look also in Fedora Input Device Configuration:
http://fedoraproject.org/wiki/Input_device_configuration

Tip : #evtest gives a list of all /dev/input/events


TouchScreen Configuration similar to ELAN:
This guy has a touchscreen with similar properties to ELAN and claims that made his touchscreen to work as (he) expected with xinput.
But his main target was to be able to use it's touch screen correctly and not to implement a right click.
http://blog.rot13.org/2013/12/touch-screen-configuration-using-xinput.html

BTW, If you look at the evtest response at the guy above, you can see that his touchscreen has only only EV_KEY available , Code 330 = BTN_TOUCH, just like my Elan, meaning that key codes for BTN_MOUSE and BTN_RIGHTCLICK is also missing.

It would be interesting to ask him besides making his screen to respond correctly in his "touches" if he was capable to perform even a right click on his touchscreen (i doubt so).

Custom Drivers
This guy built a custom driver for ELO touchscreen : https://www.plop.at/en/touchscreen.html
Notice the "ServerLayout" Section on the xorg.conf.
This driver is made with C and is indeed using the evdev-properties.h header file from evdev-dev!

Ubuntu Wiki provides quite updated info for touchscreens: https://wiki.ubuntu.com/Touchscreen
In this Wiki, worths to check the Kernel Modules start on boot (usbtouchscreen and usbhid) placed after lp and before rtc in /etc/modules file. Alternativelly for the first time sudo modprobe usbtouchscreen usbhid. Verify if they are already loaded by lsmod |grep usbhid.

PS: In my system usbhid was loaded, but usbtouchscreen not. I load usbtouchscreen with modpobe (and it was loaded sucessfully) but no change / imporvement was observed in touch screen right click.

Calibration:
It could be a matter of touch calibration (make the xserver to treat a small touch are as a single touch to be able to treat long touch presses in an area of 20x20 pixels for example)

xinput-calibrate package (runs as xinput_calibrate) makes a kind of calibration . If evdev is used as driver the callibration is automatically passed to evdev touchscreen configuration (you can verify this with list-props immediatelly).

Just for fun : Did you know that you could start Chrome like this in case it is not operating with your touscreen? google-chrome --touch-devices=10


Some more tips to try:
All evdev settings that can be applied in .conf file are well explained by Ubuntu team here:
http://manpages.ubuntu.com/manpages/wily/man4/evdev.4.html
Check out the option EmulateThirdButtonMoveTreshold instead of EmulateThirdButtonTreshold (this could explain why when we set a treshold of 30 or 50, xinput insist to reports the default value that is 20).
PS: This could make no sense since the value was changed by CLI with set-prop and parameter numeric id, and no improvement has been observed (set-prop is considered to be dynamic setting , and it's affect should be straight away applied).

Also check the options GrabDevice, DialDelta (property Evdev Scrolling Distance) and also option Resolution.

Notice that this xserver-xorg-input-evdev package in ubuntu appears with a different name =
xserver-xorg-input-evdev 1:2.10.1-1ubuntu2 .
In Debian the default xorg package is used; there is not any Debian naming/patch.

https://launchpad.net/ubuntu/xenial/+source/xserver-xorg-input-evdev

I start to believe that if we could transpose the evdev file from Ubuntu Unity to Debian, then it should work (since in Unity right click works - to be checked).
To install , we could try to get the deb file from Ubuntu, purge the existing evdev package and install the new file using dpkg -i.
But we need to check also the dependencies. Ubuntu evdev depends on a modified xserver instead of the default freedesktop xserver.

deb file and dependencies can be found here: 
https://launchpad.net/ubuntu/yakkety/amd64/xserver-xorg-input-evdev/1:2.10.1-1ubuntu2

Notice that Ubuntu releases packages in udeb format. udeb is described as micro deb for Debian Installer (?).
https://launchpad.net/ubuntu/xenial/amd64/xserver-xorg-input-evdev-udeb/1:2.10.1-1ubuntu2

https://d-i.alioth.debian.org/doc/internals/ch03.html

As a result:
Use of evdev driver instead of libinput was much better.
I could also see in reallity multitouch on my touchscreen.

Dragging and text selection seems to work ok, even with text editors.
My xinput list-pros looks almost identical to this file .

I found a lot of bugs about this issue by many people.
https://bugs.launchpad.net/ubuntu/+source/xserver-xorg-input-evdev/+bug/1084938
https://bugs.launchpad.net/ubuntu/+source/xserver-xorg-input-evdev/+bug/1280611

Programmers at 2012, claim the usb touchscreen right click will not work with this evdev options settings due to evdev.

Maybe i have to use other workarounds, like the Python Script, two fingers script, etc.
Or to try a different drive like https://www.plop.at/en/touchscreen.html driver (but modified to match ELAN) or elographics driver (xserver-xorg-input-elographics)
You can list all available input driver by apt list xserver-xorg-input*

Right Click works perfectly inside Chrome web browser, obiously due to Chrome.
Recent Ubuntu Builts based on Unity provide right click functionallity, obviously due to the Unity team development. It could be interesting to see what is the driver that Unity installs for touchscreen, and maybe this driver could work in Debian also. Sounds interesting.

Kernel Configuration:
Some other people claim that could be a kernel issue to work correctly with touch screens.
I don't believe that this is my case , since all my touchscreen functions work ok with evdev driver, except right click.

To see the kernel cmd line arguments : #cat /proc/cmdline

Kernel boot parameters : https://www.mankier.com/7/bootparam

To see the kernel CONFIG options you need to
#cat /usr/src/linux-headers-4.7.0-1-686/.config
Source:
http://www.linuxquestions.org/questions/linux-networking-3/how-to-view-current-kernel-configuration-506406/

You can cat to a file and then open with editor and search the various options for touchscreen, elan, etc

Also , you can find the .config file in /boot
By ls, you can see that there is a file called config-4.7.0-1-686.
If you cat this file, you will also see CONFIG options. 
Or more easy : cat /boot/config-`uname -r` (and thus you cat the correct - loaded - Kernel)

I suppose that these options are the one's loaded in kernel during boot. 
It may differ than the .config options - i have not compared yet.

To change this kernel options, you need actually to compile a kernel from source, by setting the options you need. 
This guide for Kernel Compiling seems nice:

In /boot/config for example, in the VirtualBox Debian, the parameter CONFIG_TOUCHSCREEN_ELAN appears as "not set". I have to check how this appears in my convertible laptop.

Explanation of the Configuration and Kernel Compiling Tutorials:

CONFIG options can have the value Y,m,n.
Y =Default = Yes = Built in kernel
m = not built in kernel, but built from module
n = not set - not available.

Kernel Documents : https://www.kernel.org/doc/Documentation/

More about Kernel CONFIG options: 
/usr/src/linux-headers-4.7.0-1-686/include/config/auto.conf and tristate.conf

Linux Kernel Driver Database (CONFIG Options) : http://cateee.net/lkddb/web-lkddb/

According to this database there is an option called CONFIG_TOUCHSCREEN_ELAN
We can check if this option is enabled in my kernel.
This option depends on module elants_12c.c (linux/drivers/input/touchscreen/elants_12c.c).
According to elants driver header comments, this driver applies to ELAN touchpanels with 12C interface and is based on hid-multitouch.c and i2c-hid.c .
Acc to CONFIG_I2C , i squared c is a serial interface so not for my case (usb).
This is the reason that in LKDD you can see seperate config options for touchscreen_usb, and elan is not present.

PS: To be checked (entries found by VBox file, with m or y value)
CONFIG_USB_FTDI_ELAN 
CONFIG_MOUSE_ELAN_I2C_SMBUS, 
CONFIG_MOUSE_PS2_ELANTECH
CONFIG_MOUSE_ELAN_I2C_I2C
CONFIG_MOUSE_ELAN_I2C
CONFIG_HID_KEYTOUCH
CONFIG_TOUCHSCREEN_PROPERTIES

Kernel Build Instruction by the master : https://github.com/torvalds/linux


More Tips:
Boot in console only: Press e in grub highlighted entry and replace words quite splash with word text
Modesetting : /etc/modprobe.d/modesetting.conf
Kernel Modules to load at boot : /etc/modules-load.d/modules.conf
Main Lightdm greeter : /usr/share/lightdm/lightdm-gtk-greeter.conf.d/01_Debian.conf (see onboard tweak here)
Aux Lightdm greeter : /usr/share/lightdm/greeter.conf.d/01_Debian.conf
Aux Lightdm greeter : /etc/lightdm/lightdm-gtk-greeter.conf
Lilo: /etc/lilo.conf
Kernel Command Line Available options : https://www.kernel.org/doc/Documentation/kernel-parameters.txt : See parameter TS (touchscreen support) & USBHID
Run scripts/command on boot : ~/.xinitrc

Conclusion: 
After a lot of research it seems that right click on ELAN Touch Screen will not work as recent kernels handle the touchscreen.

All above workaround with evdev and simulatate right click buttons would work if ELAN had been registered as a device similar to Synaptics TouchPad.

For example if you evtest synaptics you will see that in device capabilities synaptics has left and right click buttons. On the other hand the only "EV_KEY" event is a generic "touch event", with code 330. Far away from Synaptics way to operate with mouse buttons.

One solution could be to use custom scripts like this :
https://github.com/Zyell/Python-Touchscreen-RightClick

The other solution could be somebody to develop a driver that will work on ELAN touchscreen.
Mind that there are already some ELAN drivers and even some ELAN CONFIG options for Kernel but they are all targeted to I2C (serial interface) and not USB interface.

But after personal involvment in Python, i can say that Python is fine. It is just a scripting language that can simply fill the gaps without costing you a penny of performance.

Famous utilities are based on Python (i.e Onboard, nautilus-scripts-manager, etc).

More Sources
http://forums.bodhilinux.com/index.php?/topic/6375-solvedright-click-using-touchscreen/
http://www.staff.amu.edu.pl/~kalmar/blog/?p=247
https://www.raspberrypi.org/forums/viewtopic.php?f=108&t=121602