我使用VNC连接到工作中的Linux工作站。在工作中,我有一台运行在1600x1200分辨率下的20英寸显示器,而在家里,我使用1440x900分辨率的笔记本电脑。 如果我将vnc服务器设置为运行在1440x900分辨率下,我会错过很多显示空间,而如果我将其设置为运行在1600x1200分辨率下,则无法适应笔记本电脑的屏幕,并且我必须一直滚动它。
有没有好的方法可以动态调整VNC会话的大小?
我的VNC服务器是运行在SuSE64上的RealVNC E4.x(我不记得确切的版本号)。
我使用VNC连接到工作中的Linux工作站。在工作中,我有一台运行在1600x1200分辨率下的20英寸显示器,而在家里,我使用1440x900分辨率的笔记本电脑。 如果我将vnc服务器设置为运行在1440x900分辨率下,我会错过很多显示空间,而如果我将其设置为运行在1600x1200分辨率下,则无法适应笔记本电脑的屏幕,并且我必须一直滚动它。
有没有好的方法可以动态调整VNC会话的大小?
我的VNC服务器是运行在SuSE64上的RealVNC E4.x(我不记得确切的版本号)。
Real VNC服务器4.4包括对Xrandr的支持,可以改变VNC的大小。使用以下命令启动服务器:
vncserver -geometry 1600x1200 -randr 1600x1200,1440x900,1024x768
然后使用以下代码进行调整大小:
xrandr -s 1600x1200
xrandr -s 1440x900
xrandr -s 1024x768
.vnc/config
文件中。例如,我的配置文件的第一行是:-randr 800x600,1024x768,1280x800,1280x960,1280x1024,1680x1050,1920x1080,3360x1050,1024x700,1200x740,1600x1000,3200x1000
。 - bfroehletightvncserver
上能用吗? - Dimitry K发现Ubuntu(10.04)附带的vnc4server(4.1.1)已经进行了补丁修复,以支持通过xrandr动态更改分辨率。不幸的是,这个功能很难找到,因为它没有文件记录。所以在这里介绍一下......
使用多个'geometry'实例启动服务器,例如:
vnc4server -geometry 1280x1024 -geometry 800x600
在启用了“允许动态桌面调整大小”的vncviewer终端中,使用xrandr查看可用模式:
xrandr
要改变分辨率,例如使用:
xrandr -s 800x600
就是这样。
我在我的Linux服务器上运行TigerVNC,它具有基本的randr支持。 我只是启动vncserver而没有使用任何-randr或多个-geometry选项。
当我在终端中运行xrandr时,它显示所有可用的屏幕分辨率:
bash> xrandr
SZ: Pixels Physical Refresh
0 1920 x 1200 ( 271mm x 203mm ) 60
1 1920 x 1080 ( 271mm x 203mm ) 60
2 1600 x 1200 ( 271mm x 203mm ) 60
3 1680 x 1050 ( 271mm x 203mm ) 60
4 1400 x 1050 ( 271mm x 203mm ) 60
5 1360 x 768 ( 271mm x 203mm ) 60
6 1280 x 1024 ( 271mm x 203mm ) 60
7 1280 x 960 ( 271mm x 203mm ) 60
8 1280 x 800 ( 271mm x 203mm ) 60
9 1280 x 720 ( 271mm x 203mm ) 60
*10 1024 x 768 ( 271mm x 203mm ) *60
11 800 x 600 ( 271mm x 203mm ) 60
12 640 x 480 ( 271mm x 203mm ) 60
Current rotation - normal
Current reflection - none
Rotations possible - normal
Reflections possible - none
我可以轻松地切换到另一个分辨率(例如,切换到1360x768):
bash> xrandr -s 5
我正在使用 TightVnc Viewer 作为客户端,它会自动适应新的分辨率。
由于这个问题在谷歌上排名第一,我想分享一个使用 TigerVNC 的解决方案,它是现在的默认选择。
xrandr
允许选择显示模式 (也称为分辨率),但是由于模型线被硬编码,
任何额外的模型线,如 "2560x1600" 或 "1600x900" 都需要添加到代码中。我认为编写代码的开发人员非常聪明,硬编码列表只是值的示例。这导致结论必须有一种方法来添加自定义模型线,man xrandr
证实了这一点。
在此背景下,如果目标是在两台计算机之间共享 VNC 会话,并且假设 VNC 服务器的分辨率为 "1600x900":
Start a VNC session with a geometry matching the physical display:
$ vncserver -geometry 1600x900 :1
On the "2560x1600" computer start the VNC viewer (I prefer Remmina) and connect to the remote VNC session:
host:5901
Once inside the VNC session start up a terminal window.
Confirm that the new geometry is available in the VNC session:
$ xrandr
Screen 0: minimum 32 x 32, current 1600 x 900, maximum 32768 x 32768
VNC-0 connected 1600x900+0+0 0mm x 0mm
1600x900 60.00 +
1920x1200 60.00
1920x1080 60.00
1600x1200 60.00
1680x1050 60.00
1400x1050 60.00
1360x768 60.00
1280x1024 60.00
1280x960 60.00
1280x800 60.00
1280x720 60.00
1024x768 60.00
800x600 60.00
640x480 60.00
and you'll notice the screen being quite small.
List the modeline (see xrandr article in ArchLinux wiki) for the "2560x1600" resolution:
$ cvt 2560 1600
# 2560x1600 59.99 Hz (CVT 4.10MA) hsync: 99.46 kHz; pclk: 348.50 MHz
Modeline "2560x1600_60.00" 348.50 2560 2760 3032 3504 1600 1603 1609 1658 -hsync +vsync
or if the monitor is old get the GTF timings:
$ gtf 2560 1600 60
# 2560x1600 @ 60.00 Hz (GTF) hsync: 99.36 kHz; pclk: 348.16 MHz
Modeline "2560x1600_60.00" 348.16 2560 2752 3032 3504 1600 1601 1604 1656 -HSync +Vsync
Add the new modeline to the current VNC session:
$ xrandr --newmode "2560x1600_60.00" 348.16 2560 2752 3032 3504 1600 1601 1604 1656 -HSync +Vsync
In the above xrandr
output look for the display name on the second
line:
VNC-0 connected 1600x900+0+0 0mm x 0mm
Bind the new modeline to the current VNC virtual monitor:
$ xrandr --addmode VNC-0 "2560x1600_60.00"
Use it:
$ xrandr -s "2560x1600_60.00"
我认为你最好的选择是在不同的端口上以不同的几何形状运行VNC服务器。 我建议你根据手册进行尝试。
$vncserver :0 -geometry 1600x1200
$vncserver :1 -geometry 1440x900
然后您可以从工作地点连接到一个端口,从家里连接到另一个端口。
编辑:然后使用 xmove 在两个 X 服务器之间移动窗口。有趣的是没有人回答这个问题。在TigerVNC中,当您登录会话时。从顶部菜单栏进入System > Preference > Display
(我使用Cent OS作为远程服务器)。单击分辨率下拉菜单,提供了各种设置,包括1080p。选择您喜欢的一个。它将实时更改。
务必在提示对话框中应用新设置。否则它将像Windows一样恢复到以前的设置
大家这很简单。
通过ssh
登录您的树莓派
执行
vncserver -geometry 1200x1600
这将生成一个新的会话 :1
使用您的VNC客户端连接到ipaddress:1
就是这样。
在Nathan的(被接受的)答案基础上补充一点:
我想循环遍历分辨率列表,但是没有看到相关内容:
function vncNextRes()
{
xrandr -s $(($(xrandr | grep '^*'|sed 's@^\*\([0-9]*\).*$@\1@')+1)) > /dev/null 2>&1 || \
xrandr -s 0
}
function vncNextRes()
{
xrandr -s $(($(xrandr 2>/dev/null | grep -n '\* *$'| sed 's@:.*@@')-2)) || \
xrandr -s 0
}
在Xvnc TigerVNC 1.1.0中,@omiday的解决方案对我有用,因此我将其压缩为一个单独的bash函数vncsize x y。像这样使用它:vncsize 1400 1000。它适用于任何VNC输出名称,“default”或“VNC-0”。
function vncsize {
local x=$1 y=$2
local mode
if mode=$(cvt "$x" "$y" 2>/dev/null)
then
if [[ $mode =~ "Modeline (.*)$" ]]
then
local newMode=${BASH_REMATCH[1]//\"/}
local modeName=${newMode%% *}
local newSize=( ${modeName//[\"x_]/ } )
local screen=$(xrandr -q|grep connected|cut -d' ' -f1)
xrandr --newmode $newMode
xrandr --addmode "$screen" "$modeName"
xrandr --size "${newSize[0]}x${newSize[1]}" &&
return 0
else
echo "Unable to parse modeline for ($x $y) from $mode"
return 2
fi
else
echo "\`$x $y' is not a valid X Y pair"
return 1
fi
}
$sscreen
应该是什么?回显为空白。此外,newSize
似乎不是一个列表/元组...将最后的xrandr
行更改为xrandr --size "${x}x${y}" &&
似乎可以解决问题,但然后我会得到Size 1400x1400 not found in available modes
。 - nmz787$(cvt "$x" "$y" 2>/dev/null | tail -n1)
... 只取最后一行。if [[ $mode =~ Modeline\ (.*)$ ]]
... 去掉引号以启用正则表达式。OS: RHEL 6.6 (Santiago)
VNC Server:
Name : tigervnc-server
Arch : x86_64
Version : 1.1.0
Release : 16.el6
# May be this is relevant..
$ xrandr --version
xrandr program version 1.4.0
Server reports RandR version 1.4
$
# I start the server using vncserver -geometry 800x600
# Xvnc is started by vncserver with following args:
/usr/bin/Xvnc :1 -desktop plabb13.sgdcelab.sabre.com:1 (sg219898) -auth /login/sg219898/.Xauthority
-geometry 800x600 -rfbwait 30000 -rfbauth /login/sg219898/.vnc/passwd -rfbport 5901 -fp catalogue:/e
tc/X11/fontpath.d -pn
# I'm running GNOME (installed using sudo yum install gnome-*)
Name : gnome-desktop
Arch : x86_64
Version : 2.28.2
Release : 11.el6
Name : gnome-session
Arch : x86_64
Version : 2.28.0
Release : 22.el6
Connect using Tiger 32-bit VNC Client v1.3.1 on Windows 7.
$HOME
目录中运行最新的1.4.3版本可以正常工作。https://github.com/TigerVNC/tigervnc/issues/155 - cdwilson