IT박스

리눅스에서 VNC 세션의 해상도 변경하기

itboxs 2020. 6. 16. 20:40
반응형

리눅스에서 VNC 세션의 해상도 변경하기


VNC를 사용하여 직장에서 Linux 워크 스테이션에 연결합니다. 직장에서는 1600x1200에서 실행되는 20 인치 모니터가 있고 집에서는 해상도가 1440x900 인 랩톱을 사용합니다. vncserver를 1440x900에서 실행하도록 설정하면 모니터의 많은 공간을 놓치게됩니다. 1600x1200에서 실행되도록 설정하면 랩톱 화면에 맞지 않으며 항상 스크롤해야합니다.

VNC 세션 크기를 즉시 조정할 수있는 좋은 방법이 있습니까?

내 VNC 서버는 SuSE64에서 실행되는 RealVNC E4.x (정확한 버전은 기억 나지 않습니다)입니다.


Real VNC 서버 4.4에는 Vrand 크기를 조정할 수있는 Xrandr 지원이 포함되어 있습니다. 다음을 사용하여 서버를 시작하십시오.

vncserver -geometry 1600x1200 -randr 1600x1200,1440x900,1024x768

그런 다음 크기를 조정하십시오.

xrandr -s 1600x1200
xrandr -s 1440x900
xrandr -s 1024x768

Ubuntu (10.04)와 함께 제공되는 vnc4server (4.1.1)는 xrandr를 통해 즉시 해상도 변경을 지원하도록 패치되었습니다. 불행히도이 기능은 문서화되지 않았기 때문에 찾기 어려웠습니다. 그래서 여기에 ...

다음과 같이 여러 '형상'인스턴스로 서버를 시작하십시오.

vnc4server -geometry 1280x1024 -geometry 800x600

vncviewer의 터미널에서 ( 'dymanic desktop resizing 허용'사용) xrandr을 사용하여 사용 가능한 모드를보십시오.

xrandr

예를 들어 resulution을 변경하려면 다음을 사용하십시오.

xrandr -s 800x600

그게 다야.


기본 randr을 지원 하는 Linux 서버 에서 TigerVNC실행 하고 있습니다. -randr 또는 다중 -geometry 옵션없이 vncserver를 시작합니다.

터미널에서 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

그런 다음 다른 해상도로 쉽게 전환 할 수 있습니다 (fe는 1360x768로 전환).

bash> xrandr -s 5

클라이언트로 TightVnc 뷰어를 사용하고 있으며 새 해상도에 자동으로 적응합니다.


최선의 방법은 다른 포트에서 다른 지오메트리로 VNC 서버를 실행하는 것입니다. 맨 페이지를 기반으로 시도 합니다

$vncserver :0 -geometry 1600x1200
$vncserver :1 -geometry 1440x900

그런 다음 직장에서 한 포트로, 집에서 다른 포트로 연결할 수 있습니다.

편집 : 그런 다음 xmove를 사용하여 두 x 서버 사이에서 창을 이동하십시오.


흥미롭게도 아무도 대답하지 않았습니다. TigerVNC에서 세션에 로그인 할 때 System > Preference > Display상단 메뉴 표시 줄에서 이동 하십시오 (Cent OS를 원격 서버로 사용하고있었습니다). 해상도 드롭 다운을 클릭하면 1080p를 포함한 다양한 설정이 가능합니다. 원하는 것을 선택하십시오. 즉시 변경됩니다.

여기에 이미지 설명을 입력하십시오

대화 상자가 표시되면 새 설정을 적용하십시오. 그렇지 않으면 Windows와 마찬가지로 이전 설정으로 되돌아갑니다.


이 질문은 Google에서 처음으로 나오기 때문에 요즘 기본값 인 TigerVNC를 사용하는 솔루션을 공유한다고 생각했습니다.

xrandr디스플레이 모드 (일명 해상도)를 선택할 수 있지만, 모델 코드하드 코딩 되어 있기 때문에 "2560x1600"또는 "1600x900"과 같은 추가 모델을 코드에 추가 해야 합니다 . 코드를 작성한 개발자가 훨씬 똑똑하고 하드 코딩 된 목록은 단순한 샘플 일 뿐이라고 생각합니다. 사용자 지정 모델을 추가하고 man xrandr확인 하는 방법이 있어야한다는 결론으로 ​​이어집니다 .

위의 해상도를 가진 두 컴퓨터간에 VNC 세션을 공유하고 VNC 서버가 "1600x900"해상도의 컴퓨터라고 가정하는 것이 목표 인 경우 :

  1. 물리적 디스플레이와 일치하는 형상으로 VNC 세션을 시작합니다.

    $ vncserver -geometry 1600x900 :1
    
  2. "2560x1600"컴퓨터에서 VNC 뷰어를 시작하고 (Remmina를 선호 함) 원격 VNC 세션에 연결하십시오.

    host:5901
    
  3. VNC 세션 내부에서 터미널 창을 시작하십시오.

  4. VNC 세션에서 새 형상을 사용할 수 있는지 확인하십시오.

    $ 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  
    

    화면이 매우 작습니다.

  5. "2560x1600"해상도에 대한 modeline (ArchLinux 위키의 xrandr 기사 참조)을 나열하십시오.

    $ 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
    

    또는 모니터가 오래된 경우 GTF 타이밍을 얻습니다.

    $ 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
    
  6. 현재 VNC 세션에 새 모델을 추가하십시오.

    $ xrandr --newmode "2560x1600_60.00"  348.16  2560 2752 3032 3504  1600 1601 1604 1656 -HSync +Vsync
    
  7. xrandr출력에서 두 번째 줄에서 표시 이름을 찾으십시오.

    VNC-0 connected 1600x900+0+0 0mm x 0mm
    
  8. 새 모델을 현재 VNC 가상 모니터에 바인딩합니다.

    $ xrandr --addmode VNC-0 "2560x1600_60.00"
    
  9. 사용해:

    $ xrandr -s "2560x1600_60.00"
    

여러분 이건 정말 간단합니다.

ssh파이에 로그인

실행하다

vncserver -geometry 1200x1600

이것은 새로운 세션을 생성합니다 :1

에서 VNC 클라이언트와 연결 ipaddress:1

그게 다야.


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@')+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)


EDIT

Modified to match a later version of xrandr ("*" is on end of line and no leading resolution identifier).

function vncNextRes()
{
   xrandr -s $(($(xrandr 2>/dev/null | grep -n '\* *$'| sed 's@:.*@@')-2))  || \
   xrandr -s 0
}

Perhaps the most ignorant answer I've posted but here goes: Use TigerVNC client/viewer and check 'Resize remote session to local window' under Screen tab of options.

I don't know what the $%#@ TigerVNC client tells remote vncserver or xrandr or Xvnc or gnome or ... but it resizes when I change the TigerVNC Client window.

My setup:

  • Tiger VNC Server running on CentOS 6. Hosting GNOME desktop. (Works with RHEL 6.6 too)
  • Windows some version with Tiger VNC Client.

With this the resolution changes to fit the size of the client window no matter what it is, and it's not zooming, it's actual resolution change (I can see the new resolution in xrandr output).

I tried all I could to add a new resolution to the xrandr, but to no avail, always end up with 'xrandr: Failed to get size of gamma for output default' error.

Versions with which it works for me right now (although I've not had issues with ANY versions in the past, I just install the latest using yum install gnome-* tigervnc-server and works fine):

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.

Solution by @omiday worked for me in Xvnc TigerVNC 1.1.0, so I condensed it into a single bash function vncsize x y. Use it like this: vncsize 1400 1000. It assumes that xrandr reports VNC output name as default.

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_]/ } )
            xrandr --newmode $newMode
            xrandr --addmode default "$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
}

I'm not sure about linux, but under windows, tightvnc will detect and adapt to resolution changes on the server.

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.


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.

I think you can use xmove to 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.


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.

TightVNC however (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.


I have a simple idea, something like this:

#!/bin/sh

echo `xrandr --current | grep current | awk '{print $8}'` >> RES1
echo `xrandr --current | grep current | awk '{print $10}'` >> 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


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-Server running on linux machines - at least on ones that might be interesting targets for VNC - that you can connect to with "X-Clients"?

VNC는 화면에있는 모든 것을 가져 와서 "네트워크를 통해 터널링"합니다. 내가 완전히 틀리지 않으면 "X"프로토콜은 클라이언트의 데스크톱 해상도를 사용할 수있는 기회를 제공해야합니다.

주고 X-서버 당신에게 대략적인 개요를 제공 할 수 위키 백과 시도에.

참고 URL : https://stackoverflow.com/questions/15816/changing-the-resolution-of-a-vnc-session-in-linux

반응형