Configuring default resolution and color depth for RealVNC's vncserver-x11-serviced?

5,602

NOTE: I'm aware that this answer applies to the Virtual Mode of RealVNC rather than the Service Mode (vncserver-x11-serviced), but I think the Virtual Mode is generally more useful anyway, and it's the only one whose resolution can be changed dynamically. It's probably a pretty similar technique to change resolution for RealVNC when it's running in Service Mode.


After installing RealVNC (at the time of writing, version 5.2.1), applying a free license to it using vnclicense -add ..., and running the VNC server in its "Virtual Mode" (there are also Service and User modes which I won't go into here as it's complex enough already), I discovered how deep this rabbithole goes. :-) The documentation for this is far from comprehensive or obvious, and the only KB articles on RealVNC's site are somewhat dated (talking about the vncserver command instead of the apparent current recommendation, vncserver-virtual), or about changing the resolution dynamically with RandR during a session, not choosing what resolution should be used when the VNC server is started.

Firstly, the word "geometry" tends to be used in the context of The X Window System instead of the word "resolution". The default resolution given to you by the VNC server (or maybe X itself?) seems to be 800x600.

Now, you can pass parameters directly to the X Server when starting RealVNC's server manually from the commandline (or obviously in an automated way on boot from something like rc.local), and the param to pass to set the resolution is geometry. So, this will start a virtual RealVNC server instance with 1280x1024 resolution:

> vncserver-virtual -geometry 1280x1024

I usually run as root when I'm testing stuff like this, so I switch to the user whose desktop I want to VNC into first:

> sudo -u [someuser] vncserver-virtual -geometry 1280x1024

That requires passing a geometry parameter on the commandline, of course. RealVNC also supports configuration of the VNC service through various configuration files. However, confusingly, config for "Xvnc" (the underlying RealVNC server used on UNIX systems that communicates with X, and which needs to take the geometry config parameter) has to go in a different location from the "normal" RealVNC config files; either /etc/vnc/config.custom for server-wide settings, or ~/.vnc/config for user-specific settings. These are wholly separate from the other RealVNC config files and finding this out was pretty tough. As I said, the docs on this are terrible. So, in order to not have to specify resolution at the commandline, create the file /etc/vnc/config.custom and give it the following contents:

-geometry 1280x1024

Then when you run:

> sudo -u [someuser] vncserver-virtual

... the resolution for that VNC server instance will default to 1280x1024.

I assume this config file will also be used by the daemon vncserver-virtuald as well, for each of the vncserver-virtual instances it spawns (in fact it may be the only way to set the default resolution for the daemon), but as the daemon requires an enterprise license to use and I'm only using the free license, I couldn't test it.

Whew!


By the way, I mentioned RandR earlier. That's another way of getting a different resolution/geometry when connecting to the RealVNC server on UNIX systems. It only works when the RealVNC server is running in "Virtual Mode". It also allows dynamic changing of resolutions during the VNC session, and is somewhat better documented than the -geometry parameter stuff I mentioned above. :-) When this config setting is set (and it goes in the "normal" set of RealVNC config files, not those separate ones for Xvnc... go figure), you should be able to use the xrandr command from within the VNC session to change the resolution dynamically to one of the resolutions specified in the RandR setting.

Share:
5,602
Jez
Author by

Jez

Long-time coder, with some interest in French and Philosophy. I sometimes hang out in the English Language & Usage chatroom. Check out my Firefox addons! :-)

Updated on September 18, 2022

Comments

  • Jez
    Jez over 1 year

    When searching the web for information about how to configure the default resolution and color depth for RealVNC sessions, I always come across stuff that talks about passing commandline parameters to vncserver, such as vncserver -geometry 1024x768 or something. However, I have my system configured to start the RealVNC server on boot (for runlevels 2-5; I'm using Debian) via the /etc/init.d/vncserver-x11-serviced script that RealVNC installs; I'm not using the vncserver command. How do I configure this to have a particular default resolution and color depth? Is there a config file somewhere I can use?