Documentation
¶
Overview ¶
Package touch provides touch input handling and gesture recognition. Package touch provides HID touch input reading, gesture recognition, and zone-aware event dispatch for the Corsair iCUE Nexus display.
Package touch provides zone-aware touch input handling and gesture recognition.
Package touch provides HID touch input reading with velocity-aware smoothing (One-Euro filter).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrDeviceDisconnected = errors.New("device disconnected")
)
Common errors
var NewUSBTouchReader = NewHIDTouchReader
NewUSBTouchReader is an alias for NewHIDTouchReader.
Functions ¶
This section is empty.
Types ¶
type DeviceReader ¶
DeviceReader is an interface for reading touch events from a device. This allows the handler to work with any device implementation without importing the device package (breaking circular dependency).
type Event ¶
type Event struct {
Button int // Button identifier (0-4 for 5 buttons)
Pressed bool // true if pressed, false if released
Duration time.Duration // How long the button was held
SwipeProgress float32 // Live swipe progress (0.0 to 1.0)
SwipeActive bool // true if swipe is in progress (live tracking)
Velocity float32 // Swipe velocity in pixels/second (for completed swipes)
SwipePixels int // Signed pixel delta from gesture start (left is negative)
Timestamp time.Time // When this event was captured
TapX int // Display pixel X position of tap (0–639); only valid for Button==0 taps
SlideX int // Net horizontal movement during the press (px, signed); non-zero means finger slid on lift
}
Event represents a touch/button input event from the device.
type HIDTouchReader ¶
type HIDTouchReader struct {
// contains filtered or unexported fields
}
func NewHIDTouchReader ¶
func NewHIDTouchReader(device TouchDevice, logger *slog.Logger) *HIDTouchReader
NewHIDTouchReader creates a new touch reader.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler processes touch events and dispatches them to zone-aware actions.
func NewHandler ¶
NewHandler creates a new touch handler.
func (*Handler) GetLastTouchTime ¶
GetLastTouchTime returns the timestamp of the last touch event.
func (*Handler) SetSwipeEnabled ¶
SetSwipeEnabled enables or disables swipe gesture recognition.
func (*Handler) SetTapEnabled ¶
SetTapEnabled enables or disables tap gesture recognition.
type SwipeConfig ¶
type SwipeConfig struct {
// VelocityFastFlick is the velocity threshold for "fast flick" behavior.
VelocityFastFlick float32
// VelocityFlick is a higher tier — very strong flick, commit with minimal distance.
VelocityFlick float32
// VelocityMedium is the boundary between medium and slow velocity.
VelocityMedium float32
// DistanceAutoCancel is the minimum threshold below which swipes always cancel,
// regardless of velocity. This prevents accidental triggers.
// Default: 0.15 (15% of screen width ≈ 96px on 640px screen)
DistanceAutoCancel float32
// DistanceAutoCommit is the threshold above which swipes always commit,
// regardless of velocity. Dragging past halfway shows clear intent.
// Default: 0.50 (50% of screen width ≈ 320px on 640px screen)
DistanceAutoCommit float32
// DistanceStandard is the threshold for medium-velocity swipes.
// This is the "normal" swipe distance for typical gestures.
// Default: 0.30 (30% of screen width ≈ 192px on 640px screen)
DistanceStandard float32
// DistanceFastFlick is the reduced threshold for high-velocity swipes.
DistanceFastFlick float32
// DistanceFlick is the threshold for very strong flicks (VelocityFlick tier).
DistanceFlick float32
// DistanceSlowDrag is the increased threshold for low-velocity swipes.
DistanceSlowDrag float32
}
SwipeConfig contains tunable parameters for intelligent swipe gesture detection. These parameters control the multi-heuristic decision making that determines whether a swipe should commit to a page change or cancel back to the current page.
func DefaultSwipeConfig ¶
func DefaultSwipeConfig() SwipeConfig
DefaultSwipeConfig returns a SwipeConfig with sensible defaults based on iOS/Android gesture behavior research and tuned for 640px Nexus screen. Note: Velocity thresholds are calibrated for the smaller screen size - actual swipe velocities on this device range from ~150-400 px/s for typical gestures.