How to toggle a command with a keypress in Arch Linux using i3
I find the mouse pad on my laptop annoying because I often brush it with my arm when I am typing so I figured I would make a toggle to turn it off and back on again when I want to use the mouse. For some reason synaptics doesn't pick up my mouse pad so I'm resorting to using xinput disable 11 with 11 being the ID of my mouse pad. I'm trying to use bindsym in the i3 config to make "m" toggle the mouse pad. I've made an sh script to disable the mousepad but it doesn't seem to turn back on when I press "m" again. I figured I would make a system variable to determine whether the mousepad is on or not but the sh script doesn't seem to see it properly. This is my script at the moment called "trackpad" in /bin:
#!/bin/bash if [[ $1 -eq 1 ]] then xinput enable 11 && export TRACKPAD=0 else xinput disable 11 && export TRACKPAD=1 fi
Then in my i3 config file I have:
bindsym $mod+m exec trackpad $TRACKPAD
I'm not sure if this is even the best method to do this so any alternative suggestions would be great. Otherwise, how can I fix this? I'm fairly new to Linux.
xinput offers the argument list-props for listing all properties of a device. At least with my touchpad, executing xinput enable and xinput disable toggles the property Device Enabled (0/1). Greping the status of this property makes you able to test if the device is currently enabled.
A quick-and-dirty approach to use this for your problem could be the following snippet:
#!/bin/bash if xinput list-props 11 | grep -qE "Device Enabled.*1$" then xinput disable 11 else xinput enable 11 fi
or as a simple one-liner:
#!/bin/bash xinput list-props 11 | grep -qE "Device Enabled.*1$" && xinput disable 11 || xinput enable 11
As you can see those scripts don't need an argument to be passed. Simple execution toggles the device-state.