aboutsummaryrefslogtreecommitdiff
path: root/articles/2025/DWM-Dunst-and-Thinkpad-audio-keys.html
blob: ee184b8466a4d5044f806f966d18b2fb5bfdf2ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!doctype html>
<html lang="EN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="/style.css">
    <title>DWM Dunst and Thinkpad audio keys</title>
  </head>
  <body>
    <header>
      <h1>Bloggings</h1>
      <a href="/index.php">Back</a>
      
    </header>
    
<main>
<article>
<h2>DWM Dunst and Thinkpad audio keys</h2>
<h3>2025-04-24</h3>
<h4>How I got them working, microphone mute led included</h4>
<p>DWM isn't a desktop environment, so there are a few things to add, like notifications and
audio keys.</p>
<p>I installed dunst and acpid. Dunst is managed by systemd, if you edit ~/.config/dunst/dunstrc 
restart dunst with <b>systemctl --user restart dunst.service</b></p>
<p><a href="https://github.com/dunst-project/dunst">Dunst web page</a></p>
<p><a href="https://wiki.archlinux.org/title/Acpid">Acpid Arch page</a></p>


<h4>dwm/config.h</h4>
<p>The audio keys are registered in <b>dwm/config.h</b>
<pre>
...
{ 0, XF86XK_AudioMicMute, spawn, SHCMD("~/.local/bin/dwm-audio mictoggle") },
{ 0, XF86XK_AudioMute, spawn, SHCMD("~/.local/bin/dwm-audio voltoggle") },
{ 0, XF86XK_AudioLowerVolume, spawn, SHCMD("~/.local/bin/dwm-audio volquieter") },
{ 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("~/.local/bin/dwm-audio vollouder") },
...
</pre>

<h4>~/.local/bin/dwm-audio</h4>
<p>The audio keys run a bash script which sets volume, speaker mute, and microphone mute.</p>
<pre>
#!/bin/bash
# Manage Thinkpad Audio keys

msgTag="Audio"

# Microphone
if [[ "$@" == "mictoggle" ]]; then
    pamixer --default-source -t
    micmute="$(pamixer --default-source --get-mute)"
    if [[ "$micmute" == "true" ]]; then
        # Mic muted notification
        dunstify -t 1000 -a "Microphone" -u low -i audio-input-microphone \
        -h string:x-dunst-stack-tag:$msgTag "Microphone muted"
    else
        # Mic unmuted notification
        dunstify -t 1000 -a "Microphone" -u low -i audio-input-microphone \
        -h string:x-dunst-stack-tag:$msgTag "Microphone unmuted"
    fi
    exit 0
fi

# Speakers
if [[ "$@" == "voltoggle" ]]; then
	pamixer --toggle-mute
elif [[ "$@" == "vollouder" ]]; then
	pamixer -i 10
elif [[ "$@" == "volquieter" ]]; then
    pamixer -d 10
fi

volume="$(pamixer --get-volume-human)"
mute="$(pamixer --get-mute)"
if [[ $volume == 0 || "$mute" == "true" ]]; then
    # Sound muted notification
    dunstify -t 1000 -a "changeVolume" -u low -i audio-speakers \
    -h string:x-dunst-stack-tag:$msgTag "Volume muted" 
else
    # Volume notification
    dunstify -t 1000 -a "changeVolume" -u low -i audio-speakers \
    -h string:x-dunst-stack-tag:$msgTag -h int:value:"$volume" "Volume: ${volume}"
fi
</pre>

<h4>Microphone mute led</h4>
<p>I'm running Arch Linux on a Thinkpad X220, so I need to make the mic/mute button's led
lights up when muted. This can't be done with normal user permissions, so I installed acpid.
On Arch linux all acpi events are passed to <b>/etc/acpi/handler.sh</b>, so I added another
function to this file. 
</p>
<pre>
...
button/micmute)
  if [[ "$(cat /sys/devices/platform/thinkpad_acpi/leds/platform\:\:micmute/brightness)" == "1" ]]; then
    echo "0" > /sys/devices/platform/thinkpad_acpi/leds/platform\:\:micmute/brightness
  else
    echo "1" > /sys/devices/platform/thinkpad_acpi/leds/platform\:\:micmute/brightness
  fi
;;
...
</pre>

</article>
</main>
<footer>

<p>&nbsp;</p>

<p>§</p>
  </footer>
</body>
</html>