torsdag den 30. maj 2013

Restoring multi touch gestures in Ubuntu 13.04 64-bit


I was annoyed with the fact that three finger move windows was removed (look here) - it was one of the best options in unity over kde or gnome (imho).

So, the steps below will reenable that gesture (and any other gestures you might need).

This post is based on the steps here:
http://task3.cc/1068/os-x-like-multitouch-gestures-for-macbook-pro-running-ubuntu-12-10/

1) Download the source for current unity:

sudo apt-get build-dep unity
cd /tmp
mkdir unity
cd unity
apt-get source unity
vi unity-7.0.0daily13.04.18~13.04/plugins/unityshell/src/unityshell.cpp

2) Go to line 3287, and comment out the code that intercepts the gestures:

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();
  */
} 

3) Compile the unity source (this can take a while):

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

4) Compile touchegg (and optionally set the MOVE_WINDOW delta - see last in this post):

cd /tmp
sudo apt-get build-dep touchegg
wget http://touchegg.googlecode.com/files/touchegg-1.1.1.tar.gz
cd touchegg-1.1.1
qmake
make
sudo make install

5) Create touchegg configuration file:

EDIT: If this is the first time you have touchegg installed, create this directory (thanks hpsjoshi+lauchpad):

mkdir -p ~/.config/touchegg

gedit ~/.config/touchegg/touchegg.conf

<touchégg>
        <settings>
                <property name="composed_gestures_time">0</property>
        </settings>
        <application name="All">
                <gesture type="PINCH" fingers="3" direction="OUT">
                        <action type="MAXIMIZE_RESTORE_WINDOW"></action>
                </gesture>
                <gesture type="TAP" fingers="4" direction="">
                        <action type="SEND_KEYS">Super</action>

                </gesture>
                <gesture type="DRAG" fingers="3" direction="ALL">
                        <action type="MOVE_WINDOW"></action>
                </gesture>
                <gesture type="PINCH" fingers="3" direction="IN">
                        <action type="MINIMIZE_WINDOW"></action>
                </gesture>
        </application>
</touchégg>

EDIT: added more ubuntu gestures (from here)

6) Log out, and log in again. Start 'touchegg' in a terminal to see it that it catches the gestures.

The output looks like this:

[+] New gesture: 
Type      ->  "DRAG" 
Fingers   ->  3 
Direction ->  "LEFT" 
Action    ->  "MOVE_WINDOW" 
App Class ->  "Terra" 
Gesture Start 
Gesture Update 0 "Drag" 
Gesture Update 0 "Drag" 
Gesture Update 0 "Drag" 
...

--------------

A) Optional step for touchegg gesture speed:

I found that the MOVE_WINDOW gesture is very slow (it moves in 0.1 increments when triggered). To fix this, change the delta value here in line 48+49:

src/touchegg/actions/implementation/MoveWindow.cpp:

            + attrs.value(GEIS_GESTURE_ATTRIBUTE_DELTA_X).toFloat() * 0.1,
            + attrs.value(GEIS_GESTURE_ATTRIBUTE_DELTA_Y).toFloat() * 0.1, 0);

I use 0.8 which works for fine for my touchpad speed:

            + attrs.value(GEIS_GESTURE_ATTRIBUTE_DELTA_X).toFloat() * 0.8,
            + attrs.value(GEIS_GESTURE_ATTRIBUTE_DELTA_Y).toFloat() * 0.8, 0);

After changing this, repeat step 4.

B) Optionally prevent any updates to Unity:

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

To revert and allow unity to be installed/updated again, issue this command:

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

I have attached my debs here for unity and the compiled touchegg + gui:

unity:
https://docs.google.com/file/d/0B-8oOtaMaSq3YVhBWVBMeXBvU1U/edit?usp=sharing
touchegg:
https://docs.google.com/file/d/0B-8oOtaMaSq3X0kxeExFc21KOHM/edit?usp=sharing
touchegg-gce (gui for touchegg)
https://docs.google.com/file/d/0B-8oOtaMaSq3THY0VGRBLTVmdDQ/edit?usp=sharing

-----------------

One last thing is to add an autostart entry for touchegg, this can be done in "Startup Applications", and just add '/usr/bin/touchegg' as command, and give it a name. Touchègg would be a good candidate ;)

The above works great for me on latest Ubuntu 13.04, and i recommend using the touchegg gui, it does an easy job creating new gestures.

And .. no warranties, this is probably not for the average user ;)