This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Two-finger right-click and zoom with a touch screen
#1
All,
I recently got a new touchscreen, and was upset that I couldn't get multi-touch to work on it. After some research, I discovered a program called "twofing" which gives two-finger right-click and two-finger zoom. I've created a how-to for you guys.

Credit to JimmyN on raspberrypi.org. I made this a bit more generic, from his original post: https://www.raspberrypi.org/forums/viewt...p?t=138575

This modification will give two-finger right-click and two finger zoom. It does work on OpenCPN and on the web browser. I used the latest update of OpenPlotter with the most recent updates of Stretch.

First we'll need to fetch the files, I created a temp directory to work in, and afterward it can be deleted. So open a terminal and get started.

Code:
mkdir ~/temp
cd ~/temp
wget http://plippo.de/dwl/twofing/twofing-0.1.2.tar.gz


That should report that "twofing-0.1.2.tar.gz" was saved.

Now we'll add some needed packages, if any of these are already installed it's OK. We'll update first, and then install them with the following commands.

Code:
sudo apt-get update
sudo apt-get install build-essential libx11-dev libxtst-dev libxi-dev x11proto-randr-dev libxrandr-dev

Now that those are in place we can extract the downloaded twofing-0.1.2.tar.bz file and compile the binary using "make".

Code:
tar -xvzf twofing-0.1.2.tar.gz
cd twofing-0.1.2
make

It that is successful,

Code:
sudo make install

This will do a few things. It will put a new executable called "twofing" into "/usr/bin/". It will also place a new file in "/etc/udev/rules.d" called "70-touchscreen-egalax.rules". We'll do some editing on that one in a moment.

Now, we need to discover the name of the multi-touch display you are using, and the USB ID. From your display (not from a remote terminal) run:

Code:
xinput

Mine looked like this:

Code:
pi@openplotter:~ $ xinput
⎡ Virtual core pointer                          id=2 [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4 [slave  pointer  (2)]
⎜   ↳ Logitech K400                             id=9 [slave  pointer  (2)]
⎜   ↳ G2Touch Multi-Touch by G2TSP              id=8 [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3 [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5 [slave  keyboard (3)]
    ↳ C-Media Electronics Inc. USB Audio Device id=6 [slave  keyboard (3)]
    ↳ Logitech K400

The name of my touch pointer is "G2Touch Multi-Touch by G2TSP". Yours may vary. Save this name, whatever it is.

Next, you need the USB ID of your pointer. Run:

Code:
lsusb

Mine looked like this:

Code:
Bus 002 Device 002: ID 174c:0857 ASMedia Technology Inc. 
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 011: ID 2a94:564d  
Bus 001 Device 010: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter
Bus 001 Device 009: ID 1546:01a7 U-Blox AG [u-blox 7]
Bus 001 Device 008: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 007: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T
Bus 001 Device 006: ID 0d8c:0014 C-Media Electronics, Inc. Audio Adapter (Unitek Y-247A)
Bus 001 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 003: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

It took a little trial and error, but I discovered that the one unnamed USB device is actually my touch device. Yours might have a name. What you want is the USB ID for it, which in my case is "2a94:564d". You'll also need this info.

Next we are going to edit the file that was installed when you did "make install" above. The name of the file isn't important, the number at the beginning is. I just left mine with "egalax" in the name, even though I don't have an egalax touch controller.

Edit the file with:

Code:
sudo nano /etc/udev/rules.d/70-touchscreen-egalax.rules

It's going to look like this when you open it:

Code:
SUBSYSTEMS=="usb",ACTION=="add",KERNEL=="event*",ATTRS{idVendor}=="0eef",ATTRS{idProduct}=="480d",SYMLINK+="twofingtouch",RUN+="/bin/chmod a+r /dev/twofingtouch"
SUBSYSTEMS=="usb",ACTION=="add",KERNEL=="event*",ATTRS{idVendor}=="0486",ATTRS{idProduct}=="0186",SYMLINK+="twofingtouch",RUN+="/bin/chmod a+r /dev/twofingtouch"
KERNEL=="event*",ATTRS{name}=="eGalaxTouch Virtual Device for Multi",SYMLINK+="twofingtouch",RUN+="/bin/chmod a+r /dev/twofingtouch"

The first line and the last line need to be edited with the information you collected previously with xinput and lsusb. On the first line, replace the "idVendor" identifier with the first part of the USB ID you collected with lsusb (the part before the ":") and the "idProduct" identifier with the second part (the part after the ":").

On the last line, replace the "ATTRS{name}" part with the touch controller name you got when you did xinput.

The second line in this file is for another touch controller. I'm not sure why it's there, but it doesn't hurt anything. I suppose if someone were ambitious they could create a "one file to rule them all" file that would identify all touch controllers.

EDIT: it turns out, all you need is the USBID. I commented out the last two lines and mine still works fine.

You are done with this file. Save with CTRL-X, Y.

Now reboot and then we can give it a test.
Test it using the debug switch. If you have no errors you'll get a calibration screen, press <CTRL> C to exit.
Code:
twofing --debug


If that went OK then start twofing again, without the debug switch, and touching two fingers on the window titlebar should give you a "right click" dropdown menu.
Code:
twofing 

Now you'll probably want to start it up when the desktop starts, so let's add it to the autostart file. In the original instructions they identified a file in ~/.config/lxsession/LXDE-pi/ called "autostart". It wasn't there in my implementation. I editied the autostart file in "/etc/xdg/lxsession/LXDE-pi"

Code:
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Scroll down to the bottom and add this line.

Code:
@/usr/bin/twofing 

EDIT: You may find that twofing doesn't start reliably on startup. In my case, I discovered a few second delay was needed before twofing was run. I did this with a bash script, that called twofing after delay. The script looks like this:
Code:
#!/bin/bash
sleep 10
/usr/bin/twofing
which I saved to /usr/local/bin/two-finger.sh. You'll need to make it executable with "sudo chmod +x /usr/local/bin/two-finger.sh.

If yo do this, the entry in /etc/xdg/lxsession/LXDE-pi/autostart needs to be:


Code:
@/usr/local/bin/two-finger.sh

Save the change, reboot again, and it should be working. If so you can delete the /temp directory and everything in it.

Code:
rm -r ~/temp

That should do it. As I said, I now have two-finger zoom with OpenCPN, and two-finger right-click.
Reply
#2
Hi Abarrow:

Thanks for the detailed Instructions.

They are certainly easy to follow, however, my touch screen ( Hanspree 22 inches), has 2 different IDs:

This is what I get with Command Xinput:

pi@openplotter:~/temp/twofing-0.1.2 $ xinput
\u23a1 Virtual core pointer                    id=2 [master pointer  (3)]
\u239c   \u21b3 Virtual core XTEST pointer              id=4 [slave  pointer  (2)]
\u239c   \u21b3 Weida Hi-Tech                CoolTouchR System            Mouse id=6 [slave  pointer  (2)]
\u239c   \u21b3 Weida Hi-Tech                CoolTouchR System            id=7 [slave  pointer  (2)]
\u239c   \u21b3 Logitech M705                            id=8 [slave  pointer  (2)]
\u239c   \u21b3 Logitech M310                            id=9 [slave  pointer  (2)]
\u239c   \u21b3 Logitech K400                            id=10 [slave  pointer  (2)]
\u239c   \u21b3 Logitech M187                            id=11 [slave  pointer  (2)]
\u23a3 Virtual core keyboard                    id=3 [master keyboard (2)]
\u21b3 Virtual core XTEST keyboard              id=5 [slave  keyboard (3)]
\u21b3 Logitech K400                            id=12 [slave  keyboard (3)]


As you can seem the name is very long and has huge gaps with spaces; one has id6 and the other id7; both categorized as "slave pointer"

However, Later, in lsub, i have just one unnamed USD device:

Bus 002 Device 002: ID 152d:0578 JMicron Technology Corp. / JMicron USA Technology Corp. JMS567 SATA 6Gb/s bridge
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 006: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 004: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 001 Device 003: ID 2575:0401  
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

So when I edit egalax rules, Idvendor is clear (2575),Idproduct is clear too: (0401), but down on line ATRS, I should write the name; but which of both names? Should I write both?
Should i copy paste exactly as is? ( With all the spaces): "Weida Hi-Tech                CoolTouchR System            Mouse " and "[b]Weida Hi-Tech                CoolTouchR System"[/b] ??

I am still learning linux and I fear to wreck my system; I have worked so many hours on it!   Angel So I prefer to ask before continue and spoil everything

Any clues?

Thanks!
Reply
#3
I wouldn't worry about the name. The important part is the vendor id and the product id.
Reply
#4
Ok, well noted, will resume the installation and confirm if it works with my monitor. 

It's surprising that such a good thing and good explained procedure didn't get any reply from anybody, don't you think?

Have a great day!
Reply
#5
Thanks for the instructions. I have a few issues and am very new to RPi so please forgive some very simple questions:

When I try twofing --debug I get:

pi@openplotter:~ $ twofing --debug
twofing, the two-fingered daemon
Version 0.1.2.20120708

Input device name: "ILITEK ILITEK-TP"
XInput device id is 10.
XInput device id for calibration is 10.
Start calibration
No calibration data found, use default values.
No valid axis inversion data found.
pi@openplotter:~ $

So I am doing something wrong

Also for editing the startup screen I get:

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash


[ File '/etc/xdg/lxsession/LXDE-pi/autostart' is unwritable ]

So not sure what I did wrong.

I am sure this is just a beginners error but I thought I would ask.

I am running a Rasp Pi 4 (4Gb) with Hannspree HT161 tough screen monitor.

Thanks in advance
Reply
#6
Anything you do that writes to files in /etc needs to be with root privs, so in the instructions where it says "nano /etc/xdg/lxsession/LXDE-pi/autostart" it should say "sudo nano /etc/xdg/lxsession/LXDE-pi/autostart".

I'll edit the instructions.
Reply
#7
(2021-05-04, 09:58 PM)abarrow Wrote: Anything you do that writes to files in /etc needs to be with root privs, so in the instructions where it says "nano /etc/xdg/lxsession/LXDE-pi/autostart" it should say "sudo nano /etc/xdg/lxsession/LXDE-pi/autostart".

I'll edit the instructions.

I guessed the missing SUDO, but For me it is not working, I will check again once I get free time. Thanks!
Reply
#8
ah - the penny drops - of course. In my inexperience I think I missed that off.

Thanks for the time and explanation
Reply
#9
How is this working after a few months? any issues?
Reply
#10
On mine, it occasionally stops working. I got busy with other projects and haven't had a chance to track down the issue.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)