When I first installed DWM on my Arch Linux, I noticed my touchpad wasn’t working the way I was used to. Tapping wasn’t enabled and the scrolling was reversed. I was not used to clicking the button for registering the click so, I needed the tapping in touchpad enabled. The DWM is a minimal window manager, it doesn’t provide a graphical settings panel to tweak these configurations easily. I had to dig deeper into the system to fix it.
The Problem: Dynamic Touchpad and Property IDs
At first, I manually adjusted my touchpad settings using xinput commands. Running xinput list gave me the touchpad device ID, and xinput list-props <id> allowed me to modify its properties. I realized that both the touchpad’s ID and its property IDs weren’t static. They changed between reboots. This meant that every time I restarted my system, I had to figure out the new IDs and re-enter the commands manually.
Learning awk to Solve the Problem
To retrieve the touchpad and property IDs, I used awk, which is powerful text-processing tool. After some test, I wrote a shell script (touchpad.sh) that:
- Extracts the touchpad’s ID dynamically using
awk. - Finds the correct property ID for tapping and enables it.
- Finds the property ID for natural scrolling and enables it.
For more detailed manual, visit gnu’s website.
Here’s the final version of the script:
#!/bin/bash
# Extract the ID of the Touchpad
touchpad_id=$(xinput list | awk -F'=' '/Touchpad/{print $2}' | awk '{print $1}')
# Enable Tapping
prop_id=$(xinput list-props "$touchpad_id" | awk -F'[()]' '/Tapping Enabled/{print $2; exit}')
xinput set-prop "$touchpad_id" "$prop_id" 1
# Enable Natural Scrolling
prop_id=$(xinput list-props "$touchpad_id" | awk -F'[()]' '/Natural Scrolling Enabled/{print $2; exit}')
xinput set-prop "$touchpad_id" "$prop_id" 1
Automating the Script at Startup
After I had the working script, I needed to make sure it ran automatically at system startup. Since I was using startx to launch DWM, the best place to include it was in my .xinitrc file. I simply added:
sh /path/to/touchpad.sh &
Now, every time I start my system, the script runs and my touchpad works how I want it to without any of my manual intervention.
Final Thoughts
This small project taught me a bit about parsing text with awk, and integrating scripts into my Linux OS. It’s also a good example of why I love using Linux.
If you’re using DWM or any minimal window manager and facing similar issues, writing a simple script like this can save you a lot of time and hassle!