From 1b77dc4e5c06af101c563ae6f4f51efea8f726f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Sun, 4 Aug 2019 09:46:17 -0700 Subject: use xss-lock --- .config/i3/config | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to '.config') diff --git a/.config/i3/config b/.config/i3/config index f4770e2..f3c8e49 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -1,3 +1,4 @@ + # Debian packages: redshift-gtk dunst compton conky-std network-manager-gnome nitrogen xautolock set $mod Mod4 @@ -193,7 +194,8 @@ bar { } } -exec --no-startup-id xautolock -locker i3lock-wrapper -time 2 -corners -+00 -cornerdelay 5 & +exec --no-startup-id xset s 120 +exec --no-startup-id xss-lock -l -n dim-screen.sh i3lock-wrapper & exec --no-startup-id compton -b exec --no-startup-id conky exec --no-startup-id touchpad-enable-tap -- cgit v1.2.3 From 826c03929d034f9fbbc8e580a94eb4399930af22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Sun, 4 Aug 2019 10:20:22 -0700 Subject: fix transparency quirks --- .config/compton.conf | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to '.config') diff --git a/.config/compton.conf b/.config/compton.conf index fceb4a2..9fcee62 100644 --- a/.config/compton.conf +++ b/.config/compton.conf @@ -1,16 +1,6 @@ -# Shadow -shadow = false; -no-dnd-shadow = true; -no-dock-shadow = true; -clear-shadow = true; -shadow-radius = 12.0; -shadow-offset-x = -12; -shadow-offset-y = -12; -shadow-opacity = 0.95; - # Opacity menu-opacity = 1.0; -inactive-opacity = 1.0; +inactive-opacity = 0.0; active-opacity = 1.0; # Fading -- cgit v1.2.3 From e3b421c86bb49fd3d44e88867aeb99d5b7d53319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Sun, 4 Aug 2019 10:20:46 -0700 Subject: audio and brightness buttons --- .config/i3/config | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to '.config') diff --git a/.config/i3/config b/.config/i3/config index f3c8e49..a7b52a0 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -136,10 +136,14 @@ bindsym $mod+Shift+r restart # exit i3 (logs you out of your X session) bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -B 'Yes, exit i3' 'i3-msg exit'" -#change volume -bindsym XF86AudioRaiseVolume exec amixer -q set Master 5%+ -bindsym XF86AudioLowerVolume exec amixer -q set Master 5%- -bindsym XF86AudioMute exec amixer set Master toggle +# Pulse Audio controls +bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume 0 +5% #increase sound volume +bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume 0 -5% #decrease sound volume +bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute 0 toggle # mute sound + +# Sreen brightness controls +bindsym XF86MonBrightnessUp exec xbacklight -inc 20 # increase screen brightness +bindsym XF86MonBrightnessDown exec xbacklight -dec 20 # decrease screen brightness # music control bindsym XF86AudioNext exec mpc next -- cgit v1.2.3 From 9346f23a7bb6c9428ff752e747f268d9f9c8db21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Sun, 4 Aug 2019 10:56:07 -0700 Subject: better battery --- .config/i3/config | 6 +- .config/i3blocks/blocks/battery-plus | 793 +++++++++++++++++++++++++++++++++++ .config/i3blocks/config | 14 +- 3 files changed, 803 insertions(+), 10 deletions(-) create mode 100755 .config/i3blocks/blocks/battery-plus (limited to '.config') diff --git a/.config/i3/config b/.config/i3/config index a7b52a0..a5bd3cf 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -137,9 +137,9 @@ bindsym $mod+Shift+r restart bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -B 'Yes, exit i3' 'i3-msg exit'" # Pulse Audio controls -bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume 0 +5% #increase sound volume -bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume 0 -5% #decrease sound volume -bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute 0 toggle # mute sound +bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume 0 +5% && pkill -RTMIN+10 i3blocks #increase sound volume +bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume 0 -5% && pkill -RTMIN+10 i3blocks #decrease sound volume +bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute 0 toggle && pkill -RTMIN+10 i3blocks # mute sound # Sreen brightness controls bindsym XF86MonBrightnessUp exec xbacklight -inc 20 # increase screen brightness diff --git a/.config/i3blocks/blocks/battery-plus b/.config/i3blocks/blocks/battery-plus new file mode 100755 index 0000000..d097f72 --- /dev/null +++ b/.config/i3blocks/blocks/battery-plus @@ -0,0 +1,793 @@ +#!/usr/bin/env bash +# +# battery-plus +# +# An enhanced battery status indicator for i3blocks. +# +# Requires: +# awk (POSIX compatible) +# bc +# upower +# +# Optional: +# fonts-font-awesome +# notify-send or dunstify -- for notifications +# zenity -- for dialogs +# +# Copyright (c) 2018 Beau Hastings. All rights reserved. +# License: GNU General Public License v2 +# +# Author: Beau Hastings +# URL: https://github.com/hastinbe/i3blocks-battery-plus + +_FONT=${_FONT:-"FontAwesome"} +_PERCENT="%" + +# Hide the battery status if fully-charged, +_HIDE_IF_CHARGED=${_HIDE_IF_CHARGED:-false} + +# Color the battery symbol using gradient. +_USE_BATT_GRADIENT=${_USE_BATT_GRADIENT:-false} + +# Only show symbols. +_SYMBOLS_ONLY=${_SYMBOLS_ONLY:-false} + +# Hide the battery percentage +_HIDE_PERCENTAGE=${_HIDE_PERCENTAGE:-false} + +# Hide the battery time remaining +_HIDE_TIME_REMAINING=${_HIDE_TIME_REMAINING:-true} + +# Hide the time to charge the battery to full +_HIDE_TIME_TO_FULL=${_HIDE_TIME_TO_FULL:-true} + +# Show the direction of change for the battery's percentage +_SHOW_CHARGE_DIRECTION=${_SHOW_CHARGE_DIRECTION:-true} + +# Show an alert symbol when the battery capacity drops to the given percent (0=disable). +_CAPACITY_ALERT=${_CAPACITY_ALERT:0} + +# Action to take when the battery level reaches critical. +_CRITICAL_ACTION=${_CRITICAL_ACTION:-"notify"} + +# Action to take when the battery level reaches low. +_LOW_ACTION=${_LOW_ACTION:-"notify"} + +# Method to use for notifications +_NOTIFY_PROGRAM=${_NOTIFY_PROGRAM:-"notify-send"} + +# The duration, in milliseconds, for the notification to appear on screen. +_NOTIFY_EXPIRES="1500" + +# Minimum time in seconds between notifications to prevent spam. +_NOTIFY_THROTTLE=${_NOTIFY_THROTTLE:-120} + +# Colors +_COLOR_FULLY_CHARGED=${_COLOR_FULLY_CHARGED:-""} +_COLOR_CHARGING=${_COLOR_CHARGING:-"yellow"} +_COLOR_DISCHARGING=${_COLOR_CHARGING:-"yellow"} +_COLOR_PENDING=${_COLOR_PENDING:-"blue"} +_COLOR_ERROR=${_COLOR_ERROR:-"red"} +_COLOR_BATTERY=${_COLOR_BATTERY:-"white"} +_COLOR_ALERT=${_COLOR_ALERT:-"orange"} +_COLOR_DIRECTIONAL_UP=${_COLOR_DIRECTIONAL_UP:-"green"} +_COLOR_DIRECTIONAL_DOWN=${_COLOR_DIRECTIONAL_DOWN:-"red"} +_COLOR_GRADIENT_START=${_COLOR_GRADIENT_START:-"#FF0000"} +_COLOR_GRADIENT_END=${_COLOR_GRADIENT_END:-"#00FF00"} + +# Symbols +_SYMBOL_FULLY_CHARGED=${_SYMBOL_FULLY_CHARGED:-""} +_SYMBOL_CHARGING=${_SYMBOL_CHARGING:-""} +_SYMBOL_DISCHARGING=${_SYMBOL_DISCHARGING:-""} +_SYMBOL_UNKNOWN=${_SYMBOL_UNKNOWN:-""} +_SYMBOL_PENDING=${_SYMBOL_PENDING:-""} +_SYMBOL_ERROR=${_SYMBOL_ERROR:-""} +_SYMBOL_ALERT=${_SYMBOL_ALERT:-""} +_SYMBOL_BATT_100=${_SYMBOL_BATT_100:-""} +_SYMBOL_BATT_75=${_SYMBOL_BATT_75:-""} +_SYMBOL_BATT_50=${_SYMBOL_BATT_50:-""} +_SYMBOL_BATT_25=${_SYMBOL_BATT_25:-""} +_SYMBOL_BATT_0=${_SYMBOL_BATT_0:-""} +_SYMBOL_DIRECTION_UP=${_SYMBOL_DIRECTION_UP:-"↑"} +_SYMBOL_DIRECTION_DOWN=${_SYMBOL_DIRECTION_DOWN:-"↓"} + +# Get a the system's temporary files directory. +# +# Notes: +# Executes a dry-run so we don't create a file. +# Linux doesn't require the template option, but MacOSX does. +# +# Returns: +# The path to the temporary directory. +get_temp_dir() { + echo $(dirname $(mktemp -ut "battery-plus.XXX")) +} + +# Output text wrapped in a span element +# +# Options: +# -c To specify a text color +# +# Arguments: +# $1 or $3 - String to encapsulate within a span +span() { + local -A attribs + local text="$*" + + if [ -n "$FONT" ]; then attribs[font]="$FONT"; fi + + if [ "$1" = "-c" ]; then + attribs[color]="$2" + text="${*:3}" + fi + + echo "$text" +} + +# Builds html element attributes +# +# Arguments: +# $1 - An associative array of attribute-value pairs +build_attribs() { + local -n array=$1 + for k in "${!array[@]}"; do + echo -n " $k='${array[$k]}'" + done + echo +} + +# Interpolate between 2 RGB colors +# +# Arguments: +# $1 - Color to interpolate from, as a hex triplet prefixed with # +# $2 - Color to interpolate to, as a hex triplet prefixed with # +# $3 - Amount of steps needed to get from start to end color +interpolate_rgb() { + local -i steps=$3 + local -a colors + local color1=$1 + local color2=$2 + local reversed=false + + if (( 0x${color1:1:5} > 0x${color2:1:5} )); then + color1=$2 + color2=$1 + reversed=true + fi + + printf -v startR "%d" 0x${color1:1:2} + printf -v startG "%d" 0x${color1:3:2} + printf -v startB "%d" 0x${color1:5:2} + printf -v endR "%d" 0x${color2:1:2} + printf -v endG "%d" 0x${color2:3:2} + printf -v endB "%d" 0x${color2:5:2} + + stepR=$(( ($endR - $startR) / $steps )) + stepG=$(( ($endG - $startG) / $steps )) + stepB=$(( ($endB - $startB) / $steps )) + + for i in $(seq 0 $steps); do + local -i R=$(( $startR + ($stepR * $i) )) + local -i G=$(( $startG + ($stepG * $i) )) + local -i B=$(( $startB + ($stepB * $i) )) + + colors+=( "$(printf "#%02x%02x%02x\n" $R $G $B)" ) + done + colors+=( "$(printf "#%02x%02x%02x\n" $endR $endB $endG)" ) + + if $reversed; then + reverse colors colors_reversed + echo "${colors_reversed[@]}" + else + echo "${colors[@]}" + fi +} + +# Reverse an array +# +# Arguments: +# $1 - Array to reverse +# $2 - Destination array +reverse() { + local -n arr="$1" rev="$2" + for i in "${arr[@]}" + do + rev=("$i" "${rev[@]}") + done +} + +min() { + echo "if ($1 < $2) $1 else $2" | bc +} + +max() { + echo "if ($1 > $2) $1 else $2" | bc +} + +clamp() { + echo $(min $(max $1 $2) $3) +} + +# Retrieve an item from the provided lookup table based on the percentage of a number +# +# Arguments: +# $1 - A number +# $2 - Number to get a percentage of +# $3 - An array of potential values +plookup() { + if [ -z "$2" -o -z "$3" ]; then + return + fi + + local table=( ${@:3} ) + local number2=${2%.*} + local number1=$(min ${1%.*} $number2) + local percent_max=$(( $number1 * $number2 / 100 )) + local index=$(( $percent_max * ${#table[@]} / 100 )) + + index=$(clamp $index 0 $(( ${#table[@]} - 1 )) ) + + echo ${table[$index]} +} + +# Get battery status. +# +# Returns: +# The battery's status or state. +get_battery_status() { + echo "$__UPOWER_INFO" | awk -W posix '$1 == "state:" {print $2}' +} + +# Get battery warning level. +# +# Returns: +# The battery's warning level. +get_battery_warning_level() { + echo "$__UPOWER_INFO" | awk -W posix '$1 == "warning-level:" {print $2}' +} + +# Get battery percentage. +# +# Returns: +# The battery's percentage, without the %. +get_battery_percent() { + echo "$__UPOWER_INFO" | awk -W posix '$1 == "percentage:" { gsub("%","",$2); print $2}' +} + +# Get battery capacity. +# +# Returns: +# The battery's capcity, without the %. +get_battery_capacity() { + echo "$__UPOWER_INFO" | awk -W posix '$1 == "capacity:" { gsub("%","",$2); print $2}' +} + +# Get battery time left. +# +# Returns: +# The battery's time left. +get_time_to_empty() { + echo "$__UPOWER_INFO" | awk -W posix -F':' '/time to empty:/{print $2}' | xargs +} + +# Get the time remaining until the battery is fully charged. +# +# Returns: +# The time remaining until battery is fully charged. +get_time_to_full() { + echo "$__UPOWER_INFO" | awk -W posix -F':' '/time to full:/{print $2}' | xargs +} + +# Get symbol for the given battery percentage. +# +# Arguments: +# $percent (int) Battery percentage. +# +# Returns: +# The battery symbol. +get_battery_charge_symbol() { + local percent="$1" + local symbol + + if [ "$battery_percentage" -ge 90 ]; then symbol="$_SYMBOL_BATT_100" + elif [ "$battery_percentage" -ge 70 ]; then symbol="$_SYMBOL_BATT_75" + elif [ "$battery_percentage" -ge 40 ]; then symbol="$_SYMBOL_BATT_50" + elif [ "$battery_percentage" -ge 20 ]; then symbol="$_SYMBOL_BATT_25" + else symbol="$_SYMBOL_BATT_0" + fi + + echo "$symbol" +} + +# Get battery status symbol. +# +# Returns: +# An symbol name, following the Symbol Naming Specification +get_battery_status_symbol() { + echo "$__UPOWER_INFO" | awk -W posix '$1 == "symbol-name:" {print $2}' +} + +# Get color for the given battery percentage. +# +# Arguments: +# $percent (int) Battery percentage. +# +# Returns: +# The color to use for the given battery percentage. +get_percentage_color() { + local colors=( $(interpolate_rgb "$_COLOR_GRADIENT_START" "$_COLOR_GRADIENT_END" 8) ) + echo $(plookup $1 100 ${colors[@]}) +} + +# Determines whether or not we can send a notification. +# +# Returns: +# 0 on false, 1 on true. +can_notify() { + local -i now=$(date +"%s") + local -i last=$(get_last_notify_time) + + if [ -z "$last" ]; then return 0; fi + + local -i diff=$(($now - $last)) + + [ $diff -gt $_NOTIFY_THROTTLE ] +} + +# Get the last time we sent a notification. +# +# Returns: +# Time in seconds since the Epoch. +get_last_notify_time() { + if [ -f "$TMP_NOTIFY" ]; then + echo $(stat -c '%Y' "$TMP_NOTIFY") + fi +} + +# Save the last time we sent a notification. +save_last_notify_time() { + touch -m "$TMP_NOTIFY" +} + +# Display the charging indicator. +# +# Returns: +# The charging indicator. +display_batt_charging() { + if [ -n "$_SYMBOL_CHARGING" ]; then + echo -n "$(span -c "${_COLOR_CHARGING}" "$_SYMBOL_CHARGING") " + fi + + echo "$colored_battery_symbol" +} + +# Display the discharging indicator. +# +# Returns: +# The discharging indicator. +display_batt_discharging() { + if [ -n "$_SYMBOL_DISCHARGING" ]; then + echo -n "$(span -c "${_COLOR_DISCHARGING}" "$_SYMBOL_DISCHARGING") " + fi + + echo "$battery_charge_symbol" +} + +# Display the pending charge indicator. +# +# Returns: +# The pending charge indicator. +display_batt_pending_charge() { + if [ -n "$_SYMBOL_PENDING" ]; then + echo -n "$(span -c "${_COLOR_PENDING}" "$_SYMBOL_PENDING") " + fi + + if [ -n "$_SYMBOL_CHARGING" ]; then + echo -n "$(span -c "${_COLOR_CHARGING}" "$_SYMBOL_CHARGING") " + fi + + echo "${battery_charge_symbol}" +} + +# Display the pending discharge indicator. +# +# Returns: +# The pending discharge indicator. +display_batt_pending_discharge() { + if [ -n "$_SYMBOL_PENDING" ]; then + echo -n "$(span -c "${_COLOR_PENDING}" "$_SYMBOL_PENDING") " + fi + + if [ -n "$_SYMBOL_DISCHARGING" ]; then + echo -n "$(span -c "${_COLOR_DISCHARGING}" "$_SYMBOL_DISCHARGING") " + fi + + echo "$colored_battery_symbol" +} + +# Display the empty battery indicator. +# +# Returns: +# The empty battery indicator. +display_batt_empty() { + echo "$battery_charge_symbol" +} + +# Display the fully charged indicator. +# +# Returns: +# The fully-charged indicator. +display_batt_fully_charged() { + if [ -n "$_SYMBOL_FULLY_CHARGED" ]; then + echo -n "$(span -c "${_COLOR_FULLY_CHARGED}" "$_SYMBOL_FULLY_CHARGED") " + fi + + echo "$battery_charge_symbol" +} + +# Display the unknown battery indicator. +# +# Returns: +# The unknonw battery indicator. +display_batt_unknown() { + if [ -n "$_SYMBOL_UNKNOWN" ]; then + echo -n "$(span "$_SYMBOL_UNKNOWN") " + fi + + echo "$(get_battery_charge_symbol 0)" +} + +# Display the battery error indicator. +# +# Returns: +# The battery error indicator. +display_batt_error() { + echo "$(span -c "${_COLOR_ERROR}" "$_SYMBOL_ERROR" "$_SYMBOL_BATT_0")" +} + +# Display the battery percentage. +# +# Returns: +# The battery percentage, or nothing if disabled. +display_percentage() { + if ! [ $_SYMBOLS_ONLY = true -o $_HIDE_PERCENTAGE = true ]; then + echo -n " $(span -c "${percentage_color}" "${battery_percentage:---}${_PERCENT}")" + + if [ "$status" = "charging" ] && $_SHOW_CHARGE_DIRECTION; then + echo -n "$(span -c "${_COLOR_DIRECTIONAL_UP}" "${_SYMBOL_DIRECTION_UP}")" + elif [ "$status" = "discharging" ] && $_SHOW_CHARGE_DIRECTION; then + echo -n "$(span -c "${_COLOR_DIRECTIONAL_DOWN}" "${_SYMBOL_DIRECTION_DOWN}")" + fi + + echo + fi +} + +# Display the battery time remaining. +# +# Arguments: +# $force (bool) Force display. +# +# Returns: +# The time remaining, or nothing if disabled. +display_time_remaining() { + local force=${1:-false} + + if [ $force = true ] || ! [ $_SYMBOLS_ONLY = true -o $_HIDE_TIME_REMAINING = true ]; then + time_to_empty=$(get_time_to_empty "$battery_info") + if [ -n "$time_to_empty" ]; then + echo "$time_to_empty" + fi + fi +} + +# Display the battery time to fully charge. +# +# Arguments: +# $force (bool) Force display. +# +# Returns: +# The time to fully charge, or nothing if disabled. +display_time_to_full() { + local force=${1:-false} + + if [ $force = true ] || ! [ $_SYMBOLS_ONLY = true -o $_HIDE_TIME_TO_FULL = true ]; then + time_to_full=$(get_time_to_full "$battery_info") + if [ -n "$time_to_full" ]; then + echo "$time_to_full" + fi + fi +} + +# Displays an array of segments. +# +# Arguments: +# $segments (array) The an array of segments. +# +# Returns: +# Each segment after another, followed by a newline. +display_segments() { + local -a segments="$@" + + for segment in "${segments[@]}"; do + if [ -n "$segment" ]; then + echo -n "$segment" + fi + done + + echo +} + +# Colors text using either the first or second color +# +# Arguments: +# $1 - Text +# $2 - Color to use if toggle is false +# $3 - Color to use if toggle is true +# $4 - A boolean used to toggle between colors +# +# Returns: +# The colored text +multicolor() { + local color="$2" + local toggle=$4 + + if $toggle && [ -n "$3" ]; then + color="$3" + fi + + if [ -n "$color" ]; then + echo "$(span -c "$color" "$1")" + else + echo "$(span "$1")" + fi +} + + +# Display a notification. +# +# Arguments: +# $text (string) The notification text. +# $symbol (string) Name of an symbol. +# $type (string) The type of notification. +# $force (string) Force the notification, ignoring any throttle. +# $rest (string) Any additional options to pass to the command. +notify() { + local text="$1" + local symbol="$2" + local type="$3" + local force="$4" + local rest="${@:5}" + local command + + if [ -z "$text" ] || ! $force && ! $(can_notify); then return; fi + + if [ "$_NOTIFY_PROGRAM" = "dunstify" ]; then + command="dunstify -r 1001" + elif [ "$_NOTIFY_PROGRAM" = "notify-send" ]; then + command="notify-send" + fi + + if [ -n "$_NOTIFY_EXPIRES" ]; then command="$command -t $_NOTIFY_EXPIRES"; fi + if [ -n "$symbol" ]; then command="$command -i $symbol"; fi + if [ -n "$type" ]; then command="$command -u $type"; fi + + command="$command $rest \"$text\"" + if eval $command; then + save_last_notify_time + fi +} + +# Display a dialog. +# +# Arguments: +# $text (string) The dialog text. +# $symbol (string) Name of an symbol. +# $type (string) The type of dialog. +# $rest (string) Any additional options to pass to the command. +dialog() { + local text="$1" + local symbol="$2" + local type="$3" + local rest="${@:4}" + + if [ -z "$text" ]; then + return + fi + + command="zenity" + + if [ -n "$symbol" ]; then command="$command --symbol-name=\"$symbol\""; fi + if [ -n "$type" ]; then command="$command --${type}"; fi + + command="$command --text=\"$text\" $rest" + eval $command +} + +# Display program usage. +usage() { + echo -e "Usage: $0 [options] +Display the battery status using upower for i3blocks.\n +Options: + -a \taction to take when battery is low + -A \t\tcolor of the alert symbol + -B \t\tcolor of the battery symbol + -c \t\tset battery capacity alert percentage (0=disable) + -C \t\tcolor of the charging symbol + -d\t\t\tshow the direction of change for the battery's percentage + -D \t\tcolor of the discharging symbol + -e \texpiration time of notifications (Ubuntu's Notify OSD and GNOME Shell both ignore this parameter.) + -E \t\tcolor of the battery error symbol + -f \t\tfont for text and symbols + -F \t\tcolor of the fully-charged symbol + -G\t\t\tcolor the battery symbol according to battery percentage + -h\t\t\tdisplay this help and exit + -H\t\t\tsuppress displaying if battery is fully-charged + -i \t\tcolor gradient start color + -I\t\t\tonly display symbols + -j \t\tcolor gradient end color + -J \t\tsymbol for a battery 100% charged + -k\t\t\thide the battery percentage + -K \t\tsymbol for a battery 75% charged + -l \taction to take when the battery level reaches critical + -L \t\tsymbol to indicate there is an alert + -M \t\tsymbol for a battery 50% charged + -n \t\ta libnotify compatible notification program + -N \t\tcolor of the battery charge decreasing indicator + -O \t\tsymbol for a battery with no/low charge + -p \t\tsymbol to use for the percent sign + -P \t\tcolor of the pending charge symbol + -Q \t\tsymbol for a battery 25% charged + -r\t\t\thide the battery time remaining + -R \t\tsymbol to indicate the battery state is undefined + -S \t\tsymbol to indicate battery is fully charged + -t \t\tminimum time in seconds between notifications to prevent spam + -T \t\tsymbol to indicate the battery is charging + -u\t\t\thide the time to charge the battery to full + -U \t\tcolor of the battery charge increasing indicator + -V \t\tsymbol to indicate the battery state is unknown + -W \t\tsymbol to indicate battery charge is increasing + -X \t\tsymbol to indicate the battery state is pending + -Y \t\tsymbol to indicate the battery is discharging + -Z \t\tsymbol to indicate battery charge is decreasing +" 1>&2 + exit 1 +} + +############################################################################### + +declare -a long_segments +declare -a short_segments + +__UPOWER_INFO=$(upower --show-info "/org/freedesktop/UPower/devices/battery_${BLOCK_INSTANCE:-BAT0}") +TMP_NOTIFY="$(get_temp_dir)/battery-plus.last_notify" + +while getopts "a:A:B:c:C:dD:e:E:f:F:GhHi:Ij:J:kK:l:L:M:n:N:O:p:P:Q:rR:S:t:T:uU:V:W:X:Y:Z:" o; do + case "$o" in + a) _LOW_ACTION="${OPTARG}" ;; + A) _COLOR_ALERT="${OPTARG}" ;; + B) _COLOR_BATTERY="${OPTARG}" ;; + c) _CAPACITY_ALERT="${OPTARG}" ;; + C) _COLOR_CHARGING="${OPTARG}" ;; + d) _SHOW_CHARGE_DIRECTION=true ;; + D) _COLOR_DISCHARGING="${OPTARG}" ;; + e) _NOTIFY_EXPIRES="${OPTARG}" ;; + E) _COLOR_ERROR="${OPTARG}" ;; + f) _FONT="${OPTARG}" ;; + F) _COLOR_FULLY_CHARGED="${OPTARG}" ;; + G) _USE_BATT_GRADIENT=true ;; + h | *) usage ;; + H) _HIDE_IF_CHARGED=true ;; + i) _COLOR_GRADIENT_START="${OPTARG}" ;; + I) _SYMBOLS_ONLY=true ;; + j) _COLOR_GRADIENT_END="${OPTARG}" ;; + J) _SYMBOL_BATT_100="${OPTARG}" ;; + k) _HIDE_PERCENTAGE=true ;; + K) _SYMBOL_BATT_75="${OPTARG}" ;; + l) _CRITICAL_ACTION="${OPTARG}" ;; + L) _SYMBOL_ALERT="${OPTARG}" ;; + M) _SYMBOL_BATT_50="${OPTARG}" ;; + n) _NOTIFY_PROGRAM="${OPTARG}" ;; + N) _COLOR_DIRECTIONAL_DOWN="${OPTARG}" ;; + O) _SYMBOL_BATT_0="${OPTARG}" ;; + p) _PERCENT="${OPTARG}" ;; + P) _COLOR_PENDING="${OPTARG}" ;; + Q) _SYMBOL_BATT_25="${OPTARG}" ;; + r) _HIDE_TIME_REMAINING=true ;; + R) _SYMBOL_ERROR="${OPTARG}" ;; + S) _SYMBOL_FULLY_CHARGED="${OPTARG}" ;; + t) _NOTIFY_THROTTLE="${OPTARG}" ;; + T) _SYMBOL_CHARGING="${OPTARG}" ;; + u) _HIDE_TIME_TO_FULL=true ;; + U) _COLOR_DIRECTIONAL_UP="${OPTARG}" ;; + V) _SYMBOL_UNKNOWN="${OPTARG}" ;; + W) _SYMBOL_DIRECTION_UP="${OPTARG}" ;; + X) _SYMBOL_PENDING="${OPTARG}" ;; + Y) _SYMBOL_DISCHARGING="${OPTARG}" ;; + Z) _SYMBOL_DIRECTION_DOWN="${OPTARG}" ;; + esac +done +shift $((OPTIND-1)) # Shift off options and optional -- + +battery_percentage=$(get_battery_percent) +percentage_color=$(get_percentage_color "$battery_percentage") +capacity=$(get_battery_capacity) +battery_charge_symbol=$(get_battery_charge_symbol "$battery_percentage") +battery_status_symbol=$(get_battery_status_symbol) +colored_battery_symbol=$(multicolor "$battery_charge_symbol" "$_COLOR_BATTERY" "$percentage_color" $_USE_BATT_GRADIENT) +warning_level=$(get_battery_warning_level) + +# Handle battery warning levels +case "$warning_level" in + critical) + case "$_CRITICAL_ACTION" in + notify) $(notify "$(span "Your battery level is ${warning_level}!")" "$battery_status_symbol" "critical" false "-c device") ;; + esac + ;; + low) + case "$_LOW_ACTION" in + notify) $(notify "$(span "Your battery level is ${warning_level}")" "$battery_status_symbol" "normal" false "-c device") ;; + esac + ;; +esac + +# Displayable alerts +if [ "$_CAPACITY_ALERT" -gt 0 ] && [ "${capacity%.*}" -le $_CAPACITY_ALERT ]; then + CAPACITY_TRIGGERED=true + long_segments+=( "$(span -c "$_COLOR_ALERT" "$_SYMBOL_ALERT") " ) +fi + +# Battery statuses +status=$(get_battery_status) +case "$status" in + charging) long_segments+=( "$(display_batt_charging)" ) ;; + discharging) long_segments+=( "$(display_batt_discharging)" ) ;; + empty) long_segments+=( "$(display_batt_empty)" ) ;; + fully-charged) + if $_HIDE_IF_CHARGED; then + exit 0 + fi + long_segments+=( "$(display_batt_fully_charged)" ) + ;; + pending-charge) long_segments+=( "$(display_batt_pending_charge)" ) ;; + pending-discharge) long_segments+=( "$(display_batt_pending_discharge)" ) ;; + unknown) long_segments+=( "$(display_batt_unknown)" ) ;; + *) long_segments+=( "$(display_batt_error)" ) ;; +esac + +# Since long_segments contains no text at this point, lets use it for the short_text +short_segments=( "${long_segments[@]}" ) + +# Append all text segments +long_segments+=( "$(display_percentage)" ) +if [ -n "$(display_time_remaining)" ]; then + long_segments+=( "($(display_time_remaining))" ) +fi +if [ -n "$(display_time_to_full)" ]; then + long_segments+=( "($(display_time_to_full))" ) +fi + +# Display the block long_text +display_segments ${long_segments[@]} + +# Display the block short_text +display_segments ${short_segments[@]} + +# Handle click events +case $BLOCK_BUTTON in + 1) + if [ -n "$CAPACITY_TRIGGERED" ]; then + $(dialog "$(span "Your battery capacity has reduced to ${capacity%.*}${_PERCENT}!")" "battery-caution" "warning" "--no-wrap") + else + if [ "$status" = "discharging" ]; then + $(notify "$(span "$(display_time_remaining true) remaining")" "alarm-symbolic" "normal" true "-c device") + elif [ "$status" = "charging" ]; then + $(notify "$(span "$(display_time_to_full true) until fully charged")" "alarm-symbolic" "normal" true "-c device") + fi + fi + ;; +esac + +if [ -n "$battery_percentage" ] && [ "$battery_percentage" -le 5 ]; then + exit 33 +fi diff --git a/.config/i3blocks/config b/.config/i3blocks/config index 7d399b0..2dd239f 100644 --- a/.config/i3blocks/config +++ b/.config/i3blocks/config @@ -3,26 +3,26 @@ command=/usr/share/i3blocks/$BLOCK_NAME separator_block_width=15 markup=none -# Battery indicator -[battery] -label=⚡ -instance=1 +[battery-plus] +command=~/.config/i3blocks/blocks/battery-plus +markup=pango +instance=BAT0 interval=30 -# Volume indicator [volume] label=♪ instance=Master +#instance=PCM interval=once signal=10 -# Date Time -# +# Date [time] label= command=date '+%A %d-%m-%Y' interval=30 +# Time [time] label=⏱ command=date "+%H:%M" -- cgit v1.2.3