feat(waybar): add custom Logitech battery status module and script
This commit is contained in:
parent
66c886130e
commit
88f7edf1a6
@ -16,6 +16,7 @@
|
|||||||
"temperature",
|
"temperature",
|
||||||
"pulseaudio",
|
"pulseaudio",
|
||||||
"network",
|
"network",
|
||||||
|
"custom/logitech-battery",
|
||||||
"tray",
|
"tray",
|
||||||
"custom/wlogout"
|
"custom/wlogout"
|
||||||
],
|
],
|
||||||
@ -103,6 +104,15 @@
|
|||||||
"tray": {
|
"tray": {
|
||||||
"icon-size": 20
|
"icon-size": 20
|
||||||
},
|
},
|
||||||
|
"custom/logitech-battery": {
|
||||||
|
"exec": "~/.local/bin/logitech_battery.sh",
|
||||||
|
"interval": 60,
|
||||||
|
"return-type": "json",
|
||||||
|
"format": "{text}",
|
||||||
|
"tooltip": "{tooltip}",
|
||||||
|
"class": "logitech-battery",
|
||||||
|
"on-click": "solaar gui"
|
||||||
|
},
|
||||||
"custom/wlogout": {
|
"custom/wlogout": {
|
||||||
"format": "⏻",
|
"format": "⏻",
|
||||||
"tooltip": "Logout/Shutdown",
|
"tooltip": "Logout/Shutdown",
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
"pulseaudio",
|
"pulseaudio",
|
||||||
"network",
|
"network",
|
||||||
"battery",
|
"battery",
|
||||||
|
"custom/logitech-battery",
|
||||||
"tray",
|
"tray",
|
||||||
"custom/wlogout"
|
"custom/wlogout"
|
||||||
],
|
],
|
||||||
@ -136,6 +137,15 @@
|
|||||||
"tray": {
|
"tray": {
|
||||||
"icon-size": 20
|
"icon-size": 20
|
||||||
},
|
},
|
||||||
|
"custom/logitech-battery": {
|
||||||
|
"exec": "~/.local/bin/logitech_battery.sh",
|
||||||
|
"interval": 60,
|
||||||
|
"return-type": "json",
|
||||||
|
"format": "{text}",
|
||||||
|
"tooltip": "{tooltip}",
|
||||||
|
"class": "logitech-battery",
|
||||||
|
"on-click": "solaar gui"
|
||||||
|
},
|
||||||
"custom/wlogout": {
|
"custom/wlogout": {
|
||||||
"format": "⏻",
|
"format": "⏻",
|
||||||
"tooltip": "Logout/Shutdown",
|
"tooltip": "Logout/Shutdown",
|
||||||
|
|||||||
@ -36,7 +36,7 @@ window#waybar {
|
|||||||
color: #1e1e2e;
|
color: #1e1e2e;
|
||||||
}
|
}
|
||||||
|
|
||||||
#clock, #cpu, #memory, #temperature, #pulseaudio, #network, #battery, #tray, #backlight, #disk, #idle_inhibitor {
|
#clock, #cpu, #memory, #temperature, #pulseaudio, #network, #battery, #tray, #backlight, #disk, #idle_inhibitor, #custom-logitech-battery {
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
margin: 0 2px;
|
margin: 0 2px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
@ -69,3 +69,4 @@ window#waybar {
|
|||||||
color: #1e1e2e;
|
color: #1e1e2e;
|
||||||
box-shadow: 0 2px 8px rgba(0,0,0,0.18);
|
box-shadow: 0 2px 8px rgba(0,0,0,0.18);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
52
.local/bin/logitech_battery.sh
Executable file
52
.local/bin/logitech_battery.sh
Executable file
@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Helper: map percent to icon and color
|
||||||
|
get_icon() {
|
||||||
|
local percent=$1
|
||||||
|
if ! [[ "$percent" =~ ^[0-9]+$ ]]; then percent=0; fi
|
||||||
|
if [ "$percent" -ge 90 ]; then echo ""; elif [ "$percent" -ge 60 ]; then echo ""; elif [ "$percent" -ge 40 ]; then echo ""; elif [ "$percent" -ge 20 ]; then echo ""; else echo ""; fi
|
||||||
|
}
|
||||||
|
get_color() {
|
||||||
|
local percent=$1
|
||||||
|
if ! [[ "$percent" =~ ^[0-9]+$ ]]; then percent=0; fi
|
||||||
|
if [ "$percent" -ge 90 ]; then echo "#00ff00"; elif [ "$percent" -ge 60 ]; then echo "#aaff00"; elif [ "$percent" -ge 40 ]; then echo "#ffff00"; elif [ "$percent" -ge 20 ]; then echo "#ff8800"; else echo "#ff0000"; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
KEYBOARD_NAME="G915"
|
||||||
|
MOUSE_NAME="G903"
|
||||||
|
|
||||||
|
# Use actual Unicode icons
|
||||||
|
KEYBOARD_ICON=""
|
||||||
|
MOUSE_ICON="🖱️"
|
||||||
|
|
||||||
|
# Parse keyboard info
|
||||||
|
kb_line=$(solaar show 2>/dev/null | awk '/G915/ {dev=1} /Battery:/ && dev==1 {print; dev=0}')
|
||||||
|
kb_percent=$(echo "$kb_line" | awk '{print $2}' | tr -d '%' | grep -E '^[0-9]+$' || echo "N/A")
|
||||||
|
kb_voltage=$(echo "$kb_line" | grep -o '[0-9]*mV' | grep -o '[0-9]*' || echo "N/A")
|
||||||
|
kb_status=$(echo "$kb_line" | awk '{print $3}' || echo "N/A")
|
||||||
|
|
||||||
|
# Parse mouse info, handle offline/unknown
|
||||||
|
mouse_line=$(solaar show 2>/dev/null | awk '/G903/ {dev=1} /Battery:/ && dev==1 {print; dev=0}')
|
||||||
|
if echo "$mouse_line" | grep -qi "unknown"; then
|
||||||
|
mouse_percent="N/A"
|
||||||
|
mouse_voltage="N/A"
|
||||||
|
mouse_status="offline"
|
||||||
|
else
|
||||||
|
mouse_percent=$(echo "$mouse_line" | awk '{print $2}' | tr -d '%' | grep -E '^[0-9]+$' || echo "N/A")
|
||||||
|
mouse_voltage=$(echo "$mouse_line" | grep -o '[0-9]*mV' | grep -o '[0-9]*' || echo "N/A")
|
||||||
|
mouse_status=$(echo "$mouse_line" | awk '{print $3}' || echo "N/A")
|
||||||
|
fi
|
||||||
|
|
||||||
|
kb_icon=$(get_icon "$kb_percent")
|
||||||
|
kb_color=$(get_color "$kb_percent")
|
||||||
|
kb_tooltip="${KEYBOARD_NAME}: ${kb_percent:-N/A}% @ ${kb_voltage:-N/A}mV (${kb_status:-N/A})"
|
||||||
|
|
||||||
|
mouse_icon=$(get_icon "$mouse_percent")
|
||||||
|
mouse_tooltip="${MOUSE_NAME}: ${mouse_percent:-N/A}% @ ${mouse_voltage:-N/A}mV (${mouse_status:-N/A})"
|
||||||
|
|
||||||
|
# Escape newlines for JSON
|
||||||
|
tooltip=$(echo -e "$kb_tooltip\n$mouse_tooltip" | sed ':a;N;$!ba;s/\n/\\n/g')
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
{"text": "$KEYBOARD_ICON $kb_icon | $MOUSE_ICON $mouse_icon ","tooltip": "$tooltip","class": "logitech-battery","color": "$kb_color"}
|
||||||
|
EOF
|
||||||
@ -98,6 +98,10 @@ The script will install all required packages and symlink dotfiles and configs (
|
|||||||
- **TTY Keymap:** Console uses German nodeadkeys layout for all users (system-wide via `localectl`).
|
- **TTY Keymap:** Console uses German nodeadkeys layout for all users (system-wide via `localectl`).
|
||||||
- **No official Teams/Outlook client:** Use the web app or AUR wrappers for best compatibility.
|
- **No official Teams/Outlook client:** Use the web app or AUR wrappers for best compatibility.
|
||||||
- **TortoiseGit alternative:** Use GitKraken, Sublime Merge, SmartGit, or lazygit for graphical Git workflows.
|
- **TortoiseGit alternative:** Use GitKraken, Sublime Merge, SmartGit, or lazygit for graphical Git workflows.
|
||||||
|
- **Logitech Battery Status:**
|
||||||
|
If you have Logitech G915 (keyboard) or G903 (mouse), battery status is shown in Waybar via the `custom/logitech-battery` module.
|
||||||
|
The script at `.local/bin/logitech_battery.sh` uses `solaar` to report battery and status for both devices.
|
||||||
|
To use, ensure `solaar` is installed and your devices are paired. The module appears in the Waybar right section on both desktop and laptop profiles.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user