Last active
September 25, 2023 23:21
-
-
Save digitalsignalperson/34c1df16fdcd4b87c873aaba29d70b22 to your computer and use it in GitHub Desktop.
A script to auto-disable a trackpad N seconds after last press.
This file contains 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/python | |
import time | |
import subprocess | |
import threading | |
def get_device_node(name, strip_path=False): | |
# output = subprocess.check_output(["xinput", "list-props", name]).decode('utf-8') | |
# for line in output.splitlines(): | |
# if line.strip().startswith('Device Node'): | |
# device_node = line.strip().split()[-1].strip('"') | |
# if strip_path: | |
# device_node = device_node.split('/')[-1] | |
# return device_node | |
output = subprocess.check_output(["toggle_touchpad.sh", "1"]).decode('utf-8') | |
if '/' in output: | |
node = output.split('/')[-1] | |
if node.startswith('event'): | |
return node.strip() | |
raise ValueError(f"device node not found") | |
def disable_after_t(device_name, t_thresh=5.0): | |
event_n = get_device_node(device_name, strip_path=True) | |
process = subprocess.Popen(['libinput', 'debug-events'], stdout=subprocess.PIPE, universal_newlines=True) | |
t_last = time.time() | |
for line in process.stdout: | |
if line.strip().startswith(event_n): | |
t_last = time.time() | |
if time.time() - t_last > t_thresh: | |
break | |
#subprocess.run(["xinput", "disable", device_name]) | |
subprocess.run(["toggle_touchpad.sh", "0"]) | |
process.kill() | |
#name = "Apple Inc. Magic Trackpad 2" | |
#subprocess.run(["xinput", "enable", name]) | |
subprocess.run(["toggle_touchpad.sh", "1"]) | |
disable_after_t(name, t_thresh=5.0) |
This file contains 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 | |
# original from https://gist.github.com/jpsutton/ba3b40ae5d2e44b88bd6ce9a0f9971d6 | |
# added argument to enable/disable, added print event node | |
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" | |
echo $DBUS_PATH | |
if [ "$1" == "1" ]; then | |
status="true" | |
elif [ "$1" == "0" ]; then | |
status="false" | |
else | |
# 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) | |
fi | |
# Set the new status | |
qdbus "$SERVICE" "$DBUS_PATH" "$METHOD_SET" "$INTERFACE" "$PROPERTY" "$status" | |
} | |
toggle_touchpad "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated for wayland based on https://gist.github.com/jpsutton/ba3b40ae5d2e44b88bd6ce9a0f9971d6
fusuma config is now this