From a4434d7f973c8f4985d88ca49c24e7befe855a27 Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Wed, 23 Jul 2025 12:46:08 +0200 Subject: [PATCH] fixed battery display --- waybar/config.jsonc | 2 +- waybar/scripts/tlp-profile.sh | 68 +++++++++---- waybar/style.css | 54 +++++------ waybar/style.css-without-borders | 157 +++++++++++++++++++++++++++++++ 4 files changed, 232 insertions(+), 49 deletions(-) create mode 100644 waybar/style.css-without-borders diff --git a/waybar/config.jsonc b/waybar/config.jsonc index 1aa3885..7fe4c47 100644 --- a/waybar/config.jsonc +++ b/waybar/config.jsonc @@ -5,7 +5,7 @@ "height": 35, "modules-left": ["hyprland/workspaces", "hyprland/window"], "modules-center": [], - "modules-right": ["tray", "wireplumber", "network", "cpu", "memory", "custom/tlp", "battery", "clock", "custom/power"], + "modules-right": ["tray", "wireplumber", "network", "cpu", "memory", "custom/tlp", "clock", "custom/power"], "hyprland/workspaces": { "format": "{icon}", diff --git a/waybar/scripts/tlp-profile.sh b/waybar/scripts/tlp-profile.sh index 7f4158c..c3ac7f6 100755 --- a/waybar/scripts/tlp-profile.sh +++ b/waybar/scripts/tlp-profile.sh @@ -1,24 +1,54 @@ #!/bin/bash -# Get the current power source from tlp-stat -power_source=$(tlp-stat -s | grep -i "power source" | awk '{print $4}') +# --- Configuration --- +CRITICAL_THRESHOLD=15 +WARNING_THRESHOLD=50 +# --------------------- -if [ "$power_source" == "AC" ]; then - # On AC power - icon="" - tooltip="TLP Profile: AC" - class="ac" -elif [ "$power_source" == "battery" ]; then - # On Battery power - icon="" - tooltip="TLP Profile: Battery" - class="bat" -else - # Fallback for unknown state - icon="" - tooltip="TLP Profile: Unknown" - class="unknown" +# Get the battery path from upower +battery_path=$(upower -e | grep 'BAT') + +# Handle case where no battery is found +if [ -z "$battery_path" ]; then + # Check if we are on AC power anyway + if [[ $(tlp-stat -s | grep "Power source" | awk '{print $4}') == "AC" ]]; then + printf '{"text": "", "tooltip": "AC Power (No Battery)", "class": "ac"}\n' + else + printf '{"text": "", "tooltip": "Error: Battery not found", "class": "unknown"}\n' + fi + exit 0 fi -# Output in JSON format for Waybar -printf '{"text": "%s", "tooltip": "%s", "class": "%s"}\n' "$icon" "$tooltip" "$class" +# Get battery percentage and state +percentage=$(upower -i "$battery_path" | grep "percentage" | awk '{print $2}' | tr -d '%') +state=$(upower -i "$battery_path" | grep "state" | awk '{print $2}') +tlp_profile=$(tlp-stat -s | grep "Power source" | awk '{print $4}') + +# Set icon, class, and tooltip based on state and percentage +if [ "$state" == "charging" ] || [ "$tlp_profile" == "AC" ]; then + icon="" + class="charging" + tooltip="TLP: AC | Charging at ${percentage}%" +elif [ "$state" == "discharging" ]; then + tooltip="TLP: Battery | Discharging at ${percentage}%" + if [ "$percentage" -le "$CRITICAL_THRESHOLD" ]; then + icon="" # Very low + class="critical" + elif [ "$percentage" -le "$WARNING_THRESHOLD" ]; then + icon="" # Low + class="warning" + elif [ "$percentage" -le 85 ]; then + icon="" # Healthy + class="bat" + else + icon="" # Full + class="bat" + fi +else # Fallback for "fully-charged", "pending-charge", etc. + icon="" + class="charging" + tooltip="TLP: AC | Fully Charged at ${percentage}%" +fi + +# Output JSON for Waybar +printf '{"text": "%s %s%%", "tooltip": "%s", "class": "%s"}\n' "$icon" "$percentage" "$tooltip" "$class" diff --git a/waybar/style.css b/waybar/style.css index c3d8dca..5917555 100644 --- a/waybar/style.css +++ b/waybar/style.css @@ -12,7 +12,7 @@ window#waybar { background-color: alpha(@base, 0.6); - margin: 10px; + padding: 10px; transition-property: background-color; transition-duration: 0.5s; color: @text; @@ -78,51 +78,46 @@ window#waybar.hidden { #custom-tlp { padding: 0 10px; - padding-right: 10px; - margin-right: 0; + min-width: 10px; } -#custom-tlp.ac { - color: @green; /* Catppuccin Green for AC power */ +#custom-tlp.charging { + color: @teal; + border-bottom: 3px solid @teal; } #custom-tlp.bat { - color: @yellow; /* Catppuccin Yellow for Battery power */ + color: @sapphire; + border-bottom: 3px solid @sapphire; } -#battery { - color: @text; - padding: 0 10px; - padding-left: 0; - margin-left: 0; +#custom-tlp.warning { + color: @yellow; + border-bottom: 3px solid @yellow; } -#battery.charging, #battery.plugged { - color: @green; -} - -#battery.warning { - color: @yellow; -} - -#battery.critical { - color: @red; - animation-name: blink; - animation-duration: 0.8s; - animation-timing-function: linear; - animation-iteration-count: infinite; - animation-direction: alternate; +#custom-tlp.critical { + color: @red; + border-bottom: 3px solid @red; + animation-name: blink; + animation-duration: 0.8s; + animation-timing-function: linear; + animation-iteration-count: infinite; + animation-direction: alternate; } @keyframes blink { - to { - color: @text; - } + to { + color: @yellow; + border-bottom: 3px solid @yellow; + opacity: 0.6; + } } #memory, #cpu { color: @maroon; + border-bottom: 3px solid @maroon; } @@ -133,6 +128,7 @@ window#waybar.hidden { #wireplumber { color: @mauve; padding-right: 15px; + border-bottom: 3px solid @mauve; } #network { diff --git a/waybar/style.css-without-borders b/waybar/style.css-without-borders new file mode 100644 index 0000000..c3d8dca --- /dev/null +++ b/waybar/style.css-without-borders @@ -0,0 +1,157 @@ + +/* ~/.config/waybar/style.css */ +@import "./catppuccin-waybar/themes/mocha.css"; + +* { + border: none; + border-radius: 0; + min-height: 0; + font-family: JetBrainsMono Nerd Font; + font-size: 13px; +} + +window#waybar { + background-color: alpha(@base, 0.6); + margin: 10px; + transition-property: background-color; + transition-duration: 0.5s; + color: @text; +} + +window#waybar.hidden { + opacity: 0.5; +} + +#workspaces { +} + +#workspaces button { + all: initial; + /* Remove GTK theme values (waybar #1351) */ + min-width: 0; + /* Fix weird spacing in materia (waybar #450) */ + box-shadow: inset 0 -3px transparent; + /* Use box-shadow instead of border so the text isn't offset */ + padding: 6px 18px; + margin: 6px 3px; + border-radius: 3px; + background-color: alpha(@base, 0.9); + color: @text; +} + +#workspaces button.active { + border-bottom: 3px solid @green; +} + +#workspaces button:hover { + box-shadow: inherit; + text-shadow: inherit; + background-color: @teal; + color: @base; +} + +#workspaces button.urgent { + border-bottom: 3px solid @red; +} + +#memory, +#cpu, +#custom-power, +#custom-tlp, +#battery, +#backlight, +#wireplumber, +#network, +#clock, +#tray { + border-radius: 4px; + margin: 6px 3px; + padding: 6px 12px; + background-color: @base; + color: @text; +} + +#custom-power { + color: @red; + padding: 6px 12px 6px 10px; +} + +#custom-tlp { + padding: 0 10px; + padding-right: 10px; + margin-right: 0; +} + +#custom-tlp.ac { + color: @green; /* Catppuccin Green for AC power */ +} + +#custom-tlp.bat { + color: @yellow; /* Catppuccin Yellow for Battery power */ +} + +#battery { + color: @text; + padding: 0 10px; + padding-left: 0; + margin-left: 0; +} + +#battery.charging, #battery.plugged { + color: @green; +} + +#battery.warning { + color: @yellow; +} + +#battery.critical { + color: @red; + animation-name: blink; + animation-duration: 0.8s; + animation-timing-function: linear; + animation-iteration-count: infinite; + animation-direction: alternate; +} + +@keyframes blink { + to { + color: @text; + } +} + +#memory, +#cpu { + color: @maroon; +} + + +#backlight { + color: @mauve; +} + +#wireplumber { + color: @mauve; + padding-right: 15px; +} + +#network { + color: @mauve; + padding-right: 15px; +} + +#clock { + font-family: JetBrainsMono Nerd Font; + color: @mauve; +} + +tooltip { + border-radius: 8px; + padding: 15px; + background-color: @base; +} + +tooltip label { + padding: 5px; + background-color: @base; +}