Synergy - Avoid stuck modifier keys when undocking and redocking a laptop

Synergy is a very useful piece of software that allows two (or I suppose more) computers to share a keyboard and a mouse. One computer is configured as a server, one as a client, and the client computer can be then controlled with the server computer's input devices.

In my typical setup at work I have two Ubuntu computers (although I'm a Fedora user at home) - a desktop and a laptop with a dock. The desktop is configured as the server and the client is the laptop.

Everything basically would work until such time as I undocked and redocked the laptop. Without thinking too much about what I was doing or why - when it came time to go to a meeting I would simply undock the laptop and go. Usually undocking wasn't too much of an issue but when I returned to my desk on redocking the laptop it would sometimes (but not always) behave incorrectly.

The laptop would act as if some modifier key were permanently pressed. And up-arrow press might show "3A" on the terminal window. Left clicks on a browser would not have the expected effect. The effects were somewhat variable probably due to the laptop thinking one or another modifier key was being pressed.

Correcting the situation was also variable. In some cases hitting combinations of Shift, ALT, CTRL, etc. could correct the problem in some cases but in other cases not. Killing the synergy client and/or the server was most often not helpful. Undocking the laptop again would not correct the issue.

The only consistent way to solve the problem was to kill X on the laptop and start another X session.

The solution was as simple as it was, in retrospect, obvious. Stop Synergy on the laptop before undocking. I created some desktop shortcuts to turn Synergy on and off and put these shortcuts in my Gnome launcher. Once I started doing this the "stuck modifier key" problem has entirely gone away.

Without being able to give a complete technical explanation of what is going on - I can simply say that if you look at xev or something similar you will quickly see that pressing a modifier key results in two events - a Keypress event like so:

KeyPress event, serial 33, synthetic NO, window 0x2600001,
    root 0x2c6, subw 0x0, time 568359611, (91,49), root:(91,868),
    state 0x10, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

and a KeyRelease event like so:

KeyRelease event, serial 36, synthetic NO, window 0x2600001,
    root 0x2c6, subw 0x0, time 568359755, (91,49), root:(91,868),
    state 0x14, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 

    XFilterEvent returns: False

Presumably while synergy is running and during an undocking event a KeyPress event has been sent via synergy probably into X and the corresponding KeyRelease event gets lost. And once this occurs it is difficult (but not altogether impossible) to get  X back into a sane state no matter how many keys are pressed or released.

However by taking the simple precaution of stopping Synergy (and having some handy buttons to make this happen makes the process marginally easier) you can avoid the situation altogether.

In retrospect this is all rather simple, straightforward and one might even say obvious.

Post a Comment

Popular posts from this blog

Hit failing alternator with a hammer to confirm diagnosis of failing alternator due to bad brushes

alternatives --install gets stuck: failed to read link: No such file or directory

Using SSH, SOCKS, tsocks, and proxy settings to create a simultaneous "dual use" work/home computer