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": [
"wireplumber",
"custom/audio-output",
"custom/pixelbuds",
"custom/anc",
"custom/pixelbuds_pro",
"network",
"cpu",
"memory",
@@ -32,9 +31,10 @@
"max-length": 35
},
"clock": {
"format": "{:%H:%M}",
"format-alt": "{:%a, %b %d}",
"on-click-right": "xdg-open https://calendar.proton.me/u/0/month &> /dev/null & disown"
"format": "{:%a %d %b %H:%M}",
"format-alt": false,
"on-click-right": "xdg-open https://calendar.proton.me/u/0/month &> /dev/null & disown",
"tooltip": false,
},
"custom/gpu": {
"format": "GPU: {}%",
@@ -108,20 +108,13 @@
"format-full": "{capacity}%",
"format-icons": ["", "", "", "", ""]
},
"custom/pixelbuds": {
"custom/pixelbuds_pro": {
"format": "{}",
"return-type": "json",
"exec": "~/.config/waybar/scripts/pixelbuds.sh",
"interval": 10,
"on-click": "bluetoothctl disconnect B4:23:A2:09:D3:53"
},
"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"
"exec": "~/.config/waybar/scripts/pixelbuds_pro_control.sh",
"interval": 5,
"on-click": "~/.config/waybar/scripts/pixelbuds_pro_control.sh connect",
"on-click-right": "~/.config/waybar/scripts/pixelbuds_pro_control.sh disconnect",
},
"custom/audio-output": {
"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 {
background-color: alpha(@base, 0.6);
/* background-color: alpha(@crust, 0.9); */
background-color: alpha(@base, 0.4);
padding: 10px;
transition-property: background-color;
transition-duration: 0.5s;
@@ -33,20 +34,21 @@ window#waybar.hidden {
/* 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;
border-radius: 4px;
background-color: @base;
color: @subtext0;
}
#workspaces button.active {
color: @text;
border-bottom: 3px solid @green;
}
#workspaces button:hover {
box-shadow: inherit;
text-shadow: inherit;
background-color: @teal;
color: @base;
background-color: @surface0;
color: @text;
}
#workspaces button.urgent {
@@ -65,39 +67,35 @@ window#waybar.hidden {
#network,
#clock,
#tray,
#custom-pixelbuds,
#custom-anc,
#custom-pixelbuds_pro,
#custom-audio-output,
#custom-gpu-screen-recorder {
border-radius: 4px;
margin: 6px 3px;
padding: 6px 16px 6px 12px;
padding: 6px 12px;
background-color: @base;
color: @text;
}
#custom-anc.anc-active {
#custom-pixelbuds_pro.anc-active {
color: @teal;
border-bottom: 3px solid @teal;
}
#custom-anc.anc-aware {
#custom-pixelbuds_pro.anc-aware {
color: @yellow;
border-bottom: 3px solid @yellow;
}
#custom-anc.anc-off {
#custom-pixelbuds_pro.anc-off {
color: @text;
border-bottom: 3px solid @text;
}
#custom-anc.disconnected {
#custom-pixelbuds_pro.disconnected {
color: @subtext1;
}
#custom-gpu-screen-recorder,
#custom-gamemode {
color: @teal;
border-bottom: 3px solid @teal;
}
#custom-power {
@@ -107,7 +105,6 @@ window#waybar.hidden {
#custom-gpu-screen-recorder.recording,
#custom-gamemode.active {
color: @red;
border-bottom: 3px solid @red;
}
#custom-tlp {
@@ -117,22 +114,18 @@ window#waybar.hidden {
#custom-tlp.charging {
color: @teal;
border-bottom: 3px solid @teal;
}
#custom-tlp.bat {
color: @sapphire;
border-bottom: 3px solid @sapphire;
}
#custom-tlp.warning {
color: @yellow;
border-bottom: 3px solid @yellow;
}
#custom-tlp.critical {
color: @red;
border-bottom: 3px solid @red;
animation-name: blink;
animation-duration: 0.8s;
animation-timing-function: linear;
@@ -143,26 +136,28 @@ window#waybar.hidden {
@keyframes blink {
to {
color: @yellow;
border-bottom: 3px solid @yellow;
opacity: 0.6;
}
}
#custom-gpu-usage.max_usage {
color: @maroon;
border-bottom: 3px solid @maroon;
}
#custom-gpu-usage.high_usage {
color: @yellow;
border-bottom: 3px solid @yellow;
}
#custom-gpu-usage.normal_usage {
color: @teal;
border-bottom: 3px solid @teal;
}
#memory,
#cpu {
#memory, #cpu {
color: @teal;
border-bottom: 3px solid @teal;
}
@@ -173,23 +168,21 @@ window#waybar.hidden {
#wireplumber {
color: @mauve;
padding-right: 15px;
border-bottom: 3px solid @mauve;
}
#custom-audio-output {
color: @mauve;
border-bottom: 3px solid @mauve;
}
#network {
color: @mauve;
padding-right: 15px;
border-bottom: 3px solid @mauve;
}
#clock {
font-family: JetBrainsMono Nerd Font;
color: @green;
border-bottom: 3px solid @green;
}
tooltip {
@@ -203,7 +196,22 @@ tooltip label {
background-color: @base;
}
#custom-pixelbuds.connected {
color: @teal; /* A pleasant green */
border-bottom: 3px solid @teal;
#battery.charging {
color: @green;
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;
}