‹ back home

My desktop-wide microphone mute toggle

2021-06-16 #desktop #discord #kiss #linux #meet

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 statusbar showing an icon that blends in.
The muted ("closed") indicator.
The statusbar showing an icon with a red background that stands out.
The unmuted ("open") indicator.

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.

Hotkey implementation

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.

  1. Also known as Meta, , Command or Windows↩︎

  2. Older Linux desktops use Xorg, which does allow applications to freely snoop on keystrokes and what others are rendering. ↩︎

— § —