Loosely based on this gist from el-grad
This is a near-complete rewrite of that person's script, because I couldn't follow what they were doing and I thought it was a little bit complicated and didn't need to be. It also didn't work for this laptop at all so one thing lead to another...
I wrote this for me, and it works decently for me. I put it on github in the hopes that another die-hard linux user may find it useful.
I add this script to my window manager's startup and keep it backgrounded.
The script is pretty dirt simple and in my testing doesn't consume much system resources, so it can be run like a daemon.