add colormodw for brightness module

This commit is contained in:
koksnuss 2018-05-21 22:42:13 +02:00
parent 92de1d9b55
commit f7c886dbda
4 changed files with 34 additions and 13 deletions

View File

@ -11,6 +11,7 @@ This is a simple collection of i3blocks-modules accompagnied by a config file wi
- module *ram*: by default free ram and swap are shown in the format `a+b G` where `a` is ram and `b` is swap. If you want to show ram and swap seperatly, use `instance=ram` or `instance=swap`. If you left click on the block, `top` will be openend. - module *ram*: by default free ram and swap are shown in the format `a+b G` where `a` is ram and `b` is swap. If you want to show ram and swap seperatly, use `instance=ram` or `instance=swap`. If you left click on the block, `top` will be openend.
- *cpu*: by default total idle cpu time of all cores together is displayed. If you left click on the block, `top` will be openend. - *cpu*: by default total idle cpu time of all cores together is displayed. If you left click on the block, `top` will be openend.
- module *battery*: by default the total left energy of all attached batteries is shown. If you want to display the batteries seperatly, use `instance=x` will show the status of BATx in case you have more than one battery attached to your device. - module *battery*: by default the total left energy of all attached batteries is shown. If you want to display the batteries seperatly, use `instance=x` will show the status of BATx in case you have more than one battery attached to your device.
- module *brightness*: By default the brightness level is shown in the default font color (depending on your i3 config). When set to "color" the brightness level is printed colored which is nice when using a device in battery mode.
# Requirements # Requirements
Install [i3 window manager](https://i3wm.org) alongside with [i3blocks](https://github.com/vivien/i3blocks) and `git`. The following shows the requirements for each module: Install [i3 window manager](https://i3wm.org) alongside with [i3blocks](https://github.com/vivien/i3blocks) and `git`. The following shows the requirements for each module:

5
config
View File

@ -5,9 +5,10 @@ separator=false
command=$HOME/.config/i3blocks/modules/$BLOCK_NAME command=$HOME/.config/i3blocks/modules/$BLOCK_NAME
interval=5 interval=5
# [backlight] [backlight]
# label=☼ label=☼
# label=☀,☼,✱,✲,✳,✴,✵,✺ # label=☀,☼,✱,✲,✳,✴,✵,✺
instance=color
[storage] [storage]
label=⛁ label=⛁

View File

@ -2,6 +2,8 @@
DIR="/sys/class/backlight" DIR="/sys/class/backlight"
[[ "${BLOCK_INSTANCE}" == "color" ]] && MODE="color" || MODE="bw"
if [[ -d "$DIR/acpi_video0" ]]; then if [[ -d "$DIR/acpi_video0" ]]; then
DIR="$DIR/acpi_video0" DIR="$DIR/acpi_video0"
elif [[ -d "$DIR/intel_backlight" ]]; then elif [[ -d "$DIR/intel_backlight" ]]; then
@ -12,12 +14,29 @@ else
exit 33 exit 33
fi fi
cat "$DIR/brightness" "$DIR/max_brightness" | gawk ' cat "$DIR/brightness" "$DIR/max_brightness" | gawk -v MODE="$MODE" '
NR==1 { cbr = $1 } NR==1 { current_brightness = $1 }
NR==2 { mbr = $1 } NR==2 { max_brightness = $1 }
END { END {
printf("%d%\n", cbr / mbr * 100) relative_brightness = ( current_brightness / max_brightness ) * 100
printf("%d\n", cbr / mbr * 100) printf("%d%\n", relative_brightness)
print("\n") printf("%d\n", relative_brightness)
if (MODE == "color") {
if (relative_brightness < 50) {
print("#04B431\n")
} else if (relative_brightness < 60) {
print("#A8FF00\n")
} else if (relative_brightness < 70) {
print("#FFF600\n")
} else if (relative_brightness < 80) {
print("#FFAE00\n")
} else if (relative_brightness < 90) {
print("#FF0000\n")
} else {
exit 33
}
} else {
printf("\n")
}
} }
' '

View File

@ -2,13 +2,13 @@
[[ "$BLOCK_BUTTON" == 1 ]] && i3-sensible-terminal -e htop [[ "$BLOCK_BUTTON" == 1 ]] && i3-sensible-terminal -e htop
case ${BLOCK_INSTANCE} in case "${BLOCK_INSTANCE}" in
swap) TYPE="swap";; swap) TYPE="swap";;
ram) TYPE="ram";; ram) TYPE="ram";;
*) TYPE="";; *) TYPE="";;
esac esac
gawk -v type="$TYPE" ' gawk -v TYPE="$TYPE" '
/^MemAvailable/ { /^MemAvailable/ {
rfg = $2 / 1024^2 rfg = $2 / 1024^2
rfm = $2 / 1024 rfm = $2 / 1024
@ -18,7 +18,7 @@ gawk -v type="$TYPE" '
sfm = $2 / 1024 sfm = $2 / 1024
} }
END { END {
if (type == "") { if (TYPE == "") {
mfg = rfg + sfg mfg = rfg + sfg
mfm = rfm + sfm mfm = rfm + sfm
if (mfg > 2) { if (mfg > 2) {
@ -28,7 +28,7 @@ gawk -v type="$TYPE" '
printf("%d+%d M\n", rfm, sfm) printf("%d+%d M\n", rfm, sfm)
printf("%d+%dM\n", rfm, sfm) printf("%d+%dM\n", rfm, sfm)
} }
} else if (type == "ram") { } else if (TYPE == "ram") {
if (rfg > 2) { if (rfg > 2) {
printf("%d G\n", rfg) printf("%d G\n", rfg)
printf("%dG\n", rfg) printf("%dG\n", rfg)
@ -37,7 +37,7 @@ gawk -v type="$TYPE" '
printf("%d M\n", rfm) printf("%d M\n", rfm)
printf("%dM\n", rfm) printf("%dM\n", rfm)
} }
} else if (type == "swap") { } else if (TYPE == "swap") {
if (sfg > 2) { if (sfg > 2) {
printf("%d G\n", sfg) printf("%d G\n", sfg)
printf("%dG\n", sfg) printf("%dG\n", sfg)