Skip to content

Instantly share code, notes, and snippets.

@jpsutton
Last active May 31, 2024 16:53
Show Gist options
  • Save jpsutton/ba3b40ae5d2e44b88bd6ce9a0f9971d6 to your computer and use it in GitHub Desktop.
Save jpsutton/ba3b40ae5d2e44b88bd6ce9a0f9971d6 to your computer and use it in GitHub Desktop.
Bash script to toggle the enabled status on your touchpad while running under KDE Plasma 5
#!/bin/bash
SERVICE="org.kde.KWin"
DBUS_PATH="/org/kde/KWin/InputDevice"
INTERFACE="org.kde.KWin.InputDevice"
METHOD_GET="org.freedesktop.DBus.Properties.Get"
METHOD_SET="org.freedesktop.DBus.Properties.Set"
function find_touchpad {
DM_INTERFACE="org.kde.KWin.InputDeviceManager"
DM_PROPERTY="devicesSysNames"
for sysname in $(qdbus "$SERVICE" "$DBUS_PATH" "$METHOD_GET" "$DM_INTERFACE" "$DM_PROPERTY"); do
is_touchpad=$(qdbus "$SERVICE" "${DBUS_PATH}/${sysname}" "$METHOD_GET" "$INTERFACE" touchpad)
if [ "$is_touchpad" == "true" ]; then
echo "$sysname"
break
fi
done
}
function toggle_touchpad {
DBUS_PATH="${DBUS_PATH}/$(find_touchpad)"
PROPERTY="enabled"
# Get the current status of the touchpad
status=$(qdbus "$SERVICE" "$DBUS_PATH" "$METHOD_GET" "$INTERFACE" "$PROPERTY")
# Flip the status
status=$([[ "$status" == "false" ]] && echo true || echo false)
# Set the new status
qdbus "$SERVICE" "$DBUS_PATH" "$METHOD_SET" "$INTERFACE" "$PROPERTY" "$status"
}
toggle_touchpad
@jpsutton
Copy link
Author

Updated to abstract a bit more

@digitalsignalperson
Copy link

Thanks for this, this is a nice wayland solution to replace xinput stuff. I've incorporated it in my fusuma config to enable/disable my trackpad based on a gesture and/or timeout: https://gist.github.com/digitalsignalperson/34c1df16fdcd4b87c873aaba29d70b22

@jpsutton
Copy link
Author

Hey, that's great! I'm glad it's useful to someone else.

@srebrovvilen
Copy link

Perfectly! It would be great to get a similar one for wireless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment