When I first installed DWM on my Arch Linux system, I immediately noticed something was off—my touchpad wasn’t behaving the way I was used to. Tapping wasn’t enabled, and the scrolling was reversed from what felt natural to me. Since DWM is a minimal window manager, it doesn’t provide a graphical settings panel to tweak these configurations easily, so 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. However, I quickly 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.

This was far from ideal, so I decided to automate the process.

Learning awk to Solve the Problem

To dynamically retrieve the touchpad and property IDs, I turned to awk, a powerful text-processing tool. After some trial and error, 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 scrolFling and enables it. If you want to learn more about awk, I suggest you go through this tutorial. 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

Now that I had a 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 exactly how I want it to without any manual intervention.

Final Thoughts

This small project taught me a lot about automating system configurations, parsing text with awk, and integrating scripts into my Linux setup. It’s a great example of why I love using Linux—it gives me complete control over my system and forces me to learn new stuffs to solve problems.

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!