2012-08-22

Using Mac Mini over VNC from Ubuntu/GNOME

If you are impatient, jump to the end and read the summary how I got things working.

Quite recently I started to play with iOS sofware development. Only challenge is that I have quite limited desk space at home and I definitely cannot fit two machines with keyboards and displays on my desk on the other hand I'm not big fan of KVM switches for connecting display, keyboard and mouse combination to multiple machines. To solve this I decided to try running headless Mac Mini with VNC server that comes as a part of OSX at least in Lion.

Things got started quite well. I connected Mac to my TV and attached a usb keyboard into it. Then I just went to "System Preferences" -> "Sharing" and enabled "Screen Sharing" on and allowed access to my user. Wonderful, could it be this easy? Nope.

After connecting with my VNC client, I realized that my keyboard was behaving quite strange way. My Finnish keyboard was emitting random keyboard events at Mac side. After testing few different VNC clients I realized that is is not a problem in my VNC client. I end up using Remmina Remote Desktop Client. It didn't really fix my keyboard problem, but it integrates much better with GNOME than most of the clients and it has few useful features over Vinagre (the default Remote Desktop Client in GNOME).

After using quite some time searching from web and testing different combinations, I finally got things working in acceptable level and there seems to be three overlapping problems when it comes to keyboard and keyboard layouts. Fourth problem was annoyance related to display resolution.

First problem: Mac keyboard layout for Finnish keyboard

As so often, Apple needs to be different in annoying ways and this time Mac defining completely different keyboard layout, at least when it comes to Finnish keyboard. It would be really awesome, if Apple would at least start supporting non-apple keyboard layouts, those that the rest of the world uses. For example Finnish Mac keyboard layout lacks the button that is located between left shift and z (button giving you <, > and |). In the end this didn't became a real issue, because I had to use English layout at Mac side, see the third problem.

Second problem: Win key behaviour at Ubuntu/GNOME

How Win key behaviour is configured in Ubuntu/GNOME by default seems to screw quite a lot at Mac side. To solve this issue change layout settings in Ubuntu side: System Settings -> Keyboard Layout then select Layouts tab and select Options. In Options view open "Alt/Win key behaviour" and instead of "Default" select "Meta is mapped to Left Win". This will break bringing up gnome-shell launcher, but you can access it still with Alt + F1 or map it somewhere else. Not optimal, but at least quite usable. If you don't do this, you will have both Windows and Left Alt mapped to Command key press at Mac side and your Option key is not available, instead of Windows key mapped to Option and Left Alt to Command.

Third problem: strange key press translations

This problem is a bit more weird. When using Finnish keyboard mapping in Ubuntu side and also at Mac side the whole mapping is quite broken, but there are few articles telling to use English (US) at Ubuntu side and your actual mapping at Mac side (for me Finnish). This way I was able to get fairly good experience, but there seems to be one problem that made this unusable for me. When pressing 8 from my keyboard it seems to produce correctly number 8 at Mac and keyboard viewer shows key press correctly. When I want to type opening parenthesis and I press Shift + 8 (in Finnish keyboard it is mapped to Shift + 8), as my surprise I get asterisk and keyboard viewer shows the key press of numpad asterisk. I'm not sure where this translation happens, but it was causing me some headache especially since I was using Mac for writing code and parenthesis is fairly commonly used. To solve this I realized that English (UK) keyboard layout is nicely in between Finnish and US layouts so that Shift + 8 is supposed to produce asterisk and opening parenthesis you get with Shift + 9. Since I'm going to use Mac only for writing some code, I don't mind if I can't access Scandinavian characters and I can reach acceptable level by configuring English (US) layout at Ubuntu side and British layout at Mac side. I also kept Finnish layout available at Ubuntu side and I use Left Alt + Left Shift key binding to switch between Finnish and English (US) layouts.

Fourth problem: screen resolution

This one is a bit annoying one. I have 1920x1080 resolution with my laptop and I would like to have my VNC server to use the same one.

In the beginning when I configured everything by using Mac through my TV that has 1920x1080 resolution, everything worked as expected until I disconnected Mac Mini and moved it to different room and restarted it.

After booting up, the device had lost 1920x1080 resolution option and was showing only 1680x1050 resolution and there seems to be no other way to get your 1920x1080 resolution defined except reboot your device always by connecting it to display that supports such resolution.

So in other words, looks like there is no fix for this one :(

Summary

These are the steps and configurations that I found giving best programming experience with Finnish keyboard on Ubuntu machine connected with VNC to Mac Mini.
  1. At Ubuntu/GNOME side go to "System Settings -> Keyboard Layout" and select "Layouts"  tab. Then open "Options..." and expand "Alt/Win key behaviour" and select "Meta is mapped to Left Win" (This will kill your gnome-shell launcher view toggling, but use Alt + F1 for it or bind some other key combination to this functionality).
  2. At same keyboard layout settings, add "English (US)" to available layouts. (At Options..., I also set "Key(s) to change layouts" to Left Alt + Left Shift)
  3. Configure Mac side key mapping to use "British" layout
  4. When rebooting your Mac Mini you end up having quite limited choice of resolutions and especially 1920x1080 (that I want to use) is not available.
To find where in the odd location your keys are expected to be found at Mac side, use keyboard viewer in top bar keyboard applet. If it is not visible enable it from: System Preferences -> Language & Text -> Input Sources and enable "Keyboard & Character Viewer" then you should have applet in the top bar.

Also when working inside a mac side, I have to make my VNC client to go into capture mode so that key events go completely into VNC client. Otherwise key presses are causing some unexpected characters. Remmina toggles capture mode by default with right ctrl. I hope this helps someone with similar problems, enjoy (regardless the fact that you are forced to use OSX).

No comments:

Post a Comment