Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dwm volume control with hardware multimedia keys (pulseaudio)
/**
* dwmconfig.h
* Hardware multimedia keys
*/
/* Somewhere at the beginning of config.h include: */
/*
You obviously need the X11 development package installed, but here is the upstream copy
of this header if you can't bother using the contents of your own hard drive. ;-P
https://cgit.freedesktop.org/xorg/proto/x11proto/tree/XF86keysym.h
*/
#include <X11/XF86keysym.h>
/* Add somewhere in your constants definition section */
static const char *upvol[] = { "/usr/bin/pactl", "set-sink-volume", "0", "+5%", NULL };
static const char *downvol[] = { "/usr/bin/pactl", "set-sink-volume", "0", "-5%", NULL };
static const char *mutevol[] = { "/usr/bin/pactl", "set-sink-mute", "0", "toggle", NULL };
/* Add to keys[] array. With 0 as modifier, you are able to use the keys directly. */
static Key keys[] = {
{ 0, XF86XK_AudioLowerVolume, spawn, {.v = downvol } },
{ 0, XF86XK_AudioMute, spawn, {.v = mutevol } },
{ 0, XF86XK_AudioRaiseVolume, spawn, {.v = upvol } },
};
/* If you have a small laptop keyboard or don't want to spring your fingers too far away. */
static Key keys[] = {
{ MODKEY, XK_F11, spawn, {.v = downvol } },
{ MODKEY, XK_F9, spawn, {.v = mutevol } },
{ MODKEY, XK_F12, spawn, {.v = upvol } },
};
@DarkNemesis200

This comment has been minimized.

Copy link

@DarkNemesis200 DarkNemesis200 commented May 13, 2019

This is really helpful thanks for making this

@ajvirgona

This comment has been minimized.

Copy link

@ajvirgona ajvirgona commented May 28, 2019

I searched google hoping to find exactly this, thanks!

@abible

This comment has been minimized.

Copy link

@abible abible commented Jun 20, 2019

Just plain excellent. Many thanks

@moadAlami

This comment has been minimized.

Copy link

@moadAlami moadAlami commented Nov 25, 2019

I had so much trouble trying to get XF86 keys to work. Thank you so much.

@aith

This comment has been minimized.

Copy link

@aith aith commented Mar 28, 2020

Thank you!!! Worked perfectly

@hb0nes

This comment has been minimized.

Copy link

@hb0nes hb0nes commented Apr 14, 2020

Omg thank you, this worked. How did you find the proper key definition for laptop volume keys? I am really curious.

@palopezv

This comment has been minimized.

Copy link
Owner Author

@palopezv palopezv commented Apr 14, 2020

@hb0nes Trial and error. And several months hitting my head on the walls.

@Umbrien

This comment has been minimized.

Copy link

@Umbrien Umbrien commented Apr 25, 2020

Thanks 👍

@aaronhooper

This comment has been minimized.

Copy link

@aaronhooper aaronhooper commented May 27, 2020

Thanks for this. Worked like a charm

@chn-cynic

This comment has been minimized.

Copy link

@chn-cynic chn-cynic commented Jun 10, 2020

Omg thank you, this worked. How did you find the proper key definition for laptop volume keys? I am really curious.

You can use xev for that!

@lytvyn139

This comment has been minimized.

Copy link

@lytvyn139 lytvyn139 commented Jun 15, 2020

Thank you ! {for those who doesn't get it, if you added lines 24-27, the hot keys are:

  • MOD+F9 mute
  • MOD+F11 down
  • MOD+F12 up
    worked fine with dwm-bar+pulse.sh
    }
@patrickmwila

This comment has been minimized.

Copy link

@patrickmwila patrickmwila commented Sep 7, 2020

Thank You

@im-alexandre

This comment has been minimized.

Copy link

@im-alexandre im-alexandre commented Sep 18, 2020

It looks great. Does it work with dose wheels in key keyboard?

@nong10

This comment has been minimized.

Copy link

@nong10 nong10 commented Oct 4, 2020

It works thanks so much

@bdealbuquerque

This comment has been minimized.

Copy link

@bdealbuquerque bdealbuquerque commented Dec 17, 2020

It works perfectly. Thank you very much !

@Hritik14

This comment has been minimized.

Copy link

@Hritik14 Hritik14 commented Jan 3, 2021

If someone's looking for XF86 keys list, here it is https://cgit.freedesktop.org/xorg/proto/x11proto/tree/XF86keysym.h

@Hritik14

This comment has been minimized.

Copy link

@Hritik14 Hritik14 commented Apr 1, 2021

@manukll

static const char
	*light_up[] = {"/usr/bin/light", "-A", "5", NULL},
	*light_down[] = {"/usr/bin/light", "-U", "5", NULL};

static Key keys[] = {
	{ 0     ,			XF86XK_MonBrightnessUp  ,			spawn ,			{.v = light_up}}     ,
	{ 0     ,			XF86XK_MonBrightnessDown,			spawn ,			{.v = light_down}}   ,
};

You'll need to install light package, of course.

@leetdude

This comment has been minimized.

Copy link

@leetdude leetdude commented Apr 11, 2021

What are the keys to change vol?

@crackself

This comment has been minimized.

Copy link

@crackself crackself commented May 18, 2021

Thanks, it work on my laptop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment