greshake / i3status-rust

Very resourcefriendly and feature-rich replacement for i3status, written in pure Rust
GNU General Public License v3.0
2.88k stars 475 forks source link

`headphones_indicator` set to `true` doesn't show when headphones are connected #2047

Closed alternateved closed 6 months ago

alternateved commented 6 months ago

Hello!

When migrating from waybar to swaybar with i3status-rust, I've noticed a small issue with sound block. Even though headphones_indicator is set to true icon does not change.

I tried that with both bluetooth headphones and wired ones. I'm using Fedora with PipeWire.

Configuration used:

[[block]]
block = "sound"
headphones_indicator = true
[[block.click]]
button = "left"
cmd = "pavucontrol"

A comparison between waybar (top) and swaybar (bottom) with i3status-rust image

MaxVerevkin commented 6 months ago

Could you try #2049?

alternateved commented 6 months ago

Hmm, I don't think that this fixes it, there is no change.

MaxVerevkin commented 6 months ago

It fixes it for me :laughing:

Let me add some debug prints...

alternateved commented 6 months ago

Is there any way that I could debug it?

MaxVerevkin commented 6 months ago

Try #2049 with RUST_LOG=sound=debug cargo r >/dev/null (I mean share the output)

alternateved commented 6 months ago
$ RUST_LOG=sound=debug ~/.cargo/bin/i3status-rs 
{"version": 1, "click_events": true}
[
[2024-04-23T19:44:21Z DEBUG sound] form_factor = None
[],
[],
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":" 0% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:44:21Z DEBUG sound] form_factor = None
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":" 0% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:44:21Z DEBUG sound] form_factor = Some("analog-output-speaker")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:44:29Z DEBUG sound] form_factor = Some("analog-output-speaker")
[2024-04-23T19:44:29Z DEBUG sound] form_factor = Some("analog-output-speaker")
[2024-04-23T19:44:29Z DEBUG sound] form_factor = Some("analog-output-speaker")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:44:29Z DEBUG sound] form_factor = Some("analog-output-speaker")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:44:29Z DEBUG sound] form_factor = Some("headset-hf-output")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"40% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:44:29Z DEBUG sound] form_factor = Some("headset-hf-output")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"40% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],

Weird, we get headset-hf-output. Let me check wired headphones too (those were BT).

alternateved commented 6 months ago

Continuation:

[2024-04-23T19:44:29Z DEBUG sound] form_factor = Some("headset-hf-output")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"40% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:45:56Z DEBUG sound] form_factor = Some("analog-output-speaker")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:45:56Z DEBUG sound] form_factor = Some("analog-output-speaker")
[2024-04-23T19:45:56Z DEBUG sound] form_factor = Some("analog-output-speaker")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:45:56Z DEBUG sound] form_factor = Some("analog-output-speaker")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:45:56Z DEBUG sound] form_factor = Some("headset-output")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"31% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:45:56Z DEBUG sound] form_factor = Some("analog-output-speaker")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:46:13Z DEBUG sound] form_factor = Some("analog-output-headphones")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"40% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:46:13Z DEBUG sound] form_factor = Some("analog-output-headphones")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"40% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T19:46:13Z DEBUG sound] form_factor = Some("analog-output-headphones")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"40% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],

So analog-output-headphones would be for wired ones.

MaxVerevkin commented 6 months ago

Waaait. https://github.com/greshake/i3status-rust/blob/6a547dbcbba3bbc622a29457026ddcb180521f82/src/blocks/sound/pulseaudio.rs#L408-L410

That should be self.form_factor.as_deref(). My mistake in https://github.com/greshake/i3status-rust/commit/477f505d5707a20d3edb0099adb0f3c9be0b2af8.

alternateved commented 6 months ago
diff --git a/src/blocks/sound.rs b/src/blocks/sound.rs
index 9ad5e706..f8477ac9 100644
--- a/src/blocks/sound.rs
+++ b/src/blocks/sound.rs
@@ -156,6 +156,8 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
                 // https://docs.rs/libpulse-binding/2.25.0/libpulse_binding/proplist/properties/constant.DEVICE_FORM_FACTOR.html
                 Some("headset")
                 | Some("headphone")
+                | Some("headset-hf-output")
+                | Some("analog-output-headphones")
                 | Some("hands-free")
                 | Some("portable")
                 | Some("[Out] Headphones") => true,

That obviously works, but doesn't seem ideal.

MaxVerevkin commented 6 months ago

Can you test that PR now?

alternateved commented 6 months ago

This works great, I've tested with both wireless and wired headphones:

 $ RUST_LOG=sound=debug ~/.cargo/bin/i3status-rs 
{"version": 1, "click_events": true}
[
[2024-04-23T20:01:13Z DEBUG sound] form_factor = None
[],
[],
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":" 0% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:01:13Z DEBUG sound] form_factor = None
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":" 0% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:01:13Z DEBUG sound] form_factor = None
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:01:24Z DEBUG sound] form_factor = None
[2024-04-23T20:01:24Z DEBUG sound] form_factor = None
[2024-04-23T20:01:24Z DEBUG sound] form_factor = None
[2024-04-23T20:01:24Z DEBUG sound] form_factor = None
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:01:24Z DEBUG sound] form_factor = Some("headset")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"40% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:01:32Z DEBUG sound] form_factor = None
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:01:32Z DEBUG sound] form_factor = None
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:01:32Z DEBUG sound] form_factor = None
[2024-04-23T20:01:32Z DEBUG sound] form_factor = None
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:01:32Z DEBUG sound] form_factor = None
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:01:32Z DEBUG sound] form_factor = Some("headset")
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"31% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:01:32Z DEBUG sound] form_factor = None
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:01:48Z DEBUG sound] form_factor = None
[2024-04-23T20:01:48Z DEBUG sound] form_factor = None
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"40% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"40% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:01:48Z DEBUG sound] form_factor = None
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"40% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:02:00Z DEBUG sound] form_factor = None
[2024-04-23T20:02:00Z DEBUG sound] form_factor = None
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[2024-04-23T20:02:00Z DEBUG sound] form_factor = None
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
[{"full_text":" ","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"  ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"},{"full_text":"75% ","name":"0","instance":"0:","separator":false,"separator_block_width":0,"markup":"pango"}],
alternateved commented 6 months ago

Thanks a lot for your time and work! I really appreciate it.