logo TeddyDD

Push to Talk in i3 WM

I figured out how to unmute microphone when right super key is pressed. I can unmute MS Teams, switch to the different workspace and keep talking with my coworkers. No more switching workspaces to click microphone icon.

Setting this up was a bit more complicated than expected.

Setup

First you have to unhook right super key from Mod4 modifier. It’s not strictly necessary but using right super as Mod4 will confuse i3, you will be switching your microphone on and off unexpectedly.

To unhook right super from Mod4 take a look at xmodmap output.

$ xmodmap
xmodmap:  up to 3 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock      
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3        
mod4        Super_L (0x85), Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

As you can see Super_R is binded to Mod4, while Mod3 is unused. I decided to move Super_R to Mod3 in case I wanted to use it as modifier later on. It would be enough to unbind Super_R from Mod4 though. In ~/.Xmodmap:

remove Mod4 = Super_R
add Mod3 = Super_R

If you don’t use display manager, remember to load your custom xmodmap in ~/.xinitrc:

xmodmap ~/.Xmodmap

Now we want to disable key repeat for Super_R keycode. This ensures that while holding Super_R only one KeyPressed event will be emited. To figure out keycode of Super_R you can use xmodmap -pke | grep Super_R. In my case it’s 134.

To disable repeating you can use xset -r 134. This sould go to your ~/.xprofile or ~/.xinitrc. I decided to put it in my i3 config though.

exec xset -r 134

The final step is to bind Super_R to mute/unmute command in i3 config:

bindsym Super_R exec pactl set-source-mute @DEFAULT_SOURCE@ 0
bindsym --release Super_R exec pactl set-source-mute @DEFAULT_SOURCE@ 1

You can also add some visual feedback like icon in i3status. I don’t feel like parsing output of pactl so I went with dunst notification:

bindsym Super_R exec pactl [...] && dunstify -p -a mic -h string:bgcolor:#4361EE -h string:fgcolor:#FFFFFF Microphone > $XDG_RUNTIME_DIR/mic-notif-id
bindsym --release Super_R exec pactl [...] && dunstify -C $(cat $XDG_RUNTIME_DIR/mic-notif-id)
Published: