1 /* $OpenBSD: wsmouseinput.h,v 1.15 2021/03/21 16:20:49 bru Exp $ */ 2 3 /* 4 * Copyright (c) 2015, 2016 Ulf Brosziewski 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /* 20 * wsmouse input processing - private header 21 */ 22 23 #ifndef _WSMOUSEINPUT_H_ 24 #define _WSMOUSEINPUT_H_ 25 26 #ifdef _KERNEL 27 28 struct position { 29 int x; 30 int y; 31 int dx; /* unfiltered coordinate deltas */ 32 int dy; 33 int acc_dx; /* delta sums used for filtering */ 34 int acc_dy; 35 }; 36 37 struct btn_state { 38 u_int buttons; 39 u_int sync; 40 }; 41 42 struct motion_state { 43 int dx; /* mouse input, or filtered deltas */ 44 int dy; 45 int dz; 46 int dw; 47 struct position pos; 48 u_int sync; 49 }; 50 #define SYNC_DELTAS (1 << 0) 51 #define SYNC_X (1 << 1) 52 #define SYNC_Y (1 << 2) 53 #define SYNC_POSITION (SYNC_X | SYNC_Y) 54 55 struct touch_state { 56 int pressure; 57 int contacts; 58 int width; 59 u_int sync; 60 61 int min_pressure; 62 int prev_contacts; 63 }; 64 #define SYNC_PRESSURE (1 << 0) 65 #define SYNC_CONTACTS (1 << 1) 66 #define SYNC_TOUCH_WIDTH (1 << 2) 67 68 struct mt_slot { 69 struct position pos; 70 int pressure; 71 int id; /* tracking ID */ 72 }; 73 #define MTS_TOUCH 0 74 #define MTS_X 1 75 #define MTS_Y 2 76 #define MTS_PRESSURE 3 77 78 #define MTS_SIZE 4 79 80 struct mt_state { 81 /* the set of slots with active touches */ 82 u_int touches; 83 /* the set of slots with unsynchronized state */ 84 u_int frame; 85 86 int num_slots; 87 struct mt_slot *slots; 88 /* the sets of changes per slot axis */ 89 u_int sync[MTS_SIZE]; 90 91 int num_touches; 92 93 /* pointer control */ 94 u_int ptr; 95 u_int ptr_cycle; 96 u_int prev_ptr; 97 u_int ptr_mask; 98 99 /* a buffer for the MT tracking function */ 100 int *matrix; 101 }; 102 103 104 struct axis_filter { 105 /* A scale factor in [*.12] fixed-point format */ 106 int scale; 107 int rmdr; 108 /* Invert coordinates. */ 109 int inv; 110 /* Hysteresis limit, and weighted delta average. */ 111 int hysteresis; 112 int avg; 113 int avg_rmdr; 114 /* A [*.12] coefficient for "magnitudes", used for deceleration. */ 115 int mag_scale; 116 int dclr_rmdr; 117 /* Ignore deltas that are greater than this limit. */ 118 int dmax; 119 }; 120 121 struct interval { 122 long avg; /* average update interval in nanoseconds */ 123 long sum; 124 int samples; 125 struct timespec ts; 126 int track; 127 }; 128 129 struct wsmouseinput { 130 u_int flags; 131 132 struct btn_state btn; 133 struct btn_state sbtn; /* softbuttons */ 134 struct motion_state motion; 135 struct touch_state touch; 136 struct mt_state mt; 137 138 struct { /* Parameters and state of various input filters. */ 139 struct axis_filter h; 140 struct axis_filter v; 141 142 int dclr; /* deceleration threshold */ 143 int mag; /* weighted average of delta magnitudes */ 144 u_int mode; /* hysteresis type, smoothing factor */ 145 146 int ratio; /* X/Y ratio */ 147 148 int swapxy; 149 int tracking_maxdist; 150 int pressure_lo; 151 int pressure_hi; 152 } filter; 153 154 struct wsmousehw hw; 155 struct interval intv; 156 struct wstpad *tp; 157 158 struct wseventvar **evar; 159 }; 160 /* wsmouseinput.flags */ 161 #define TPAD_COMPAT_MODE (1 << 0) 162 #define TPAD_NATIVE_MODE (1 << 1) 163 #define MT_TRACKING (1 << 2) 164 #define REVERSE_SCROLLING (1 << 3) 165 #define RESYNC (1 << 16) 166 #define TRACK_INTERVAL (1 << 17) 167 #define CONFIGURED (1 << 18) 168 #define LOG_INPUT (1 << 19) 169 #define LOG_EVENTS (1 << 20) 170 171 /* filter.mode (bit 0-2: smoothing factor, bit 3-n: unused) */ 172 #define SMOOTHING_MASK 7 173 #define FILTER_MODE_DEFAULT 0 174 175 struct evq_access { 176 struct wseventvar *evar; 177 struct timespec ts; 178 int put; 179 int result; 180 }; 181 #define EVQ_RESULT_OVERFLOW -1 182 #define EVQ_RESULT_NONE 0 183 #define EVQ_RESULT_SUCCESS 1 184 185 186 void wsmouse_evq_put(struct evq_access *, int, int); 187 void wsmouse_log_events(struct wsmouseinput *, struct evq_access *); 188 int wsmouse_hysteresis(struct wsmouseinput *, struct position *); 189 void wsmouse_input_reset(struct wsmouseinput *); 190 void wsmouse_input_cleanup(struct wsmouseinput *); 191 192 void wstpad_compat_convert(struct wsmouseinput *, struct evq_access *); 193 void wstpad_init_deceleration(struct wsmouseinput *); 194 int wstpad_configure(struct wsmouseinput *); 195 void wstpad_reset(struct wsmouseinput *); 196 void wstpad_cleanup(struct wsmouseinput *); 197 198 int wstpad_get_param(struct wsmouseinput *, int, int *); 199 int wstpad_set_param(struct wsmouseinput *, int, int); 200 201 202 #define FOREACHBIT(v, i) \ 203 for ((i) = ffs(v) - 1; (i) != -1; (i) = ffs((v) & (~1 << (i))) - 1) 204 205 #define DELTA_X_EV(input) ((input)->filter.swapxy ? \ 206 WSCONS_EVENT_MOUSE_DELTA_Y : WSCONS_EVENT_MOUSE_DELTA_X) 207 #define DELTA_Y_EV(input) ((input)->filter.swapxy ? \ 208 WSCONS_EVENT_MOUSE_DELTA_X : WSCONS_EVENT_MOUSE_DELTA_Y) 209 #define ABS_X_EV(input) ((input)->filter.swapxy ? \ 210 WSCONS_EVENT_MOUSE_ABSOLUTE_Y : WSCONS_EVENT_MOUSE_ABSOLUTE_X) 211 #define ABS_Y_EV(input) ((input)->filter.swapxy ? \ 212 WSCONS_EVENT_MOUSE_ABSOLUTE_X : WSCONS_EVENT_MOUSE_ABSOLUTE_Y) 213 #define DELTA_Z_EV WSCONS_EVENT_MOUSE_DELTA_Z 214 #define DELTA_W_EV WSCONS_EVENT_MOUSE_DELTA_W 215 #define VSCROLL_EV WSCONS_EVENT_VSCROLL 216 #define HSCROLL_EV WSCONS_EVENT_HSCROLL 217 #define ABS_Z_EV WSCONS_EVENT_TOUCH_PRESSURE 218 #define ABS_W_EV WSCONS_EVENT_TOUCH_CONTACTS 219 #define BTN_DOWN_EV WSCONS_EVENT_MOUSE_DOWN 220 #define BTN_UP_EV WSCONS_EVENT_MOUSE_UP 221 #define SYNC_EV WSCONS_EVENT_SYNC 222 223 /* matrix size + buffer size for wsmouse_matching */ 224 #define MATRIX_SIZE(slots) (((slots) + 6) * (slots) * sizeof(int)) 225 226 #define IS_TOUCHPAD(input) \ 227 ((input)->hw.hw_type == WSMOUSEHW_TOUCHPAD \ 228 || (input)->hw.hw_type == WSMOUSEHW_CLICKPAD) 229 230 /* Extract a four-digit millisecond value from a timespec. */ 231 #define LOGTIME(tsp) \ 232 ((int) (((tsp)->tv_sec % 10) * 1000 + ((tsp)->tv_nsec / 1000000))) 233 234 #define DEVNAME(input) ((char *) (input) \ 235 - offsetof(struct wsmouse_softc, sc_input) \ 236 + offsetof(struct device, dv_xname)) 237 238 #endif /* _KERNEL */ 239 240 #endif /* _WSMOUSEINPUT_H_ */ 241