xref: /openbsd-src/sys/dev/wscons/wsmouseinput.h (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /* $OpenBSD: wsmouseinput.h,v 1.2 2016/08/18 21:12:35 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 
27 struct btn_state {
28 	u_int buttons;
29 	u_int sync;
30 };
31 
32 struct motion_state {
33 	int dx;
34 	int dy;
35 	int dz;
36 	int dw;
37 	int x;
38 	int y;
39 	u_int sync;
40 
41 	/* deltas of absolute coordinates */
42 	int x_delta;
43 	int y_delta;
44 };
45 #define SYNC_DELTAS		(1 << 0)
46 #define SYNC_X			(1 << 1)
47 #define SYNC_Y			(1 << 2)
48 #define SYNC_POSITION		(SYNC_X | SYNC_Y)
49 
50 struct touch_state {
51 	int pressure;
52 	int contacts;
53 	int width;
54 	u_int sync;
55 
56 	int min_pressure;
57 };
58 #define SYNC_PRESSURE		(1 << 0)
59 #define SYNC_CONTACTS		(1 << 1)
60 #define SYNC_TOUCH_WIDTH	(1 << 2)
61 
62 struct mt_slot {
63 	int x;
64 	int y;
65 	int pressure;
66 	int id;		/* tracking ID */
67 };
68 #define MTS_TOUCH	0
69 #define MTS_X		1
70 #define MTS_Y		2
71 #define MTS_PRESSURE	3
72 
73 #define MTS_SIZE	4
74 
75 struct mt_state {
76 	/* the set of slots with active touches */
77 	u_int touches;
78 	/* the set of slots with unsynchronized state */
79 	u_int frame;
80 
81 	int num_slots;
82 	struct mt_slot *slots;
83 	/* the sets of changes per slot axis */
84 	u_int sync[MTS_SIZE];
85 
86 	int num_touches;
87 
88 	/* pointer control */
89 	u_int ptr;
90 	u_int ptr_cycle;
91 	u_int prev_ptr;
92 
93 	/* a buffer for the MT tracking function */
94 	int *matrix;
95 };
96 
97 
98 struct axis_filter {
99 	/* scale factor in [*.12] fixed-point format */
100 	int scale;
101 	int rmdr;
102 };
103 
104 struct wsmouseinput {
105 	u_int flags;
106 
107 	struct btn_state btn;
108 	struct motion_state motion;
109 	struct touch_state touch;
110 	struct mt_state mt;
111 
112 	struct wsmouseparams params;
113 	struct {
114 		struct axis_filter h;
115 		struct axis_filter v;
116 	} fltr;
117 
118 	struct wseventvar **evar;
119 };
120 /* wsmouseinput.flags */
121 #define TPAD_COMPAT_MODE	(1 << 0)
122 #define TPAD_NATIVE_MODE	(1 << 1)
123 #define SCALE_DELTAS		(1 << 2)
124 #define MT_TRACKING		(1 << 3)
125 #define SWAPXY			(1 << 4)
126 #define RESYNC			(1 << 16)
127 
128 struct evq_access {
129 	struct wseventvar *evar;
130 	struct timespec ts;
131 	int put;
132 	int result;
133 };
134 #define EVQ_RESULT_OVERFLOW	-1
135 #define EVQ_RESULT_NONE		0
136 #define EVQ_RESULT_SUCCESS	1
137 
138 
139 void wsmouse_evq_put(struct evq_access *, int, int);
140 void wsmouse_init_scaling(struct wsmouseinput *);
141 
142 void wsmouse_input_reset(struct wsmouseinput *);
143 void wsmouse_input_init(struct wsmouseinput *, struct wseventvar **);
144 void wsmouse_input_cleanup(struct wsmouseinput *);
145 
146 
147 #define FOREACHBIT(v, i) \
148     for ((i) = ffs(v) - 1; (i) != -1; (i) = ffs((v) & (~1 << (i))) - 1)
149 
150 
151 #define DELTA_X_EV(flags) (((flags) & SWAPXY) ? \
152     WSCONS_EVENT_MOUSE_DELTA_Y : WSCONS_EVENT_MOUSE_DELTA_X)
153 #define DELTA_Y_EV(flags) (((flags) & SWAPXY) ? \
154     WSCONS_EVENT_MOUSE_DELTA_X : WSCONS_EVENT_MOUSE_DELTA_Y)
155 #define ABS_X_EV(flags) (((flags) & SWAPXY) ? \
156     WSCONS_EVENT_MOUSE_ABSOLUTE_Y : WSCONS_EVENT_MOUSE_ABSOLUTE_X)
157 #define ABS_Y_EV(flags) (((flags) & SWAPXY) ? \
158     WSCONS_EVENT_MOUSE_ABSOLUTE_X : WSCONS_EVENT_MOUSE_ABSOLUTE_Y)
159 #define DELTA_Z_EV	WSCONS_EVENT_MOUSE_DELTA_Z
160 #define DELTA_W_EV	WSCONS_EVENT_MOUSE_DELTA_W
161 #define ABS_Z_EV	WSCONS_EVENT_TOUCH_PRESSURE
162 #define ABS_W_EV	WSCONS_EVENT_TOUCH_CONTACTS
163 #define BTN_DOWN_EV	WSCONS_EVENT_MOUSE_DOWN
164 #define BTN_UP_EV	WSCONS_EVENT_MOUSE_UP
165 #define SYNC_EV		WSCONS_EVENT_SYNC
166 
167 /* buffer size for wsmouse_matching */
168 #define MATRIX_SIZE(slots) (((slots) + 7) * (slots) * sizeof(int))
169 
170 #endif /* _WSMOUSEINPUT_H_ */
171