pointer

Hand-tracking mouse controller: point with your index finger, pinch your thumb to click

readme · slastra/pointer

Hand-tracking mouse controller: point with your index finger, pinch your thumb to click.

A GTK4/Adwaita app that watches your webcam, tracks your hand with MediaPipe, and drives the cursor through a Wayland virtual pointer. The window shows the live camera preview with the tracking overlay beside a panel of live-tunable controls.

Features

  • Real-time hand detection and tracking using MediaPipe
  • Cursor control via index finger movement
  • Left click, right click and scroll from pinches and poses, each debounced over 3 frames
  • One-Euro motion smoothing to reduce jitter, tunable while it runs
  • Motion prediction for handling brief occlusions
  • Tracking rectangle that maps part of the camera frame to the whole screen
  • Two interaction modes (single-click and drag-hold)
  • Wayland-native cursor control via zwlr_virtual_pointer_unstable_v1

Install

Requirements

  • A wlroots-based compositor (Hyprland, Sway): the cursor is driven through zwlr_virtual_pointer_manager_v1, and the app will not start without it
  • Webcam (the first one, /dev/video0)
  • GTK4 and libadwaita, for PyGObject
  • Optional: v4l2-ctl, used to turn off exposure_dynamic_framerate, which otherwise throttles many webcams to ~15 fps indoors

From source

git clone https://github.com/slastra/pointer
cd pointer
uv sync

Requires uv. Pinned to Python 3.11 / 3.12.

Usage

uv run pointer

Gestures

  • Point with the index finger alone to control the cursor
  • Thumb to index finger PIP (first knuckle): left click / drag
  • Thumb to middle finger PIP: right click
  • Peace sign (index and middle extended), move vertically: scroll

Window controls

  • Header bar: pause tracking, start calibration, reset mouse state, and a menu with delete calibration and quit (Ctrl+Q)
  • Controls panel: smoothing min-cutoff (lower = smoother at rest), smoothing beta (higher = more responsive to motion), click threshold, hold-to-drag mode, smoothing on/off
  • Status bar: fps, the current gesture, mode and whether tracking is live or paused

Calibration

The Tracking rectangle panel sets which part of the camera frame maps to the screen, as fractions of the frame (Left, Right, Top, Bottom). Bottom headroom shifts the rectangle up so your wrist stays in frame when pointing at the bottom edge, and Fit to full frame resets it. Changes are saved to calibration.json in the working directory as you make them.

Configuration

Runtime settings live in the side panel. Init-time settings (detection confidence, prediction, capture and detection resolution, the calibration file, the default bottom headroom) are fields of the frozen Config dataclass in finger_tracker/config.py:

from finger_tracker import Config, FingerTracker

config = Config(
    capture_width=1920,
    capture_height=1080,
    prediction_enabled=True,
)

tracker = FingerTracker(config)
state = tracker.update(frame)   # a BGR frame from your own capture loop
tracker.render(frame, state)    # draws the overlay onto the frame

Troubleshooting

Jittery cursor

  • Lower Smoothing min-cutoff
  • Ensure adequate lighting conditions
  • Keep hand within camera field of view

Click detection issues

  • Touch thumb to index finger knuckle (not fingertip)
  • Monitor yellow distance indicator in video feed

Performance issues

  • Close resource-intensive applications
  • Reduce camera resolution (capture_width / capture_height in Config)

Stuck mouse button

  • Press Reset mouse state in the header bar
  • Switch Hold-to-drag mode off

How it works

A worker thread runs the pipeline on every webcam frame while the GTK main loop only draws the latest result:

  1. Capture at 1280x720 MJPG, mirrored
  2. Hand landmark detection using MediaPipe, on a 640x360 downscale
  3. Gesture classification from finger extension and pinch distances, latched after 3 stable frames
  4. One-Euro smoothing of the index fingertip, reset whenever tracking starts
  5. Velocity-based position prediction during occlusions
  6. Coordinate mapping from the tracking rectangle to screen space
  7. Motion, button and scroll events through the Wayland virtual pointer

Development

uv sync                               # includes the dev group
uv run ruff check finger_tracker tests
uv run mypy finger_tracker
uv run pytest

CI runs the same three on Python 3.11 and 3.12.

pointer/
├── finger_tracker/
│   ├── __init__.py          # Package exports
│   ├── config.py            # Immutable Config dataclass
│   ├── state.py             # Per-frame FrameState dataclass
│   ├── gui.py               # GTK4/Adwaita window, camera worker thread, entry point
│   ├── calibration.py       # Coordinate mapping + calibration
│   ├── detection.py         # MediaPipe hand detection + downscale
│   ├── gestures.py          # Gesture classifier + debouncer
│   ├── mouse.py             # Click/drag state + hysteresis/debounce
│   ├── smoothing.py         # Smoother facade over the One-Euro filter
│   ├── filters/             # One-Euro filter
│   ├── backends/            # wlr-virtual-pointer mouse backend
│   ├── _wayland_generated/  # pywayland scanner output, vendored
│   ├── palette.py           # Overlay colours
│   └── tracker.py           # Orchestrator (update/render split)
├── tests/                   # pytest suite
├── pyproject.toml
├── uv.lock
└── README.md

Credits

  • MediaPipe - Hand tracking
  • OpenCV - Computer vision
  • PyAutoGUI - Screen size
  • pywayland - Wayland virtual pointer
  • PyGObject - GTK4 and libadwaita

License

MIT