How do I enable touchscreen gestures in Linux?

Recently my wife complained to me that her Dell XPS 13, which is supposed to work seamlessly with Ubuntu, didn’t let her use touchscreen scrolling. I was in the process of looking for a new laptop, so I figured I’d work through the problem and solve it before I committed to a touchscreen laptop with Linux for myself.

The solution is simple enough with a few commands, but you’ll have to use the terminal for this one.

First, the symptom: Using Firefox, it was not possible to scroll using the touchscreen. Instead, all you could do was click links or select text. You could drag the scrollbar, but generally this is not the behaviour of a tablet, and tablet behaviour was what we expected.

The solution: You need X11 Gestures, touchegg, and to adjust a few settings in Firefox and elsewhere.

First, ensure that you have touchegg installed (this link is for an older version of Ubuntu, but the same principle applies).

Next, assuming you’re using Gnome (Ubuntu out of the box uses Gnome), you’ll want to install X11 Gestures. This is a Gnome Shell Extension, and if you’ve not set yourself up to use those, you’ll want to set up Gnome Shell Extensions now.

At this point, your problem will not be solved. There are two more subtle steps, and they have to do with security, so proceed with caution. (You’ll be OK. I believe in you.)

In Firefox, in about:config, set dom.w3c_touch_events.enabled=1. Here that is in monospace:

dom.w3c_touch_events.enabled=1

Now, you need to edit a file that only root (the administrator) can edit. The instruction is this: edit /etc/security/pam_env.conf and add MOZ_USE_XINPUT2 DEFAULT=1

I use an editor called vim. You can use whatever editor you want. gedit is popular. nano is popular. Whatever you’ve settled on, use that. Replace in these commands as necessary.

sudo vim /etc/security/pam_env.conf

Once in the file, ensure you have a line that looks like this (the last blue line):

Save the file and reload modules — or just bloody reboot — as necessary.

Was all of this necessary? To be honest, I don’t know exactly; I’m unsure whether the X11 Gestures were necessary, but they’re cool and you should have them. I know that pinching and scrolling didn’t work in Firefox until these last two steps, so they’re essential.

Following this, I bought my own Lenovo Yoga 530 and set all this up. Then, when I installed Google Chrome, it worked seamlessly. So, officially, this is a troubleshooting guide for Firefox in Gnome with a touchscreen.

Enjoy.