Tuesday, October 20, 2015

Synergy on Raspberry Pi


This article was written while Synergy version 1.7.4 was the latest version, I'll try to keep this up to date with new Synergy released, check the end of the article for a change log.

The latest version of Synergy at the last update of this article is: 1.7.6

I love to use Synergy when I'm working on multiple PC's at the same time. It lets you control multiple computers with a single keyboard and mouse. You just move your cursor off one side of your monitor and it appears on the device next to it and keyboard redirects keyboard input as well, neat!
So when I ended up with a second pair of input devices on my desk because of my new Raspberry Pi, having it use Synergy was pretty high on my wish list :)

The standard Synergy client you can get using apt-get is pretty old. It's version 1.3.something whereas the current version is 1.7.4, so that's not going to work. I found this tutorial on how to compile Synergy from source, but that article is outdated as well. Fortunately compiling it isn't that difficult. It's a pretty well documented process, but it doesn't exactly specify which dependencies there are. So here we go!

Step 1: update apt-get

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install gcc cmake libx11-dev libxtst-dev qt4-dev-tools libcurl4-openssl-dev libssl-dev libavahi-compat-libdnssd-dev


The documentation also mentions python and gmake as a dependency but I think those are included in a clean Raspbian installation. I also ran into some problems related to ZeroConf (missing headers), those seem to be included with libavahi.

Step 2: get the source code

Even though you'll need to pay for Synergy nowadays (if you want binaries) you can still get the source code for free: https://github.com/synergy/synergy or you can get a tar.gz from the download page (after a login).
If you have git installed, you can do

git clone https://github.com/synergy/synergy.git

Or get the tar.gz and run

tar -xzf synergy-v1.7.4-stable-c734bab-Source.tar.gz

Enter the folder that was created.

Step 3: build it

Start by configuring the build

sudo ./hm.sh conf -g1

This will generate the needed build script and will check if all prerequisites are present. When that completed successfully you can start the actual build.

sudo ./hm.sh build

This took about an hour to complete on my RPi 2B, so grab some lunch or diner while it's compiling. When it completed successfully, the binaries will be in the ./bin folder.

Step 4: deploy it

This is just a matter of copying the binaries:

sudo cp -a ./bin/. /usr/bin

Step 5: configure it

From this point on you can just follow the adafruit article. The only difference is that I didn't have a ~/.config/lxsession/LXDE folder, it's called LXDE-pi on my RPi instead.

sudo touch ~/.config/lxsession/LXDE-pi/autostart
sudo nano ~/.config/lxsession/LXDE-pi/autostart


And add the following content to the autostart file:

~/.startsynergy.sh

Exit nano (ctrl + x) and make sure you save the changes. This calls the startsynergy script whenever you start LXDE (Lightweight X11 Desktop Environment).
Now create the startsynergy script:

sudo nano ~/.startsynergy.sh

And add the following content:

#!/bin/bash

killall synergyc
sleep 1
synergyc --name pi 192.168.0.16
exit 0


This stops all running Synergy clients. It then starts a new Synergy client. "pi" is the name of the client, you'll need this name when you configure the Synergy server. The IP address needs to match that of your Synergy server.
Finally you'll need to set the rights on the newly created script:

sudo chmod 777 ~/.startsynergy.sh

Step 6: use it!

startx

 RPi on the leftmost monitor, showing the Jenkins dashboard in the browser. The other four are from my main PC (left to right: SourceTree, Eclipse, Jira and Notepad++). And one keyboard/mouse to rule them all! :)

Changelog:
2016-01-05: v 1.7.5 tested, no changes needed.
2016-03-29: v 1.7.6 tested, no changes needed.