Ubuntu Touchpad Tap Action Swap: 2 & 3 Finger Gestures

Customizing Touchpad Click Behavior in Ubuntu
The standard configuration in Ubuntu assigns a two-finger tap to simulate a right-click and a three-finger tap to function as a middle-click on laptop touchpads.
While it's possible to reverse this functionality, Ubuntu lacks a dedicated graphical interface for making these adjustments.
Reversing the Click Configuration
Altering the touchpad click behavior is a straightforward process, achievable through the execution of a few commands.
However, ensuring these changes remain in effect after a reboot or resume from sleep necessitates a slightly more involved procedure.
This involves crafting a script and configuring GNOME to automatically execute it during system startup or upon waking from suspend.
Specifically, the script will need to apply the desired settings to ensure the customized click behavior is consistently applied.
Persistence and Automation
To maintain the modified settings, a script must be created.
This script will then be configured to run automatically whenever the system boots up or recovers from a suspended state.
This ensures that the preferred touchpad click configuration is consistently applied, providing a seamless user experience.
Image Credit: Michael Mol on Flickr
Reconfiguring Two- and Three-Finger Tap Actions
To modify the functionality of two- and three-finger taps on your touchpad, initiate a terminal session and execute the subsequent command.
synclient TapButton2=2 && synclient TapButton3=3
This command utilizes synclient to alter the touchpad's behavior.
Understanding the Command
The synclient commands specifically instruct the system to assign the action typically associated with a two-finger tap ("TapButton2") to action 2, which is a middle-click.
Similarly, the action linked to a three-finger tap ("TapButton3") is reassigned to action 3, corresponding to a right-click.
Upon successful execution, the assigned tap gestures will be effectively reversed.
Persistence Considerations
It's important to note that these changes are not automatically saved and will not survive a system reboot or a transition through suspend and resume states.
Therefore, to maintain the customized tap behavior, you will need to re-apply these commands each time your system restarts or wakes from sleep.
Ensuring Configuration Persistence
To retain this configuration across sessions, a dedicated script must be created and instructed to run by GNOME. Simply adding the script to your startup applications isn't sufficient, as Ubuntu may overwrite the touchpad settings upon system resume from suspend.
Begin by opening a text editor, such as Gedit, accessible through the Dash. This will serve as the environment for script creation.

Input the previously used commands into a new text file, structured as follows:
synclient TapButton2=2
synclient TapButton3=3
Save the file utilizing the .sh extension; for instance, touchpad.sh is a suitable name.

Once the file is saved, open a terminal and execute the following command to grant the script executable permissions. Remember to replace /home/name/touchpad.sh with the actual path to your script:
chmod +x /home/name/touchpad.sh

Subsequently, execute this command – again, substituting /home/name/touchpad.sh with the correct script path – to instruct GNOME to run the script whenever an input device is connected. This includes system boot and resume from suspend, ensuring persistent settings:
gsettings set org.gnome.settings-daemon.peripherals.input-devices hotplug-command "/home/name/touchpad.sh"
