added battery percentage indicator
This commit is contained in:
parent
0d841a0c03
commit
6a7414a9b8
16
config.jsonc
16
config.jsonc
@ -8,7 +8,7 @@
|
|||||||
"height": 45,
|
"height": 45,
|
||||||
"modules-left": ["clock","custom/weather","custom/wallpaper","hyprland/window"],
|
"modules-left": ["clock","custom/weather","custom/wallpaper","hyprland/window"],
|
||||||
"modules-center": ["hyprland/workspaces"],
|
"modules-center": ["hyprland/workspaces"],
|
||||||
"modules-right": ["network", "bluetooth", "temperature","custom/power_profile","battery","backlight","pulseaudio","pulseaudio#microphone","tray","idle_inhibitor"],
|
"modules-right": ["network", "bluetooth", "temperature","custom/power_profile","custom/battery","backlight","pulseaudio","pulseaudio#microphone","tray","idle_inhibitor"],
|
||||||
"hyprland/window": {
|
"hyprland/window": {
|
||||||
"format": "{}",
|
"format": "{}",
|
||||||
"max-length": 60,
|
"max-length": 60,
|
||||||
@ -61,6 +61,14 @@
|
|||||||
"on-click": "xdg-open https://wttr.in"
|
"on-click": "xdg-open https://wttr.in"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"custom/battery": {
|
||||||
|
"exec": "/home/Nicholai/.config/waybar/scripts/battery.sh",
|
||||||
|
"interval": 10,
|
||||||
|
"return-type": "json",
|
||||||
|
"format": "{}",
|
||||||
|
"tooltip": true
|
||||||
|
},
|
||||||
|
|
||||||
"tray": {
|
"tray": {
|
||||||
"icon-size": 18,
|
"icon-size": 18,
|
||||||
"spacing": 10
|
"spacing": 10
|
||||||
@ -93,6 +101,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"battery": {
|
"battery": {
|
||||||
|
"bat": "BAT1",
|
||||||
|
"adapter": "ACAD",
|
||||||
|
"interval": 10,
|
||||||
"states": {
|
"states": {
|
||||||
"good": 95,
|
"good": 95,
|
||||||
"warning": 30,
|
"warning": 30,
|
||||||
@ -104,7 +115,8 @@
|
|||||||
"format-alt": "{time} {icon}",
|
"format-alt": "{time} {icon}",
|
||||||
"format-icons": ["", "", "", "", "", "", "", "", "", "", ""],
|
"format-icons": ["", "", "", "", "", "", "", "", "", "", ""],
|
||||||
"tooltip": true,
|
"tooltip": true,
|
||||||
"tooltip-format": "{status} • {capacity}%\n{timeTo}\nHealth: {health}"
|
"tooltip-format": "{status} • {capacity}%\n{timeTo}\nHealth: {health}",
|
||||||
|
"max-length": 15
|
||||||
},
|
},
|
||||||
|
|
||||||
"pulseaudio": {
|
"pulseaudio": {
|
||||||
|
|||||||
65
scripts/battery.sh
Executable file
65
scripts/battery.sh
Executable file
@ -0,0 +1,65 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Simple Waybar custom battery module using sysfs
|
||||||
|
# Outputs JSON: {"text":"...","tooltip":"..."} for Waybar's custom module
|
||||||
|
|
||||||
|
BAT_PATH="/sys/class/power_supply/BAT1"
|
||||||
|
AC_PATH="/sys/class/power_supply/ACAD"
|
||||||
|
|
||||||
|
read_file() {
|
||||||
|
local f="$1"
|
||||||
|
if [[ -r "$f" ]]; then
|
||||||
|
tr -d '\n' < "$f"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ ! -d "$BAT_PATH" ]]; then
|
||||||
|
echo '{"text":" N/A","tooltip":"Battery device not found (expected BAT1)"}'
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
capacity="$(read_file "$BAT_PATH/capacity")"
|
||||||
|
status="$(read_file "$BAT_PATH/status")"
|
||||||
|
present="$(read_file "$BAT_PATH/present")"
|
||||||
|
|
||||||
|
# Fallbacks
|
||||||
|
capacity="${capacity:-0}"
|
||||||
|
status="${status:-Unknown}"
|
||||||
|
present="${present:-0}"
|
||||||
|
|
||||||
|
# Choose icon based on capacity
|
||||||
|
# Nerd Font icons similar to Waybar's default sequence
|
||||||
|
# 0-10, 10-20, ... , 90-100
|
||||||
|
icons=( "" "" "" "" "" "" "" "" "" "" "" )
|
||||||
|
|
||||||
|
idx=$(( capacity / 10 ))
|
||||||
|
if (( idx < 0 )); then idx=0; fi
|
||||||
|
if (( idx > 10 )); then idx=10; fi
|
||||||
|
|
||||||
|
icon="${icons[$idx]}"
|
||||||
|
|
||||||
|
# If charging, override icon with plug
|
||||||
|
if [[ "$status" == "Charging" || "$status" == "Full" ]]; then
|
||||||
|
icon=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# AC online?
|
||||||
|
ac_online=""
|
||||||
|
if [[ -r "$AC_PATH/online" ]]; then
|
||||||
|
ac_online="$(read_file "$AC_PATH/online")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build tooltip details
|
||||||
|
tooltip="Status: ${status}"
|
||||||
|
tooltip+="\nCapacity: ${capacity}%"
|
||||||
|
if [[ -n "$ac_online" ]]; then
|
||||||
|
tooltip+="\nAC Online: ${ac_online}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If battery is reported not present, show N/A
|
||||||
|
if [[ "$present" != "1" ]]; then
|
||||||
|
echo '{"text":" N/A","tooltip":"Battery not present"}'
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Emit JSON for Waybar
|
||||||
|
printf '{"text":"%s %s%%","tooltip":"%s"}\n' "$icon" "$capacity" "$tooltip"
|
||||||
@ -52,6 +52,7 @@ window#waybar {
|
|||||||
#window,
|
#window,
|
||||||
#clock,
|
#clock,
|
||||||
#battery,
|
#battery,
|
||||||
|
#custom-battery,
|
||||||
#pulseaudio,
|
#pulseaudio,
|
||||||
#network,
|
#network,
|
||||||
#bluetooth,
|
#bluetooth,
|
||||||
@ -169,6 +170,14 @@ window#waybar {
|
|||||||
border-left: 0px;
|
border-left: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#custom-battery {
|
||||||
|
color: @color12;
|
||||||
|
background: @background;
|
||||||
|
border-radius: 0 5px 5px 0;
|
||||||
|
margin-right: 10px;
|
||||||
|
border-left: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
#custom-weather {
|
#custom-weather {
|
||||||
border-radius: 0px 5px 5px 0px;
|
border-radius: 0px 5px 5px 0px;
|
||||||
border-right: 0px;
|
border-right: 0px;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user