26 October 2019

Make the Macbook touchpad works like MacOS (a modern and definitive guide)

There's a lot of tutorials about that on the internet, I'll try to be as much distribution-agnostic as possible. If your distribution doesn't the package that I'm talking about, you should search elsewhere or compile yourself.

Requirements:

A working Xorg (not sure if works with wayland) and a working DE/WM
xbindkeys
xdotool
dispad
mtrack driver

Recipe:

Uninstall whatever the touchpad driver you're using, like synaptics, and install mtrack. And use the following configuration for that (in /etc/X11/xorg.conf or /etc/X11/xorg.conf.d/10-mtrack.conf):

Section "InputClass"
        MatchIsTouchpad "on"
        Identifier      "Touchpads"
        MatchDevicePath "/dev/input/event*"
        Driver          "mtrack"
        # The faster you move, the more distance pointer will travel, using "polynomial" profile
        Option          "AccelerationProfile" "2"
        # Tweak cursor movement speed with this
        Option          "Sensitivity" "0.08"
        # Pressure at which a finger is detected as a touch
        Option          "FingerHigh" "5"
        # Pressure at which a finger is detected as a release
        Option          "FingerLow" "5"
        # I often use thumb to press down the physical button, so let's not ignore it
        Option          "IgnoreThumb" "true"
        Option          "ThumbRatio" "70"
        Option          "ThumbSize" "25"
        # Ignore palm, with palm takes up to 30% of your touch pad
        Option          "IgnorePalm" "true"
        Option          "PalmSize" "30"
        # Trigger mouse button when tap: 1 finger - left click, 2 finger - right click, 3 - middle click
        Option          "TapButton1" "1"
        Option          "TapButton2" "3"
        Option          "TapButton3" "2"
        Option          "TapButton4" "0"
        Option          "ClickTime" "25"
        # Disable tap-to-drag, we're using three finger drag instead
        Option          "TapDragEnable" "false"
        # While touching the touch pad with # fingers, press the touchpad physical click button
        Option          "ClickFinger1" "1"
        Option          "ClickFinger2" "3"
        Option          "ClickFinger3" "2"
        Option          "ButtonMoveEmulate" "false"
        Option          "ButtonIntegrated" "true"
        # The momentum after scroll fingers released
        Option          "ScrollCoastDuration" "300"
        Option          "ScrollCoastEnableSpeed" ".1"
        # Natural scrolling with two fingers
        Option          "ScrollSmooth" "true"
        Option          "ScrollUpButton" "5"
        Option          "ScrollDownButton" "4"
        Option          "ScrollLeftButton" "6"
        Option          "ScrollRightButton" "7"
        # Tweak scroll sensitivity with ScrollDistance, don't touch ScrollSensitivity
        Option          "ScrollDistance" "250"
        Option          "ScrollClickTime" "10"
        # Three finger drag
        Option          "SwipeDistance" "1"
        Option          "SwipeLeftButton" "1"
        Option          "SwipeRightButton" "1"
        Option          "SwipeUpButton" "1"
        Option          "SwipeDownButton" "1"
        Option          "SwipeClickTime" "0"
        Option          "SwipeSensitivity" "1500"
        # Four finger swipe, 8 & 9 are for browsers navigating back and forth respectively
        Option          "Swipe4LeftButton" "9"
        Option          "Swipe4RightButton" "8"
        # Mouse button >= 10 are not used by Xorg, so we'll map them with xbindkeys and xdotool later
        Option          "Swipe4UpButton" "11"
        Option          "Swipe4DownButton" "10"
        # Mouse buttons triggered by 2-finger pinching gesture
        Option          "ScaleDistance" "300"
        Option          "ScaleUpButton" "12"
        Option          "ScaleDownButton" "13"
        # Mouse buttons trigger by 2-finger rotating gesture, disabled to enhance the pinch gesture
        Option          "RotateLeftButton" "0"
        Option          "RotateRightButton" "0"
EndSection






By now, your trackpad will be working with a lot better. Pay attention to the comments if you need to customize. Now we'll create a map for what we still need. You can adjust the modifiers to fit your needs, or just remap then in your DE/WM. Create a $HOME/.xbindkeysrc with this:

# Next Workspace (Swipe4Left)
"xdotool key --clearmodifiers Control_L+Alt_L+Left"
   b:8
# Previous Workspace (Swipe4Right)
"xdotool key --clearmodifiers Control_L+Alt_L+Right"
   b:9
# Desktop Grid (Swipe4Down)(F4 key)
"xdotool key --clearmodifiers XF86LaunchA"
   b:11
# Toggle Present Windows (Current Desktop) (Swipe4Up)(F5 key)
"xdotool key --clearmodifiers XF86LaunchB"
   b:10
# Zoom in
"xdotool key ctrl+21"
   b:12
# Zoom out
"xdotool key ctrl+20"
   b:13


Dispad have a better touchpad-ignore than mtrack, so we're using it. Create this configuration at $HOME/.dispad (I know, it could be .dispadrc but the default is .dispad so I'll keep it):

# name of the property used to enable/disable the trackpad
property = "Trackpad Disable Input"
# the value used to enable the trackpad
enable = 0
# the value used to disable the trackpad
disable = 1
# whether or not modifier keys disable the trackpad
modifiers = false
# how long (in ms) to sleep between keyboard polls
poll = 48
# how long (in ms) to disable the trackpad after a keystroke
delay = 500


With the files in place, now we need to create a $HOME/.xprofile:

xbindkeys -f $HOME/.xbindkeysrc
dispad -c $HOME/.dispad

Reboot



Sources used:

https://int3ractive.com/2018/09/make-the-best-of-MacBook-touchpad-on-Ubuntu.html
https://bill.harding.blog/2017/12/27/toward-a-linux-touchpad-as-smooth-as-macbook-pro/