最後活躍 1792481944

Scripts to install three finger dragging on trackpad, like on Mac OS X laptops.

three-finger-drag.sh 原始檔案
1#!/usr/bin/env bash
2# Debian 13 KDE Wayland — macOS-style three-finger drag on bcm5974 trackpads.
3# Source: https://github.com/lmr97/linux-3-finger-drag
4set -Eeuo pipefail
5
6if (( EUID == 0 )); then
7 echo 'Run as your desktop user, without sudo.' >&2
8 echo 'The script will request sudo only for system-wide changes.' >&2
9 exit 1
10fi
11
12command -v sudo >/dev/null || { echo 'sudo is required.' >&2; exit 1; }
13command -v systemctl >/dev/null || { echo 'systemd is required.' >&2; exit 1; }
14if ! grep -qs 'bcm5974' /proc/bus/input/devices; then
15 echo 'Warning: bcm5974 trackpad not detected; this setup targets Apple bcm5974.' >&2
16 read -r -p 'Continue anyway? [y/N] ' reply
17 [[ "$reply" =~ ^[Yy]$ ]] || exit 1
18fi
19
20sudo -v
21sudo apt-get update
22sudo apt-get install -y git build-essential pkg-config libudev-dev libevdev-dev curl ca-certificates acl
23
24# rustup is installed per user so that Cargo does not run as root.
25if ! command -v cargo >/dev/null 2>&1; then
26 echo 'Installing Rust via rustup (official installer)...'
27 curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs -o "${TMPDIR:-/tmp}/rustup-3fd-$$.sh"
28 sh "${TMPDIR:-/tmp}/rustup-3fd-$$.sh" -y --profile minimal
29 rm -f "${TMPDIR:-/tmp}/rustup-3fd-$$.sh"
30fi
31export PATH="$HOME/.cargo/bin:$PATH"
32command -v cargo >/dev/null || { echo 'Cargo is not available.' >&2; exit 1; }
33
34source_dir="$HOME/linux-3-finger-drag"
35if [[ -d "$source_dir/.git" ]]; then
36 echo "Using existing checkout: $source_dir"
37else
38 [[ ! -e "$source_dir" ]] || { echo "Path exists but is not a git checkout: $source_dir" >&2; exit 1; }
39 git clone https://github.com/lmr97/linux-3-finger-drag.git "$source_dir"
40fi
41
42cd "$source_dir"
43# Pin the version used successfully on this machine, if its tag exists.
44if git rev-parse -q --verify 'refs/tags/v2.0.0' >/dev/null; then
45 git checkout --detach v2.0.0
46elif git rev-parse -q --verify 'refs/tags/2.0.0' >/dev/null; then
47 git checkout --detach 2.0.0
48else
49 echo 'Warning: no local v2.0.0 tag; building the existing checkout.' >&2
50fi
51cargo build --release
52[[ -x target/release/linux-3-finger-drag ]] || { echo 'Expected binary not found.' >&2; exit 1; }
53sudo install -m 0755 target/release/linux-3-finger-drag /usr/local/bin/linux-3-finger-drag
54
55mkdir -p "$HOME/.config/linux-3-finger-drag" "$HOME/.config/systemd/user"
56config="$HOME/.config/linux-3-finger-drag/3fd-config.json"
57if [[ ! -e "$config" ]]; then
58 cat > "$config" <<'JSON'
59{
60 "acceleration": 1.0,
61 "dragEndDelay": 0,
62 "logFile": "stdout",
63 "logLevel": "info",
64 "entryDebounce": 50,
65 "probeDelay": 15,
66 "pressGrace": 75
67}
68JSON
69else
70 echo "Keeping existing config: $config"
71fi
72
73# Match the device by name, not by unstable /dev/input/eventN.
74# OWNER is used instead of RUN+=setfacl because the latter failed after reboot.
75udev_rule='/etc/udev/rules.d/70-linux-3-finger-drag.rules'
76rule_tmp="$(mktemp)"
77trap 'rm -f "$rule_tmp"' EXIT
78cat > "$rule_tmp" <<EOF_RULE
79# Apple bcm5974 touchpad and uinput access for the desktop user.
80ACTION=="add|change", SUBSYSTEM=="input", KERNEL=="event*", ATTRS{name}=="bcm5974", OWNER="$(id -un)", MODE="0600"
81ACTION=="add|change", SUBSYSTEM=="misc", KERNEL=="uinput", OWNER="$(id -un)", MODE="0600"
82EOF_RULE
83sudo install -m 0644 "$rule_tmp" "$udev_rule"
84
85sudo modprobe uinput
86printf 'uinput\n' | sudo tee /etc/modules-load.d/three-finger-drag.conf >/dev/null
87sudo udevadm control --reload-rules
88sudo udevadm trigger --action=change --subsystem-match=input --sysname-match='event*'
89sudo udevadm trigger --action=change --subsystem-match=misc --sysname-match=uinput || true
90
91cat > "$HOME/.config/systemd/user/three-finger-drag.service" <<'SERVICE'
92[Unit]
93Description=macOS-like Three Finger Drag for Apple Trackpad
94After=graphical-session.target
95PartOf=graphical-session.target
96
97[Service]
98Type=exec
99ExecStart=/usr/local/bin/linux-3-finger-drag
100Restart=on-failure
101RestartSec=2
102
103[Install]
104WantedBy=graphical-session.target
105SERVICE
106
107systemctl --user daemon-reload
108systemctl --user enable three-finger-drag.service
109systemctl --user restart three-finger-drag.service
110
111echo
112echo '== Three-Finger Drag status =='
113systemctl --user --no-pager --full status three-finger-drag.service || true
114echo
115echo 'If permission errors appear, reboot and check:'
116echo ' journalctl --user -u three-finger-drag.service -b --no-pager -n 50'
117