Apple Magic Trackpad support

Hi! This is a guide of how to use the Apple Magic Trackpad in Qubes OS, and is specially meant for people like me who suffer from carpan tunnel.

It looks like touchpads and very thin keyboards are the only thing that save me from suffering this Wizard Wrist pain.

I really hate Apple, but I must admit that their Magic Trackpad worked incredibly well in their operating system. And, although I am one of those that hates touchpads, I have to say that the Apple Magic Trackpad is so well designed that I even prefer it over mouses.

I began my journey in Qubes OS a little bit more than 2 months ago. I migrated from the Apple Ecosystem. When I entered the Apple Ecosystem, I had a very problematic carpan tunnel syndrome. I had to use the left hand for the mouse.
Although I prefer my right hand, I am ambidextrous so it isn’t that a big deal right? Well, it turns out that my left hand won’t be free of this disease, so I will have this horrendous pain in both wrists. This sucks.
When I tried the Apple Magic Trackpad, hoping for my disease to disappear, IT WORKED. I mean, you can probably use a Logitech touchpad and you will also be fine. But I bought the Apple one because I was a very hardcore Apple fanboy (I bought TONS of different devices from them).
Using a touchpad results in my wrists not having that tension in the tendons or whatever suffers from that unnatural hand position, so I can continue hacking for hours and hours and hours. I cannot play more shooters or LoL tho…

So, if you have the same issue as me, I highly recommend you buying a touchpad (or if you use a laptop, stick to it).

In this tutorial, I will show you how I am setting up my Apple Magic Trackpad.
I don’t know if other different models differ from my config because I have never felt the need to replace this wonderful touchpad.
Also, this is my current config, but I will keep posting here more upgrades as I continue to upgrade my User eXperience until I reach something similar to macOS.

Man, the only thing I envy from Apple is their wonderful touchpad integration and their incredible battery life of their laptops. Hopefully in a future we have an ARM based QubesOS iso :c (IMHO more priority than Qubes Air, just sayin, dont get mad with me pls)

Okay, let’s start! First of all, I have to give @vxc credits for his solve at this post for pointing out those 2 files and the libinput thing.
I didn’t like the lack of detail of his solve, so this is the purpose of this post.

Let’s get this touchpad going:

  1. I first enabled trackpad going to the “Qubes Global Config” > “USB devices” > “Touchscreen/Tablet” > “enable”
  2. Then, in dom0 we install libinput-utils: sudo qubes-dom0-update libinput-utils
  3. Then, we list the trackpad in dom0: sudo libinput list-devices and the result is this:
Device:           sys-usb: Apple Inc. Magic Trackpad
Kernel:           /dev/input/event15
Group:            9
Seat:             seat0, default
Size:             162x115mm
Capabilities:     pointer gesture
Tap-to-click:     disabled
Tap-and-drag:     enabled
Tap drag lock:    disabled
Left-handed:      disabled
Nat.scrolling:    disabled
Middle emulation: disabled
Calibration:      n/a
Scroll methods:   *two-finger edge 
Click methods:    *button-areas clickfinger
Disable-w-typing: enabled
Disable-w-trackpointing: enabled
Accel profiles:   flat *adaptive
Rotation:         n/a

Device:           sys-usb: Apple Inc. Magic Trackpad
Kernel:           /dev/input/event16
Group:            10
Seat:             seat0, default
Size:             162x115mm
Capabilities:     pointer gesture
Tap-to-click:     disabled
Tap-and-drag:     enabled
Tap drag lock:    disabled
Left-handed:      disabled
Nat.scrolling:    disabled
Middle emulation: disabled
Calibration:      n/a
Scroll methods:   *two-finger edge 
Click methods:    *button-areas clickfinger
Disable-w-typing: enabled
Disable-w-trackpointing: enabled
Accel profiles:   flat *adaptive
Rotation:         n/a

As you can see in this line “Device: sys-usb: Apple Inc. Magic Trackpad”, this is my model.
You may have this one: “Device: sys-usb: Apple Inc. Magic Trackpad 2”. Keep that in mind.

  1. Last, config the 2 files shown by @vxc. I’m writing this data:

/etc/X11/xorg.conf.d/30-touchpad.conf:

Section "InputClass"
	Identifier "touchpad"
	Driver "libinput"
	MatchIsTouchpad "on"
	#Option "ClickMethod" "clickpad"
	#Option "ClickMethod" "buttonareas"
	#Option "ButtonMapping" "1 2 3"  # Optional: 1=left, 2=middle (3-finger), 3=right (2-finger)	
	Option "Tapping" "on"
	Option "TappingButtonMap" "lrm"
	Option "NaturalScrolling" "true"
	Option "ScrollPixelDistance" "20"
EndSection

Each field does the following:

  • Identifier "touchpad": This config affects touchpads
  • Driver "libinput": This config uses libinput
  • MatchIsTouchpad "on": Only apply this to touchpads
  • Option "Tapping" "on": I enable tapping because I like doing effortless clicks. This requires less surface pressure, therefore less wrist/fingers pain/fatigue. But I know that lots of you hate it. Disable it then with “off”.
  • Option "TappingButtonMap" "lrm" enables the following: 1 finger tap = left click | 2 finger tap = right click | 3 finger tap = middle click
  • Option "NaturalScrolling" "true": Scrolling down moves you up and viceversa, just like touchpads and touchscreens are intended to be used
  • Option "ScrollPixelDistance" "20": This is me trying to have a scroll that scrolls smoothly like in a macbook, instead of a scroll that scrolls 3 lines per scroll unit, like in a mouse wheel. It doesn’t seem to work well tho… Needs to be fixed
  • Ignore the commented lines, are not-finished experiments

/etc/libinput/local-overrides.quirks:

[Magic Trackpad pressure]
MatchUdevType=touchpad
MatchName=*Magic Trackpad
AttrPressureRange=1:0
  • MatchUdevType=touchpad This is a touchpad config
  • MatchName=*Magic Trackpad This config affects any touchpad which its name ends in “Magic Trackpad”
    • If your model was “Device: sys-usb: Apple Inc. Magic Trackpad 2”, replace it for MatchName=*Magic Trackpad 2
  • AttrPressureRange=1:0 Cursor movement starts when minimum pressure (1) is applied. Cursor movement stops when no pressure is applied (0)
    • I set up this sensitivity because i dont like pressuring the touchpad while moving my cursor. It’s a burden. I prefer effortless and no-friction UX.
  1. Reboot and everything will apply. For the moment, this is everything I’ve done.

TODO:

  • Make the scroll smoother, so it doesn’t behave like a mouse scroll that scrolls 3 terminal lines per scroll-unit. It MUST scroll smoothly like in a macOS or an iPhone, and this MUST work in every app opened in order to extremely increase user experience.
  • Add inertia to the scroll, so it keeps scrolling after you slide up or down for a moment until it stops completely (like in iPhones or a macBook) (stopabble by stepping one or more fingers in the touchpad). I guess we have to wait until the devs are able to port Qubes to Wayland. Anyways I will keep investigating about it.
  • For some reason, if you try to click and drag something (like moving a window) with a lot of pressure, the cursor will freeze. I’m trying to fix this. You will encounter this issue, at the moment you can try to move windows or select text by applying low pressure to your click or doing so by tapping (will always work)
  • Add the 3 finger gesture to move between desktops like in macOS

Cool things:

  • You can use the 3 finger tap to paste anything you’ve selected. This is an ultra-fast-way to paste things into the terminal.
  • You can move windows of apps opened in your desktop to the bottom by 3-finger-tapping their title bar. This is cool because it saves you a lot of 1-finger-taps/left-clicks bringing to the top the rest of windows you wanna focus.

Help me:

  • You can debug touchpad pressure and behaviour by running in dom0 this command: sudo libinput measure touchpad-pressure
2 Likes

You might Like Touchegg to enable trackpad gestures. You can do a three finger swipe to switch desktops, or trigger the app switcher (instead of apple’s expose) or dashboard (if you use xfdashboard).

1 Like

Things in your todo list and cool stuff are quite useful for all trackpad users, not just apple. Perhaps you could write another guide once you get there? :point_right: :point_left:

Although I guess this is generic xfce guide at this point, not qubes-specific.

This is middle-click behavior, one can do the same by clicking with a mouse scroll wheel. Very handy indeed.

As a matter of fact I’m fairly certain three-finger tap simply translates into middle click on xfce. At least in most circumstances.

This is new to me, thanks! And yes, it works with middle click as well.

1 Like

Thanks! I’ll take a look at it. I’ve also seen that it does exist libinput-gestures to do the same thing. I don’t know yet which I will implement but I’ll take a look at both!

Hey thanks!
Yeah, this is going very xfce specific, thats true.

I’ve made some advance in the Trackpad.
Now I am able to also use clicks instead of taps without issues, and I solved the Pressure of the Drag and Drop thing.

These are my files:

/etc/X11/xorg.conf.d/30-touchpad.conf:

Section "InputClass"
	# This config will only be applied to touchpads using libinput
	Identifier "touchpad"
	Driver "libinput"
	MatchIsTouchpad "on"

	# Button distribution:
	# - 1 finger = left click
	# - 2 finger = right click
	# - 3 finger = middle click
	Option "TappingButtonMap" "lrm"

	# Enable/disable tapping
	#Option "Tapping" "on"
	Option "Tapping" "off"

	# Enable clicking. If tapping is disabled, you SHOULD enable this
	Option "ClickMethod" "clickfinger"

	# Scroll up when doing a downwards 2-finger slide
	# Scroll down when doing an upwards 2-finger slide
	Option "NaturalScrolling" "true"
EndSection

Here, you can see that I added the Option "ClickMethod" "clickfinger" to enable clicks. This enables 1-finger clicks, 2-finger clicks and 3-finger clicks. They get the config specified in Option "TappingButtonMap" "lrm" (so this means that tapping and clicking will always inherit the same config).
By modifying the Option "Tapping" "<status>" you can enable/disable tapping, and also you can enable/disable clicking with the “ClickMethod” Option.
Personally, I’ve disabled tapping and went only for the clicks, but you can enable both and you will be fine. Just remember to have at least one enabled so your trackpad can do things hehe.

/etc/libinput/local-overrides.quirks:

[Touchpad pressure override]
# This config applies to the Apple Inc. Magic Trackpad
MatchUdevType=touchpad
MatchName=*Magic Trackpad

# Comment the upper MatchName and uncomment this if you are using the Apple Inc. Magic Trackpad 2
#MatchName=*Magic Trackpad 2

# Used to be able to move the cursor applying the minimal pressure to the touchpad
# This makes using the trackpad easier.
# - When a minimum pressure of 1 (the lowest existent pressure) is reached, the cursor is activated (for moving it)
# - When a maximum pressure of (touchpad surface is not being touched), the cursor is deactivated
AttrPressureRange=1:0

# Fixing pressure issue for drag and drop
# When running `sudo libinput measure touchpad-pressure`, you can observe
# that when reaching a `p` (pressure?) of 130, drag and drop stops working 
# because the cursor freezes until you release pressure to be under 130 again.
# Looks like `AttrPalmPressureThreshold` defaults its value to 130, a kind of a maximum
# pressure admitted to prevent accidental actions (like something falling over the touchpad)
# Lets max it to 250 to prevent us doing hard drag and drops
AttrPalmPressureThreshold=250

So, it appears that the Trackpad has a threshold of maximum pressure of 130, and when you reach that level of pressure or greater, the cursor stops working until that pressure returns to a lower value.
This is meant to prevent accidental clicks. For example, your phone falls over the trackpad. This prevents an accidental click.
I’ve discovered that value by runnning in dom0 sudo libinput measure touchpad-pressure and then dragging the cursor while slowly incrementing the pressure (p column), until I noticed that the limit was 130. Setting it to 250 has solved the issue and now I can drag and drop without issues while maintaining a decent ammount of threshold.

Research related to the smooth scroll:
It looks like the scroll functionality will scroll smoothly in the Terminal, but it will scroll a lot of lines per scroll unit in other apps like Mousepad or Librewolf. I’m starting to think that this cannot be solved via libinput config but rather configuring the apps themselves, but I’m not quite sure yet.
I’ll keep posting about this in the following days!

2 Likes

I’ve came to the conclusion that “High resolution scrolling” only affects dom0 when using a touchpad, but this High resolution scrolling won’t be passed to the rest of qubes.
There’s an open issue here: Support for high resolution scrolling · Issue #7942 · QubesOS/qubes-issues · GitHub
So I’m afraid this cannot be fixed by tweaking configs and we will have to wait for this to be implemented.
Maybe I can get my hands on the code.

On the other hand, the inertia of the scroll can be applied in libinput by using this 2 repos:

But I’m not working on these until the High Resolution Scrolling is implemented, because combining scroll coasting with a discrete scroll (3 lines per scroll unit) can be even a worse UX.

1 Like