在 Linux 中更改 VNC 会话的分辨率
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing the resolution of a VNC session in linux
提问by Nathan Fellman
I use VNC to connect to a Linux workstation at work. At work I have a 20" monitor that runs at 1600x1200, while at home I use my laptop with its resolution of 1440x900. If I set the vncserver to run at 1440x900 I miss out on a lot of space on my monitor, whereas if I set it to run at 1600x1200 it doesn't fit on the laptop's screen, and I have to scroll it all the time.
我使用 VNC 连接到工作中的 Linux 工作站。在工作时,我有一台 20" 显示器,分辨率为 1600x1200,而在家里,我使用分辨率为 1440x900 的笔记本电脑。如果我将 vncserver 设置为以 1440x900 运行,我会错过显示器上的很多空间,而如果我将它设置为以 1600x1200 运行,它不适合笔记本电脑的屏幕,我必须一直滚动它。
Is there any good way to resize a VNC session on the fly?
有什么好的方法可以动态调整 VNC 会话的大小吗?
My VNC server is RealVNC E4.x (I don't remember the exact version) running on SuSE64.
我的 VNC 服务器是在 SuSE64 上运行的 RealVNC E4.x(我不记得确切的版本)。
采纳答案by Nathan Fellman
Real VNC server 4.4 includes support for Xrandr, which allows resizing the VNC. Start the server with:
Real VNC server 4.4 包括对 Xrandr 的支持,它允许调整 VNC 的大小。使用以下命令启动服务器:
vncserver -geometry 1600x1200 -randr 1600x1200,1440x900,1024x768
Then resize with:
然后调整大小:
xrandr -s 1600x1200
xrandr -s 1440x900
xrandr -s 1024x768
回答by BlaM
As far as I know there's no way to change the client's resolution just using VNC, as it is just a "monitor mirroring" application.
据我所知,仅使用 VNC 无法更改客户端的分辨率,因为它只是一个“监视器镜像”应用程序。
TightVNChowever (which is a VNC client and server application) can resize the screen on the client side, i.e. making everything a little smaller (similar to image resizing techniques in graphics programs). That should work if you don't use too small font sizes. VNC should theoretically be compatible between different VNC applications.
然而,TightVNC(它是一个 VNC 客户端和服务器应用程序)可以在客户端调整屏幕大小,即让一切都变小一点(类似于图形程序中的图像调整技术)。如果您不使用太小的字体大小,那应该可行。VNC 理论上应该在不同的 VNC 应用程序之间兼容。
回答by BlaM
I think that depends on your window manager.
我认为这取决于您的窗口管理器。
I'm a windows user, so this might be a wrong guess, but: Isn't there something called X-Serverrunning on linux machines - at least on ones that might be interesting targets for VNC - that you can connect to with "X-Clients"?
我是一个 Windows 用户,所以这可能是一个错误的猜测,但是:在 Linux 机器上是否有一种叫做X-Server 的东西——至少在那些可能是 VNC 有趣目标的机器上——你可以连接到“ X 客户”?
VNC just takes everything that's on the screen and "tunnels it through your network". If I'm not totally wrong then the "X" protocol should give you the chance to use your client's desktop resolution.
VNC 只是获取屏幕上的所有内容并“通过您的网络将其传送”。如果我没有完全错,那么“X”协议应该让您有机会使用客户端的桌面分辨率。
Give X-Serveron Wikipedia a try, that might give you a rough overview.
给X-服务器在维基百科上一试,这可能给你一个粗略的概述。
回答by Pat
I think your best best is to run the VNC server with a different geometry on a different port. I would try based on the man page
我认为最好的办法是在不同的端口上运行具有不同几何形状的 VNC 服务器。我会根据手册页尝试
$vncserver :0 -geometry 1600x1200 $vncserver :1 -geometry 1440x900
$vncserver :0 -geometry 1600x1200 $vncserver :1 -geometry 1440x900
Then you can connect from work to one port and from home to another.
然后你可以从工作连接到一个端口,从家里连接到另一个。
Edit: Then use xmove to move windows between the two x-servers.
编辑:然后使用 xmove 在两个 x 服务器之间移动窗口。
回答by Blorgbeard is out
I'm not sure about linux, but under windows, tightvnc will detect and adapt to resolution changes on the server.
我不确定 linux,但在 windows 下,tightvnc 会检测并适应服务器上的分辨率变化。
So you should be able to VNC into the workstation, do the equivalent of right-click on desktop, properties, set resolution to whatever, and have your client vnc window resize itself accordingly.
因此,您应该能够将 VNC 连接到工作站,相当于右键单击桌面、属性、将分辨率设置为任何值,并让您的客户端 vnc 窗口相应地调整自身大小。
回答by Pat
On the other hand, if there's a way to move an existing window from one X-server to another, that might solve the problem.
另一方面,如果有办法将现有窗口从一个 X-server 移动到另一个,那可能会解决问题。
I think you can use xmoveto move windows between two separate x-servers. So if it works, this should at least give you a way to do what you want albeit not as easily as changing the resolution.
我认为您可以使用xmove在两个单独的 x 服务器之间移动窗口。所以如果它有效,这至少应该给你一种方法来做你想做的事,尽管不像改变分辨率那么容易。
回答by Tijs
Found out that the vnc4server (4.1.1) shipped with Ubuntu (10.04) is patched to also support changing the resolution on the fly via xrandr. Unfortunately the feature was hard to find because it is undocumented. So here it is...
发现 Ubuntu (10.04) 随附的 vnc4server (4.1.1) 已打补丁,还支持通过 xrandr 即时更改分辨率。不幸的是,该功能很难找到,因为它没有记录。所以这里是...
Start the server with multiple 'geometry' instances, like:
使用多个“几何”实例启动服务器,例如:
vnc4server -geometry 1280x1024 -geometry 800x600
From a terminal in a vncviewer (with: 'allow dymanic desktop resizing' enabled) use xrandr to view the available modes:
从 vncviewer 中的终端(启用:'allow dymanic desktop resizing' enabled)使用 xrandr 查看可用模式:
xrandr
to change the resulution, for example use:
改变结果,例如使用:
xrandr -s 800x600
Thats it.
就是这样。
回答by nhed
Adding to Nathan's (accepted) answer:
添加到弥敦道(已接受)的答案中:
I wanted to cycle through the list of resolutions but didnt see anything for it:
我想循环浏览决议列表,但没有看到任何内容:
function vncNextRes()
{
xrandr -s $(($(xrandr | grep '^*'|sed 's@^\*\([0-9]*\).*$@@')+1)) > /dev/null 2>&1 || \
xrandr -s 0
}
It gets the current index, steps to the next one and cycles back to 0 on error (i.e. end)
它获取当前索引,进入下一个索引,并在出错时循环回 0(即结束)
EDIT
编辑
Modified to match a later version of xrandr ("*" is on end of line and no leading resolution identifier).
修改以匹配更高版本的 xrandr(“*”在行尾且没有前导分辨率标识符)。
function vncNextRes()
{
xrandr -s $(($(xrandr 2>/dev/null | grep -n '\* *$'| sed 's@:.*@@')-2)) || \
xrandr -s 0
}
回答by Peter
I'm running TigerVNCon my Linux server, which has basic randrsupport. I just start vncserver without any -randr or multiple -geometry options.
我在我的 Linux 服务器上运行TigerVNC,它具有基本的randr支持。我只是在没有任何 -randr 或多个 -geometry 选项的情况下启动 vncserver。
When I run xrandr in a terminal, it displays all the available screen resolutions:
当我在终端中运行 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
I can then easily switch to another resolution (f.e. switch to 1360x768):
然后我可以轻松切换到另一个分辨率(fe 切换到 1360x768):
bash> xrandr -s 5
I'm using TightVnc viewer as the client and it automatically adapts to the new resolution.
我使用 TightVnc 查看器作为客户端,它会自动适应新的分辨率。
回答by inukaze
I have a simple idea, something like this:
我有一个简单的想法,就像这样:
#!/bin/sh
echo `xrandr --current | grep current | awk '{print }'` >> RES1
echo `xrandr --current | grep current | awk '{print }'` >> RES2
cat RES2 | sed -i 's/,//g' RES2
P1RES=$(cat RES1)
P2RES=$(cat RES2)
rm RES1 RES2
echo "$P1RES"'x'"$P2RES" >> RES
RES=$(cat RES)
# Play The Game
# Finish The Game with Lower Resolution
xrandr -s $RES
Well, I need a better solution for all display devices under Linux and Similars S.O
嗯,我需要一个更好的解决方案,适用于 Linux 和 Similars 下的所有显示设备 SO