Breaking Code

September 8, 2010

A dual screen hack: x2vnc

Filed under: Just for fun — Tags: , , , , — Mario Vilas @ 6:30 pm

Today I just had to use two laptop computers simultaneously, and switching back and forth was driving me insane. Then I remembered an old trick I used to pull back at my old job: the dual screen hack.

Most of you probably know it already, but just in case, here goes the explanation. You can connect two computers and simulate what would happen if you had two monitors instead: when the mouse leaves the screen in one computer, it “enters” the other computer on the opposite side of the screen. For example, if you have two laptops on your table and you move the mouse to the right, after reaching the border of the screen you see it coming out on the left side of the other computer. 🙂

The magic is done by using a remote desktop protocol like VNC, which lets you send keystrokes and mouse events, but discarding the framebuffer updates. That is, a program that connects to the remote desktop, but instead of showing you the remote screen, it monitors mouse movements locally and when the mouse reaches the screen limits, it captures the mouse and starts sending mouse events to the remote system. Similarly, when the mouse reaches the opposite limit on the remote system, it stops capturing the mouse so you can use it on the local system.

Since I use Linux my choice was x2vnc, the Linux cousin of the more famous Win2VNC, also by the same author. But unlike Win2VNC which is now actively maintained at SourceForge, x2vnc seems to have been abandoned.

x2vnc supports SSH tunneling, which is just perfect since VNC is a plaintext-only protocol and insecure by design. However there’s no easy way to tell x2vnc to which port to connect or which username to login as – it defaults always to the current local user and port 22.

I also had a problem with my other laptop, which had Windows 7. When the mouse cursor leaves the screen, it is “parked” to a corner of the screen so it doesn’t show (it’d be confusing to see two mouse cursors as you wouldn’t know which one is active). But the corner chosen by x2vnc is always the lower right corner, causing Windows 7 to hide all active windows… very annoying.

So I did what any other geek would do in my situation – branch it! 😀

The patched code is now at Google Code Github. The new command line switches I added were:

-sshuser: Log in to the SSH tunnel using the given username.

-sshport: Connect to the given TCP port number instead of the SSH default (22).

-restingx and -restingy: Tell x2vnc where to park the mouse cursor. A value of 0 means left or top, a value of -1 means right or bottom. Then for example, -restingx 0 -restingy -1 means the top right corner of the screen.

Enjoy! 🙂


Source code:


  1. Also, see synergy ( which is similar

    Comment by D — September 8, 2010 @ 7:54 pm


    Comment by D — September 8, 2010 @ 7:54 pm

  3. […] This post was mentioned on Twitter by Mario Vilas, xanda. xanda said: A dual screen hack: x2vnc […]

    Pingback by Tweets that mention A dual screen hack: x2vnc « Breaking Code -- — September 9, 2010 @ 2:31 pm

  4. At least as far as I know Synergy doesn’t directly support SSH tunneling, so I’d have to build the tunnel manually. 😦

    I do like how they reversed the client-server relationship, though, and it’s much better to handle multiple computers…

    Comment by Mario Vilas — September 9, 2010 @ 5:01 pm

  5. […] under: Just for fun Tagged: Debian, LinkedIn, linux, open source, tool Breaking Code This entry was posted in Breaking Code and tagged dual, hack, screen, x2vnc. Bookmark the […]

    Pingback by A dual screen hack: x2vnc | — January 23, 2011 @ 10:58 pm

  6. Awesome, just what I was looking for – going to give this a go right now. many thanks

    Comment by Jackpot247 — September 22, 2011 @ 4:11 pm

  7. […] to this post by Mario Vilas, I realized this is due to the ‘Aero Peek‘ feature. His approach was to […]

    Pingback by :: Disable Aero Peek when using x2vnc — September 29, 2011 @ 3:59 pm

  8. nice work!

    Comment by derp — December 31, 2014 @ 2:08 am

  9. Any chance you could share the code for this someplace new? Google Code links are broken, but your patches look really useful.

    Comment by Brian — May 27, 2016 @ 2:05 am

  10. Hi, Brian. I’ve migrated the code to Github, here:

    Comment by Mario Vilas — May 27, 2016 @ 8:38 am

  11. I also noticed this problem. I’m trying turning off the Windows 10 setting in taskbar settings: “use Peek to preview the desktop when you move your mouse to the Show desktop button at the end of the taskbar”.

    reference articel:

    Comment by endosynth — February 16, 2017 @ 3:39 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: