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

hey @tnt !
Thank you so much for the extensive documentation on this issue and trying to fix this!
May I ask if you made any progress already regarding PRing code to the QubesOS Project ?

You’re points regarding Mac’s Touchpad UX are well in line with my own, and I almost considered not migrating to QubesOS because of it, but then I was reminded that I wanted to use a keyboard-driven Tiling Window Manager any ways, so this actually turned into an opportunity to focus more heavily on using the keyboard (which I always wanted). So the past few hours I have been driving MacOS - well mostly Firefox - with the keyboard; I learned about many new commands and it feels way more ergonomic - and if keyboard-based navigation works similarly smoothly on QubesOS I think we can successfully side-step this ā€˜issue’.

So maybe we don’t need a Mouse - most of the time - any ways!

1 Like

Heyy what’s up

Nah man, I did some code but nobody replied to my questions in the git issue conversation, so I got frustrated and just stopped coding.

Anyways, I also switched to a dynamic tiling window manager: i3. It’s the one officially supported. If you manage to install rofi, you can almost do everything of qubes related things keyboard driven. i made a post of my rofi config for qubes and in another post i showed my i3 desktop, looks nice to me.

I also switched to a keyboard with a trackpoint, like the Thinkpad ones. My keyboard is a Tex Shura and it feels great. You only need 1 week forcing yourself to use it to get used to it. Using a good trackpoint is definetely a game changer.
If you ever buy one of these, you will probably need to do a little tweak in the USB Guard of Qubes OS so it does not get blocked in the LUKS prompt (easy to fix tho, this happens because the keyboard contains a mass storage device embedded inside that you can use to create custom macros and shit like that).

Cool shortcuts for firefox i use a lot:
Ctrl+W close tab
Ctrl+T creates tab
Ctrl+L edit url path
Ctrl+R reload
Ctrl+Shift+R reload and refresh cache i think
Ctrl+Tab go to next tab
Ctrl+Shift+Tab go to previous tab
Alt+Left go to previous page
Alt+Right got to the next page (inverse of Alt+Left)

Btw if you feel brave, you should try out yazi, is a file manager fully keyboard driven. I may post some shit to do qvm-copy-to-vm automatically from there without needing to spawn a terminal to type that command.

If you switch to Qubes OS with i3, follow the install guidelines of i3.
Then install

  • A notification daemon (i use dunst). This is non negotiable, you will need this, internal tooling of Qubes OS breaks if it can’t send notifications, like for example Qubes Video Companion.
  • An app launcher. I use rofi. You could live without this, but it will make your UX infinetely worse. Btw, you are meant to customize it, rofi by itself sucks. a template i made can be found here: HOW-TO: Rofi - XFCE-like menu i should update it tho
  • Customize your i3 to add custom keybinds for everything: Screenshots for example
  • Improve existing keybinds: Ctrl+Shift+C for copy to the global clipboard feels bad for me, as it makes impossible to copy from terminal. I use Win+C instead. Same for Global Clipboard paste
  • A wallpaper process like feh, or a custom solution. I use a custom solution to have a terminal as a wallpaper running a cmatrix
  • Then, make UI decision that ease up your life. I have color blindness (apart from the carpal tunnel), so I set window borders in colour tones that i won’t mistake (yeah, I am a fucking disgrace of human being lol). And
  • Last step, make it look cool as fuck so we don’t go back to macOS How long did it take you to get used to Qubes? - #31 by tnt

Now you should be able to do almost everything with keyboard with no dependency-errors in qubes os. all dependencies i mentioned can be installed with sudo qubes-dom0-update, so it should be easy to set up. Hardest part is customizing your actual desktop, which can take you 1-2 weeks.

I mean, deep inside, I fucking love macOS UX/UI decisions, but being able to fully keyboard-drive my computer with a nice looking UI feels fucking great man.

If one day I have some spare time not fucking wasted in being miserable I may end up posting a tutorial of i3 with Qubes OS to fully keyboard control your computer without the need of a mouse.

1 Like

Haha, that’s funny - those are basically the exact shortcuts I noted down when I first tried navigating Firefox purely by keyboard a few days ago!Plus, using Cmd + F to find links and load them, and Cmd + Shift + T to reopen closed tabs.

Though I will try out Vimium-FF to use the browser like vim.

Did you also try AwesomeWM? It seems maybe easier to customize and has official Qubes OS plugin as well.

Nice tip on the trackpoint ; never used one before ! Do you know of other fine TrackPoint keyboards? $300 is a bit pricey for something I’m not entirely sure about. I might stay with the mac keyboard but was looking at some low-profile options like the full Logitech MX Keys, maybe mechanical ones. But I’m guessing standard keyboard drivers might not be secure enough for Qubes, so a hardware-programmable keyboard is probably the way to go?

Since you also appreciate good aesthetics and ergonomics: is it possible to run f.lux on Qubes, or find a way to take advantage of a Mac’s ambient light sensor?

Also I’m hoping to find and transition to TUI apps for most of my everyday needs, which might also be easier on RAM.