end-4 / dots-hyprland

Modern, feature-rich and accessible desktop configuration.
https://end-4.github.io/dots-hyprland-wiki/en/
GNU General Public License v3.0
3.34k stars 218 forks source link

[Feature] Button to Mute/Unmute Mic in top-bar #367

Closed Yasuhan closed 4 months ago

Yasuhan commented 4 months ago

What would you like to be added? I'd like to have a button in the top bar (maybe next to the ethernet/bluetooth icons), that on-click mutes/unmutes the microphone.

How will it help I use this rice on my work rig as well, and sometimes I need to quickly mute/unmute myself in meetings or Mumble even when the window is hidden/covered by something else. A mute button for the mic that's accessible from all my screens with just one simple click would be the perfect solution to that for me, and I would also see at a glance if my mic is on/off. It also helps, that it would be a global mute, with so many different things I sometime lose track what I'm actually talking on right now.

Extra info image Something likes this, to see it at a glance is super helpful for work setups.

end-4 commented 4 months ago

There are 2 solutions I'm thinking of:

  1. Have a "no mic" icon on the left of the Network icon if mic is muted globally. Muting/unmuting would be toggled with a keybind, but not mouse, since that area is for indicators only and mouse control is reserved for sidebar toggle and media actions
  2. Have that thing as a tray item. This way I'm fine with it being clickable. A quick search returns this app https://github.com/Junker/mictray , but I've tested it and the tray item doesn't show up.
end-4 commented 4 months ago

ooh, there's a list on arch wiki for what we're looking for: https://wiki.archlinux.org/title/PulseAudio#Graphical so far

Yasuhan commented 4 months ago

The previous rice I used had waybar and used something akin to this:

# Toggle Mic toggle_mic() { if [ "$(pamixer --default-source --get-mute)" == "false" ]; then pamixer --default-source -m && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$iDIR/microphone-mute.png" "Microphone Switched OFF" elif [ "$(pamixer --default-source --get-mute)" == "true" ]; then pamixer -u --default-source u && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$iDIR/microphone.png" "Microphone Switched ON" fi }

Not sure how you'd best implement that into AGS though?

Edit: Less ugly, not sure how to properly format here:

image

end-4 commented 4 months ago

to format wrap in a code block with 3 backticks, like this: ```bash # write code here # that "bash" there is the language name ```

end-4 commented 4 months ago

anyway i'm going to implement the 1st solution real quick

end-4 commented 4 months ago

now, what keybind should i use :thinking:

Yasuhan commented 4 months ago

I'd probably put it on Super+XF86AudioMute?

end-4 commented 4 months ago

sure

end-4 commented 4 months ago

done test it please?

Yasuhan commented 4 months ago

The keybind works, I just don't get the icon.

end-4 commented 4 months ago

what

https://github.com/end-4/dots-hyprland/assets/97237370/8d671977-f76d-4d1b-9db4-107bd890a192

Yasuhan commented 4 months ago

Yeah..that doesn't happen for me. :sweat_smile:

end-4 commented 4 months ago

did you update the ags config? is there anything in the logs? can you open a terminal, run pkill ags; ags and show the output when you press the toggle keybind?

Yasuhan commented 4 months ago

image

https://github.com/end-4/dots-hyprland/assets/30007466/0fadc94c-b0a8-4911-a6dc-8424767c2ee5

Config updated, since the bluetooth toggles you added earlier also just appeared.

end-4 commented 4 months ago

just commited 7a9f25aa99e72d642ed6cd387aefb85eee723090 which i think should fix the logs try again

Yasuhan commented 4 months ago

It fixed the logs, but now I only have the bar on my main monitor and the icon still isn't loading.

Yasuhan commented 4 months ago

I fixed it by changing

Audio.microphone.isMuted

to

Audio.microphone.stream.is_muted

as that seems to be the proper way to do it? https://github.com/Aylur/ags/issues/123

Only have the issue that I now get this:

(com.github.Aylur.ags:33404): Gjs-CRITICAL **: 17:56:33.465: JS ERROR: TypeError: (intermediate value).microphone.stream is null

The toggle works fine though..so no clue what's up there.

yrnmsk commented 4 months ago

Yea that's the proper way to do it. And from what I last remember from reading the ags docs maybe months ago (that was January), both the isMuted and stream are async and their values initially are null. So optional object chaining is preferred instead, like so:

- Audio.microphone.stream.isMuted
+ Audio.microphone?.stream?.isMuted

That intermediate value is null something error/warning is initially displayed at first since value is still null so it errors out, until it's been properly set up and its value is no longer null. That's maybe why it eventually works just fine as you said.

Shrug, just async things I guess?

Yasuhan commented 4 months ago

Ah, perfect. Changing that now completely fixed it and no more errors appear. Thanks!

Edit: Changed the whole thing in my own fork now to be always visible, too - in case someone else wants it?

export const MicMuteIndicator = () => Widget.Stack({
   transition: 'slide_up_down',
   transitionDuration: userOptions.animations.durationSmall,
   children: {
        'off': Widget.Label({ className: 'txt-norm icon-material', label: 'mic_off' }),
        'on': Widget.Label({ className: 'txt-norm icon-material', label: 'mic' }),
    },
    setup: (self) => self.hook(Audio, stack => {
        if (Audio.microphone?.stream?.is_muted)
            stack.shown = 'off';
        else
            stack.shown = 'on';
    }),
});
end-4 commented 4 months ago

i guess that'll do