但具備 GUI 的 Linux 好似只有安裝在手提電腦的 Linux 發佈版才能設定螢幕光度
莫非一般桌面 Linux 不能螢幕光度 ?
Linux 本身其實都能夠設定螢幕光度,需要透過 xrandr 指令進行
輸入
xrandr會顯示閣下電腦中能連接的螢幕,例如:VGA, DVI, HDMI, LVDS (通常為 一體機 或 手提電腦 螢幕)
已連接的螢幕會顯示為 connected
輸入
xrandr | grep -o '.\+ connected'便可只顯示已連接的螢幕
例如閣下使用 VGA-0 要設定光度為 90%
輸入
xrandr --output VGA-0 --brightness 0.90xrandr 設定光度基本數值為 0.00 ~ 1.00
但數值降至 0.10 實際上已經接近不能觀察
若不小心降至 0.10 以下看不到畫面,便需要按 Alt + Ctrl + F1 ~ F6 進入 tty 操作
但由於 tty 沒有 GUI ,使用 xrandr 後顯示 Can't not open display
輸入
export DISPLAY=:0.0才能設定
xrandr --output VGA-0 --brightness 1.00完成後按 Alt + Ctrl + F7 / F8 回到 GUI 顯示
xrandr 還能夠設定超越 100% 螢幕光度
即輸入
xrandr --output VGA-0 --brightness 1.20亦是許可,同樣過量光度會將畫圖設定為白色,一樣不能觀察
不過每次設定光度都要輸入指令顯示有點麻煩
在下借用 zenity 來進行互動操作方便調整光度
while read b; do B=`echo "${b}" 100 | awk '{print $1/$2}'` B=`printf '%01.2f' "${B}"` xrandr --output VGA-0 --brightness "${B}" done < <(zenity --scale --title="Brightness Scaler" --text='' --value=100 --step=1 --min-value=10 --max-value=100 --print-partial)另一個版本可以自動檢查電腦連接的螢幕數量,可以個別或所有同時設定
#!/bin/bash ifs=$IFS IFS=$'\n' ESCAPE="\\\\" NEWLINE="\\n" WIDTH='400' HEIGHT='250' TITLE='Brightness Scaler' MIN_VALUE='1' MAX_VALUE='10' ALL_SCREENS='All Screens' XRANDR=`xrandr --verbose` DEFAULT_SCREENS=`echo -n "${XRANDR}" | grep '.\+ connected' | sed -r 's/^(.+) connected.+/\1/g'` DEFAULT_BRIGHTNESSES=`echo -n "${XRANDR}" | grep '.\+Brightness: [0-9]\+\.[0-9]\+' | sed -r 's/.+Brightness: ([0-9]+\.[0-9]+)/\1/g'` while [ 1 ]; do selected_screen=`zenity --list --width="${WIDTH}" --height="${HEIGHT}" --title="${TITLE}" --text="Select a Screen" --column 'List of connected screen' "${ALL_SCREENS}" $(echo -n "${DEFAULT_SCREENS}") 2>/dev/null` if [ "${?}" = '0' ]; then if [ "${#selected_screen}" -eq '0' ] || [ "${selected_screen}" = "${ALL_SCREENS}" ]; then brightness=`echo -n $(echo -n "${DEFAULT_BRIGHTNESSES}" | sed -n '1p') "${MAX_VALUE}" | awk '{print $1 * $2}'` screen=`echo -n "${DEFAULT_SCREENS}" | sed -n '1p'` zenity --scale --title="${TITLE}" --text="Adjusting ${ALL_SCREENS} Brightness${NEWLINE}Using Screen '${screen}' as default brightness" --min-value="${MIN_VALUE}" --max-value="${MAX_VALUE}" --value="${brightness}" --print-partial 2>/dev/null | while read value; do for screen in `echo -n "${DEFAULT_SCREENS}"`; do brightness=`echo -n "${value}" "${MAX_VALUE}" | awk '{print $1 / $2}'` brightness=`printf '%01.2f' "${brightness}"` command="xrandr --output '${screen}' --brightness '${brightness}'" eval "${command}" done done if [ "${PIPESTATUS[0]}" = '0' ]; then DEFAULT_BRIGHTNESSES=`xrandr --verbose | grep '.\+Brightness: [0-9]\+\.[0-9]\+' | sed -r 's/.+Brightness: ([0-9]+\.[0-9]+)/\1/g'` else i='1' for screen in `echo -n "${DEFAULT_SCREENS}"`; do brightness=`echo -n "${DEFAULT_BRIGHTNESSES}" | sed -n "${i}p"` command="xrandr --output '${screen}' --brightness '${brightness}'" eval "${command}" i=$(($i+1)) done fi else i='1' for screen in `echo -n "${DEFAULT_SCREENS}"`; do if [ "${selected_screen}" = `echo -n "${DEFAULT_SCREENS}" | sed -n "${i}p"` ]; then break; fi i=$(($i+1)) done brightness=`echo -n $(echo "${DEFAULT_BRIGHTNESSES}" | sed -n "${i}p") "${MAX_VALUE}" | awk '{print $1 * $2}'` zenity --scale --title="${TITLE}" --text="Adjusting Screen '${selected_screen}' Brightness" --min-value="${MIN_VALUE}" --max-value="${MAX_VALUE}" --value="${brightness}" --print-partial 2>/dev/null | while read value; do brightness=`echo -n "${value}" "${MAX_VALUE}" | awk '{print $1 / $2}'` brightness=`printf '%01.2f' "${brightness}"` command="xrandr --output '${selected_screen}' --brightness '${brightness}'" eval "${command}" done if [ "${PIPESTATUS[0]}" = '0' ]; then DEFAULT_BRIGHTNESSES=`xrandr --verbose | grep '.\+Brightness: [0-9]\+\.[0-9]\+' | sed -r 's/.+Brightness: ([0-9]+\.[0-9]+)/\1/g'` else brightness=`echo -n "${DEFAULT_BRIGHTNESSES}" | sed -n "${i}p"` command="xrandr --output '${selected_screen}' --brightness '${brightness}'" eval "${command}" fi fi else break fi done IFS=$ifs
沒有留言 :
張貼留言