Sunday 7 June 2015

tightvnc and vino study

I decide to work on vnc due to the necessary to work at home using the graphic interface. I think the main reason to display the whole thing remotely is because X11 forward is still too slow, at least for matlab figures.


1. Install vnc.
# Make sure Debian is the latest and greatest:
# be noticed
# http://raspberrypi.stackexchange.com/questions/4474/tightvnc-copy-paste-between-local-os-and-raspberry-pi
apt-get install xorg lxde-core tightvncserver 

# Start VNC to create config file for password (run as a normal user)
tightvncserver :1
# Then stop VNC
tightvncserver -kill :1
# Edit config file to start session with LXDE:
vim ~/.vnc/xstartup
# Add this at the bottom of the file:

#!/bin/sh
xrdb $HOME/.Xresources
#xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
#/etc/X11/Xsession
#lxterminal &
#/usr/bin/lxsession -s LXDE &
exec openbox-session &
#--------------  openbox -----------------------------
#!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid grey
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
openbox &
# ------   working for twm  ------
xrdb $HOME/.Xresources
xsetroot -solid grey
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
# --------------------- a working solution for i3----------------------------
xrdb $HOME/.Xresources
xsetroot -solid grey
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
i3 &


and make sure this file is executable.


# Restart VNC
tightvncserver :1   # working for a debian distro but not on gentoo distributions..

for the client, the things that are needed to execute is
1. openup vnc, for example the app within chrome and input
192.168.0.4::5901


for the office (gentoo) machine, i use
 vncviewer ae429-1105:1  #from a ssh that connects to office.

vncserver :1 -geometry 1440x900 -depth 24  # start the server
pkill Xvnc # stop
vncserver -geometry  1680x1010 -depth 24 :1  # works perfectly with office machine

2. Solving X11 forward problem when using tightvnc combining with tmux.
The problem of using this conbination is that at tightvnc when attaching a seesion that was used to be working locally (i.e., DISPLAY=:0), all the X11 pops out locally rather than the window from tightvnc. The way of solving such problem is:
a. check "echo $DISPLAY" at the terminal in tightvnc window.
b. attach tmux sessions
c. change DISPLAY variable into the value displayed in a. e.g., "export DISPLAY=:1"

This may indicate that every time there is a swich of change working environment (from local use to ssh). one needs to change the environment variables.
more reading http://unix.stackexchange.com/questions/75681/why-do-i-have-to-re-set-env-vars-in-tmux-when-i-re-attach

3. Is vino a good package?
it should be pointed out that ubuntu uses Vino to do the remote connecting stuff. which is albeit identical to the desktop, very slow comparing with tightvnc (pretty much like qq remote).
the way to setup such connections is
a. type vino-preferences and enable desktopsharing ability.
b. tricky part : apt-get install dconf-tool, then find org->gnome->desktop->applications->remote-access-> deselect require-encryption.
c. use vnc application to remote connecting the desktop.

4. scalling in tightvnc viewer.
It is found that tightvnc viewer does not support dynamically changing resolution, but in windows tightvncviewer, one can scale the resolution to satisfy the change of the screen, which is pretty convinent.

5. working seamlessly with termserv.
Somehow the termserv machine does not support directly connecting to 5901 port, which is the default port for tightvnc. but I have made a way to workaround.
1. open putty->tunnel->sourceport 5901, destination 127.0.0.1:5901, choose local, choose auto.
2. go to tightvncviewer, choose127.0.0.1:5901. then you should be able to see the result perfectly.
in tightvncviewer, one can scale the size of the window so changing resolution dynamicly is not a issue at all.
6. working seamlessly with linux
the problem using linux as a client to control a vnc client is that, one has to remap some of the keys (e.g., win key) so that the host machine and guest machine has individual keys representing their functions. (e.g., user does not want to press win buttom with both host and client behaving the same as press win, instead, one key has to be working for host machine and another one for guest).

resolving this problem requires knowledge of the desktop environment on both client and host machine. this paragraph only works for the situation where client has i3wm (using mod4 as function key).

if server is openbox, one can add the following script to rc.xml for achieving aerosnap:
<keybind key="C-Left">        # HalfLeftScreen
      <action name="UnmaximizeFull"/>
      <action name="MoveResizeTo"><x>0</x><y>0</y><height>97%</height><width>50%</width></action>
    </keybind>
    <keybind key="C-Right">        # HalfRightScreen
      <action name="UnmaximizeFull"/>
      <action name="MoveResizeTo"><x>-0</x><y>0</y><height>97%</height><width>50%</width></action>
    </keybind>
 if server is i3wm then one can change the mod key as right window key.
note that openbox and i3wm is not the same in terms of master key. for i3wm, one can assign a key as master key, so if one is able to map the master key to another key, problem gets solved. Instead, openbox always use 'absolute address' to define a key (C represents control, W represents windows key). this is a bit difficult to change, unless one define and keybinding that does not conflict with other keybindings, just like the snippet above.




No comments:

Post a Comment