1 /* $OpenBSD: wsmousevar.h,v 1.11 2016/06/06 22:32:47 bru Exp $ */ 2 /* $NetBSD: wsmousevar.h,v 1.4 2000/01/08 02:57:24 takemura Exp $ */ 3 4 /* 5 * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Christopher G. Demetriou 18 * for the NetBSD Project. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* 35 * Copyright (c) 2015, 2016 Ulf Brosziewski 36 * 37 * Permission to use, copy, modify, and distribute this software for any 38 * purpose with or without fee is hereby granted, provided that the above 39 * copyright notice and this permission notice appear in all copies. 40 * 41 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 42 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 43 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 44 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 45 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 46 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 47 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 48 */ 49 50 /* 51 * WSMOUSE interfaces. 52 */ 53 54 /* 55 * Mouse access functions (must be provided by all mice). 56 * 57 * There is a "void *" cookie provided by the mouse driver associated 58 * with these functions, which is passed to them when they are invoked. 59 */ 60 struct wsmouse_accessops { 61 int (*enable)(void *); 62 int (*ioctl)(void *v, u_long cmd, caddr_t data, int flag, 63 struct proc *p); 64 void (*disable)(void *); 65 }; 66 67 /* 68 * Attachment information provided by wsmousedev devices when attaching 69 * wsmouse units. 70 */ 71 struct wsmousedev_attach_args { 72 const struct wsmouse_accessops *accessops; /* access ops */ 73 void *accesscookie; /* access cookie */ 74 }; 75 76 #define wsmousedevcf_mux cf_loc[WSMOUSEDEVCF_MUX] 77 78 /* 79 * Autoconfiguration helper functions. 80 */ 81 int wsmousedevprint(void *, const char *); 82 83 84 /* Process standard mouse input. */ 85 #define WSMOUSE_INPUT(sc_wsmousedev, btns, dx, dy, dz, dw) \ 86 do { \ 87 wsmouse_buttons((sc_wsmousedev), (btns)); \ 88 wsmouse_motion((sc_wsmousedev), (dx), (dy), (dz), (dw));\ 89 wsmouse_input_sync(sc_wsmousedev); \ 90 } while (0) 91 92 93 /* Process standard touchpad input. */ 94 #define WSMOUSE_TOUCH(sc_wsmousedev, btns, x, y, pressure, contacts) \ 95 do { \ 96 wsmouse_buttons((sc_wsmousedev), (btns)); \ 97 wsmouse_position((sc_wsmousedev), (x), (y)); \ 98 wsmouse_touch((sc_wsmousedev), (pressure), (contacts)); \ 99 wsmouse_input_sync(sc_wsmousedev); \ 100 } while (0) 101 102 103 /* 104 * Drivers for touchpads that don't report pressure values can pass 105 * WSMOUSE_DEFAULT_PRESSURE to wsmouse_touch or wsmouse_mtstate. 106 * 107 * A pressure value of 0 signals that a touch has been released (coordinates 108 * will be ignored). Based on its pressure argument, wsmouse_touch will 109 * normalize the contact count (drivers for touch devices that don't 110 * recognize multiple contacts can always pass 0 as contact count to 111 * wsmouse_touch). 112 */ 113 #define WSMOUSE_DEFAULT_PRESSURE -1 114 115 116 struct device; 117 struct mtpoint; 118 119 /* 120 * Type codes for wsmouse_set. REL_X/Y, MT_REL_X/Y, and TOUCH_WIDTH 121 * cannot be reported by other functions. Please note that REL_X/Y 122 * values are deltas to be applied to the absolute coordinates and 123 * don't represent "pure" relative motion. 124 */ 125 enum wsmouseval { 126 WSMOUSE_REL_X, 127 WSMOUSE_ABS_X, 128 WSMOUSE_REL_Y, 129 WSMOUSE_ABS_Y, 130 WSMOUSE_PRESSURE, 131 WSMOUSE_CONTACTS, 132 WSMOUSE_TOUCH_WIDTH, 133 WSMOUSE_MT_REL_X, 134 WSMOUSE_MT_ABS_X, 135 WSMOUSE_MT_REL_Y, 136 WSMOUSE_MT_ABS_Y, 137 WSMOUSE_MT_PRESSURE 138 }; 139 140 #define WSMOUSE_IS_MT_CODE(code) \ 141 ((code) >= WSMOUSE_MT_REL_X && (code) <= WSMOUSE_MT_PRESSURE) 142 143 144 145 146 /* Report button state. */ 147 void wsmouse_buttons(struct device *, u_int); 148 149 /* Report motion deltas (dx, dy, dz, dw). */ 150 void wsmouse_motion(struct device *, int, int, int, int); 151 152 /* Report absolute coordinates (x, y). */ 153 void wsmouse_position(struct device *, int, int); 154 155 /* Report (single-)touch input (pressure, contacts). */ 156 void wsmouse_touch(struct device *, int, int); 157 158 /* Report slot-based multitouch input (slot, x, y, pressure). */ 159 void wsmouse_mtstate(struct device *, int, int, int, int); 160 161 /* Report multitouch input (mtpoints, size). */ 162 void wsmouse_mtframe(struct device *, struct mtpoint *, int); 163 164 /* Report a single value (type, value, aux). */ 165 void wsmouse_set(struct device *, enum wsmouseval, int, int); 166 167 /* Assign or look up a slot number for a tracking ID (id). */ 168 int wsmouse_id_to_slot(struct device *, int); 169 170 171 /* Synchronize (generate wscons events) */ 172 void wsmouse_input_sync(struct device *); 173 174 175 /* Initialize MT structures (num_slots, tracking). */ 176 int wsmouse_mt_init(struct device *, int, int); 177 178 /* Set a filter/transformation value (param type, value). */ 179 void wsmouse_set_param(struct device *, size_t, int); 180 181 /* Switch between compatibility mode and native mode. */ 182 int wsmouse_set_mode(struct device *, int); 183 184 185 struct mtpoint { 186 int x; 187 int y; 188 int pressure; 189 int slot; /* An output field, set by wsmouse_mtframe. */ 190 }; 191 192 193 struct wsmouseparams { 194 int x_inv; 195 int y_inv; 196 197 int dx_mul; /* delta scaling */ 198 int dx_div; 199 int dy_mul; 200 int dy_div; 201 202 int swapxy; 203 204 int pressure_lo; 205 int pressure_hi; 206 207 int dx_max; /* (compat mode) */ 208 int dy_max; 209 210 int tracking_maxdist; 211 }; 212 213 #define WSMPARAM_X_INV offsetof(struct wsmouseparams, x_inv) 214 #define WSMPARAM_Y_INV offsetof(struct wsmouseparams, y_inv) 215 #define WSMPARAM_DX_MUL offsetof(struct wsmouseparams, dx_mul) 216 #define WSMPARAM_DX_DIV offsetof(struct wsmouseparams, dx_div) 217 #define WSMPARAM_DY_MUL offsetof(struct wsmouseparams, dy_mul) 218 #define WSMPARAM_DY_DIV offsetof(struct wsmouseparams, dy_div) 219 #define WSMPARAM_SWAPXY offsetof(struct wsmouseparams, swapxy) 220 #define WSMPARAM_PRESSURE_LO offsetof(struct wsmouseparams, pressure_lo) 221 #define WSMPARAM_PRESSURE_HI offsetof(struct wsmouseparams, pressure_hi) 222 #define WSMPARAM_DX_MAX offsetof(struct wsmouseparams, dx_max) 223 #define WSMPARAM_DY_MAX offsetof(struct wsmouseparams, dy_max) 224 225 #define WSMPARAM_LASTFIELD WSMPARAM_DY_MAX 226 227 #define IS_WSMFLTR_PARAM(param) \ 228 ((param) >= WSMPARAM_DX_MUL && (param) <= WSMPARAM_DY_DIV) 229 230 #define WSMOUSE_MT_SLOTS_MAX 10 231