但具備 GUI 的 Linux 好似只有安裝在手提電腦的 Linux 發佈版才能設定螢幕光度
莫非一般桌面 Linux 不能螢幕光度 ?
Linux 本身其實都能夠設定螢幕光度,需要透過 xrandr 指令進行
輸入
1 | xrandr |
已連接的螢幕會顯示為 connected
輸入
1 | xrandr | grep -o '.\+ connected' |
例如閣下使用 VGA-0 要設定光度為 90%
輸入
1 | xrandr --output VGA-0 --brightness 0.90 |
但數值降至 0.10 實際上已經接近不能觀察
若不小心降至 0.10 以下看不到畫面,便需要按 Alt + Ctrl + F1 ~ F6 進入 tty 操作
但由於 tty 沒有 GUI ,使用 xrandr 後顯示 Can't not open display
輸入
1 | export DISPLAY=:0.0 |
1 | xrandr --output VGA-0 --brightness 1.00 |
xrandr 還能夠設定超越 100% 螢幕光度
即輸入
1 | xrandr --output VGA-0 --brightness 1.20 |
不過每次設定光度都要輸入指令顯示有點麻煩
在下借用 zenity 來進行互動操作方便調整光度
1 2 3 4 5 | 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) |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #!/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 |
沒有留言 :
張貼留言