1 /***************************************************************************
3 * Copyright 2010, 2011 BMW Car IT GmbH
4 * Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
21 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
23 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
24 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
25 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
26 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 ****************************************************************************/
30 #ifndef _WAYLANDEVDEVINPUTEVENT_H_
31 #define _WAYLANDEVDEVINPUTEVENT_H_
34 #include <wayland-server.h>
36 #include "WindowSystems/WaylandInputEvent.h"
37 #include "WindowSystems/WaylandBaseWindowSystem.h"
39 //////////////////////////////////////////////////////////////////////////////
44 EVDEV_ABSOLUTE_MOTION = (1 << 0),
45 EVDEV_ABSOLUTE_MT_DOWN = (1 << 1),
46 EVDEV_ABSOLUTE_MT_MOTION = (1 << 2),
47 EVDEV_ABSOLUTE_MT_UP = (1 << 3),
48 EVDEV_RELATIVE_MOTION = (1 << 4)
51 enum evdev_device_capability
53 EVDEV_KEYBOARD = (1 << 0),
54 EVDEV_BUTTON = (1 << 1),
55 EVDEV_MOTION_ABS = (1 << 2),
56 EVDEV_MOTION_REL = (1 << 3),
57 EVDEV_TOUCH = (1 << 4)
62 STATE_UPDATE_AUTOMATIC,
66 class WaylandEvdevInputEvent;
67 struct evdev_dispatch;
69 struct evdev_input_device
71 WaylandEvdevInputEvent *master;
73 struct wl_event_source *source;
74 struct evdev_dispatch *dispatch;
102 unsigned int pending_events;
107 struct evdev_dispatch_interface
109 // Process an evdev input event
110 void (*process)(struct evdev_dispatch *dispatch,
111 struct evdev_input_device *device,
112 struct input_event *event,
115 // Destroy an event dispatch handler and free all its resources
116 void (*destroy)(struct evdev_dispatch *dispatch);
119 struct evdev_dispatch
121 struct evdev_dispatch_interface *interface;
124 //////////////////////////////////////////////////////////////////////////////
127 #define DEFAULT_CONSTANT_ACCEL_NUMERATOR 50
128 #define DEFAULT_MIN_ACCEL_FACTOR 0.16
129 #define DEFAULT_MAX_ACCEL_FACTOR 1.0
130 #define DEFAULT_HYSTERESIS_MARGIN_DENOMINATOR 700.0
134 TOUCHPAD_MODEL_UNKNOWN = 0,
135 TOUCHPAD_MODEL_SYNAPTICS,
137 TOUCHPAD_MODEL_APPLETOUCH,
138 TOUCHPAD_MODEL_ELANTECH
141 #define TOUCHPAD_EVENT_NONE 0
142 #define TOUCHPAD_EVENT_ABSOLUTE_ANY (1 << 0)
143 #define TOUCHPAD_EVENT_ABSOLUTE_X (1 << 1)
144 #define TOUCHPAD_EVENT_ABSOLUTE_Y (1 << 2)
145 #define TOUCHPAD_EVENT_REPORT (1 << 3)
147 struct touchpad_model_spec
151 enum touchpad_model model;
156 TOUCHPAD_STATE_NONE = 0,
157 TOUCHPAD_STATE_TOUCH,
161 #define TOUCHPAD_HISTORY_LENGTH 4
163 struct touchpad_motion
169 enum touchpad_fingers_state
171 TOUCHPAD_FINGERS_ONE = (1 << 0),
172 TOUCHPAD_FINGERS_TWO = (1 << 1),
173 TOUCHPAD_FINGERS_THREE = (1 << 2)
176 struct touchpad_dispatch
178 struct evdev_dispatch base;
179 struct evdev_input_device *device;
181 enum touchpad_model model;
182 enum touchpad_state state;
184 int last_finger_state;
186 double constant_accel_factor;
187 double min_accel_factor;
188 double max_accel_factor;
190 unsigned int event_mask;
191 unsigned int event_mask_filter;
217 struct touchpad_motion motion_history[TOUCHPAD_HISTORY_LENGTH];
219 unsigned int motion_count;
221 struct wl_list motion_filters;
230 struct motion_filter;
232 struct motion_filter_interface
234 void (*filter)(struct motion_filter *filter,
235 struct motion_params *motion,
236 void *data, uint32_t time);
237 void (*destroy)(struct motion_filter *filter);
242 struct motion_filter_interface *interface;
246 typedef double (*accel_profile_func_t)(struct motion_filter *filter,
251 struct pointer_tracker
259 struct pointer_accelerator
261 struct motion_filter base;
262 accel_profile_func_t profile;
265 double last_velocity;
269 struct pointer_tracker *trackers;
283 UNDEFINED_DIRECTION = 0xff
286 //////////////////////////////////////////////////////////////////////////////
288 class WaylandEvdevInputEvent : public WaylandInputEvent
293 struct wl_list m_deviceList;
299 WaylandEvdevInputEvent(WaylandBaseWindowSystem *windowSystem);
300 virtual ~WaylandEvdevInputEvent();
302 virtual void setupInputEvent();
304 // Default event handler
305 static void fallbackProcess(struct evdev_dispatch *dispatch,
306 struct evdev_input_device *device,
307 struct input_event *e,
309 static void fallbackDestroy(struct evdev_dispatch *dispatch);
311 // Multi-touch event handler
312 static void touchpadProcess(struct evdev_dispatch *dispatch,
313 struct evdev_input_device *device,
314 struct input_event *e,
316 static void touchpadDestroy(struct evdev_dispatch *dispatch);
318 static void flushMotion(struct evdev_input_device *device, uint32_t time);
321 static int handleInputEvent(int fd, uint32_t mask, void *data);
322 static void processEvents(struct evdev_input_device *device,
323 struct input_event *ev, int count);
325 // Default event handler
326 static void evdevProcessRelative(struct evdev_input_device *device,
327 uint32_t time, struct input_event *e);
328 static void evdevProcessAbsolute(struct evdev_input_device *device,
329 struct input_event *e);
330 static void evdevProcessKey(struct evdev_input_device *device,
331 uint32_t time, struct input_event *e);
333 // Multi-touch event handler
334 static void touchpadProcessAbsolute(struct touchpad_dispatch *touchpad,
335 struct evdev_input_device *device,
336 struct input_event *e);
337 static void touchpadProcessKey(struct touchpad_dispatch *touchpad,
338 struct evdev_input_device *device,
339 struct input_event *e,
341 static void touchpadUpdateState(struct touchpad_dispatch *touchpad,
345 static void notifyButton(struct evdev_input_device *device, uint32_t time,
346 int32_t button, enum wl_pointer_button_state state);
347 static void notifyMotion(struct evdev_input_device *device, uint32_t time,
348 wl_fixed_t fx, wl_fixed_t fy);
349 static void notifyKey(struct evdev_input_device *device, uint32_t time,
350 uint32_t key, enum wl_keyboard_key_state state,
351 bool bUpdateAutomatic);
352 static void notifyTouch(struct evdev_input_device *device);
355 void addDevice(struct udev_device *udevDevice);
356 void removeDevice(struct evdev_input_device *device);
357 void createInputDevice(struct wl_display *display, const char *path);
358 int configureDevice(struct evdev_input_device *device);
359 void dispatchProcess(struct evdev_input_device *device,
360 struct input_event *ev,
362 void notifyKeyboardFocus();
363 void notifyKeyboardFocusIn(struct wl_array *keys, enum key_state_update updateState);
364 void updateModifierState(struct wl_seat *wlSeat, uint32_t serial, uint32_t key,
365 enum wl_keyboard_key_state state);
366 void notifyModifiers(struct wl_seat *wlSeat, uint32_t serial);
368 struct evdev_dispatch* createTouchpad(struct evdev_input_device *device);
369 void configureTouchpad(struct touchpad_dispatch *touchpad,
370 struct evdev_input_device *device);
373 #endif /* _WAYLANDEVDEVINPUTEVENT_H_ */