os x-like multitouch gestures for macbook pro running ubuntu

2012-10-25

Ubuntu 13.04 Raring Ringtail fits well on my Macbook Pro. Now we can even have a better fan management system for your Macbook.

What I still was missing from OS X is a good set of touchpad gestures. Sure, Unity has builtin support for 2, 3, and 4-fingers drags and tap. However, I don’t like how they are configured. Yet, it is impossible to configure these gestures anywhere.

On the other hand, the Touchégg project is an amazing manager for the gestures. Unfortunately, there are issues with Unity, which has got precedence with its hardcoded gestures. There is an increasing demand to either configure or disable Unity builtin multitouch gestures.

In this post, I will show how we can disable Unity default multitouch gestures and bring in OS X like touchpad gestures.

Prerequisites

There are two prerequisites plus an optional one.

  1. To have a Macbook like keyboard configuration.

  2. To enable the virtual desktops (workspaces) in Ubuntu 13.04

  3. To set the 4 Unity virtual desktops to be all on a single row (4x1) instead of the default (2x2) grid.

dconf write /org/compiz/profiles/unity/plugins/core/hsize 4
dconf write /org/compiz/profiles/unity/plugins/core/vsize 1
  1. Optional: reverse, natural scrolling a la OS X Lion+.

Disable Unity built-in gestures

This section is based on an askubuntu question and two answers to it: one written by user domster and the other one written by myself.

We obtain Unity sourcecode with the following:

sudo apt-get build-dep unity
cd /tmp
mkdir unity
cd unity
apt-get source unity

To disable its built-in multitouch gestures, we open the file

/tmp/unity/unity-*/plugins/unityshell/src/unityshell.cpp

with a text editor (e.g., gedit or Sublime Text 2).

After we locate the method

UnityScreen::InitGesturesSupport()

(line 3381 for Unity 6.10.0, line 3287 for Unity 7.0.0), we comment all the lines starting with

gestures_

.

This is how it will look like:

void UnityScreen::InitGesturesSupport()
{
  std::unique_ptr<nux::gesturebroker> gesture_broker(new UnityGestureBroker);
  wt->GetWindowCompositor().SetGestureBroker(std::move(gesture_broker));
  /*
  gestures_sub_launcher_.reset(new nux::GesturesSubscription);
  gestures_sub_launcher_->SetGestureClasses(nux::DRAG_GESTURE);
  gestures_sub_launcher_->SetNumTouches(4);
  gestures_sub_launcher_->SetWindowId(GDK_ROOT_WINDOW());
  gestures_sub_launcher_->Activate();

  gestures_sub_dash_.reset(new nux::GesturesSubscription);
  gestures_sub_dash_->SetGestureClasses(nux::TAP_GESTURE);
  gestures_sub_dash_->SetNumTouches(4);
  gestures_sub_dash_->SetWindowId(GDK_ROOT_WINDOW());
  gestures_sub_dash_->Activate();

  gestures_sub_windows_.reset(new nux::GesturesSubscription);
  gestures_sub_windows_->SetGestureClasses(nux::TOUCH_GESTURE
                                         | nux::DRAG_GESTURE
                                         | nux::PINCH_GESTURE);
  gestures_sub_windows_->SetNumTouches(3);
  gestures_sub_windows_->SetWindowId(GDK_ROOT_WINDOW());
  gestures_sub_windows_->Activate();
  */
}

We re-build Unity .deb packages and install them in our system.

cd /tmp/unity/unity-*
dpkg-buildpackage -us -uc -nc
cd ..
sudo dpkg -i *deb
sudo apt-get -f install
sudo apt-get autoremove

Optionally, we may want to block upgrades to Unity packages. In this way, we do not have to repeat the patch steps every time an upgrade is released. However, we might miss important bug fixes.

What follows blocks updates to Unity:

echo "unity hold"|sudo dpkg --set-selections

After a logout and a login, we can see that (among the others) Unity 3-fingers drag gestures has disappeared.

Install Touchégg and enable OS-X like gestures

First, we download Touchégg source code and unpack it. Please note that the following instructions can be obtained in Touchégg documentation.

We install the required dependencies to compile Touchégg.

sudo apt-get build-dep touchegg

We compile touchégg and install it. Give the following commands inside touchégg source folder.

qmake
make
sudo make install

The following is a good starting configuration file for touchégg, which should be placed in

~/.config/touchegg/touchegg.conf

(create the directories if they do not exist).

<touchégg>
        <settings>
                <property name="composed_gestures_time">0</property>
        </settings>
        <application name="All">
                <gesture direction="RIGHT" type="DRAG" fingers="3">
                        <action type="SEND_KEYS">Control+Alt+Left</action>
                </gesture>
                <gesture direction="LEFT" type="DRAG" fingers="3">
                        <action type="SEND_KEYS">Control+Alt+Right</action>
                </gesture>
                <gesture direction="DOWN" type="DRAG" fingers="4">
                        <action type="SEND_KEYS">Super+s</action>
                </gesture>
                <gesture direction="UP" type="DRAG" fingers="4">
                        <action type="SEND_KEYS">Super+w</action>
                </gesture>
        </application>
</touchégg>

With this starting configuration, we change virtual desktop using 3-fingers drags (LEFT and RIGHT); we see the currently active windows using 4-fingers up drags; we invoke the Expo of all the 4 workspaces using 4-fingers down drags.

Feel free to change the config following Touchégg instructions regarding gestures and actions.

We can also employ Touchegg-gce, a graphical program to configure Touchégg.

To automatically start Touchégg when Unity starts, we create the file

~/.config/autostart/touchegg.desktop

with the following content.

[Desktop Entry]
Version=0.1
Name=Touchegg
GenericName=Touchégg
Comment=Touchégg Gestures Manager
Exec=/usr/bin/touchegg %u
Terminal=false
Type=Application

Another logout and login is required.

What next?

More sophisticated gestures like pinch-to-zoom can be configured on an application basis (e.g., Firefox, Chromium).

However, gestures like

PINCH

do not work at the moment. We probably have to wait the Ubuntu Mactel team to release

xf86-input-multitouch

and

xserver-xorg-input-synaptics

packages for Ubuntu 12.10. I will update this post if needed.

Extra

Douglas Galetti Ribeiro was so kind to post a high-res video on Youtube illustrating what this post enables. Although it is in Portuguese, the video and his hand gestures are pretty clear. Being Italian, I understand much of it. Thank you Douglas for taking the time to make the video and to link to this article.

http://www.youtube.com/watch?feature=player_embedded&v;=7mvN9sSCeOs


I do not use a commenting system anymore, but I would be glad to read your comments and feedback. Feel free to contact me.