I use a global hotkey (Super1+m) to toggle my microphone between muted and unmuted.
It’s been very handy so far. Different videocall applications all have different hotkeys to mute / unmute oneself, and this avoids me having to keep a mental map of all the different mappings.
It’s also been super handy when pair-programming; I can mute while typing and unmute when I need to talk, saving my co-programmer the pain of hearing my rather loud keyboard.
I recently wanted to game online with some friends, and, again, since my keyboard is pretty loud, it made sense to try to have a global hotkey for toggling my mic (so that my co-gamers don’t hate me).
Note: Voice auto-detection isn’t an option since, apparently, my keyboard is as loud as my voice.
Discord supports a global hotkey on Windows and macOS, but the way it’s
implemented relies on
security issues “features” present on those platform
that are not present in Linux desktop. On these other platforms, applications
can freely act as keylogger and intercept keystrokes when they’re not in
foreground. This is not possible on Wayland (the display server protocol on
Linux2) for obvious reasons.
Global hotkeys have a rather different philosophy: you configure the compositor itself to grab certain hotkeys, and execute an action in response. If Discord had something like a D-Bus API, configuring such a thing would be possible. Sadly, Discord support no such thing.
However, the toggle works as is. It work on any application since it mutes the microphone at a system level. It’s just a shame that other can’t easily determine if I’m deliberately muted or not.
Aside from being globally accesible, this technique is also globally visible. There’s an icon on my status bar indicating the microphone status at all times:
The design of the icon is vaguely inspired on the iOS icon used when applications are using a microphone in the background (e.g.: during background calls).
It works, and it’s just a tiny script. No polling either, it actually sleeps 99% of the time, and only wakes up for changes on microphone state.
The global hotkey is just a one-liner which just calls ponymix. If you use sway, this can be freely copy-pasted. If you use a different compositor, just map global hotkeys to a similar command.