Enable Touch Support For Firefox In Linux (X11/Xorg)

If you’re using Linux (Kubuntu in my case) on a touchscreen device like the Microsoft Surface for example, and you’re running on X11/Xorg, then you might have noticed that Firefox doesn’t properly support touch in a way you might expect it to behave on a tablet/touchscreen like device.
It would then just behave like a mouse cursor, and trying to scroll/swipe with the touchscreen will then result in the same type of behavior you will see when just pressing (and holding) the left mouse button and then moving the mouse (and thus just selecting large chunks of the page).
TIP: I recently released a detailed video guide on how to install Linux/Kubuntu on the Microsoft Surface Tablets on my YouTube.
Luckily, fixing this issue isn’t such a big deal though.
EXTRA NOTES:
– This tutorial is mainly aimed at Kubuntu (24.04 LTS) users, but should in general also work on other distro’s running on X11/Xorg and using the PAM. Like for example (but not limited to): Linux Mint, KDE Neon, POP!_OS, Debian (Stable), OpenSUSE Leap etc.
– This tutorial does NOT apply to Wayland users/sessions!
Enabling Touch
First we’ll have to start Firefox and enter: about:config in the address bar (followed by enter of course). You will then see this warning:

Just click on Accept the Risk and Continue, and then search/filter for touch (this will make it a bit easier to find the one we actually need to alter). Then search for (not by typing but just in the list) for: dom.w3c_touch_events.enabled (which if you’re following this tutorial, you can also just paste in the search/filter bar though of course 😉). And change the value from 2 to 1 (as shown below):

You can now close this (config) page, and even Firefox entirely. But we’re not there yet though.
Technical details: This basically changes the touch_events.enabled from Auto-Detect (2) to Forced-Enabled (1).
Advertisement blocked due to cookie settings.
Please consider reading our AdSense Information page to learn why we use advertisments on our website, how you can enable them, or how you can even get rid of this 'red box' by becoming a Patreon (any tier). The AdSense Information page also explains that and how we are telling Google/AdSense to only show non personalized / non tracking advertisements. |
Editing the Config File
Lastly we’ll need to edit a config file to ensure Firefox will properly use the touch input. We’ll need the pam_env.conf file for this. This is config file is (to keep it simple) part of the Pluggable Authentication Modules (PAM). This config file defines environment variables which should be set (or modified) during your login session. And we’ll need to add an environment variable to this file.
And this might sound super complicated for beginners, but don’t worry, it’s a lot easier than you might think 😉.
To open this config file (and to keep it simple), we’re first going to open a new terminal (by pressing CTRL+ALT+T or by clicking on Konsole in your Launcher (or “Start Menu” for new Windows refugees), and in that terminal you’re either going to type or copy the following line:
kate /etc/security/pam_env.conf
This will open the default text editor of Kubuntu/KDE with the config file already open. Then scroll all the way to the bottom and paste the following line onto a blank line at the bottom followed by an enter: MOZ_USE_XINPUT2 DEFAULT=1

This will basically set the MOZ_USE_XINPUT2 environment variable to 1, which will force Mozilla applications (Firefox, Thunderbird etc) to use XInput2 instead of the legacy X11 input handling.
Once you’ve done that, you can save the file, after which is will ask for your password. It is normal that it asks for your password, because you are basically modifying a system file.
Once you’ve saved the file, you can close Kate and reboot your machine.
Extra educational fun fact: You can also use the command reboot or init 6 in the terminal to make your Kubuntu machine reboot 😊
Happy Browsing
And once you’ve rebooted your machine, your Firefox should now properly support swiping, gestures like zooming etc. So happy browsing, and I hope this small Linux/Firefox Touch tutorial was useful to you😊