Lubuntu: 디스플레이를 전환하는 단축키

Lubuntu: 디스플레이를 전환하는 단축키

저는 Linux를 처음 접했고 bash 스크립팅을 처음 접했습니다.

내부 모니터와 외부 모니터 사이를 전환하기 위해 기존 Asus EEE 넷북에 Fn-F5 키를 설정하려고 합니다.

다음에서 bash 스크립트 만들기 ~/bin/toggle_displays.sh:

    #!/bin/bash

if (xrandr | grep "VGA1 disconnected"); then
# external monitor not connected: do nothing
    xrandr --output LVDS1 --auto --output VGA1 --off 
else
# external monitor connected: toggle monitors
    if (xrandr | grep -E "LVDS1 connected (primary )?\("); then
        xrandr --output LVDS1 --auto --output VGA1 --off
    else
        xrandr --output LVDS1 --off --output VGA1 --auto
    fi
fi

<keyboard>섹션 에 단축키 추가 ~/.config/openbox/lubuntu-rc.xml:

...
<keybind key="XF86Display">
  <action name="Execute">
    <command>~/bin/toggle_displays.sh</command>
  </action>
</keybind>
...

문제는 매우 이상합니다. 내부 디스플레이가 활성화되면 외부로 전환하면 항상 작동합니다. 그러나 외부가 활성화된 경우 전환하면 내부 디스플레이에 마우스 커서가 있는 검은색 화면만 나타납니다. 더 놀랍게도 핫키가 아닌 터미널에서 스크립트를 실행하면 후자의 스위치가 작동하는 경우가 있습니다.

무엇이 문제가 될 수 있나요? 그리고 이것을 어떻게 디버깅할 수 있을까요?

참고로 터미널에서 스크립트를 실행하여 외부 디스플레이에서 내부 디스플레이로 전환하면 LVDS1 connected primary (normal left inverted right x axis y axis)터미널에 인쇄됩니다. echo스크립트에 없으면 왜 이런 일이 발생합니까 ?

편집: 내 xrandr출력은 다음과 같습니다(외부 모니터 사용).

Screen 0: minimum 8 x 8, current 1680 x 1050, maximum 32767 x 32767
LVDS1 connected primary (normal left inverted right x axis y axis)
   1024x600       60.0 +
   800x600        60.3     56.2  
   640x480        59.9  
VGA1 connected 1680x1050+0+0 (normal left inverted right x axis y axis) 473mm x 296mm
   1680x1050      60.0*+
   1600x1200      60.0  
   1280x1024      75.0     60.0  
   1440x900       75.0     59.9  
   1280x800       59.8  
   1152x864       75.0  
   1024x768       75.1     70.1     60.0  
   832x624        74.6  
   800x600        72.2     75.0     60.3     56.2  
   640x480        75.0     72.8     66.7     60.0  
   720x400        70.1  
VIRTUAL1 disconnected (normal left inverted right x axis y axis)

답변1

나는 노트북 화면과 외부 화면 사이를 전환하는 bash 스크립트를 직접 작성했습니다. 어느 화면이 켜져 있는지 확인하고 화면을 끄고 기본 해상도로 다른 화면을 켭니다. 좋은 점은. xrandr에서 수집된 화면 이름을 알 필요가 없습니다.

#!/bin/bash
#Toggles between two screens. Assuming only one external screen is connected

monitors=`xrandr | grep -P ' connected' | grep -o '^[^ ]*'`
set -- "$monitors"
#monArr contains an array of the id's of the connected screens
declare -a monArr=($*)

#onMon holds the id of the *first* on screen found
onMon=`xrandr --listmonitors | head -2 | grep -oP "[a-zA-Z]*-[0-9]$"`

#offMon holds the id of the other monitor, which is not on
if [ "$onMon" = "${monArr[0]}" ]

then
    offMon=${monArr[1]}
else
    offMon=${monArr[0]}
fi

#Switches the on screen off and vice versa
xrandr --output $offMon --auto --output $onMon --off

관련 정보