相信不少背著筆電(laptop)到處跑的伙伴都習慣在一處要塞[註1]使用雙螢幕(Multiple Monitor),可惜 Ubuntu 目前還無法像 Windows7 那樣自動切換,讓凍仁每每使用雙螢幕都得重新設定,真的是很惱人啊。
在早期還可以透過編寫 /etc/rc.local 與 /etc/X11/xorg.conf 來達到切換的效果,但如今的 Ubuntu 已不吃這套。最後得知 disper 也可達到同樣的效果,索性就小小研究一下,不得不說 Windows7 真的整合得不錯。
![]() |
| 延伸後的顯示器設定 |
1. Disper 簡介
Disper 是一支快速(on-the-fly)切換螢幕的小工具,它是為了讓筆記型電腦可以在連接投影機時即時切換螢幕而設計的。強大歸強大,但它除了得在 console 下執行外,還得使用對應的參數才行!若您只是想快速切換投影機,不妨試試看 disper-indicator。
2. 安裝 Disper
目前 disper 與 disper-indicator 還未列入官方的套件庫,故需手動加入 PPA 上的來源。
2.1. 新增套件來源。
[ jonny@precise ~ ]$ sudo add-apt-repository ppa:disper-dev/ppa && sudo aptitude update [Enter]
2.2. 安裝 disper。
[ jonny@precise ~ ]$ sudo aptitude install disper [Enter]
3. Disper 使用說明
3.1. 列出已連接的螢幕,以下以 ThinkPad T410 為範例。
[ jonny@precise ~ ]$ disper -l [Enter]# - with HannStar Display Corp JG171A (17")
display DFP-0: LEN # DFP-0 為 T410 內建螢幕裝置代號。
resolutions: 320x175, 320x200, 360x200, 320x240, 400x300, 416x312, 512x384, 640x350, 576x432, 640x400, 680x384, 720x400, 640x480, 720x450, 640x512, 700x525, 800x512, 840x525, 800x600, 960x540, 832x624, 960x600, 896x672, 928x696, 1024x768, 1152x864, 1360x768, 1440x900
display CRT-0: HannStar Display Corp JG171A # CRT-0 為 VGA 裝置代號。
resolutions: 320x240, 400x300, 512x384, 680x384, 640x480, 720x450, 700x525, 840x525, 800x600, 960x540, 832x624, 960x600, 1024x768, 1152x864, 1360x768, 1280x960, 1440x900, 1400x1050, 1680x1050, 1920x1080, 1280x1024
# - whit Toshiba TSB-TV (32")
display DFP-0: LEN
resolutions: 320x175, 320x200, 360x200, 320x240, 400x300, 416x312, 512x384, 640x350, 576x432, 640x400, 680x384, 720x400, 640x480, 720x450, 640x512, 700x525, 800x512, 840x525, 800x600, 960x540, 832x624, 960x600, 896x672, 928x696, 1024x768, 1152x864, 1360x768, 1440x900
display DFP-2: Toshiba TSB-TV # DFP-2 為 Display Port(DP) 裝置代號。
resolutions: 320x175, 320x200, 360x200, 320x240, 400x300, 416x312, 512x384, 640x350, 576x432, 640x400, 680x384, 720x400, 640x480, 720x450, 640x512, 700x525, 800x512, 840x525, 800x600, 960x540, 832x624, 960x600, 896x672, 928x696, 960x720, 1440x480, 1024x768, 1280x720, 1152x864, 1360x768, 1280x960, 1440x900, 1280x1024, 1400x1050, 1600x1024, 1680x1050, 720x480, 1920x1080
3.2. 使用雙螢幕並啟用延伸桌面(Extend)。
[ jonny@precise ~ ]$ disper -d auto -e [Enter]
3.3. 使用雙螢幕並啟用複製桌面(Clone),此功能同時也有鏡像(Mirror)與同步桌面之稱。
[ jonny@precise ~ ]$ disper -d auto -c [Enter]
3.4. 只使用筆記型電腦上的螢幕。
[ jonny@precise ~ ]$ disper -d DFP-0 -s [Enter]
3.5. 其他相關參數。
[ jonny@precise ~ ]$ disper --help [Enter]Usage: disper [options] (-l|-s|-c|-e|-p|-i)
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-v, --verbose show what's happening
-q, --quiet be quiet and only show errors
-r RESOLUTION, --resolution=RESOLUTION
set resolution, e.g. "800x600", or "auto" to detect
the display's preferred resolution, or "max" to use
the maximum resolution advertised. For extend it is
possible to enter a single resolution for all displays
or a comma-separated list of resolutions (one for each
display). Beware that many displays advertise
resolutions they can not fully show, so "max" is not
advised.
-d DISPLAYS, --displays=DISPLAYS
comma-separated list of displays to operate on, or
"auto" to detect; the first is the primary display.
-t DIRECTION, --direction=DIRECTION
where to extend displays: "left", "right", "top", or
"bottom"
--scaling=SCALING flat-panel scaling mode: "default", "native",
"scaled", "centered", or "aspect-scaled"
--plugins=PLUGINS comma-separated list of plugins to enable. Special
names: "user" for all user plugins in ~/.disper/hooks;
"all" for all plugins found; "none" for no plugins.
--cycle-stages=CYCLE_STAGES
colon-separated list command-line arguments to cycle
through
Actions:
Select exactly one of the following actions
-l, --list list the attached displays
-s, --single only enable the primary display
-S, --secondary only enable the secondary display
-c, --clone clone displays
-e, --extend extend displays
-p, --export export current settings to standard output
-i, --import import current settings from standard input
-C, --cycle cycle through the list of cycle stages
4. Shell Script 應用
此 script 執行時會自動偵測螢幕數量,當螢幕數量大於 2 時才會啟用延伸桌面,當然它也需加入 Startup Applications(自動啟動),
[ jonny@precise ~ ] $ vi display-switcher.sh [Enter]1 #!/bin/bash
2 # Info: Auto switch single/extend display with disper on Multiple Monitor.
3
4 lines=`disper -l | wc -l`
5 display_count=$((lines / 2))
6
7 if [ $display_count -eq "1" ]; then
8 disper -d DFP-0 -s
9 else
10 disper -d auto -e
11 #disper -d auto -e -t left #向左延伸桌面。
12 fi
有空在試著整合至快捷鍵 Fn + F7 了。
# - 註1: 這個要塞可以是公司的辦公室也可以家裡的工作室,會用「要塞」這個字眼來形容是因為通常都還會搭配 USB Hub 或是專屬底座(Dock)來連接其他的週邊設備。
2012-05-024
心血來潮的外接 32" Toshiba TV 測試 Display Port 轉 HDMI 音效輸出,發現 Ubuntu 12.04 也可以把聲音輸出給電視播放了,而且還可以直接使用 Disper 延伸 Display Port 出去,真的是賺到了,
![]() |
| Disper 預設的主螢幕是筆記型電腦內建的 |
![]() |
| Disper 的自動設定目前很夠凍仁用了。 |
延伸閱讀:
★Disper Indicator, Easily Clone or Extend Displays on Multiple Monitor Setups [NVIDIA Cards Only] ~ Ubuntu Vibes
★Disper › Wiki › ubuntuusers.de
★Sample Fn-F7 script - ThinkWiki
相關連結:
★NVIDIA - Ubuntu 中文
★Modify xorg.conf for better performance | TuxRadar Linux
★Installing Ubuntu 11.10 on a ThinkPad T410: 1.7 Workarounds
★Sample Fn-F7 script - ThinkWiki
資料來源:
★[ubuntu] nvidia-settings command line - Ubuntu Forums
★Disper package archive : “disper” team
★Disper - Willem






















感謝 BlueT 前輩介紹的 








