Saturday, March 15, 2008

Getting synergy to work with a non-rectangular multiple screen setup.

So I like to work with multiple screens. I really do. These days, my setup at work looks like this one:

Short story: This CANNOT work properly with synergy's current code. Below you'll find a patch (for synergys) and a config file with which everything works as expected. THE PATCH IS NOT GENERIC AND MUST BE ADJUSTED IF YOUR SETUP ISN'T EXACTLY IDENTICAL.

Long story:
I really like to use my Mac, I don't want to bother with another keyboard/mouse to use my Linux workstation. And yes, I'm happy with the track pad of the Mac and don't need an external mouse or anything else other than my Mac (exception being when playing Q3, then I really need a mouse). Of course, synergy is the tool I need. Now it's not that simple. First, let's just have a quick look at part of my xorg.conf:
Section "ServerLayout"
Identifier "Default Layout"
Screen "Main Screen" Absolute 0 150
Screen "Secondary Screen" Absolute 1920 0
InputDevice "Generic Keyboard"
InputDevice "Configured Mouse"
Option "Xinerama" "on"
EndSection

Notice that Xinerama is on so I can have one huge desktop instead of two different window managers that can barely talk together. Notice also that the top-edges of both screens are not aligned.

Now let's try to setup synergys (s stands for "server") on my MacBook Pro and connect the client on the Linux workstation (with the synergyc command). I wrote the following naive configuration file:
section: screens
workstation:
macbook:
end
section: links
workstation:
down = macbook
macbook:
up = workstation
end

Which led me to the following setup:


This setup is uber-b0rken because of the way synergy seems to work. When I leave the screen of the MacBook from the upper edge, most of the time I will end up in the orange zone, where the mouse is actually considered to be on the workstation but isn't actually anywhere. It's just moving in a zone that can't be seen. So I have to move the mouse even further up to eventually see it appear on the 1st screen of the workstation. This is due to the non-rectangular nature of the setup, and due to the fact that synergy doesn't seem to be coded to handle that.

Another problem is that leaving the screen of the MacBook from the right-half-ish of the upper-edge makes the mouse enter the bottom of the 2nd screen of the workstation. This doesn't feel natural at all. Hopefully, in this case, we can adjust the behavior by telling synergy that when I leave the MacBook through the upper-edge, it should only enter the 1st screen. So, since synergy does not even seem to realize that the workstation has two screens, you tell it this by telling it that it should only enter the first 61% of the width of the bottom edge of the workstation "screen" (as seen by synergy, that is, in this case, a 3120x1920 virtual screen).

In a similar fashion, exiting through the bottom edge of the 2nd screen of the workstation isn't natural, so we can setup synergy with a similar behavior. So now the configuration file looks like this one:
section: screens
workstation:
xtestIsXineramaUnaware = false
macbook:
end
section: links
workstation:
down(0,60) = macbook
macbook:
up = workstation(1,61)
end

Notice that I don't start at 0% when leving the upper edge of the MacBook screen because I activated the top-left hot-corner of my Mac to enable the screen saver and I find it more convenient to just stuff the mouse pointer in there without worrying that pushing it too hard could let it slip through to the other screen. I also noticed that setting xtestIsXineramaUnaware to false helped a little bit (ref: synergy config guide).

It's getting better but it's still unusable. First off, there's this part of the screen where the pointer is just invisible. Admittedly, it's not that bad but it gets really annoying to have to move it around to eventually see where it was hidden. Personally, I can't live with that. The other major problem is that the 2nd screen of the work station has a huge band of 1200x150 unreachable pixels. You CAN'T move the mouse in there.

So, I really searched hard, I've read everything I could find on setting up synergy, but honestly, this setup just can't work with synergy's code. But I really want to use it this way. So I had a look at the code and tried to hack it to suit my needs. I eventually got it to work, and thought it could be useful to others. My patch, however, is NOT generic. It circumvents synergy's misbehavior only for my very specific setup with hard coded constants. I just don't have time to fix synergy properly. But. It could still be useful for others to modify my patch and achieve similar dirty-workarounds.

The patch is here. It also contains an additional workaround to simulate a border. This way, when trying to leave the 2nd screen from the left edge, you can't enter the invisible region. I find this handy.

Rebuild synergy with this patch, and use the binary cmd/synergys/synergys instead of you're distro's. The client (synergyc, on the workstation) does not need any change.

Hope synergy fixes their code. This isn't a trivial fix, it needs to completely change the way synergy parses its config file and handles remote screens. My suggestion for synergy developers (if this cool tool is still being developed) would be to change the config file format so that the user declares the size of the overall bounding box (in my case it's 3120x2250, 1200 + 900 + 150 = 2250) and then position each screen individually in within this huge bounding box and specify which range of pixels (no percentages please!) is mapped to which other edge of which screen on which range of pixels. And even though Xinerama might not help, please do consider each physical screen separately!

Hope this will be useful to others.

5 comments:

Anonymous said...

Have you tried Mango Lassi ?

It's a gnome-based thing to do just that, and it's really sweeter than Synergy, you probably want to code on that rather than on Synergy.

http://0pointer.de/blog/projects/mango-lassi.html

Anonymous said...

Well I to but I dream the post should acquire more info then it has.

Vianney said...
This comment has been removed by the author.
Vianney said...
This comment has been removed by the author.
Unknown said...

This is nice! thnx for the 'xtestIsXineramaUnaware = false' tip!