fucked my pixelbuds module

This commit is contained in:
2025-08-15 10:08:20 +02:00
parent dc3133cc94
commit ac16d751ce
5 changed files with 153 additions and 170 deletions

View File

@@ -10,8 +10,7 @@
"modules-right": [ "modules-right": [
"wireplumber", "wireplumber",
"custom/audio-output", "custom/audio-output",
"custom/pixelbuds", "custom/pixelbuds_pro",
"custom/anc",
"network", "network",
"cpu", "cpu",
"memory", "memory",
@@ -32,9 +31,10 @@
"max-length": 35 "max-length": 35
}, },
"clock": { "clock": {
"format": "{:%H:%M}", "format": "{:%a %d %b %H:%M}",
"format-alt": "{:%a, %b %d}", "format-alt": false,
"on-click-right": "xdg-open https://calendar.proton.me/u/0/month &> /dev/null & disown" "on-click-right": "xdg-open https://calendar.proton.me/u/0/month &> /dev/null & disown",
"tooltip": false,
}, },
"custom/gpu": { "custom/gpu": {
"format": "GPU: {}%", "format": "GPU: {}%",
@@ -108,20 +108,13 @@
"format-full": "{capacity}%", "format-full": "{capacity}%",
"format-icons": ["", "", "", "", ""] "format-icons": ["", "", "", "", ""]
}, },
"custom/pixelbuds": { "custom/pixelbuds_pro": {
"format": "{}", "format": "{}",
"return-type": "json", "return-type": "json",
"exec": "~/.config/waybar/scripts/pixelbuds.sh", "exec": "~/.config/waybar/scripts/pixelbuds_pro_control.sh",
"interval": 10, "interval": 5,
"on-click": "bluetoothctl disconnect B4:23:A2:09:D3:53" "on-click": "~/.config/waybar/scripts/pixelbuds_pro_control.sh connect",
}, "on-click-right": "~/.config/waybar/scripts/pixelbuds_pro_control.sh disconnect",
"custom/anc": {
"format": "{}",
"return-type": "json",
"exec": "~/.config/waybar/scripts/anc_control.sh",
"interval": 10,
"on-click": "~/.config/waybar/scripts/anc_control.sh off",
"on-click-right": "~/.config/waybar/scripts/anc_control.sh cycle"
}, },
"custom/audio-output": { "custom/audio-output": {
"format": "{}", "format": "{}",

View File

@@ -1,73 +0,0 @@
#!/bin/bash
# --- CONFIGURATION ---
# Your Pixel Buds Pro's MAC Address
MAC_ADDRESS="B4:23:A2:09:D3:53"
# --- END CONFIGURATION ---
# First, check if the device is connected using bluetoothctl.
if bluetoothctl info "$MAC_ADDRESS" | grep -q "Connected: yes"; then
# --- DEVICE IS CONNECTED ---
# This function gets the current ANC status and formats it for Waybar.
get_status() {
# Get the mode from pbpctrl. Redirect errors to null in case of a temporary glitch.
current_mode=$(pbpctrl get anc 2>/dev/null)
# Fallback: If pbpctrl fails or returns 'unknown', hide the module.
# This handles cases where buds are connected but not fully ready.
if [[ $? -ne 0 || "$current_mode" == "unknown (0)"* || -z "$current_mode" ]]; then
echo "{}"
exit 0
fi
# Set icon and tooltip based on the current mode.
case "$current_mode" in
"active")
icon="ANC: Active"
class="anc-active"
;;
"aware")
icon="ANC: Aware"
class="anc-aware"
;;
"off")
icon="ANC: Off"
class="anc-off"
;;
*)
# Failsafe to hide the module if the mode is unrecognized.
echo "{}"
exit 0
;;
esac
echo "{\"text\":\"$icon\", \"class\":\"$class\"}"
}
# Handle click actions passed from Waybar.
case "$1" in
# Right-click: Cycle between active and aware modes.
cycle)
current_mode=$(pbpctrl get anc 2>/dev/null)
if [[ "$current_mode" == "active" ]]; then
pbpctrl set anc aware
else
pbpctrl set anc active
fi
sleep 0.1 # Brief pause for the state to update.
;;
# Left-click: Turn ANC off.
off)
pbpctrl set anc off
sleep 0.1 # Brief pause for the state to update.
;;
esac
# Always display the current status after any action or on a scheduled interval.
get_status
else
# --- DEVICE IS NOT CONNECTED ---
# Output an empty JSON object to completely hide the Waybar module.
echo "{}"
fi

View File

@@ -1,49 +0,0 @@
#!/bin/bash
# --- CONFIGURATION ---
# Your Pixel Buds Pro's MAC Address
MAC_ADDRESS="B4:23:A2:09:D3:53"
# --- END CONFIGURATION ---
# Check if the device is connected using bluetoothctl.
if bluetoothctl info "$MAC_ADDRESS" | grep -q "Connected: yes"; then
# If connected, get battery info from pbpctrl.
if battery_output=$(pbpctrl show battery); then
# Use awk to grab the third field, which is the percentage or "unknown".
left_bud=$(echo "$battery_output" | grep "left bud:" | awk '{print $3}')
right_bud=$(echo "$battery_output" | grep "right bud:" | awk '{print $3}')
# If both buds are unknown (e.g., case is closed and buds are out of range),
# or if the command output is empty, hide the module.
if ([[ "$left_bud" == "unknown" ]] && [[ "$right_bud" == "unknown" ]]) || \
[[ -z "$left_bud" && -z "$right_bud" ]]; then
echo "{}"
exit 0
fi
# Prepare the display string for the left bud.
if [[ "$left_bud" == "unknown" ]]; then
left_display="L: ---"
else
left_display="L: $left_bud"
fi
# Prepare the display string for the right bud.
if [[ "$right_bud" == "unknown" ]]; then
right_display="R: ---"
else
right_display="R: $right_bud"
fi
# Format the final output for Waybar as JSON.
printf '{"text": "%s | %s", "tooltip": "Pixel Buds Pro 2", "class": "connected"}\n' "$left_display" "$right_display"
else
# pbpctrl failed to run, so hide the module.
echo "{}"
fi
else
# Not connected, output an empty JSON object to hide the module.
echo "{}"
fi

View File

@@ -0,0 +1,104 @@
#!/bin/bash
# --- CONFIGURATION ---
# Your Pixel Buds Pro's MAC Address
MAC_ADDRESS="B4:23:A2:09:D3:53"
# --- END CONFIGURATION ---
# First, check if the device is connected using bluetoothctl.
if bluetoothctl info "$MAC_ADDRESS" | grep -q "Connected: yes"; then
# --- DEVICE IS CONNECTED ---
# This function gets the current status and formats it for Waybar.
get_status() {
# Get all info from pbpctrl in one go. Redirect errors to null.
battery_output=$(pbpctrl show battery 2>/dev/null)
# Fallback: If pbpctrl fails or returns 'unknown', hide the module.
if [[ $? -ne 0 || -z "$battery_output" ]]; then
not_connected
fi
# --- PARSE BATTERY INFO ---
left_bud=$(echo "$battery_output" | grep "left bud:" | awk '{print $3}')
right_bud=$(echo "$battery_output" | grep "right bud:" | awk '{print $3}')
if ([[ "$left_bud" == "unknown" ]] && [[ "$right_bud" == "unknown" ]]) || \
[[ -z "$left_bud" && -z "$right_bud" ]]; then
echo "{}"
exit 0
fi
if [[ "$left_bud" == "unknown" ]]; then
left_display="L: ---"
else
left_display="L: $left_bud"
fi
if [[ "$right_bud" == "unknown" ]]; then
right_display="R: ---"
else
right_display="R: $right_bud"
fi
# --- PARSE ANC INFO ---
current_mode=$(pbpctrl get anc 2>/dev/null)
case "$current_mode" in
"active")
anc_icon="ANC"
class="anc-active"
;;
"aware")
anc_icon="Aware"
class="anc-aware"
;;
"off")
anc_icon="Off"
class="anc-off"
;;
*)
anc_icon="?"
class="anc-unknown"
;;
esac
# --- FORMAT OUTPUT ---
printf '{"text": "%s | %s | %s", "tooltip": "Pixel Buds Pro 2", "class": "%s"}\n' \
"$left_display" "$right_display" "$anc_icon" "$class"
}
# Handle click actions passed from Waybar.
case "$1" in
cycle_anc)
current_mode=$(pbpctrl get anc 2>/dev/null)
if [[ "$current_mode" == "active" ]]; then
pbpctrl set anc aware
else
pbpctrl set anc active
fi
sleep 0.1
;;
toggle_anc_off)
pbpctrl set anc off
sleep 0.1
;;
connect)
bluetoothctl connect "$MAC_ADDRESS"
;;
disconnect)
bluetoothctl disconnect "$MAC_ADDRESS"
;;
esac
get_status
else
# --- DEVICE IS NOT CONNECTED ---
not_connected
fi
not_connected() {
printf '{"text": "L: --- | R: --- | Off", "tooltip": "Pixel Buds Pro 2", "class": "disconnected"}\n'
exit 0
}

View File

@@ -10,7 +10,8 @@
} }
window#waybar { window#waybar {
background-color: alpha(@base, 0.6); /* background-color: alpha(@crust, 0.9); */
background-color: alpha(@base, 0.4);
padding: 10px; padding: 10px;
transition-property: background-color; transition-property: background-color;
transition-duration: 0.5s; transition-duration: 0.5s;
@@ -33,20 +34,21 @@ window#waybar.hidden {
/* Use box-shadow instead of border so the text isn't offset */ /* Use box-shadow instead of border so the text isn't offset */
padding: 6px 18px; padding: 6px 18px;
margin: 6px 3px; margin: 6px 3px;
border-radius: 3px; border-radius: 4px;
background-color: alpha(@base, 0.9); background-color: @base;
color: @text; color: @subtext0;
} }
#workspaces button.active { #workspaces button.active {
color: @text;
border-bottom: 3px solid @green; border-bottom: 3px solid @green;
} }
#workspaces button:hover { #workspaces button:hover {
box-shadow: inherit; box-shadow: inherit;
text-shadow: inherit; text-shadow: inherit;
background-color: @teal; background-color: @surface0;
color: @base; color: @text;
} }
#workspaces button.urgent { #workspaces button.urgent {
@@ -65,39 +67,35 @@ window#waybar.hidden {
#network, #network,
#clock, #clock,
#tray, #tray,
#custom-pixelbuds, #custom-pixelbuds_pro,
#custom-anc,
#custom-audio-output, #custom-audio-output,
#custom-gpu-screen-recorder { #custom-gpu-screen-recorder {
border-radius: 4px; border-radius: 4px;
margin: 6px 3px; margin: 6px 3px;
padding: 6px 16px 6px 12px; padding: 6px 12px;
background-color: @base; background-color: @base;
color: @text; color: @text;
} }
#custom-anc.anc-active { #custom-pixelbuds_pro.anc-active {
color: @teal; color: @teal;
border-bottom: 3px solid @teal;
} }
#custom-anc.anc-aware { #custom-pixelbuds_pro.anc-aware {
color: @yellow; color: @yellow;
border-bottom: 3px solid @yellow;
} }
#custom-anc.anc-off { #custom-pixelbuds_pro.anc-off {
color: @text; color: @text;
border-bottom: 3px solid @text;
} }
#custom-anc.disconnected { #custom-pixelbuds_pro.disconnected {
color: @subtext1;
} }
#custom-gpu-screen-recorder, #custom-gpu-screen-recorder,
#custom-gamemode { #custom-gamemode {
color: @teal; color: @teal;
border-bottom: 3px solid @teal;
} }
#custom-power { #custom-power {
@@ -107,7 +105,6 @@ window#waybar.hidden {
#custom-gpu-screen-recorder.recording, #custom-gpu-screen-recorder.recording,
#custom-gamemode.active { #custom-gamemode.active {
color: @red; color: @red;
border-bottom: 3px solid @red;
} }
#custom-tlp { #custom-tlp {
@@ -117,22 +114,18 @@ window#waybar.hidden {
#custom-tlp.charging { #custom-tlp.charging {
color: @teal; color: @teal;
border-bottom: 3px solid @teal;
} }
#custom-tlp.bat { #custom-tlp.bat {
color: @sapphire; color: @sapphire;
border-bottom: 3px solid @sapphire;
} }
#custom-tlp.warning { #custom-tlp.warning {
color: @yellow; color: @yellow;
border-bottom: 3px solid @yellow;
} }
#custom-tlp.critical { #custom-tlp.critical {
color: @red; color: @red;
border-bottom: 3px solid @red;
animation-name: blink; animation-name: blink;
animation-duration: 0.8s; animation-duration: 0.8s;
animation-timing-function: linear; animation-timing-function: linear;
@@ -143,26 +136,28 @@ window#waybar.hidden {
@keyframes blink { @keyframes blink {
to { to {
color: @yellow; color: @yellow;
border-bottom: 3px solid @yellow;
opacity: 0.6; opacity: 0.6;
} }
} }
#custom-gpu-usage.max_usage { #custom-gpu-usage.max_usage {
color: @maroon; color: @maroon;
border-bottom: 3px solid @maroon;
} }
#custom-gpu-usage.high_usage { #custom-gpu-usage.high_usage {
color: @yellow; color: @yellow;
border-bottom: 3px solid @yellow;
} }
#custom-gpu-usage.normal_usage { #custom-gpu-usage.normal_usage {
color: @teal; color: @teal;
border-bottom: 3px solid @teal;
} }
#memory, #memory, #cpu {
#cpu {
color: @teal; color: @teal;
border-bottom: 3px solid @teal;
} }
@@ -173,23 +168,21 @@ window#waybar.hidden {
#wireplumber { #wireplumber {
color: @mauve; color: @mauve;
padding-right: 15px; padding-right: 15px;
border-bottom: 3px solid @mauve;
} }
#custom-audio-output { #custom-audio-output {
color: @mauve; color: @mauve;
border-bottom: 3px solid @mauve;
} }
#network { #network {
color: @mauve; color: @mauve;
padding-right: 15px; padding-right: 15px;
border-bottom: 3px solid @mauve;
} }
#clock { #clock {
font-family: JetBrainsMono Nerd Font; font-family: JetBrainsMono Nerd Font;
color: @green; color: @green;
border-bottom: 3px solid @green;
} }
tooltip { tooltip {
@@ -203,7 +196,22 @@ tooltip label {
background-color: @base; background-color: @base;
} }
#custom-pixelbuds.connected { #battery.charging {
color: @teal; /* A pleasant green */ color: @green;
border-bottom: 3px solid @teal; border-bottom: 3px solid @green;
} }
#battery.critical {
color: @red;
border-bottom: 3px solid @red;
}
#battery.warning {
color: @yellow;
border-bottom: 3px solid @yellow;
}
#battery.bat {
color: @text;
border-bottom: 3px solid @text;
}