fix many stuff, apply uniform color handling ith right click

This commit is contained in:
koksnuss 2018-08-14 00:48:07 +02:00
parent 0b39bbeb46
commit 65d6bb9773
7 changed files with 66 additions and 50 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
*.state *.long

View File

@ -6,13 +6,10 @@
This is a simple collection of i3blocks-modules accompagnied by a config file with the aim to display only important information in favor of not spilling lots of numbers into the status bar. This is a simple collection of i3blocks-modules accompagnied by a config file with the aim to display only important information in favor of not spilling lots of numbers into the status bar.
# Usage # Usage
- *datetime* -- A left click will toggle long and short displays. The short version is displayed in the format `HH:MM`. The long version also shows the day of the week, weeknumber, date and seconds. Some modules accept an `instance` argument:
- *audio* -- Current audio output level. `instance=mic` will show the microphone input level instead. -- audio: default instance is audio output. The optional instance `mic` shows microphone information.
- *ram* -- 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`. -- battery: default instance collects informations from all attached batteries and treats them as one battery. The optional instance `BAT#` can be specified to display results only for battery #.
- *cpu* -- Total idle cpu time of all cores together. Use `instance=long` to show the percentage instead. -- ram: default instance collects information from physical memory and swap. The optional instances `phys` and `swap` only collect information for physical- and swap-memory respectiveley.
- *temp* -- Current temperature of the cpu.
- *battery* -- Total energy left of all batteries. Use `instance=x` to show the status of `BATx` in case you have more than one battery in `/sys/class/powersupply`.
- *backlight* -- Brightness level. Use `instance=long` to show the brightness percentage. Use `instance="color"` to print the brightness level 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:
@ -39,7 +36,6 @@ One-Liner: Open up a terminal and paste: `bash <(curl -s https://will.kein.hk/gi
- Make sure you've added `bar { status_command i3blocks }` in your i3-config file (i.e. `~/config/i3/config`). - Make sure you've added `bar { status_command i3blocks }` in your i3-config file (i.e. `~/config/i3/config`).
- Finally reload your `i3` window manager. The default shortcut is `mod + SHIFT + r`, you should see a flickering. - Finally reload your `i3` window manager. The default shortcut is `mod + SHIFT + r`, you should see a flickering.
# Roadmap # Roadmap
## Modules ## Modules
@ -59,23 +55,28 @@ One-Liner: Open up a terminal and paste: `bash <(curl -s https://will.kein.hk/gi
## Refractor ## Refractor
- [x] centralize color palette and progress bar in abstract.sh - [x] centralize color palette and progress bar in abstract.sh
- [x] centralize long/short view in abstract.sh - [x] centralize long/short view in abstract.sh
- [ ] make long/short permanent: rewrite config + i3reload? how to make it permanent? - [x] centralize color/blackwhite view in abstract.sh
- [ ] the progress bar logic seems to repeat itself again and again, this can be done better - [x] make long/short permanent
- [x] make color/blackwhite permanent
- [x] the progress bar logic seems to repeat itself again and again, this can be done better
## Click interactions ## Click interactions
### Long/Short preview: Middle click ### Long/Short preview: Left click
- [ ] Toggle long (numbers and units) and short (representative bar) preview - [x] Toggle long (numbers and units) and short (representative bar) preview
### Color/Blackwhite preview: right click
- [x] Toggle color and blackwhite preview
### Open another program: Left click ### Open another program: Left click
- [c] audio/mic: open pavucontrol - [x] audio/mic: pavucontrol
- [c] ram/cpu/temp: open htop - [x] ram/cpu/temp: htop
- [c] storage: open ranger - [x] storage: ranger
- [c] ip: middle: open firefox - [x] ip: firefox
- [ ] mount: mount it somewhere (with pmount?) and open ranger - [ ] mount: mount it somewhere (with pmount?) and open ranger
### Other behaviour ### Other behaviour
- [c] audio/mic: toggle mute - [c] audio/mic: toggle mute, TODO: conflicte with color toggle
- [ ] onn/off behaviour: backlight, ethernet, audio, mic - [ ] onn/off behaviour: backlight, ethernet, audio, mic
## Signals ## Signals

17
config
View File

@ -9,8 +9,7 @@ interval=5
label=☼ label=☼
# label=☀,☼,✱,✲,✳,✴,✵,✺ # label=☀,☼,✱,✲,✳,✴,✵,✺
signal=3 signal=3
instance=color # instance=color
# instance=color,bw
# [iface] # [iface]
# label=iface # label=iface
@ -20,11 +19,11 @@ instance=color
# label=⛀,⛁,⛂,⛃ # label=⛀,⛁,⛂,⛃
# interval=60 # interval=60
# if you want to display ram and swap seperately, you can assign another [ram] module # if you want to display physical ram and swap seperately, you can assign another [ram] module
# with instance=ram or instance=swap # with instance=phys or instance=swap
[ram] [ram]
label=⚟ label=⚟
instance=ram # instance=phys
# [ram] # [ram]
# instance=swap # instance=swap
@ -61,16 +60,16 @@ interval=60
[audio] [audio]
label=◍ label=◍
# label=♩,♪,♫,♬
signal=1 signal=1
interval=once interval=once
instance=color # instance=color
# label=♩,♪,♫,♬
# separator_block_width=0 # separator_block_width=0
[audio] [audio]
label=◎ label=◎
signal=2
# label=⋓ℹ⋒ⅈ # label=⋓ℹ⋒ⅈ
instance=mic,color signal=2
instance=mic
interval=once interval=once
[datetime] [datetime]

View File

@ -1,7 +1,7 @@
# click interactions # click interactions
[[ "$BLOCK_INSTANCE" =~ "color" ]] && COLORS=True
## toggle long and short preview ## toggle long and short preview
STATE="${HOME}/.config/i3blocks/modules/${1}.state" STATE="${HOME}/.config/i3blocks/modules/${1}-${BLOCK_INSTANCE}.long"
COLORS="${HOME}/.config/i3blocks/modules/${1}-${BLOCK_INSTANCE}.color"
if [[ "$BLOCK_BUTTON" == 1 ]]; then if [[ "$BLOCK_BUTTON" == 1 ]]; then
if [[ -f "$STATE" ]]; then if [[ -f "$STATE" ]]; then
rm $STATE rm $STATE
@ -14,6 +14,18 @@ else
[[ -f "$STATE" ]] && LONG=true || LONG=false [[ -f "$STATE" ]] && LONG=true || LONG=false
fi fi
## toggle color and black/white mode
if [[ "$BLOCK_BUTTON" == 3 ]]; then
if [[ -f "$COLORS" ]]; then
rm $COLORS
COLORS=false
else
touch $COLORS
COLORS=true
fi
else
[[ -f "$COLORS" ]] && COLORS=true || COLORS=false
fi
# global variables # global variables
BAR=("▁" "▂" "▃" "▄" "▅" "▆" "▇" "█") BAR=("▁" "▂" "▃" "▄" "▅" "▆" "▇" "█")
@ -24,7 +36,6 @@ BW=("#565656" "#6d6d6d" "#848485" "#9c9c9c" "#b1b1b1" "#c7c7c7" "#dcdcdc" "#f5f5
# get $LOAD, $LONG_TEXT and $SHORT_TEXT # get $LOAD, $LONG_TEXT and $SHORT_TEXT
source $HOME/.config/i3blocks/modules/${1}.sh source $HOME/.config/i3blocks/modules/${1}.sh
# text # text
if [[ "$LOAD" = false && "$LONG" = false ]]; then if [[ "$LOAD" = false && "$LONG" = false ]]; then
echo $SHORT_TEXT echo $SHORT_TEXT
@ -45,6 +56,6 @@ fi
# colors # colors
for i in "${!BW[@]}"; do for i in "${!BW[@]}"; do
if [[ $LOAD -lt $((($i+1) * $INTERVAL)) ]]; then if [[ $LOAD -lt $((($i+1) * $INTERVAL)) ]]; then
[[ $COLORS ]] && echo "${COLOR[$i]}" || echo "${BW[$i]}" [[ "$COLORS" = true ]] && echo "${COLOR[$i]}" || echo "${BW[$i]}"
fi fi
done done

View File

@ -14,7 +14,7 @@ if [[ $(amixer get $DEV) =~ \[([0-9]+)\%\][[:space:]]\[(on|off)\] ]]; then
LOAD=false LOAD=false
fi fi
else else
LONG_TEXT="no audio source" LONG_TEXT="Audio source not found"
SHORT_TEXT="n/a" SHORT_TEXT="n/a"
LOAD=false LOAD=false
fi fi

0
modules/backlight-.color Normal file
View File

View File

@ -1,26 +1,16 @@
[[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e htop [[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e htop
[[ $BLOCK_INSTANCE =~ (phys|swap) ]] && TYPE=${BASH_REMATCH[1]} [[ $BLOCK_INSTANCE =~ (phys|swap) ]] && TYPE=${BASH_REMATCH[1]}
MEMINFO=$(cat /proc/meminfo) MEMINFO=$(cat /proc/meminfo)
if [[ $MEMINFO =~ MemTotal:[[:space:]]+([0-9]+) ]]; then [[ $MEMINFO =~ MemTotal:[[:space:]]+([0-9]+) ]] && PHYS_TOTAL=$((${BASH_REMATCH[1]} / 1024**2))
PHYS_TOTAL=${BASH_REMATCH[1]}
PHYS_TOTAL=$((${PHYS_TOTAL} / 1024**2))
fi
if [[ $MEMINFO =~ MemAvailable:[[:space:]]+([0-9]+) ]]; then if [[ $MEMINFO =~ MemAvailable:[[:space:]]+([0-9]+) ]]; then
PHYS_AVAILABLE=${BASH_REMATCH[1]} [[ ${BASH_REMATCH[1]} -gt 2000000 ]] && PHYS_AVAILABLE=$((${BASH_REMATCH[1]} / 1024**2)) || PHYS_AVAILABLE=$((${BASH_REMATCH[1]} / 1024))
PHYS_AVAILABLE=$((${PHYS_AVAILABLE} / 1024**2))
PHYS_AVAILABLE_M=$((${PHYS_AVAILABLE} / 1024))
fi
if [[ $MEMINFO =~ SwapTotal:[[:space:]]+([0-9]+) ]]; then
SWAP_TOTAL=${BASH_REMATCH[1]}
SWAP_TOTAL=$((${SWAP_TOTAL} / 1024**2))
fi fi
[[ $MEMINFO =~ SwapTotal:[[:space:]]+([0-9]+) ]] && SWAP_TOTAL=$((${BASH_REMATCH[1]} / 1024**2))
if [[ $MEMINFO =~ SwapFree:[[:space:]]+([0-9]+) ]]; then if [[ $MEMINFO =~ SwapFree:[[:space:]]+([0-9]+) ]]; then
SWAP_AVAILABLE=${BASH_REMATCH[1]} [[ ${BASH_REMATCH[1]} -gt 2000000 ]] && SWAP_AVAILABLE=$((${BASH_REMATCH[1]} / 1024**2)) || SWAP_AVAILABLE=$((${BASH_REMATCH[1]} / 1024))
SWAP_AVAILABLE=$((${SWAP_AVAILABLE} / 1024**2))
SWAP_AVAILABLE_M=$((${SWAP_AVAILABLE} / 1024))
fi fi
[[ ! $PHYS_AVAILABLE || ! $PHYS_TOTAL || ! $SWAP_AVAILABLE || ! $SWAP_TOTAL ]] && printf "Ram not found\nn/a\n" && exit 33
if [[ "$TYPE" == "" ]]; then if [[ "$TYPE" == "" ]]; then
MEM_FREE=$((${PHYS_AVAILABLE} + ${SWAP_AVAILABLE})) MEM_FREE=$((${PHYS_AVAILABLE} + ${SWAP_AVAILABLE}))
@ -29,13 +19,28 @@ if [[ "$TYPE" == "" ]]; then
LONG_TEXT="${PHYS_AVAILABLE}+${SWAP_AVAILABLE}G" LONG_TEXT="${PHYS_AVAILABLE}+${SWAP_AVAILABLE}G"
SHORT_TEXT="${PHYS_AVAILABLE}+${SWAP_AVAILABLE}G" SHORT_TEXT="${PHYS_AVAILABLE}+${SWAP_AVAILABLE}G"
else else
LONG_TEXT="${PHYS_AVAILABLE_M}+${SWAP_AVAILABLE}M" LONG_TEXT="${PHYS_AVAILABLE}+${SWAP_AVAILABLE}M"
SHORT_TEXT="${PHYS_AVAILABLE_M}+${SWAP_AVAILABLE}M" SHORT_TEXT="${PHYS_AVAILABLE}+${SWAP_AVAILABLE}M"
fi fi
elif [[ "$TYPE" == "ram" ]]; then elif [[ "$TYPE" == "phys" ]]; then
MEM_FREE=${PHYS_AVAILABLE} MEM_FREE=${PHYS_AVAILABLE}
MEM_TOTAL=${PHYS_TOTAL} MEM_TOTAL=${PHYS_TOTAL}
if [[ "$MEM_FREE" -gt 2 ]]; then
LONG_TEXT="${PHYS_AVAILABLE}G"
SHORT_TEXT="${PHYS_AVAILABLE}G"
else
LONG_TEXT="${PHYS_AVAILABLE}M"
SHORT_TEXT="${PHYS_AVAILABLE}M"
fi
elif [[ "$TYPE" == "swap" ]]; then elif [[ "$TYPE" == "swap" ]]; then
MEM_FREE=${SWAP_AVAILABLE} MEM_FREE=${SWAP_AVAILABLE}
MEM_TOTAL=${SWAP_TOTAL} MEM_TOTAL=${SWAP_TOTAL}
if [[ "$MEM_FREE" -gt 2 ]]; then
LONG_TEXT="${SWAP_AVAILABLE}G"
SHORT_TEXT="${SWAP_AVAILABLE}G"
else
LONG_TEXT="${SWAP_AVAILABLE}M"
SHORT_TEXT="${SWAP_AVAILABLE}M"
fi
fi fi
LOAD=$(((${MEM_TOTAL} - ${MEM_FREE}) * 100 / ${MEM_TOTAL}))