/* Device-independent touchpad contact gestures. * * A hardware driver decodes its reports into up to two contact positions plus * the total contact count and the physical clickpad bit, and calls * tpg_frame() once per report. The engine owns pointer delta scaling, tap * detection, the synthesized button press, the physical-button latch and * two-finger scrolling, so a PS/2, I2C or USB touchpad backend only has to * decode its own protocol. * * Scroll output is in pixels: positive means "toward later content" (the page * moves up), matching a wheel-down event under natural scrolling. The Elan * and pointer delta scale defaults to 2 device units per pixel; a backend * with a different resolution passes its own units_per_px to tpg_init(). */ #ifndef TOUCHPAD_GESTURE_H #define TOUCHPAD_GESTURE_H #define TPG_CONTACTS 2 /* Option bits. */ #define TPG_TAPCLICK 0x01 /* one-finger tap = left click */ #define TPG_RIGHT_TAP 0x02 /* two-finger tap = right click */ #define TPG_RIGHT_CORNER 0x04 /* corner tap/press = right click */ #define TPG_SCROLL 0x08 /* two-finger scroll */ #define TPG_SCROLL_INVERT 0x10 /* traditional instead of natural */ #define TPG_DEFAULT_OPTIONS (TPG_TAPCLICK | TPG_RIGHT_TAP | \ TPG_RIGHT_CORNER | TPG_SCROLL) /* Software right-button zone: right 25% x bottom 25% of the pad. */ #define TPG_CORNER_X_PCT 75 #define TPG_CORNER_Y_PCT 25 struct tpg_contact { int x, y; /* absolute device coordinates */ }; struct tpg_frame { unsigned int count; /* total active contacts, 0..5 */ unsigned int mask; /* bit 0/1: contact[] entry is present */ struct tpg_contact contact[TPG_CONTACTS]; int button; /* physical clickpad/left button */ unsigned int now_ms; }; struct tpg_result { int dx, dy; /* pointer motion, PS/2 convention (+dy up) */ int scroll; /* pixels, positive = later content */ unsigned int buttons; /* bit0 left, bit1 right, bit2 middle */ }; struct tpg_state { int max_x, max_y; int units_per_px; unsigned int opts; int tap_move; /* max movement for a tap, device units */ int scroll_start; /* movement before scrolling starts */ int btn_raw; int btn_latched; /* physical button: 0, 0x01 or 0x02 */ unsigned int synth_btn; unsigned int synth_release_ms; unsigned int taps_left; /* synthesized tap counters (status) */ unsigned int taps_right; /* One contact sequence, from first finger down to last finger up. */ int active; unsigned int start_ms; int start_x, start_y; int started; int moved; int two; int physical; int scrolled; unsigned int last_count; /* Pointer delta accumulation. */ int last_x, last_y; int have_last; int acc_x, acc_y; /* Two-finger scroll tracking. */ int scroll_have; int scroll_last_y; int scroll_total; int scroll_acc; }; void tpg_init(struct tpg_state *s, int max_x, int max_y, int units_per_px); void tpg_set_limits(struct tpg_state *s, int max_x, int max_y); void tpg_set_options(struct tpg_state *s, unsigned int opts); unsigned int tpg_options(const struct tpg_state *s); /* Feed one report. r is fully overwritten. */ void tpg_frame(struct tpg_state *s, const struct tpg_frame *f, struct tpg_result *r); /* Time-only poll: releases a synthesized tap press after its hold. Call it * between reports (and before the report throttle) so the release is * delivered even though no new contact report is coming. */ void tpg_tick(struct tpg_state *s, unsigned int now_ms, struct tpg_result *r); #endif