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 packages installed, X11proto in particular, but
here is the location of the upstream copy of the keysyms 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 };
/* If you use amixer, use this instead. Thanks go to DaniOrt3ga. */
static const char *upvol[] = { "/usr/bin/amixer", "set", "Master", "5%+", NULL };
static const char *downvol[] = { "/usr/bin/amixer", "set", "Master", "5%-", NULL };
static const char *mutevol[] = { "/usr/bin/amixerl", "set", "Master", "toggle", NULL };
/* To use light add this to the constant definition section. Thanks Hritik14. */
static const char *light_up[] = {"/usr/bin/light", "-A", "5", NULL};
static const char *light_down[] = {"/usr/bin/light", "-U", "5", 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 } },
};
/* To use light add this to the keys[] array. Thanks Hritik14. */
static Key keys[] = {
{ 0, XF86XK_MonBrightnessUp, spawn, {.v = light_up} },
{ 0, XF86XK_MonBrightnessDown, spawn, {.v = light_down} },
};
@palopezv
Copy link
Author

palopezv commented Jan 1, 2022

@oyMarcel Look for the section where constants are defined. The C syntax is static const char *pointer.

@palopezv
Copy link
Author

palopezv commented Jan 1, 2022

@ahmedsamyh You'll need to write a small script or program in the language of your choice that executes what you need and map it to a key combination in your keyboard, I advice you write another to undo it as well ;-).

@hard-tek
Copy link

hard-tek commented Jan 5, 2022

Worked like a charm!

Copy link

ghost commented Jan 28, 2022

Amazing! Thanks.

@Arqib
Copy link

Arqib commented Feb 28, 2022

This works! Thanks.

@kravandir
Copy link

kravandir commented Mar 9, 2022

PERFECT

@GabubuAvailable
Copy link

GabubuAvailable commented Apr 9, 2022

That helped me. Thank you so much :-D

@DaniOrt3ga
Copy link

DaniOrt3ga commented Jun 16, 2022

In case you use amixer:

static const char *upvol[] = { "/usr/bin/amixer", "set", "Master", "5%+", NULL };
static const char *downvol[] = { "/usr/bin/amixer", "set", "Master", "5%-", NULL };
static const char *mutevol[] = { "/usr/bin/amixer", "set", "Master", "toggle", NULL };

Check the +/- position

@GabubuAvailable
Copy link

GabubuAvailable commented Jun 17, 2022

i used amixer long time ago but thanks :)

@pranshuthegamer
Copy link

pranshuthegamer commented Jul 9, 2022

how do i install the x11 dev thing on arch?

@moodfew
Copy link

moodfew commented Oct 3, 2022

GOD BLESS YOU DUDE!

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