summaryrefslogtreecommitdiff
path: root/sys/dev/wscons/wsmousevar.h
blob: 1cc60ba0908251d63ca01eb16c78c76148a7e505 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* $OpenBSD: wsmousevar.h,v 1.12 2016/10/23 22:59:19 bru Exp $ */
/* $NetBSD: wsmousevar.h,v 1.4 2000/01/08 02:57:24 takemura Exp $ */

/*
 * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by Christopher G. Demetriou
 *	for the NetBSD Project.
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Copyright (c) 2015, 2016 Ulf Brosziewski
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * WSMOUSE interfaces.
 */

/*
 * Mouse access functions (must be provided by all mice).
 *
 * There is a "void *" cookie provided by the mouse driver associated
 * with these functions, which is passed to them when they are invoked.
 */
struct wsmouse_accessops {
	int	(*enable)(void *);
	int	(*ioctl)(void *v, u_long cmd, caddr_t data, int flag,
		    struct proc *p);
	void	(*disable)(void *);
};

/*
 * Attachment information provided by wsmousedev devices when attaching
 * wsmouse units.
 */
struct wsmousedev_attach_args {
	const struct wsmouse_accessops *accessops;	/* access ops */
	void	*accesscookie;				/* access cookie */
};

#define	wsmousedevcf_mux	cf_loc[WSMOUSEDEVCF_MUX]

/*
 * Autoconfiguration helper functions.
 */
int	wsmousedevprint(void *, const char *);


/* Process standard mouse input. */
#define WSMOUSE_INPUT(sc_wsmousedev, btns, dx, dy, dz, dw)		\
	do {								\
		wsmouse_buttons((sc_wsmousedev), (btns));		\
		wsmouse_motion((sc_wsmousedev), (dx), (dy), (dz), (dw));\
		wsmouse_input_sync(sc_wsmousedev);			\
	} while (0)


/* Process standard touchpad input. */
#define WSMOUSE_TOUCH(sc_wsmousedev, btns, x, y, pressure, contacts)	\
	do {								\
		wsmouse_buttons((sc_wsmousedev), (btns));		\
		wsmouse_position((sc_wsmousedev), (x), (y));		\
		wsmouse_touch((sc_wsmousedev), (pressure), (contacts));	\
		wsmouse_input_sync(sc_wsmousedev);			\
	} while (0)


/*
 * Drivers for touchpads that don't report pressure values can pass
 * WSMOUSE_DEFAULT_PRESSURE to wsmouse_touch or wsmouse_mtstate.
 *
 * A pressure value of 0 signals that a touch has been released (coordinates
 * will be ignored). Based on its pressure argument, wsmouse_touch will
 * normalize the contact count (drivers for touch devices that don't
 * recognize multiple contacts can always pass 0 as contact count to
 * wsmouse_touch).
 */
#define WSMOUSE_DEFAULT_PRESSURE	-1


struct device;

/*
 * Type codes for wsmouse_set. REL_X/Y, MT_REL_X/Y, and TOUCH_WIDTH
 * cannot be reported by other functions. Please note that REL_X/Y
 * values are deltas to be applied to the absolute coordinates and
 * don't represent "pure" relative motion.
 */
enum wsmouseval {
	WSMOUSE_REL_X,
	WSMOUSE_ABS_X,
	WSMOUSE_REL_Y,
	WSMOUSE_ABS_Y,
	WSMOUSE_PRESSURE,
	WSMOUSE_CONTACTS,
	WSMOUSE_TOUCH_WIDTH,
	WSMOUSE_MT_REL_X,
	WSMOUSE_MT_ABS_X,
	WSMOUSE_MT_REL_Y,
	WSMOUSE_MT_ABS_Y,
	WSMOUSE_MT_PRESSURE
};

#define WSMOUSE_IS_MT_CODE(code) \
    ((code) >= WSMOUSE_MT_REL_X && (code) <= WSMOUSE_MT_PRESSURE)

struct mtpoint {
	int x;
	int y;
	int pressure;
	int slot;		/* An output field, set by wsmouse_mtframe. */
};

/* Report button state. */
void wsmouse_buttons(struct device *, u_int);

/* Report motion deltas (dx, dy, dz, dw). */
void wsmouse_motion(struct device *, int, int, int, int);

/* Report absolute coordinates (x, y). */
void wsmouse_position(struct device *, int, int);

/* Report (single-)touch input (pressure, contacts). */
void wsmouse_touch(struct device *, int, int);

/* Report slot-based multitouch input (slot, x, y, pressure). */
void wsmouse_mtstate(struct device *, int, int, int, int);

/* Report multitouch input (mtpoints, size). */
void wsmouse_mtframe(struct device *, struct mtpoint *, int);

/* Report a single value (type, value, aux). */
void wsmouse_set(struct device *, enum wsmouseval, int, int);

/* Assign or look up a slot number for a tracking ID (id). */
int wsmouse_id_to_slot(struct device *, int);


/* Synchronize (generate wscons events) */
void wsmouse_input_sync(struct device *);


/* Initialize MT structures (num_slots, tracking). */
int wsmouse_mt_init(struct device *, int, int);

#define WSMOUSE_MT_SLOTS_MAX 10
#define WSMOUSE_MT_INIT_TRACKING 1

/* Switch between compatibility mode and native mode. */
int wsmouse_set_mode(struct device *, int);

/* Read/Set parameter values. */
int wsmouse_get_params(struct device *, struct wsmouse_param *, u_int);
int wsmouse_set_params(struct device *, const struct wsmouse_param *, u_int);