2 * Copyright © 2014 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #ifndef EVDEV_MT_TOUCHPAD_H
25 #define EVDEV_MT_TOUCHPAD_H
33 #define TOUCHPAD_HISTORY_LENGTH 4
34 #define TOUCHPAD_MIN_SAMPLES 4
36 #define VENDOR_ID_APPLE 0x5ac
39 TOUCHPAD_EVENT_NONE = 0,
40 TOUCHPAD_EVENT_MOTION = (1 << 0),
41 TOUCHPAD_EVENT_BUTTON_PRESS = (1 << 1),
42 TOUCHPAD_EVENT_BUTTON_RELEASE = (1 << 2),
53 BUTTON_EVENT_IN_BOTTOM_R = 30,
54 BUTTON_EVENT_IN_BOTTOM_L,
55 BUTTON_EVENT_IN_TOP_R,
56 BUTTON_EVENT_IN_TOP_M,
57 BUTTON_EVENT_IN_TOP_L,
71 BUTTON_STATE_TOP_TO_IGNORE,
81 TAP_STATE_TOUCH_2_HOLD,
83 TAP_STATE_TOUCH_3_HOLD,
84 TAP_STATE_DRAGGING_OR_DOUBLETAP,
86 TAP_STATE_DRAGGING_WAIT,
88 TAP_STATE_DEAD, /**< finger count exceeded */
91 enum tp_tap_touch_state {
92 TAP_TOUCH_STATE_IDLE = 16, /**< not in touch */
93 TAP_TOUCH_STATE_TOUCH, /**< touching, may tap */
94 TAP_TOUCH_STATE_DEAD, /**< exceeded motion/timeout */
103 struct tp_dispatch *tp;
104 enum touch_state state;
106 bool is_pointer; /* the pointer-controlling touch */
112 struct tp_motion samples[TOUCHPAD_HISTORY_LENGTH];
122 /* A pinned touchpoint is the one that pressed the physical button
123 * on a clickpad. After the release, it won't move until the center
124 * moves more than a threshold away from the original coordinates
132 /* Software-button state and timeout if applicable */
134 enum button_state state;
135 /* We use button_event here so we can use == on events */
136 enum button_event curr;
137 struct libinput_timer timer;
141 enum tp_tap_touch_state state;
146 int32_t x, y; /* first coordinates if is_palm == true */
147 uint32_t time; /* first timestamp if is_palm == true */
152 struct evdev_dispatch base;
153 struct evdev_device *device;
154 unsigned int nfingers_down; /* number of fingers down */
155 unsigned int old_nfingers_down; /* previous no fingers down */
156 unsigned int slot; /* current slot */
160 unsigned int real_touches; /* number of slots */
161 unsigned int ntouches; /* no slots inc. fakes */
162 struct tp_touch *touches; /* len == ntouches */
163 unsigned int fake_touches; /* fake touch mask */
171 double x_scale_coeff;
172 double y_scale_coeff;
176 bool is_clickpad; /* true for clickpads */
178 bool use_clickfinger; /* number of fingers decides button number */
182 uint32_t motion_dist; /* for pinned touches */
183 unsigned int active; /* currently active button, for release event */
184 bool active_is_topbutton; /* is active a top button? */
186 /* Only used for clickpads. The software button areas are
187 * always 2 horizontal stripes across the touchpad.
188 * The buttons are split according to the edge settings.
192 int32_t rightbutton_left_edge;
197 int32_t rightbutton_left_edge;
198 int32_t leftbutton_right_edge;
201 struct evdev_device *trackpoint;
202 } buttons; /* physical buttons */
205 struct libinput_device_config_natural_scroll config;
206 bool natural_scrolling_enabled;
209 enum touchpad_event queued;
212 struct libinput_device_config_tap config;
214 struct libinput_timer timer;
215 enum tp_tap_state state;
224 struct libinput_device_config_send_events config;
225 enum libinput_config_send_events_mode current_mode;
229 #define tp_for_each_touch(_tp, _t) \
230 for (unsigned int _i = 0; _i < (_tp)->ntouches && (_t = &(_tp)->touches[_i]); _i++)
233 tp_get_delta(struct tp_touch *t, double *dx, double *dy);
236 tp_set_pointer(struct tp_dispatch *tp, struct tp_touch *t);
239 tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time);
242 tp_init_tap(struct tp_dispatch *tp);
245 tp_destroy_tap(struct tp_dispatch *tp);
248 tp_init_buttons(struct tp_dispatch *tp, struct evdev_device *device);
251 tp_init_softbuttons(struct tp_dispatch *tp,
252 struct evdev_device *device,
253 double topbutton_size_mult);
256 tp_destroy_buttons(struct tp_dispatch *tp);
259 tp_process_button(struct tp_dispatch *tp,
260 const struct input_event *e,
264 tp_release_all_buttons(struct tp_dispatch *tp,
268 tp_post_button_events(struct tp_dispatch *tp, uint64_t time);
271 tp_button_handle_state(struct tp_dispatch *tp, uint64_t time);
274 tp_button_touch_active(struct tp_dispatch *tp, struct tp_touch *t);
277 tp_button_is_inside_softbutton_area(struct tp_dispatch *tp, struct tp_touch *t);
280 tp_release_all_taps(struct tp_dispatch *tp,