1 /* 2 * Permission to use, copy, modify, distribute, and sell this software 3 * and its documentation for any purpose is hereby granted without 4 * fee, provided that the above copyright notice appear in all copies 5 * and that both that copyright notice and this permission notice 6 * appear in supporting documentation, and that the name of Red Hat 7 * not be used in advertising or publicity pertaining to distribution 8 * of the software without specific, written prior permission. Red 9 * Hat makes no representations about the suitability of this software 10 * for any purpose. It is provided "as is" without express or implied 11 * warranty. 12 * 13 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 14 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN 15 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 16 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 17 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 18 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 19 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 */ 21 22 #ifndef _SYNAPTICSSTR_H_ 23 #define _SYNAPTICSSTR_H_ 24 25 #include "synproto.h" 26 27 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 18 28 #define LogMessageVerbSigSafe xf86MsgVerb 29 #endif 30 31 #ifdef DBG 32 #undef DBG 33 #endif 34 35 #ifdef DEBUG 36 #define DBG(verb, ...) \ 37 xf86MsgVerb(X_INFO, verb, __VA_ARGS__) 38 #else 39 #define DBG(verb, msg, ...) /* */ 40 #endif 41 42 /****************************************************************************** 43 * Definitions 44 * structs, typedefs, #defines, enums 45 *****************************************************************************/ 46 #define SYNAPTICS_MOVE_HISTORY 5 47 #define SYNAPTICS_MAX_TOUCHES 10 48 #define SYN_MAX_BUTTONS 12 /* Max number of mouse buttons */ 49 50 enum OffState { 51 TOUCHPAD_ON = 0, 52 TOUCHPAD_OFF = 1, 53 TOUCHPAD_TAP_OFF = 2, 54 }; 55 56 enum TapEvent { 57 RT_TAP = 0, /* Right top corner */ 58 RB_TAP, /* Right bottom corner */ 59 LT_TAP, /* Left top corner */ 60 LB_TAP, /* Left bottom corner */ 61 F1_TAP, /* Non-corner tap, one finger */ 62 F2_TAP, /* Non-corner tap, two fingers */ 63 F3_TAP, /* Non-corner tap, three fingers */ 64 MAX_TAP 65 }; 66 67 enum ClickFingerEvent { 68 F1_CLICK1 = 0, /* Click left, one finger */ 69 F2_CLICK1, /* Click left, two fingers */ 70 F3_CLICK1, /* Click left, three fingers */ 71 MAX_CLICK 72 }; 73 74 75 typedef struct _SynapticsMoveHist { 76 int x, y; 77 CARD32 millis; 78 } SynapticsMoveHistRec; 79 80 typedef struct _SynapticsTouchAxis { 81 const char *label; 82 int min; 83 int max; 84 int res; 85 } SynapticsTouchAxisRec; 86 87 enum FingerState { /* Note! The order matters. Compared with < operator. */ 88 FS_BLOCKED = -1, 89 FS_UNTOUCHED = 0, /* this is 0 so it's the initialized value. */ 90 FS_TOUCHED = 1, 91 FS_PRESSED = 2, 92 }; 93 94 enum MovingState { 95 MS_FALSE, 96 MS_TOUCHPAD_RELATIVE, 97 }; 98 99 enum MidButtonEmulation { 100 MBE_OFF, /* No button pressed */ 101 MBE_LEFT, /* Left button pressed, waiting for right button or timeout */ 102 MBE_RIGHT, /* Right button pressed, waiting for left button or timeout */ 103 MBE_MID, /* Left and right buttons pressed, waiting for both buttons 104 to be released */ 105 MBE_TIMEOUT, /* Waiting for both buttons to be released. */ 106 MBE_LEFT_CLICK, /* Emulate left button click. */ 107 MBE_RIGHT_CLICK, /* Emulate right button click. */ 108 }; 109 110 /* See docs/tapndrag.dia for a state machine diagram */ 111 enum TapState { 112 TS_START, /* No tap/drag in progress */ 113 TS_1, /* After first touch */ 114 TS_MOVE, /* Pointer movement enabled */ 115 TS_2A, /* After first release */ 116 TS_2B, /* After second/third/... release */ 117 TS_SINGLETAP, /* After timeout after first release */ 118 TS_3, /* After second touch */ 119 TS_DRAG, /* Pointer drag enabled */ 120 TS_4, /* After release when "locked drags" enabled */ 121 TS_5, /* After touch when "locked drags" enabled */ 122 TS_CLICKPAD_MOVE, /* After left button press on a clickpad */ 123 }; 124 125 enum TapButtonState { 126 TBS_BUTTON_UP, /* "Virtual tap button" is up */ 127 TBS_BUTTON_DOWN, /* "Virtual tap button" is down */ 128 TBS_BUTTON_DOWN_UP /* Send button down event + set up state */ 129 }; 130 131 enum TouchpadModel { 132 MODEL_UNKNOWN = 0, 133 MODEL_SYNAPTICS, 134 MODEL_ALPS, 135 MODEL_APPLETOUCH, 136 MODEL_ELANTECH, 137 MODEL_UNIBODY_MACBOOK 138 }; 139 140 typedef struct _SynapticsParameters { 141 /* Parameter data */ 142 int left_edge, right_edge, top_edge, bottom_edge; /* edge coordinates absolute */ 143 int finger_low, finger_high, finger_press; /* finger detection values in Z-values */ 144 int tap_time; 145 int tap_move; /* max. tapping time and movement in packets and coord. */ 146 int single_tap_timeout; /* timeout to recognize a single tap */ 147 int tap_time_2; /* max. tapping time for double taps */ 148 int click_time; /* The duration of a single click */ 149 Bool clickpad; /* Device is a has integrated buttons */ 150 int emulate_mid_button_time; /* Max time between left and right button presses to 151 emulate a middle button press. */ 152 int emulate_twofinger_z; /* pressure threshold to emulate two finger touch (for Alps) */ 153 int emulate_twofinger_w; /* Finger width threshold to emulate two finger touch */ 154 int scroll_dist_vert; /* Scrolling distance in absolute coordinates */ 155 int scroll_dist_horiz; /* Scrolling distance in absolute coordinates */ 156 Bool scroll_edge_vert; /* Enable/disable vertical scrolling on right edge */ 157 Bool scroll_edge_horiz; /* Enable/disable horizontal scrolling on left edge */ 158 Bool scroll_edge_corner; /* Enable/disable continuous edge scrolling when in the corner */ 159 Bool scroll_twofinger_vert; /* Enable/disable vertical two-finger scrolling */ 160 Bool scroll_twofinger_horiz; /* Enable/disable horizontal two-finger scrolling */ 161 double min_speed, max_speed, accl; /* movement parameters */ 162 163 int touchpad_off; /* Switches the touchpad off 164 * 0 : Not off 165 * 1 : Off 166 * 2 : Only tapping and scrolling off 167 */ 168 Bool locked_drags; /* Enable locked drags */ 169 int locked_drag_time; /* timeout for locked drags */ 170 int tap_action[MAX_TAP]; /* Button to report on tap events */ 171 int click_action[MAX_CLICK]; /* Button to report on click with fingers */ 172 Bool circular_scrolling; /* Enable circular scrolling */ 173 double scroll_dist_circ; /* Scrolling angle radians */ 174 int circular_trigger; /* Trigger area for circular scrolling */ 175 Bool palm_detect; /* Enable Palm Detection */ 176 int palm_min_width; /* Palm detection width */ 177 int palm_min_z; /* Palm detection depth */ 178 double coasting_speed; /* Coasting threshold scrolling speed in scrolls/s */ 179 double coasting_friction; /* Number of scrolls per second per second to change coasting speed */ 180 int press_motion_min_z; /* finger pressure at which minimum pressure motion factor is applied */ 181 int press_motion_max_z; /* finger pressure at which maximum pressure motion factor is applied */ 182 double press_motion_min_factor; /* factor applied on speed when finger pressure is at minimum */ 183 double press_motion_max_factor; /* factor applied on speed when finger pressure is at minimum */ 184 Bool grab_event_device; /* grab event device for exclusive use? */ 185 Bool tap_and_drag_gesture; /* Switches the tap-and-drag gesture on/off */ 186 unsigned int resolution_horiz; /* horizontal resolution of touchpad in units/mm */ 187 unsigned int resolution_vert; /* vertical resolution of touchpad in units/mm */ 188 int area_left_edge, area_right_edge, area_top_edge, area_bottom_edge; /* area coordinates absolute */ 189 int softbutton_areas[2][4]; /* soft button area coordinates, 0 => right, 1 => middle button */ 190 int hyst_x, hyst_y; /* x and y width of hysteresis box */ 191 } SynapticsParameters; 192 193 struct _SynapticsPrivateRec { 194 SynapticsParameters synpara; /* Default parameter settings, read from 195 the X config file */ 196 struct SynapticsProtocolOperations *proto_ops; 197 void *proto_data; /* protocol-specific data */ 198 199 struct SynapticsHwState *hwState; 200 struct SynapticsHwState *old_hw_state; /* previous logical hw state */ 201 202 const char *device; /* device node */ 203 CARD32 timer_time; /* when timer last fired */ 204 OsTimerPtr timer; /* for tap processing, etc */ 205 206 struct CommData comm; 207 208 struct SynapticsHwState *local_hw_state; /* used in place of local hw state variables */ 209 210 SynapticsMoveHistRec move_hist[SYNAPTICS_MOVE_HISTORY]; /* movement history */ 211 int hist_index; /* Last added entry in move_hist[] */ 212 int hyst_center_x; /* center x of hysteresis */ 213 int hyst_center_y; /* center y of hysteresis */ 214 struct { 215 int last_x; /* last x-scroll position */ 216 int last_y; /* last y-scroll position */ 217 double delta_x; /* accumulated horiz scroll delta */ 218 double delta_y; /* accumulated vert scroll delta */ 219 double last_a; /* last angle-scroll position */ 220 CARD32 last_millis; /* time last scroll event posted */ 221 double coast_speed_x; /* Horizontal coasting speed in scrolls/s */ 222 double coast_speed_y; /* Vertical coasting speed in scrolls/s */ 223 double coast_delta_x; /* Accumulated horizontal coast delta */ 224 double coast_delta_y; /* Accumulated vertical coast delta */ 225 int packets_this_scroll; /* Events received for this scroll */ 226 } scroll; 227 int count_packet_finger; /* packet counter with finger on the touchpad */ 228 int button_delay_millis; /* button delay for 3rd button emulation */ 229 Bool prev_up; /* Previous up button value, for double click emulation */ 230 enum FingerState finger_state; /* previous finger state */ 231 CARD32 last_motion_millis; /* time of the last motion */ 232 233 enum TapState tap_state; /* State of tap processing */ 234 int tap_max_fingers; /* Max number of fingers seen since entering start state */ 235 int tap_button; /* Which button started the tap processing */ 236 enum TapButtonState tap_button_state; /* Current tap action */ 237 SynapticsMoveHistRec touch_on; /* data when the touchpad is touched/released */ 238 239 enum MovingState moving_state; /* previous moving state */ 240 Bool vert_scroll_edge_on; /* Keeps track of currently active scroll modes */ 241 Bool horiz_scroll_edge_on; /* Keeps track of currently active scroll modes */ 242 Bool vert_scroll_twofinger_on; /* Keeps track of currently active scroll modes */ 243 Bool horiz_scroll_twofinger_on; /* Keeps track of currently active scroll modes */ 244 Bool circ_scroll_on; /* Keeps track of currently active scroll modes */ 245 Bool circ_scroll_vert; /* True: Generate vertical scroll events 246 False: Generate horizontal events */ 247 double frac_x, frac_y; /* absolute -> relative fraction */ 248 enum MidButtonEmulation mid_emu_state; /* emulated 3rd button */ 249 int lastButtons; /* last state of the buttons */ 250 int prev_z; /* previous z value, for palm detection */ 251 int prevFingers; /* previous numFingers, for transition detection */ 252 int avg_width; /* weighted average of previous fingerWidth values */ 253 double horiz_coeff; /* normalization factor for x coordintes */ 254 double vert_coeff; /* normalization factor for y coordintes */ 255 256 int minx, maxx, miny, maxy; /* min/max dimensions as detected */ 257 int minp, maxp, minw, maxw; /* min/max pressure and finger width as detected */ 258 int resx, resy; /* resolution of coordinates as detected in units/mm */ 259 Bool has_left; /* left button detected for this device */ 260 Bool has_right; /* right button detected for this device */ 261 Bool has_middle; /* middle button detected for this device */ 262 Bool has_double; /* double click detected for this device */ 263 Bool has_triple; /* triple click detected for this device */ 264 Bool has_pressure; /* device reports pressure */ 265 Bool has_width; /* device reports finger width */ 266 Bool has_scrollbuttons; /* device has physical scrollbuttons */ 267 Bool has_semi_mt; /* device is only semi-multitouch capable */ 268 269 enum TouchpadModel model; /* The detected model */ 270 unsigned short id_vendor; /* vendor id */ 271 unsigned short id_product; /* product id */ 272 273 int scroll_axis_horiz; /* Horizontal smooth-scrolling axis */ 274 int scroll_axis_vert; /* Vertical smooth-scrolling axis */ 275 ValuatorMask *scroll_events_mask; /* ValuatorMask for smooth-scrolling */ 276 277 Bool has_touch; /* Device has multitouch capabilities */ 278 int max_touches; /* Number of touches supported */ 279 int num_mt_axes; /* Number of multitouch axes other than X, Y */ 280 SynapticsTouchAxisRec *touch_axes; /* Touch axis information other than X, Y */ 281 int num_slots; /* Number of touch slots allocated */ 282 int *open_slots; /* Array of currently open touch slots */ 283 int num_active_touches; /* Number of active touches on device */ 284 }; 285 286 #endif /* _SYNAPTICSSTR_H_ */ 287