Created
September 20, 2023 13:52
-
-
Save pipelinedave/506f476da81fcf1ef9789fcc03c33822 to your computer and use it in GitHub Desktop.
Switch virtual desktop on three finger touchpad swipe with this bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ---------------------------------------------------------------------------- | |
# Script Name: three_finger_touchpad_desktop_switch.sh | |
# Description: Switch desktops using a 3-finger swipe gesture | |
# Author: github.com/pipelinedave | |
# Version: 1.1 | |
# Usage: sudo sh three_finger_touchpad_desktop_switch.sh | |
# Note: Update the "device" variable to point to your actual input device. | |
# ---------------------------------------------------------------------------- | |
# Check if wmctrl is installed | |
if ! command -v wmctrl &> /dev/null; then | |
echo "Hey, playa! wmctrl ain't installed. Get it via your package manager." | |
exit 1 | |
fi | |
# Your touchpad device (change to your actual device) | |
device="/dev/input/event6" | |
# Start the loop and capture libinput events | |
echo "Looping..." | |
libinput debug-events --device $device | while read -r line | |
do | |
# Looking for 3-finger swipes | |
gesture=$(echo "$line" | grep 'GESTURE_SWIPE_UPDATE' | awk '{ print $4 }') | |
if [ "$gesture" = "3" ]; then | |
# Get the vertical direction of the swipe | |
direction=$(echo "$line" | grep 'GESTURE_SWIPE_UPDATE' | awk '{ print $7 }') | |
# If swipe is up | |
if [ -n "$direction" ] && (( $(echo "$direction > 0" | bc -l) )); then | |
echo "Direction: up" | |
wmctrl -s 0 # Switch to desktop 0 | |
# If swipe is down | |
elif [ -n "$direction" ] && (( $(echo "$direction < 0" | bc -l) )); then | |
echo "Direction: down" | |
wmctrl -s 1 # Switch to desktop 1 | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment