Toward a Linux touchpad as smooth as Macbook Pro

Update: After continuing to use my system, I opted for the Synaptics driver instead. Learn why in my follow-up.

As a longtime Macbook Pro user, I’ve grown an insatiable appetite for exceptional hardware+software implementations of laptop functionality like suspend/wake, bluetooth, wifi, and touchpad.  If there’s anything that my past Linux laptops taught me, it’s that these functions are not automatically perfect [insert shock here]. They seem easy & perfect only when they work flawlessly, and they work flawlessly only because Apple employs large teams of experts to test & polish the hardware/software interplay on a Macbook such that it feels perfect.

Since Apple gave me and the rest of the Developer community the heave-ho with its decisions on the latest generation of Macbook Pro [1], it has been a long & harsh journey toward getting a laptop experience that feels as flawless as my Macbook Pro did. But after weeks of experimentation, I wanted to share my current touchpad setup, which feels like it is approaching the buttery smoothness of my past Macbook Pros.

Touchpad options

There are two good articles on setting up a touchpad with Linux (Arch, Antergos, Debian, Ubuntu et al). As these articles explain it, there are three touchpad drivers available on Linux: synaptics (no longer supported), libinput, and mtrack. Preferring to avoid starting with abandonware, I narrowed my search down to libinput and mtrack. The choice between these options was made easier by reading the libinput philosophy not to implement features that aren’t likely to be needed by mainstream users. In their words: “In the old synaptics driver, we added options whenever something new came up and we tried to make those options generic. This was a big mistake… we’re having none of that” Practically speaking, this means that the limit of configurability in libinput is far more limited than the 1,001 settings offered by mtrack.

This isn’t to say that mtrack is a flawless choice. This is not a driver being supported and tested by teams of users & experts. It has no visual settings panel that I’m aware of, all configuration is done via text file. And the correct version to install is initially ambiguous. The officially developed version hasn’t been advanced since 2015, so a popular fork has taken up the torch in recent years. This is why Dayne’s Medium Post recommends installing directly via git. And I recommend the same.

Installing mtrack

Here are the basics to get the latest mtrack installed on your system:

cd /tmp
git clone https://github.com/p2rkw/xf86-input-mtrack.git
cd xf86-input-mtrack
./configure --with-xorg-module-dir=/usr/lib/xorg/modules
make
sudo make install

At this point you’ll have mtrack’s driver files built/installed, but Xorg still calls the shots in enabling it vs other drivers. By default, mtrack’s xorg configuration file gets placed in /usr/shared/X11/xorg.conf.d/50-mtrack.conf, which in my case meant its precedence was lower than both synaptics (placed in /etc/X11/xorg.conf.d, which takes precedence over the /usr/shared/X11/xorg.conf.d directory) and libinput (which initially had an alphanumerically lower file name (40-libinput.conf) than 50-mtrack.conf. To fix these issues, your best bet is to move your mtrack.conf file to a location/filename with higher precedence:

sudo mv /usr/share/X11/xorg.conf.d/50-mtrack.conf /etc/X11/xorg.conf.d/10-mtrack.conf

Once you’ve done these steps, mtrack should become your default touchpad driver after restarting X server. Of course, this being Linux, there is no single answer as to most easily restart X server. These people think that you can simply run startx, but that didn’t work for me without sudo, and when I ran it with sudo, I ended up setting root permissions on a file (~/.Xauthority) that prevented me from logging in. This well-rated response thinks you can sudo restart lightdm, which did work for me (albeit with different syntax since I’m on arch), but still ended up logging me out, so my official recommendation for re-starting X server is unfortunately to log out then log back in. At that point, if you run cat /var/log/Xorg.0.log | grep mtrack you should see a series of messages that show mtrack being loaded. If you don’t, this was the best thread I found for diagnosing what input driver is actually being used. If you find anything interesting, please do post it to the comments.

Crafting the dream touchpad experience

Once you get mtrack functional, then begins the process of creating a configuration file that best approximates Macbook Pro settings.  Here is my annotated config file:

# https://github.com/p2rkw/xf86-input-mtrack
Section "InputClass"
MatchIsTouchpad "on"
Identifier      "Touchpads"
MatchDevicePath "/dev/input/event*"
Driver          "mtrack"
# Sensitivity controls how fast your cursor will move. 1 is the default
Option          "Sensitivity" "1.1"
Option          "FingerHigh" "5"
Option          "FingerLow" "5"
Option          "IgnoreThumb" "true"
Option          "ThumbRatio" "70"
Option          "ThumbSize" "25"
Option          "IgnorePalm" "true"
# This ignores tap-to-click, which causes more problems than benefit in my experience
Option          "TapButton1" "0"
Option          "TapButton2" "0"
Option          "TapButton3" "0"
# If you want a middle-click, then "ClickFinger2" should be value "2"
Option          "ClickFinger1" "1"
Option          "ClickFinger2" "1"
Option          "ClickFinger3" "3"
Option          "ButtonMoveEmulate" "true"
Option          "ButtonIntegrated" "true"
Option		"ButtonEnable" "true"
# "ButtonZonesEnable" means that your trackpad gets divided into three equal sections, where clicking any third of the touchpad sends the click code in "ClickFingerX". Since I didn't want middle-click, the left two thirds of my touchpad are left click, and the right third is right click:
Option          "ButtonZonesEnable" "true"
Option          "ClickTime" "25"
# Ensures that bottom 5% of touchpad doesn't register taps
Option          "EdgeBottomSize" "5"
Option          "SwipeLeftButton" "8"
Option          "SwipeRightButton" "9"
Option          "SwipeUpButton" "0"
Option          "SwipeDownButton" "0"
Option          "SwipeDistance" "700"
# ScrollCoast makes touchpad feel a bit more Mac-like, although it coasts in chunks and isn't relative to speed at which two finger scroll was happening
Option          "ScrollCoastDuration" "600"
Option          "ScrollCoastEnableSpeed" "0.05"
# This sets up Macbook-like natural scroll. If you want to scroll down by swiping your fingers down, reverse the "5" and the "4" here:
Option          "ScrollUpButton" "5"
Option          "ScrollDownButton" "4"
Option          "ScrollLeftButton" "7"
Option          "ScrollRightButton" "6"
# Without this option set to a high value, there are types of click+hold-and-move functionality (most easily reproed by click and then move up-right) that get ignored
Option          "Hold1Move1StationaryMaxMove" "1000"
# Smaller ScrollDistance translates to faster scrolling. ScrollDistance of 10 scrolls a long page in one swipe.
Option          "ScrollDistance" "22"
Option		"ScrollClickTime" "12"
Option		"ScrollSensitivity" "0"
EndSection

In a more perfect world, Wordpest wouldn’t have removed the indentation in that block. It is not the world in which we live.

Future improvements

Compared to the miserable touchpad experience I had endured with synaptics and libinput, it has been delightful to get reliable two-finger scrolling that coasts, and to get my two-finger scroll speed comparable to what feels normal from my time in OS X. Still on my list to try to improve the configuration as I move forward:

  • Fix the couple pixels that touchpad tends to stray when I am setting down my thumb in an attempt to click (classic Linux touchpad annoyance)
  • When beginning a new scroll action while coast is active, scroll occurs at 10x normal speed
  • Setup two-finger scrolling to work as smoothly as OS X, rather than scrolling the page in small, discrete increments
  • Determine if it’s somehow possible to restart X server without getting logged out (unlikely, given how much Googling I’ve done on this topic)

Footnotes
[1] While the touch bar is as bad for programming as numerous developers predicted, it was minuscule amount key travel inherent in their butterfly keys that served as my breaking point. Honorable mentions to the laptop hard crashing every few days, and the touchpad that is so impossibly large as to occasionally pick up spurious input (although their software integration makes that problem occur a fraction as often as it would for a comparable Linux laptop)

13 Replies to “Toward a Linux touchpad as smooth as Macbook Pro”

  1. I used the same thing on my linux mint dell laptop, and it’s pretty decent. I am also shifting to linux because of the reasons mentioned above and this is as near to as I have seen. I just need your help with two things, how to get touchpad to cover slightly more distance than it does now in one swipe ?

  2. Hey Aniessh,
    I’m getting an error on ubuntu 18.04 when running make and add dependencies, can you help, please?
    jan@ThinkPad:/tmp/xf86-input-mtrack$ make
    make all-am
    make[1]: Entering directory ‘/tmp/xf86-input-mtrack’
    CC src/capabilities.lo
    In file included from ./include/capabilities.h:25:0,
    from src/capabilities.c:22:
    ./include/common.h:35:10: fatal error: mtdev-mapping.h: No such file or directory
    #include
    ^~~~~~~~~~~~~~~~~
    compilation terminated.
    Makefile:614: recipe for target ‘src/capabilities.lo’ failed
    make[1]: *** [src/capabilities.lo] Error 1
    make[1]: Leaving directory ‘/tmp/xf86-input-mtrack’
    Makefile:419: recipe for target ‘all’ failed
    make: *** [all] Error 2
    jan@ThinkPad:/tmp/xf86-input-mtrack$ sudo apt build-dep xserver-xorg-input-mtrack
    Reading package lists… Done
    E: You must put some ‘source’ URIs in your sources.list

  3. I can’t build it due to a old xorg-server. I get the following error:

    “configure: error: Package requirements (xorg-server >= 1.7 xproto inputproto ) were not met:

    No package ‘xorg-server’ found
    No package ‘xproto’ found
    No package ‘inputproto’ found”

    I’m using the latest elementary OS (0.4.1 LOKI)

    is there any work around?

    1. goto software sources in menu search for it
      in there enable source repo that is disabled by default
      then “sudo apt build-dep xserver-xorg-input-mtrack”

      build will not work if source repo is not enabled because you have to build it from source

  4. Im getting this error message when I run, “`cat /var/log/Xorg.0.log | grep mtrack“`

    [ 1195.543] (II) LoadModule: “mtrack”
    [ 1195.543] (WW) Warning, couldn’t open module mtrack
    [ 1195.543] (EE) Failed to load module “mtrack” (module does not exist, 0)
    [ 1195.543] (EE) No input driver matching `mtrack’
    [ 1195.582] (II) LoadModule: “mtrack”
    [ 1195.583] (WW) Warning, couldn’t open module mtrack
    [ 1195.583] (EE) Failed to load module “mtrack” (module does not exist, 0)
    [ 1195.583] (EE) No input driver matching `mtrack’

  5. I just wanted to say thank you. This is the most enjoyable experience I have had with my X1 Carbon machine since I got it more than 2 years ago 🙂

  6. I got my trackpad working very briefly when I rebooted my computer. However, the wifi was off. I reset the wifi, rebooted, and trackpad no longer worked. I literally was trying to reset sensitivity when this happened after and now it doesnt work. I followed all the above steps and found that my xf86-input-mtrack repo keeps deleting everytime I reboot the computer

  7. Hello,

    Thank you very much for your informative article !

    I really loved your article and it’s still relevant for me after installing Ubuntu 22.04 last week on my MacBook Pro 2015 with a ‘Dual-Boot’ option, so currently my main OS in usage is Ubuntu.

    I really like Ubuntu, but I’m a programmer, and miss a LOT a smooth touch-pad experience I have on my Mac OS Partition.

    Do you think your install guide is relevant for Ubuntu 22.04 (LTS) ?
    (I noticed the mentioned repo’s in the article did not updated in the last years, and I do not want to destroy my Ubuntu since It’s in usage for work)

    Thank you.
    Regards

Leave a Reply to praveen Cancel reply

Your email address will not be published. Required fields are marked *