1 /* $OpenBSD: wsmousevar.h,v 1.15 2017/06/18 13:21:48 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 #ifndef _WSMOUSEVAR_H_ 51 #define _WSMOUSEVAR_H_ 52 53 #ifdef _KERNEL 54 55 /* 56 * WSMOUSE interfaces. 57 */ 58 59 /* 60 * Mouse access functions (must be provided by all mice). 61 * 62 * There is a "void *" cookie provided by the mouse driver associated 63 * with these functions, which is passed to them when they are invoked. 64 */ 65 struct wsmouse_accessops { 66 int (*enable)(void *); 67 int (*ioctl)(void *v, u_long cmd, caddr_t data, int flag, 68 struct proc *p); 69 void (*disable)(void *); 70 }; 71 72 /* 73 * Attachment information provided by wsmousedev devices when attaching 74 * wsmouse units. 75 */ 76 struct wsmousedev_attach_args { 77 const struct wsmouse_accessops *accessops; /* access ops */ 78 void *accesscookie; /* access cookie */ 79 }; 80 81 #define wsmousedevcf_mux cf_loc[WSMOUSEDEVCF_MUX] 82 83 /* 84 * Autoconfiguration helper functions. 85 */ 86 int wsmousedevprint(void *, const char *); 87 88 89 /* Process standard mouse input. */ 90 #define WSMOUSE_INPUT(sc_wsmousedev, btns, dx, dy, dz, dw) \ 91 do { \ 92 wsmouse_buttons((sc_wsmousedev), (btns)); \ 93 wsmouse_motion((sc_wsmousedev), (dx), (dy), (dz), (dw));\ 94 wsmouse_input_sync(sc_wsmousedev); \ 95 } while (0) 96 97 98 /* Process standard touchpad input. */ 99 #define WSMOUSE_TOUCH(sc_wsmousedev, btns, x, y, pressure, contacts) \ 100 do { \ 101 wsmouse_buttons((sc_wsmousedev), (btns)); \ 102 wsmouse_position((sc_wsmousedev), (x), (y)); \ 103 wsmouse_touch((sc_wsmousedev), (pressure), (contacts)); \ 104 wsmouse_input_sync(sc_wsmousedev); \ 105 } while (0) 106 107 108 /* 109 * Drivers for touchpads that don't report pressure values can pass 110 * WSMOUSE_DEFAULT_PRESSURE to wsmouse_touch or wsmouse_mtstate. 111 * 112 * A pressure value of 0 signals that a touch has been released (coordinates 113 * will be ignored). Based on its pressure argument, wsmouse_touch will 114 * normalize the contact count (drivers for touch devices that don't 115 * recognize multiple contacts can always pass 0 as contact count to 116 * wsmouse_touch). 117 */ 118 /* Use a synaptics-compatible value. */ 119 #define WSMOUSE_DEFAULT_PRESSURE 45 120 121 122 struct device; 123 124 /* 125 * Type codes for wsmouse_set. REL_X/Y, MT_REL_X/Y, and TOUCH_WIDTH 126 * cannot be reported by other functions. Please note that REL_X/Y 127 * values are deltas to be applied to the absolute coordinates and 128 * don't represent "pure" relative motion. 129 */ 130 enum wsmouseval { 131 WSMOUSE_REL_X, 132 WSMOUSE_ABS_X, 133 WSMOUSE_REL_Y, 134 WSMOUSE_ABS_Y, 135 WSMOUSE_PRESSURE, 136 WSMOUSE_CONTACTS, 137 WSMOUSE_TOUCH_WIDTH, 138 WSMOUSE_MT_REL_X, 139 WSMOUSE_MT_ABS_X, 140 WSMOUSE_MT_REL_Y, 141 WSMOUSE_MT_ABS_Y, 142 WSMOUSE_MT_PRESSURE 143 }; 144 145 #define WSMOUSE_IS_MT_CODE(code) \ 146 ((code) >= WSMOUSE_MT_REL_X && (code) <= WSMOUSE_MT_PRESSURE) 147 148 struct mtpoint { 149 int x; 150 int y; 151 int pressure; 152 int slot; /* An output field, set by wsmouse_mtframe. */ 153 }; 154 155 /* Report button state. */ 156 void wsmouse_buttons(struct device *, u_int); 157 158 /* Report motion deltas (dx, dy, dz, dw). */ 159 void wsmouse_motion(struct device *, int, int, int, int); 160 161 /* Report absolute coordinates (x, y). */ 162 void wsmouse_position(struct device *, int, int); 163 164 /* Report (single-)touch input (pressure, contacts). */ 165 void wsmouse_touch(struct device *, int, int); 166 167 /* Report slot-based multitouch input (slot, x, y, pressure). */ 168 void wsmouse_mtstate(struct device *, int, int, int, int); 169 170 /* Report multitouch input (mtpoints, size). */ 171 void wsmouse_mtframe(struct device *, struct mtpoint *, int); 172 173 /* Report a single value (type, value, aux). */ 174 void wsmouse_set(struct device *, enum wsmouseval, int, int); 175 176 /* Assign or look up a slot number for a tracking ID (id). */ 177 int wsmouse_id_to_slot(struct device *, int); 178 179 180 /* Synchronize (generate wscons events) */ 181 void wsmouse_input_sync(struct device *); 182 183 184 /* Initialize MT structures (num_slots, tracking). */ 185 int wsmouse_mt_init(struct device *, int, int); 186 187 #define WSMOUSE_MT_SLOTS_MAX 10 188 #define WSMOUSE_MT_INIT_TRACKING 1 189 190 /* Switch between compatibility mode and native mode. */ 191 int wsmouse_set_mode(struct device *, int); 192 193 /* Read/Set parameter values. */ 194 int wsmouse_get_params(struct device *, struct wsmouse_param *, u_int); 195 int wsmouse_set_params(struct device *, const struct wsmouse_param *, u_int); 196 197 198 enum wsmousehw_type { 199 WSMOUSEHW_RAW, 200 WSMOUSEHW_MOUSE, 201 WSMOUSEHW_TOUCHPAD, 202 WSMOUSEHW_CLICKPAD, 203 WSMOUSEHW_TPANEL, 204 }; 205 206 /* 207 * wsmousehw.flags 208 */ 209 /* Invert Y-coordinates */ 210 #define WSMOUSEHW_LR_DOWN (1 << 0) 211 /* Allocate the buffers for wsmouse_mtframe(). */ 212 #define WSMOUSEHW_MT_TRACKING (1 << 1) 213 214 215 /* 216 * The more or less minimal hardware description for the default 217 * configuration. 218 * 219 * Drivers that report coordinates with a downward orientation 220 * must set the flag WSMOUSEHW_LR_DOWN. Drivers for MT hardware 221 * must provide the number of slots. If they use wsmouse_mtframe(), 222 * WSMOUSEHW_MT_TRACKING must be set. 223 * 224 * The resolution values are optional. 225 */ 226 struct wsmousehw { 227 int type; /* WSMOUSE_TYPE_*, cf. wsconsio.h */ 228 enum wsmousehw_type hw_type; 229 int x_min; 230 int x_max; 231 int y_min; 232 int y_max; 233 int h_res; 234 int v_res; 235 236 int flags; 237 int mt_slots; 238 239 int contacts_max; /* inclusive (not needed for MT touchpads) */ 240 }; 241 242 struct wsmousehw *wsmouse_get_hw(struct device*); 243 244 /* Configure the input context. */ 245 int wsmouse_configure(struct device *, struct wsmouse_param *, u_int); 246 247 #endif /* _KERNEL */ 248 249 #endif /* _WSMOUSEVAR_H_ */ 250