Merge lp:~thomas-voss/grail/rework_cosmetics into lp:grail

Proposed by Thomas Voß on 2011-11-01
Status: Rejected
Rejected by: Chase Douglas on 2011-11-03
Proposed branch: lp:~thomas-voss/grail/rework_cosmetics
Merge into: lp:grail
Diff against target: 11075 lines (+7924/-2754) (has conflicts)
67 files modified
configure.ac (+5/-2)
include/utouch/grail.h (+628/-0)
src/Makefile.am (+41/-21)
src/evbuf.h (+0/-57)
src/gebuf.h (+0/-68)
src/gestures-drag.c (+0/-135)
src/gestures-pinch.c (+0/-131)
src/gestures-rotate.c (+0/-130)
src/gestures-tapping.c (+0/-100)
src/gestures-touch.c (+0/-98)
src/grail-api.c (+0/-328)
src/grail-bits.c (+0/-93)
src/grail-event.c (+0/-118)
src/grail-frame.c (+0/-410)
src/grail-gestures.h (+0/-115)
src/grail-impl.h (+0/-88)
src/grail-init.c (+0/-236)
src/grail-inserter.c (+0/-304)
src/grail-inserter.h (+0/-93)
src/grail-legacy.c (+0/-64)
src/grail-recognizer.c (+0/-58)
src/grail-recognizer.h (+0/-44)
src/grailbuf.h (+0/-59)
src/v2/evbuf.h (+57/-0)
src/v2/gebuf.h (+68/-0)
src/v2/gestures-drag.c (+135/-0)
src/v2/gestures-pinch.c (+131/-0)
src/v2/gestures-rotate.c (+130/-0)
src/v2/gestures-tapping.c (+100/-0)
src/v2/gestures-touch.c (+98/-0)
src/v2/grail-api.c (+328/-0)
src/v2/grail-bits.c (+93/-0)
src/v2/grail-event.c (+118/-0)
src/v2/grail-frame.c (+410/-0)
src/v2/grail-gestures.c (+223/-0)
src/v2/grail-gestures.h (+115/-0)
src/v2/grail-impl.h (+88/-0)
src/v2/grail-init.c (+236/-0)
src/v2/grail-inserter.c (+304/-0)
src/v2/grail-inserter.h (+93/-0)
src/v2/grail-legacy.c (+64/-0)
src/v2/grail-recognizer.c (+58/-0)
src/v2/grail-recognizer.h (+44/-0)
src/v2/grailbuf.h (+59/-0)
src/v3/event.cpp (+91/-0)
src/v3/event.h (+54/-0)
src/v3/gesture.cpp (+278/-0)
src/v3/gesture.h (+76/-0)
src/v3/handle.cpp (+379/-0)
src/v3/handle.h (+73/-0)
src/v3/recognizer.cpp (+575/-0)
src/v3/recognizer.h (+75/-0)
src/v3/slice.cpp (+718/-0)
src/v3/slice.h (+87/-0)
src/v3/subscription.cpp (+323/-0)
src/v3/subscription.h (+72/-0)
tools/Makefile.am (+29/-1)
tools/common/device.c (+188/-0)
tools/common/device.h (+28/-0)
tools/common/servertime.c (+84/-0)
tools/common/servertime.h (+30/-0)
tools/common/slice.c (+91/-0)
tools/common/slice.h (+24/-0)
tools/grail-eventprinter.c (+1/-1)
tools/grail-test-3-1.c (+342/-0)
tools/grail-test-edge.c (+356/-0)
tools/grail-test-propagation.c (+324/-0)
Contents conflict in src/grail-gestures.c
To merge this branch: bzr merge lp:~thomas-voss/grail/rework_cosmetics
Reviewer Review Type Date Requested Status
Jussi Pakkanen (community) 2011-11-01 Needs Fixing on 2011-11-01
Review via email: mp+80942@code.launchpad.net

Description of the change

Wrapped up the actual implementation in namespace utouch::grail. PIMPL-ed classes and switched to opaque-pointers for the C interface.

To post a comment you must log in.
Jussi Pakkanen (jpakkane) wrote :

This merge request has conflicts which it absolutely must not have.

It also has two intermingled things, Chase's new code and Thomas' cleanups. These need to go in different merge requests.

review: Needs Fixing

Unmerged revisions

241. By Thomas Voß on 2011-10-31

Modified: Reverted changes to initialization of limits.

240. By Thomas Voß on 2011-10-31

Cleaned up v3, introduced utouch::grail namespace and PIMPL-ed classes.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2011-08-31 17:20:48 +0000
3+++ configure.ac 2011-11-01 19:17:00 +0000
4@@ -1,7 +1,7 @@
5 # Initialize Autoconf
6 AC_PREREQ([2.60])
7 AC_INIT([Gesture Recognition And Instantiation Library],
8- [2.1.0],
9+ [2.99.1],
10 [],
11 [utouch-grail])
12 AC_CONFIG_SRCDIR([Makefile.am])
13@@ -10,6 +10,7 @@
14
15 # Initialize Automake
16 AM_INIT_AUTOMAKE([foreign dist-bzip2])
17+AM_SILENT_RULES([yes])
18 AM_MAINTAINER_MODE
19
20 LIB_VERSION=3:0:2
21@@ -20,11 +21,12 @@
22
23 # Checks for programs.
24 AC_PROG_CC
25+AC_PROG_CXX
26 AC_PROG_INSTALL
27
28 PKG_CHECK_MODULES([MTDEV], [mtdev >= 1.1])
29 PKG_CHECK_MODULES([EVEMU], [utouch-evemu >= 1.0.5])
30-PKG_CHECK_MODULES([FRAME], [utouch-frame >= 1.2])
31+PKG_CHECK_MODULES([FRAME], [utouch-frame >= 1.9.0])
32
33 AC_ARG_WITH([xi], AS_HELP_STRING([--with-xi], [Build with XI2.1 support]))
34 AM_CONDITIONAL([HAVE_XI], [test "x$with_xi" != "x"])
35@@ -46,6 +48,7 @@
36 utouch-grail.pc])
37
38 AC_SUBST(AM_CPPFLAGS, "-Wall -Werror")
39+AC_SUBST(AM_CXXFLAGS, "-std=c++0x")
40
41 AC_OUTPUT
42
43
44=== added directory 'include/utouch'
45=== added file 'include/utouch/grail.h'
46--- include/utouch/grail.h 1970-01-01 00:00:00 +0000
47+++ include/utouch/grail.h 2011-11-01 19:17:00 +0000
48@@ -0,0 +1,628 @@
49+/*****************************************************************************
50+ *
51+ * utouch-grail - Multitouch Gesture Recognition Library
52+ *
53+ * Copyright (C) 2010-2011 Canonical Ltd.
54+ *
55+ * This program is free software: you can redistribute it and/or modify it
56+ * under the terms of the GNU General Public License as published by the
57+ * Free Software Foundation, either version 3 of the License, or (at your
58+ * option) any later version.
59+ *
60+ * This program is distributed in the hope that it will be useful, but
61+ * WITHOUT ANY WARRANTY; without even the implied warranty of
62+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
63+ * General Public License for more details.
64+ *
65+ * You should have received a copy of the GNU General Public License along
66+ * with this program. If not, see <http://www.gnu.org/licenses/>.
67+ *
68+ ****************************************************************************/
69+
70+/**
71+ * @file utouch/grail.h
72+ * Definitions of the main and platform-generic API
73+ */
74+
75+#ifndef UTOUCH_GRAIL_UTOUCH_GRAIL_H_
76+#define UTOUCH_GRAIL_UTOUCH_GRAIL_H_
77+
78+#include <stdint.h>
79+
80+#include <utouch/frame.h>
81+
82+#ifdef __cplusplus
83+extern "C" {
84+#endif
85+
86+/**
87+ * @defgroup v3 uTouch-Grail 3.x
88+ * @{
89+ */
90+
91+/** An object for the context of the uTouch Frame instance */
92+typedef void * UGHandle;
93+/** An object for a gesture subscription */
94+typedef void * UGSubscription;
95+/** An object for an event */
96+typedef const void * UGEvent;
97+/** An object for a gesture state in time */
98+typedef void * UGSlice;
99+
100+/** The status code denoting the result of a function call */
101+typedef enum UGStatus {
102+ UGStatusSuccess = 0, /**< The call was successful */
103+ UGStatusErrorGeneric, /**< A platform-dependent error occurred */
104+ UGStatusErrorResources, /**< An error occurred due to insufficient resources */
105+ UGStatusErrorNoEvent, /**< No events were available to get */
106+ UGStatusErrorUnknownProperty, /**< The requested property value was not set */
107+ UGStatusErrorInvalidValue, /**< The property value passed in is invalid */
108+ UGStatusErrorInvalidDevice, /**< The requested device does not exist */
109+ UGStatusErrorInvalidSubscription, /**< The subscription is invalid */
110+ UGStatusErrorInvalidGesture, /**< The requested gesture does not exist */
111+ UGStatusErrorInvalidIndex, /**< The requested touch index is invalid */
112+} UGStatus;
113+
114+/** Subscription properties */
115+typedef enum UGSubscriptionProperty {
116+ /**
117+ * Device to subscribe to gesture events for
118+ *
119+ * Value type: UFDevice
120+ */
121+ UGSubscriptionPropertyDevice,
122+ /**
123+ * Window to subscribe to gesture events for
124+ *
125+ * Value type: Window server dependent
126+ *
127+ * For X11, the value type is unsigned int.
128+ */
129+ UGSubscriptionPropertyWindow,
130+ /**
131+ * Gesture types to subscribe for
132+ *
133+ * Value type: UGGestureTypeMask
134+ */
135+ UGSubscriptionPropertyMask,
136+ /**
137+ * Number of touches required to begin gesture
138+ *
139+ * Value type: unsigned int
140+ */
141+ UGSubscriptionPropertyTouchesStart,
142+ /**
143+ * Minimum number of touches for gesture
144+ *
145+ * Value type: unsigned int
146+ */
147+ UGSubscriptionPropertyTouchesMinimum,
148+ /**
149+ * Maximum number of touches for gesture
150+ *
151+ * Value type: unsigned int
152+ */
153+ UGSubscriptionPropertyTouchesMaximum,
154+ /**
155+ * Timeout for recognizing a drag gesture
156+ *
157+ * Value type: 64-bit unsigned integer
158+ */
159+ UGSubscriptionPropertyDragTimeout,
160+ /**
161+ * Threshold value for recognizing a drag gesture
162+ *
163+ * Value type: float
164+ */
165+ UGSubscriptionPropertyDragThreshold,
166+ /**
167+ * Timeout for recognizing a pinch gesture
168+ *
169+ * Value type: 64-bit unsigned integer
170+ */
171+ UGSubscriptionPropertyPinchTimeout,
172+ /**
173+ * Threshold value for recognizing a pinch gesture
174+ *
175+ * Value type: float
176+ */
177+ UGSubscriptionPropertyPinchThreshold,
178+ /**
179+ * Timeout for recognizing a rotate gesture
180+ *
181+ * Value type: 64-bit unsigned integer
182+ */
183+ UGSubscriptionPropertyRotateTimeout,
184+ /**
185+ * Threshold value for recognizing a rotate gesture
186+ *
187+ * Value type: float
188+ */
189+ UGSubscriptionPropertyRotateThreshold,
190+ /**
191+ * Timeout for recognizing a tap gesture
192+ *
193+ * Value type: 64-bit unsigned integer
194+ */
195+ UGSubscriptionPropertyTapTimeout,
196+ /**
197+ * Threshold value for recognizing a tap gesture
198+ *
199+ * Value type: float
200+ */
201+ UGSubscriptionPropertyTapThreshold,
202+} UGSubscriptionProperty;
203+
204+/** Event type */
205+typedef enum UGEventType {
206+ UGEventTypeSlice = 0, /**< A new gesture slice */
207+} UGEventType;
208+
209+/** Event properties */
210+typedef enum UGEventProperty {
211+ /**
212+ * Type of event
213+ *
214+ * Value type: UGEventType
215+ */
216+ UGEventPropertyType = 0,
217+ /**
218+ * Slice of a gesture
219+ *
220+ * Value type: UGSlice
221+ */
222+ UGEventPropertySlice,
223+ /**
224+ * Event time
225+ *
226+ * Value type: 64-bit unsigned int
227+ *
228+ * This property holds the time the event occurred in display server
229+ * timespace. The time is provided in milliseconds (ms).
230+ */
231+ UGEventPropertyTime,
232+} UGEventProperty;
233+
234+/** Gesture type bit indices */
235+typedef enum UGGestureType {
236+ UGGestureTypeDrag = 0x1, /**< Drag gesture */
237+ UGGestureTypePinch = 0x2, /**< Pinch gesture */
238+ UGGestureTypeRotate = 0x4, /**< Rotate gesture */
239+ UGGestureTypeTap = 0x8, /**< Tap gesture */
240+ UGGestureTypeTouch = 0x10, /**< Touch gesture */
241+} UGGestureType;
242+
243+/** Bit-mask of gesture types */
244+typedef uint32_t UGGestureTypeMask;
245+
246+/** 2D affine transformation */
247+typedef const float UGTransform[3][3];
248+
249+/** Gesture slice state */
250+typedef enum UGGestureState {
251+ UGGestureStateBegin = 0, /**< Gesture slice begin */
252+ UGGestureStateUpdate, /**< Gesture slice update */
253+ UGGestureStateEnd, /**< Gesture slice end */
254+} UGGestureState;
255+
256+/** Gesture slice properties */
257+typedef enum UGSliceProperty {
258+ /**
259+ * Gesture ID
260+ *
261+ * Value type: unsigned int
262+ */
263+ UGSlicePropertyId = 0,
264+ /**
265+ * Gesture set state
266+ *
267+ * Value type: UGGestureState
268+ */
269+ UGSlicePropertyState,
270+ /**
271+ * Gesture subscription
272+ *
273+ * Value type: UGSubscription
274+ */
275+ UGSlicePropertySubscription,
276+ /**
277+ * Recognized gestures
278+ *
279+ * Value type: UGGestureTypeMask
280+ */
281+ UGSlicePropertyRecognized,
282+ /**
283+ * Number of touches
284+ *
285+ * Value type: unsigned int
286+ */
287+ UGSlicePropertyNumTouches,
288+ /**
289+ * Touch frame
290+ *
291+ * Value type: UFFrame
292+ */
293+ UGSlicePropertyFrame,
294+ /**
295+ * Original gesture center along the X axis
296+ *
297+ * Value type: float
298+ *
299+ * This value represents the original geometric center of the touches.
300+ */
301+ UGSlicePropertyOriginalCenterX,
302+ /**
303+ * Original gesture center along the Y axis
304+ *
305+ * Value type: float
306+ *
307+ * This value represents the original geometric center of the touches.
308+ */
309+ UGSlicePropertyOriginalCenterY,
310+ /**
311+ * Original radius of touches
312+ *
313+ * Value type: float
314+ *
315+ * This value represents the average of the square of the euclidean distance
316+ * from the geometric center of the original touches to each touch.
317+ */
318+ UGSlicePropertyOriginalRadius,
319+ /**
320+ * Best-fit 2D affine transformation of previous to current touch locations
321+ *
322+ * Value type: pointer to UGTransform
323+ *
324+ * The transformation is relative to the previous geometric center of the
325+ * touches.
326+ */
327+ UGSlicePropertyTransform,
328+ /**
329+ * Best-fit 2D affine transformation of original to current touch locations
330+ *
331+ * Value type: pointer to UGTransform
332+ *
333+ * The transformation is relative to the original geometric center of the
334+ * touches.
335+ */
336+ UGSlicePropertyCumulativeTransform,
337+ /**
338+ * Best-fit instant center of rotation along the X axis
339+ *
340+ * Value type: float
341+ */
342+ UGSlicePropertyCenterOfRotationX,
343+ /**
344+ * Best-fit instant center of rotation along the Y axis
345+ *
346+ * Value type: float
347+ */
348+ UGSlicePropertyCenterOfRotationY,
349+} UGSliceProperty;
350+
351+/**
352+ * Create a new grail context
353+ *
354+ * @param [in] frame_handle The uTouch frame context object
355+ * @param [out] handle The new uTouch grail context object
356+ * @return UGStatusSuccess or UGStatusErrorResources
357+ */
358+UGStatus grail_new(UFHandle frame_handle, UGHandle *handle);
359+
360+/**
361+ * Delete a grail context
362+ *
363+ * @param [in] handle The uTouch Grail context object
364+ */
365+void grail_delete_v3(UGHandle handle);
366+
367+/**
368+ * Get the event file descriptor for the uTouch Frame context
369+ *
370+ * @param [in] handle The uTouch Grail context object
371+ * @return A file descriptor for the context
372+ *
373+ * When events are available for processing, the file descriptor will be
374+ * readable. Perform an 8-byte read from the file descriptor to clear the state.
375+ * Refer to the EVENTFD(2) man page for more details.
376+ */
377+int grail_get_fd(UGHandle handle);
378+
379+/**
380+ * Create a new subscription object
381+ *
382+ * @param [out] subscription The new subscription object
383+ * @return UGStatusSuccess or UGStatusErrorResources
384+ */
385+UGStatus grail_subscription_new(UGSubscription* subscription);
386+
387+/**
388+ * Delete a subscription object
389+ *
390+ * @param [in] subscription The subscription object
391+ */
392+void grail_subscription_delete(UGSubscription subscription);
393+
394+/**
395+ * Set a subscription property
396+ *
397+ * @param [in] subscription The subscription object
398+ * @param [in] property The subscription property
399+ * @param [in] value The new value of the property
400+ * @return UGStatusSuccess or UGStatusInvalidProperty
401+ */
402+UGStatus grail_subscription_set_property(UGSubscription subscription,
403+ UGSubscriptionProperty property,
404+ const void* value);
405+
406+/**
407+ * Get a subscription property
408+ *
409+ * @param [in] subscription The subscription object
410+ * @param [in] property The subscription property
411+ * @param [out] value The value of the property
412+ * @return UGStatusSuccess or UGStatusInvalidProperty
413+ */
414+UGStatus grail_subscription_get_property(UGSubscription subscription,
415+ UGSubscriptionProperty property,
416+ void* value);
417+
418+/**
419+ * Activate a subscription
420+ *
421+ * @param [in] handle The context object
422+ * @param [in] subscription The subscription object
423+ * @return UGStatusSuccess or UGStatusErrorInvalidDevice
424+ */
425+UGStatus grail_subscription_activate(UGHandle handle, UGSubscription subscription);
426+
427+/**
428+ * Deactivate a subscription
429+ *
430+ * @param [in] handle The context object
431+ * @param [in] subscription The subscription object
432+ */
433+void grail_subscription_deactivate(UGHandle handle,
434+ UGSubscription subscription);
435+
436+/**
437+ * Process a uTouch Frame event
438+ *
439+ * @param [in] handle The context object
440+ * @param [in] event The uTouch Frame event
441+ */
442+void grail_process_frame_event(UGHandle handle, const UFEvent event);
443+
444+/**
445+ * Get an event from the uTouch Grail context
446+ *
447+ * @param [in] handle The context object
448+ * @param [out] event The retrieved event
449+ * @return UGStatusSuccess or UGStatusErrorNoEvent
450+ */
451+UGStatus grail_get_event(UGHandle handle, UGEvent * event );
452+
453+/**
454+ * Release an event back to the uTouch Grail context
455+ *
456+ * @param [in] handle The context object
457+ * @param [in] event The event to be released
458+ */
459+void grail_release_event(UGHandle handle, UGEvent event);
460+
461+/**
462+ * Update the grail state for the given server time
463+ *
464+ * @param [in] handle The context object
465+ * @param [in] time The current server time
466+ *
467+ * The recognizer uses timeouts for deciding whether to accept or reject
468+ * touches. Calling this function will perform any pending decisions based on
469+ * the current server time.
470+ */
471+void grail_update_time(UGHandle handle, uint64_t time);
472+
473+/**
474+ * Get the next timeout at which to update the grail state
475+ *
476+ * @param [in] handle The context object
477+ * @return The next server time at which the grail state should be updated
478+ *
479+ * To update the grail state, call grail_update_time().
480+ */
481+uint64_t grail_next_timeout(UGHandle handle);
482+
483+/**
484+ * Get the value of a property of an event
485+ *
486+ * @param [in] event The event object
487+ * @param [in] property The property to retrieve a value for
488+ * @param [out] value The value retrieved
489+ * @return UGStatusSuccess or UGStatusErrorUnknownProperty
490+ */
491+UGStatus grail_event_get_property(const UGEvent event, UGEventProperty property,
492+ void *value);
493+
494+/**
495+ * Get the touch ID of a touch in a slice
496+ *
497+ * @param [in] slice The gesture slcie object
498+ * @param [in] index The index of the touch in the slice
499+ * @param [out] touch_id The touch ID of the touch
500+ *
501+ * The touch ID type is window server dependent. For X11, the type is unsigned
502+ * int.
503+ */
504+UGStatus grail_slice_get_touch_id(const UGSlice slice, unsigned int index,
505+ void *touch_id);
506+
507+/**
508+ * Get the value of a property of a gesture slice
509+ *
510+ * @param [in] slice The gesture slice object
511+ * @param [in] property The property to retrieve a value for
512+ * @param [out] value The value retrieved
513+ * @return UGStatusSuccess or UGStatusErrorUnknownProperty
514+ */
515+UGStatus grail_slice_get_property(const UGSlice slice, UGSliceProperty property,
516+ void *value);
517+
518+/**
519+ * Accept gesture associated with gesture slice
520+ *
521+ * @param [in] handle The context object
522+ * @param [in] id The ID of the gesture to accept
523+ * @return UGStatusSuccess or UGStatusErrorInvalidGesture
524+ */
525+UGStatus grail_accept_gesture(UGHandle handle, unsigned int id);
526+
527+/**
528+ * Reject gesture associated with gesture slice
529+ *
530+ * @param [in] handle The context object
531+ * @param [in] id The ID of the gesture to reject
532+ * @return UGStatusSuccess or UGStatusErrorInvalidGesture
533+ */
534+UGStatus grail_reject_gesture(UGHandle handle, unsigned int id);
535+
536+/**
537+ * @defgroup v3-helpers Helper Functions
538+ * These helper functions may be used in place of the generic property getters.
539+ * They are limited to properties that are guaranteed to exist in all instances
540+ * of the objects.
541+ * @{
542+ */
543+
544+/**
545+ * Get the type of an event
546+ *
547+ * @param [in] event The event object
548+ * @return The type of the event
549+ */
550+UGEventType grail_event_get_type( UGEvent event);
551+
552+/**
553+ * Get the time of an event
554+ *
555+ * @param [in] event The event object
556+ * @return The time of the event
557+ */
558+uint64_t grail_event_get_time(UGEvent event);
559+
560+/**
561+ * Get the ID of a gesture from a slice
562+ *
563+ * @param [in] slice The gesture slice object
564+ * @return The ID of the gesture
565+ */
566+unsigned int grail_slice_get_id(const UGSlice slice);
567+
568+/**
569+ * Get the state of a gesture in a slice
570+ *
571+ * @param [in] slice The gesture slice object
572+ * @return The state of the gesture in the slice
573+ */
574+UGGestureState grail_slice_get_state(const UGSlice slice);
575+
576+/**
577+ * Get the subscription for the gesture from the slice
578+ *
579+ * @param [in] slice The gesture slice object
580+ * @return The subscription
581+ */
582+UGSubscription grail_slice_get_subscription(const UGSlice slice);
583+
584+/**
585+ * Get the gestures recognized through the slice
586+ *
587+ * @param [in] slice The gesture slice object
588+ * @return The recognized gestures
589+ */
590+UGGestureTypeMask grail_slice_get_recognized(const UGSlice slice);
591+
592+/**
593+ * Get the current number of touches in the slice
594+ *
595+ * @param [in] slice The gesture slice object
596+ * @return The number of touches
597+ */
598+unsigned int grail_slice_get_num_touches(const UGSlice slice);
599+
600+/**
601+ * Get the original centroid position of the gesture along the X axis
602+ *
603+ * @param [in] slice The gesture slice object
604+ * @return The position
605+ */
606+float grail_slice_get_original_center_x(const UGSlice slice);
607+
608+/**
609+ * Get the original centroid position of the gesture along the Y axis
610+ *
611+ * @param [in] slice The gesture slice object
612+ * @return The position
613+ */
614+float grail_slice_get_original_center_y(const UGSlice slice);
615+
616+/**
617+ * Get the original radius of the gesture
618+ *
619+ * @param [in] slice The gesture slice object
620+ * @return The position
621+ */
622+float grail_slice_get_original_radius(const UGSlice slice);
623+
624+/**
625+ * Get the instantaneous center of rotation of the gesture along the X axis
626+ *
627+ * @param [in] slice The gesture slice object
628+ * @return The position
629+ */
630+float grail_slice_get_center_of_rotation_x(const UGSlice slice);
631+
632+/**
633+ * Get the instantaneous center of rotation of the gesture along the Y axis
634+ *
635+ * @param [in] slice The gesture slice object
636+ * @return The position
637+ */
638+float grail_slice_get_center_of_rotation_y(const UGSlice slice);
639+
640+/**
641+ * Get the best-fit instantaneous 2D affine transformation for the gesture slice
642+ *
643+ * @param [in] slice The gesture slice object
644+ * @return the transformation
645+ *
646+ * The returned transformation is owned by the gesture slice.
647+ */
648+const UGTransform *grail_slice_get_transform(const UGSlice slice);
649+
650+/**
651+ * Get the best-fit cumulative 2D affine transformation for the gesture slice
652+ *
653+ * @param [in] slice The gesture slice object
654+ * @return the transformation
655+ *
656+ * The returned transformation is owned by the gesture slice.
657+ */
658+const UGTransform *grail_slice_get_cumulative_transform(const UGSlice slice);
659+
660+/**
661+ * Get the uTouch-Frame frame for the slice
662+ *
663+ * @param [in] slice The gesture slice object
664+ * @return the frame
665+ */
666+const UFFrame grail_slice_get_frame(const UGSlice slice);
667+
668+/** @} */
669+
670+/** @} */
671+
672+#ifdef __cplusplus
673+}
674+#endif
675+
676+#endif // UTOUCH_GRAIL_UTOUCH_GRAIL_H_
677
678=== modified file 'src/Makefile.am'
679--- src/Makefile.am 2011-04-28 16:53:41 +0000
680+++ src/Makefile.am 2011-11-01 19:17:00 +0000
681@@ -1,3 +1,5 @@
682+AUTOMAKE_OPTIONS = subdir-objects
683+
684 lib_LTLIBRARIES = libutouch-grail.la
685
686 libutouch_grail_la_LDFLAGS = \
687@@ -7,28 +9,42 @@
688 $(EVEMU_LIBS) \
689 $(FRAME_LIBS)
690
691+v2dir = v2
692+v3dir = v3
693 libutouch_grail_la_SOURCES = \
694- evbuf.h \
695- gebuf.h \
696- grailbuf.h \
697- grail-bits.c \
698- grail-inserter.c \
699- grail-inserter.h \
700- grail-gestures.c \
701- grail-gestures.h \
702- gestures-touch.c \
703- gestures-drag.c \
704- gestures-pinch.c \
705- gestures-rotate.c \
706- gestures-tapping.c \
707- grail-recognizer.c \
708- grail-recognizer.h \
709- grail-event.c \
710- grail-impl.h \
711- grail-api.c \
712- grail-legacy.c \
713- grail-init.c \
714- grail-frame.c
715+ v2/evbuf.h \
716+ v2/gebuf.h \
717+ v2/grailbuf.h \
718+ v2/grail-bits.c \
719+ v2/grail-inserter.c \
720+ v2/grail-inserter.h \
721+ v2/grail-gestures.c \
722+ v2/grail-gestures.h \
723+ v2/gestures-touch.c \
724+ v2/gestures-drag.c \
725+ v2/gestures-pinch.c \
726+ v2/gestures-rotate.c \
727+ v2/gestures-tapping.c \
728+ v2/grail-recognizer.c \
729+ v2/grail-recognizer.h \
730+ v2/grail-event.c \
731+ v2/grail-impl.h \
732+ v2/grail-api.c \
733+ v2/grail-legacy.c \
734+ v2/grail-init.c \
735+ v2/grail-frame.c \
736+ v3/event.cpp \
737+ v3/event.h \
738+ v3/gesture.cpp \
739+ v3/gesture.h \
740+ v3/handle.cpp \
741+ v3/handle.h \
742+ v3/recognizer.cpp \
743+ v3/recognizer.h \
744+ v3/slice.cpp \
745+ v3/slice.h \
746+ v3/subscription.cpp \
747+ v3/subscription.h
748
749 # These are flags required to properly set up
750 # the build. -fvisibility requires GCC > 4 (or clang)
751@@ -41,3 +57,7 @@
752 $(top_srcdir)/include/grail-bits.h \
753 $(top_srcdir)/include/grail-types.h \
754 $(top_srcdir)/include/grail.h
755+
756+libutouch_grail_v3includedir = $(includedir)/utouch
757+libutouch_grail_v3include_HEADERS = \
758+ $(top_srcdir)/include/utouch/grail.h
759
760=== removed file 'src/evbuf.h'
761--- src/evbuf.h 2011-04-28 16:53:57 +0000
762+++ src/evbuf.h 1970-01-01 00:00:00 +0000
763@@ -1,57 +0,0 @@
764-/*****************************************************************************
765- *
766- * grail - Gesture Recognition And Instantiation Library
767- *
768- * Copyright (C) 2010-2011 Canonical Ltd.
769- *
770- * This program is free software: you can redistribute it and/or modify it
771- * under the terms of the GNU General Public License as published by the
772- * Free Software Foundation, either version 3 of the License, or (at your
773- * option) any later version.
774- *
775- * This program is distributed in the hope that it will be useful, but
776- * WITHOUT ANY WARRANTY; without even the implied warranty of
777- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
778- * General Public License for more details.
779- *
780- * You should have received a copy of the GNU General Public License along
781- * with this program. If not, see <http://www.gnu.org/licenses/>.
782- *
783- ****************************************************************************/
784-
785-#ifndef GRAIL_EVBUF_H
786-#define GRAIL_EVBUF_H
787-
788-#define DIM_EVENTS 4096
789-
790-struct evbuf {
791- int head;
792- int tail;
793- struct input_event buffer[DIM_EVENTS];
794-};
795-
796-static inline void evbuf_clear(struct evbuf *evbuf)
797-{
798- evbuf->head = evbuf->tail = 0;
799-}
800-
801-static inline int evbuf_empty(const struct evbuf *evbuf)
802-{
803- return evbuf->head == evbuf->tail;
804-}
805-
806-static inline void evbuf_put(struct evbuf *evbuf,
807- const struct input_event *ev)
808-{
809- evbuf->buffer[evbuf->head++] = *ev;
810- evbuf->head &= DIM_EVENTS - 1;
811-}
812-
813-static inline void evbuf_get(struct evbuf *evbuf,
814- struct input_event *ev)
815-{
816- *ev = evbuf->buffer[evbuf->tail++];
817- evbuf->tail &= DIM_EVENTS - 1;
818-}
819-
820-#endif
821
822=== removed file 'src/gebuf.h'
823--- src/gebuf.h 2011-05-17 14:15:22 +0000
824+++ src/gebuf.h 1970-01-01 00:00:00 +0000
825@@ -1,68 +0,0 @@
826-/*****************************************************************************
827- *
828- * grail - Gesture Recognition And Instantiation Library
829- *
830- * Copyright (C) 2010-2011 Canonical Ltd.
831- *
832- * This program is free software: you can redistribute it and/or modify it
833- * under the terms of the GNU General Public License as published by the
834- * Free Software Foundation, either version 3 of the License, or (at your
835- * option) any later version.
836- *
837- * This program is distributed in the hope that it will be useful, but
838- * WITHOUT ANY WARRANTY; without even the implied warranty of
839- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
840- * General Public License for more details.
841- *
842- * You should have received a copy of the GNU General Public License along
843- * with this program. If not, see <http://www.gnu.org/licenses/>.
844- *
845- ****************************************************************************/
846-
847-#ifndef GRAIL_GESTURE_BUFFER_H
848-#define GRAIL_GESTURE_BUFFER_H
849-
850-#include "grail-impl.h"
851-
852-#define DIM_GESTURE_EVENTS 512
853-
854-struct gesture_event {
855- int status;
856- int ntouch;
857- int nprop;
858- utouch_frame_time_t time;
859- struct grail_coord pos;
860- grail_prop_t prop[DIM_GRAIL_PROP];
861-};
862-
863-struct gebuf {
864- int head;
865- int tail;
866- struct gesture_event buffer[DIM_GESTURE_EVENTS];
867-};
868-
869-static inline void gebuf_clear(struct gebuf *gebuf)
870-{
871- gebuf->head = gebuf->tail = 0;
872-}
873-
874-static inline int gebuf_empty(const struct gebuf *gebuf)
875-{
876- return gebuf->head == gebuf->tail;
877-}
878-
879-static inline void gebuf_put(struct gebuf *gebuf,
880- const struct gesture_event *ev)
881-{
882- gebuf->buffer[gebuf->head++] = *ev;
883- gebuf->head &= DIM_GESTURE_EVENTS - 1;
884-}
885-
886-static inline void gebuf_get(struct gebuf *gebuf,
887- struct gesture_event *ev)
888-{
889- *ev = gebuf->buffer[gebuf->tail++];
890- gebuf->tail &= DIM_GESTURE_EVENTS - 1;
891-}
892-
893-#endif
894
895=== removed file 'src/gestures-drag.c'
896--- src/gestures-drag.c 2011-04-28 16:53:57 +0000
897+++ src/gestures-drag.c 1970-01-01 00:00:00 +0000
898@@ -1,135 +0,0 @@
899-/*****************************************************************************
900- *
901- * grail - Gesture Recognition And Instantiation Library
902- *
903- * Copyright (C) 2010-2011 Canonical Ltd.
904- *
905- * This program is free software: you can redistribute it and/or modify it
906- * under the terms of the GNU General Public License as published by the
907- * Free Software Foundation, either version 3 of the License, or (at your
908- * option) any later version.
909- *
910- * This program is distributed in the hope that it will be useful, but
911- * WITHOUT ANY WARRANTY; without even the implied warranty of
912- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
913- * General Public License for more details.
914- *
915- * You should have received a copy of the GNU General Public License along
916- * with this program. If not, see <http://www.gnu.org/licenses/>.
917- *
918- ****************************************************************************/
919-
920-#include "grail-recognizer.h"
921-#include <math.h>
922-#include <stdio.h>
923-
924-static const int getype[DIM_TOUCH + 1] = {
925- -1,
926- GRAIL_TYPE_DRAG1,
927- GRAIL_TYPE_DRAG2,
928- GRAIL_TYPE_DRAG3,
929- GRAIL_TYPE_DRAG4,
930- GRAIL_TYPE_DRAG5,
931-};
932-
933-static void set_props(const struct gesture_inserter *gin,
934- struct combo_model *s, const struct move_model *m,
935- const struct utouch_frame *frame)
936-{
937- if (m->single) {
938- s->prop[GRAIL_PROP_DRAG_DX] = m->fm[FM_X].raw_delta;
939- s->prop[GRAIL_PROP_DRAG_DY] = m->fm[FM_Y].raw_delta;
940- } else {
941- s->prop[GRAIL_PROP_DRAG_DX] = m->fm[FM_X].action_delta;
942- s->prop[GRAIL_PROP_DRAG_DY] = m->fm[FM_Y].action_delta;
943- }
944- s->prop[GRAIL_PROP_DRAG_VX] = m->fm[FM_X].velocity;
945- s->prop[GRAIL_PROP_DRAG_VY] = m->fm[FM_Y].velocity;
946- s->prop[GRAIL_PROP_DRAG_X] = m->fm[FM_X].value;
947- s->prop[GRAIL_PROP_DRAG_Y] = m->fm[FM_Y].value;
948- s->nprop = 6;
949- s->nprop += gin_add_contact_props(gin, s->prop + s->nprop, frame);
950-}
951-
952-static const int fm_mask = 0x03;
953-
954-int gru_drag(struct grail *ge,
955- const struct utouch_frame *frame)
956-{
957- struct gesture_recognizer *gru = ge->gru;
958- struct combo_model *state = &gru->drag;
959- struct move_model *move = &gru->move;
960- int mask = state->active ? (move->active & fm_mask) : fm_mask;
961- if (!move->multi && !move->single) {
962- if (state->active) {
963- gru_end(ge, state->gid, move,
964- state->prop, state->nprop);
965- state->active = 0;
966- }
967- }
968- if ((move->timeout & fm_mask) == fm_mask) {
969- if (state->active) {
970- gin_gid_timeout(ge, state->gid);
971- }
972- }
973- if (!state->active) {
974- int type = getype[move->ntouch];
975- if (type < 0)
976- return 0;
977- state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
978- state->active = 1;
979- }
980- if (!(move->tickle & mask))
981- return 0;
982- if (!(move->active & fm_mask))
983- return 0;
984- set_props(ge->gin, state, move, frame);
985- gru_event(ge, state->gid, move, state->prop, state->nprop);
986- return 1;
987-}
988-
989-int gru_windrag(struct grail *ge,
990- const struct utouch_frame *frame)
991-{
992- struct gesture_recognizer *gru = ge->gru;
993- struct combo_model *state = &gru->windrag;
994- struct move_model *move = &gru->move;
995- int mask = state->active ? (move->active & fm_mask) : fm_mask;
996- if (!move->multi && !move->single) {
997- if (state->active && out_of_bounds(state, move)) {
998- gru_end(ge, state->gid, move,
999- state->prop, state->nprop);
1000- state->active = 0;
1001- }
1002- }
1003- if ((move->timeout & fm_mask) == fm_mask) {
1004- if (state->active) {
1005- gin_gid_timeout(ge, state->gid);
1006- }
1007- }
1008- if (!state->active) {
1009- if (move->ntouch == 4) {
1010- state->gid = gin_gid_begin(ge, GRAIL_TYPE_MDRAG,
1011- PRIO_META, frame);
1012- state->mintouch = 1;
1013- state->maxtouch = 4;
1014- state->active = 1;
1015- } else if (move->ntouch == 3) {
1016- state->gid = gin_gid_begin(ge, GRAIL_TYPE_EDRAG,
1017- PRIO_ENV, frame);
1018- state->mintouch = 1;
1019- state->maxtouch = 3;
1020- state->active = 1;
1021- } else {
1022- return 0;
1023- }
1024- }
1025- if (!(move->tickle & mask))
1026- return 0;
1027- if (!(move->active & fm_mask))
1028- return 0;
1029- set_props(ge->gin, state, move, frame);
1030- gru_event(ge, state->gid, move, state->prop, state->nprop);
1031- return 1;
1032-}
1033-
1034
1035=== removed file 'src/gestures-pinch.c'
1036--- src/gestures-pinch.c 2011-06-06 14:42:39 +0000
1037+++ src/gestures-pinch.c 1970-01-01 00:00:00 +0000
1038@@ -1,131 +0,0 @@
1039-/*****************************************************************************
1040- *
1041- * grail - Gesture Recognition And Instantiation Library
1042- *
1043- * Copyright (C) 2010-2011 Canonical Ltd.
1044- *
1045- * This program is free software: you can redistribute it and/or modify it
1046- * under the terms of the GNU General Public License as published by the
1047- * Free Software Foundation, either version 3 of the License, or (at your
1048- * option) any later version.
1049- *
1050- * This program is distributed in the hope that it will be useful, but
1051- * WITHOUT ANY WARRANTY; without even the implied warranty of
1052- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1053- * General Public License for more details.
1054- *
1055- * You should have received a copy of the GNU General Public License along
1056- * with this program. If not, see <http://www.gnu.org/licenses/>.
1057- *
1058- ****************************************************************************/
1059-
1060-#include "grail-recognizer.h"
1061-#include <math.h>
1062-#include <stdio.h>
1063-
1064-static const int getype[DIM_TOUCH + 1] = {
1065- 0,
1066- 0,
1067- GRAIL_TYPE_PINCH2,
1068- GRAIL_TYPE_PINCH3,
1069- GRAIL_TYPE_PINCH4,
1070- GRAIL_TYPE_PINCH5,
1071-};
1072-
1073-static const int fm_mask = 0x04;
1074-
1075-static void set_props(const struct gesture_inserter *gin,
1076- struct combo_model *s,
1077- const struct move_model *m,
1078- const struct utouch_frame *frame)
1079-{
1080- s->prop[GRAIL_PROP_PINCH_DR] = m->fm[FM_R].action_delta;
1081- s->prop[GRAIL_PROP_PINCH_VR] = m->fm[FM_R].velocity;
1082- s->prop[GRAIL_PROP_PINCH_R] = m->fm[FM_R].value;
1083- s->prop[GRAIL_PROP_PINCH_X] = m->fm[FM_X].value;
1084- s->prop[GRAIL_PROP_PINCH_Y] = m->fm[FM_Y].value;
1085- s->nprop = 5;
1086- s->nprop += gin_add_contact_props(gin, s->prop + s->nprop, frame);
1087-}
1088-
1089-int gru_pinch(struct grail *ge,
1090- const struct utouch_frame *frame)
1091-{
1092- struct gesture_recognizer *gru = ge->gru;
1093- struct combo_model *state = &gru->pinch;
1094- struct move_model *move = &gru->move;
1095- int mask = state->active ? (move->active & fm_mask) : fm_mask;
1096- if (!move->multi && !move->single) {
1097- if (state->active) {
1098- gru_end(ge, state->gid, move,
1099- state->prop, state->nprop);
1100- state->active = 0;
1101- }
1102- return 0;
1103- }
1104- if ((move->timeout & fm_mask) == fm_mask) {
1105- if (state->active) {
1106- gin_gid_timeout(ge, state->gid);
1107- }
1108- }
1109- if (!(move->tickle & mask))
1110- return 0;
1111- if (!state->active) {
1112- int type = getype[move->ntouch];
1113- if (!type)
1114- return 0;
1115- state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
1116- state->active = 1;
1117- }
1118- if (!(move->active & fm_mask))
1119- return 0;
1120- set_props(ge->gin, state, move, frame);
1121- gru_event(ge, state->gid, move, state->prop, state->nprop);
1122- return 1;
1123-}
1124-
1125-int gru_winpinch(struct grail *ge,
1126- const struct utouch_frame *frame)
1127-{
1128- struct gesture_recognizer *gru = ge->gru;
1129- struct combo_model *state = &gru->winpinch;
1130- struct move_model *move = &gru->move;
1131- int mask = state->active ? (move->active & fm_mask) : fm_mask;
1132- if (!move->multi) {
1133- if (state->active && out_of_bounds(state, move)) {
1134- gru_end(ge, state->gid, move,
1135- state->prop, state->nprop);
1136- state->active = 0;
1137- }
1138- return 0;
1139- }
1140- if ((move->timeout & fm_mask) == fm_mask) {
1141- if (state->active) {
1142- gin_gid_timeout(ge, state->gid);
1143- }
1144- }
1145- if (!(move->tickle & mask))
1146- return 0;
1147- if (!state->active) {
1148- if (move->ntouch == 4) {
1149- state->gid = gin_gid_begin(ge, GRAIL_TYPE_MPINCH,
1150- PRIO_META, frame);
1151- state->mintouch = 2;
1152- state->maxtouch = 4;
1153- state->active = 1;
1154- } else if (move->ntouch == 3) {
1155- state->gid = gin_gid_begin(ge, GRAIL_TYPE_EPINCH,
1156- PRIO_ENV, frame);
1157- state->mintouch = 2;
1158- state->maxtouch = 3;
1159- state->active = 1;
1160- } else {
1161- return 0;
1162- }
1163- }
1164- if (!(move->active & fm_mask))
1165- return 0;
1166- set_props(ge->gin, state, move, frame);
1167- gru_event(ge, state->gid, move, state->prop, state->nprop);
1168- return 1;
1169-}
1170
1171=== removed file 'src/gestures-rotate.c'
1172--- src/gestures-rotate.c 2011-06-03 12:54:23 +0000
1173+++ src/gestures-rotate.c 1970-01-01 00:00:00 +0000
1174@@ -1,130 +0,0 @@
1175-/*****************************************************************************
1176- *
1177- * grail - Gesture Recognition And Instantiation Library
1178- *
1179- * Copyright (C) 2010-2011 Canonical Ltd.
1180- *
1181- * This program is free software: you can redistribute it and/or modify it
1182- * under the terms of the GNU General Public License as published by the
1183- * Free Software Foundation, either version 3 of the License, or (at your
1184- * option) any later version.
1185- *
1186- * This program is distributed in the hope that it will be useful, but
1187- * WITHOUT ANY WARRANTY; without even the implied warranty of
1188- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1189- * General Public License for more details.
1190- *
1191- * You should have received a copy of the GNU General Public License along
1192- * with this program. If not, see <http://www.gnu.org/licenses/>.
1193- *
1194- ****************************************************************************/
1195-
1196-#include "grail-recognizer.h"
1197-#include <math.h>
1198-#include <stdio.h>
1199-
1200-static const int getype[DIM_TOUCH + 1] = {
1201- 0,
1202- 0,
1203- GRAIL_TYPE_ROTATE2,
1204- GRAIL_TYPE_ROTATE3,
1205- GRAIL_TYPE_ROTATE4,
1206- GRAIL_TYPE_ROTATE5,
1207-};
1208-
1209-static const int fm_mask = 0x08;
1210-
1211-static void set_props(const struct gesture_inserter *gin,
1212- struct combo_model *s, const struct move_model *m,
1213- const struct utouch_frame *frame)
1214-{
1215- s->prop[GRAIL_PROP_ROTATE_DA] = m->fm[FM_A].action_delta;
1216- s->prop[GRAIL_PROP_ROTATE_VA] = m->fm[FM_A].velocity;
1217- s->prop[GRAIL_PROP_ROTATE_A] = m->fm[FM_A].value;
1218- s->prop[GRAIL_PROP_ROTATE_X] = m->fm[FM_X].value;
1219- s->prop[GRAIL_PROP_ROTATE_Y] = m->fm[FM_Y].value;
1220- s->nprop = 5;
1221- s->nprop += gin_add_contact_props(gin, s->prop + s->nprop, frame);
1222-}
1223-
1224-int gru_rotate(struct grail *ge,
1225- const struct utouch_frame *frame)
1226-{
1227- struct gesture_recognizer *gru = ge->gru;
1228- struct combo_model *state = &gru->rotate;
1229- struct move_model *move = &gru->move;
1230- int mask = state->active ? (move->active & fm_mask) : fm_mask;
1231- if (!move->multi && !move->single) {
1232- if (state->active) {
1233- gru_end(ge, state->gid, move,
1234- state->prop, state->nprop);
1235- state->active = 0;
1236- }
1237- return 0;
1238- }
1239- if ((move->timeout & fm_mask) == fm_mask) {
1240- if (state->active) {
1241- gin_gid_timeout(ge, state->gid);
1242- }
1243- }
1244- if (!(move->tickle & mask))
1245- return 0;
1246- if (!state->active) {
1247- int type = getype[move->ntouch];
1248- if (!type)
1249- return 0;
1250- state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
1251- state->active = 1;
1252- }
1253- if (!(move->active & fm_mask))
1254- return 0;
1255- set_props(ge->gin, state, move, frame);
1256- gru_event(ge, state->gid, move, state->prop, state->nprop);
1257- return 1;
1258-}
1259-
1260-int gru_winrotate(struct grail *ge,
1261- const struct utouch_frame *frame)
1262-{
1263- struct gesture_recognizer *gru = ge->gru;
1264- struct combo_model *state = &gru->winrotate;
1265- struct move_model *move = &gru->move;
1266- int mask = state->active ? (move->active & fm_mask) : fm_mask;
1267- if (!move->multi) {
1268- if (state->active && out_of_bounds(state, move)) {
1269- gru_end(ge, state->gid, move,
1270- state->prop, state->nprop);
1271- state->active = 0;
1272- }
1273- return 0;
1274- }
1275- if ((move->timeout & fm_mask) == fm_mask) {
1276- if (state->active) {
1277- gin_gid_timeout(ge, state->gid);
1278- }
1279- }
1280- if (!(move->tickle & mask))
1281- return 0;
1282- if (!state->active) {
1283- if (move->ntouch == 4) {
1284- state->gid = gin_gid_begin(ge, GRAIL_TYPE_MROTATE,
1285- PRIO_META, frame);
1286- state->mintouch = 2;
1287- state->maxtouch = 4;
1288- state->active = 1;
1289- } else if (move->ntouch == 3) {
1290- state->gid = gin_gid_begin(ge, GRAIL_TYPE_EROTATE,
1291- PRIO_ENV, frame);
1292- state->mintouch = 2;
1293- state->maxtouch = 3;
1294- state->active = 1;
1295- } else {
1296- return 0;
1297- }
1298- }
1299- if (!(move->active & fm_mask))
1300- return 0;
1301- set_props(ge->gin, state, move, frame);
1302- gru_event(ge, state->gid, move, state->prop, state->nprop);
1303- return 1;
1304-}
1305
1306=== removed file 'src/gestures-tapping.c'
1307--- src/gestures-tapping.c 2011-04-28 16:53:57 +0000
1308+++ src/gestures-tapping.c 1970-01-01 00:00:00 +0000
1309@@ -1,100 +0,0 @@
1310-/*****************************************************************************
1311- *
1312- * grail - Gesture Recognition And Instantiation Library
1313- *
1314- * Copyright (C) 2010-2011 Canonical Ltd.
1315- *
1316- * This program is free software: you can redistribute it and/or modify it
1317- * under the terms of the GNU General Public License as published by the
1318- * Free Software Foundation, either version 3 of the License, or (at your
1319- * option) any later version.
1320- *
1321- * This program is distributed in the hope that it will be useful, but
1322- * WITHOUT ANY WARRANTY; without even the implied warranty of
1323- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1324- * General Public License for more details.
1325- *
1326- * You should have received a copy of the GNU General Public License along
1327- * with this program. If not, see <http://www.gnu.org/licenses/>.
1328- *
1329- ****************************************************************************/
1330-
1331-#include "grail-recognizer.h"
1332-#include <math.h>
1333-
1334-static const int fm_mask = 0x07;
1335-
1336-static void set_props(const struct gesture_inserter *gin,
1337- struct tapping_model *s, const struct move_model *m,
1338- const struct utouch_frame *frame)
1339-{
1340- s->prop[GRAIL_PROP_TAP_DT] = m->time - s->start;
1341- s->prop[GRAIL_PROP_TAP_X] = m->fm[FM_X].value;
1342- s->prop[GRAIL_PROP_TAP_Y] = m->fm[FM_Y].value;
1343- s->nprop = 3;
1344- s->nprop += gin_add_contact_props(gin, s->prop + s->nprop, frame);
1345-}
1346-
1347-int gru_tapping(struct grail *ge,
1348- const struct utouch_frame *frame)
1349-{
1350- struct gesture_recognizer *gru = ge->gru;
1351- struct tapping_model *state = &gru->tapping;
1352- struct move_model *move = &gru->move;
1353- state->tap = 0;
1354- if (frame->num_active && !frame->prev->num_active) {
1355- state->mintouch = 0;
1356- state->maxtouch = 0;
1357- }
1358- if (move->ntouch > state->maxtouch) {
1359- if (state->active) {
1360- gin_gid_discard(ge, state->gid);
1361- state->active = 0;
1362- }
1363- state->start = move->time;
1364- state->maxtouch = move->ntouch;
1365- set_props(ge->gin, state, move, frame);
1366- if (state->maxtouch <= 5) {
1367- int type = GRAIL_TYPE_TAP1 + state->maxtouch - 1;
1368- state->gid = gin_gid_begin(ge, type, PRIO_TAP, frame);
1369- state->active = 1;
1370- }
1371- return 0;
1372- }
1373- if (!state->active) {
1374- state->mintouch = move->ntouch;
1375- state->maxtouch = move->ntouch;
1376- return 0;
1377- }
1378- if (move->ntouch <= state->mintouch) {
1379- int x = state->prop[GRAIL_PROP_TAP_X];
1380- int y = state->prop[GRAIL_PROP_TAP_Y];
1381- int t = move->time - state->start;
1382- if (t > move->fm[FM_X].bar_ms) {
1383- gin_gid_discard(ge, state->gid);
1384- state->mintouch = move->ntouch;
1385- state->maxtouch = move->ntouch;
1386- state->active = 0;
1387- return 0;
1388- }
1389- state->tap = state->maxtouch;
1390- state->prop[GRAIL_PROP_TAP_DT] = t;
1391- gin_gid_event(ge, state->gid, x, y, state->maxtouch,
1392- state->prop, state->nprop, 1);
1393- state->mintouch = move->ntouch;
1394- state->maxtouch = move->ntouch;
1395- state->active = 0;
1396- return 1;
1397- }
1398- if (!move->ntouch)
1399- return 0;
1400- state->prop[GRAIL_PROP_TAP_DT] = move->time - state->start;
1401- if ((move->active & fm_mask) ||
1402- move->time - state->start > move->fm[FM_X].bar_ms) {
1403- gin_gid_discard(ge, state->gid);
1404- state->mintouch = move->ntouch;
1405- state->maxtouch = move->ntouch;
1406- state->active = 0;
1407- }
1408- return 0;
1409-}
1410
1411=== removed file 'src/gestures-touch.c'
1412--- src/gestures-touch.c 2011-04-04 17:27:38 +0000
1413+++ src/gestures-touch.c 1970-01-01 00:00:00 +0000
1414@@ -1,98 +0,0 @@
1415-/*****************************************************************************
1416- *
1417- * grail - Gesture Recognition And Instantiation Library
1418- *
1419- * Copyright (C) 2010 Canonical Ltd.
1420- * Copyright (C) 2010 Henrik Rydberg <rydberg@bitmath.org>
1421- *
1422- * This program is free software: you can redistribute it and/or modify it
1423- * under the terms of the GNU General Public License as published by the
1424- * Free Software Foundation, either version 3 of the License, or (at your
1425- * option) any later version.
1426- *
1427- * This program is distributed in the hope that it will be useful, but
1428- * WITHOUT ANY WARRANTY; without even the implied warranty of
1429- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1430- * General Public License for more details.
1431- *
1432- * You should have received a copy of the GNU General Public License along
1433- * with this program. If not, see <http://www.gnu.org/licenses/>.
1434- *
1435- ****************************************************************************/
1436-
1437-#include "grail-recognizer.h"
1438-#include <math.h>
1439-#include <stdio.h>
1440-
1441-static const int getype[DIM_TOUCH + 1] = {
1442- -1,
1443- GRAIL_TYPE_TOUCH1,
1444- GRAIL_TYPE_TOUCH2,
1445- GRAIL_TYPE_TOUCH3,
1446- GRAIL_TYPE_TOUCH4,
1447- GRAIL_TYPE_TOUCH5,
1448-};
1449-
1450-int gru_touch(struct grail *ge,
1451- const struct utouch_frame *frame)
1452-{
1453- struct gesture_recognizer *gru = ge->gru;
1454- struct combo_model *state = &gru->touch;
1455- struct move_model *move = &gru->move;
1456- if (frame->slot_revision != frame->prev->slot_revision) {
1457- if (state->active) {
1458- gru_end(ge, state->gid, move,
1459- state->prop, state->nprop);
1460- state->active = 0;
1461- }
1462- }
1463- if (!state->active) {
1464- int type = getype[move->ntouch];
1465- if (type <= 0)
1466- return 0;
1467- state->gid = gin_gid_begin(ge, type, -PRIO_GESTURE, frame);
1468- state->active = 1;
1469- }
1470- if (move->time - move->fm[FM_X].original_ms <= move->fm[FM_X].hold_ms)
1471- return 0;
1472- state->nprop = gin_add_contact_props(ge->gin, state->prop, frame);
1473- gru_event(ge, state->gid, move, state->prop, state->nprop);
1474- return 1;
1475-}
1476-
1477-int gru_wintouch(struct grail *ge,
1478- const struct utouch_frame *frame)
1479-{
1480- struct gesture_recognizer *gru = ge->gru;
1481- struct combo_model *state = &gru->wintouch;
1482- struct move_model *move = &gru->move;
1483- if (frame->slot_revision != frame->prev->slot_revision) {
1484- if (state->active && out_of_bounds(state, move)) {
1485- gru_end(ge, state->gid, move,
1486- state->prop, state->nprop);
1487- state->active = 0;
1488- }
1489- }
1490- if (!state->active) {
1491- if (move->ntouch == 4) {
1492- state->gid = gin_gid_begin(ge, GRAIL_TYPE_MTOUCH,
1493- -PRIO_META, frame);
1494- state->mintouch = 1;
1495- state->maxtouch = 4;
1496- state->active = 1;
1497- } else if (move->ntouch == 3) {
1498- state->gid = gin_gid_begin(ge, GRAIL_TYPE_ETOUCH,
1499- -PRIO_ENV, frame);
1500- state->mintouch = 1;
1501- state->maxtouch = 3;
1502- state->active = 1;
1503- } else {
1504- return 0;
1505- }
1506- }
1507- if (move->time - move->fm[FM_X].original_ms <= move->fm[FM_X].hold_ms)
1508- return 0;
1509- state->nprop = gin_add_contact_props(ge->gin, state->prop, frame);
1510- gru_event(ge, state->gid, move, state->prop, state->nprop);
1511- return 1;
1512-}
1513
1514=== removed file 'src/grail-api.c'
1515--- src/grail-api.c 2011-08-31 17:20:48 +0000
1516+++ src/grail-api.c 1970-01-01 00:00:00 +0000
1517@@ -1,328 +0,0 @@
1518-/*****************************************************************************
1519- *
1520- * grail - Gesture Recognition And Instantiation Library
1521- *
1522- * Copyright (C) 2010-2011 Canonical Ltd.
1523- *
1524- * This program is free software: you can redistribute it and/or modify it
1525- * under the terms of the GNU General Public License as published by the
1526- * Free Software Foundation, either version 3 of the License, or (at your
1527- * option) any later version.
1528- *
1529- * This program is distributed in the hope that it will be useful, but
1530- * WITHOUT ANY WARRANTY; without even the implied warranty of
1531- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1532- * General Public License for more details.
1533- *
1534- * You should have received a copy of the GNU General Public License along
1535- * with this program. If not, see <http://www.gnu.org/licenses/>.
1536- *
1537- ****************************************************************************/
1538-
1539-#include "grail-impl.h"
1540-#include "grail-inserter.h"
1541-#include "grail-recognizer.h"
1542-#include <string.h>
1543-#include <stdio.h>
1544-#include <unistd.h>
1545-#include <fcntl.h>
1546-#include <malloc.h>
1547-#include <errno.h>
1548-#include <stdlib.h>
1549-#include <sys/stat.h>
1550-
1551-#define DIM_FRAMES 100
1552-#define FRAME_RATE 100
1553-
1554-unsigned int GRAIL_PUBLIC grail_get_version(void)
1555-{
1556- return GRAIL_VERSION;
1557-}
1558-
1559-int GRAIL_PUBLIC grail_open(struct grail *ge, int fd)
1560-{
1561- struct grail_impl *x;
1562- struct stat fs;
1563- int ret;
1564-
1565- ret = fstat(fd, &fs);
1566- if (ret)
1567- return ret;
1568-
1569- x = calloc(1, sizeof(*x));
1570- if (!x)
1571- return -ENOMEM;
1572-
1573- if (!fs.st_rdev)
1574- x->fptest = fdopen(fd, "r");
1575-
1576- x->evemu = evemu_new(x->fptest ? "fptest" : 0);
1577- if (!x->evemu) {
1578- ret = -ENOMEM;
1579- goto freemem;
1580- }
1581- if (x->fptest)
1582- ret = evemu_read(x->evemu, x->fptest) <= 0;
1583- else
1584- ret = evemu_extract(x->evemu, fd);
1585- if (ret)
1586- goto freemem;
1587- if (!utouch_frame_is_supported_mtdev(x->evemu)) {
1588- ret = -ENODEV;
1589- goto freemem;
1590- }
1591-
1592- if (!x->fptest) {
1593- x->mtdev = mtdev_new_open(fd);
1594- if (!x->mtdev) {
1595- ret = -ENOMEM;
1596- goto freemem;
1597- }
1598- }
1599- x->fh = utouch_frame_new_engine(DIM_FRAMES, DIM_TOUCH, FRAME_RATE);
1600- if (!x->fh) {
1601- ret = -ENOMEM;
1602- goto freedev;
1603- }
1604- ret = utouch_frame_init_mtdev(x->fh, x->evemu);
1605- if (ret)
1606- goto freeframe;
1607-
1608- ge->impl = x;
1609-
1610- ret = gin_init(ge);
1611- if (ret)
1612- goto freeframe;
1613-
1614- ret = gru_init(ge);
1615- if (ret)
1616- goto freegin;
1617-
1618- return 0;
1619- freegin:
1620- gin_destroy(ge);
1621- freeframe:
1622- utouch_frame_delete_engine(x->fh);
1623- freedev:
1624- if (x->mtdev)
1625- mtdev_close_delete(x->mtdev);
1626- freemem:
1627- evemu_delete(x->evemu);
1628- if (x->fptest)
1629- fclose(x->fptest);
1630- free(x);
1631- ge->impl = 0;
1632- return ret;
1633-}
1634-
1635-void GRAIL_PUBLIC grail_close(struct grail *ge, int fd)
1636-{
1637- struct grail_impl *x = ge->impl;
1638- gru_destroy(ge);
1639- gin_destroy(ge);
1640- utouch_frame_delete_engine(x->fh);
1641- if (x->mtdev)
1642- mtdev_close_delete(x->mtdev);
1643- evemu_delete(x->evemu);
1644- if (x->fptest)
1645- fclose(x->fptest);
1646- free(x);
1647- ge->impl = 0;
1648-}
1649-
1650-int GRAIL_PUBLIC grail_idle(struct grail *ge, int fd, int ms)
1651-{
1652- struct grail_impl *x = ge->impl;
1653- if (x->fptest)
1654- return 0;
1655- if (x->mtdev)
1656- return mtdev_idle(x->mtdev, fd, ms);
1657- return 1;
1658-}
1659-
1660-void GRAIL_PUBLIC grail_get_units(const struct grail *ge,
1661- struct grail_coord *min, struct grail_coord *max)
1662-{
1663- struct utouch_surface *s = utouch_frame_get_surface(ge->impl->fh);
1664- min->x = s->min_x;
1665- min->y = s->min_y;
1666- max->x = s->max_x;
1667- max->y = s->max_y;
1668-}
1669-
1670-const struct utouch_frame GRAIL_PUBLIC *
1671-grail_get_contact_frame(const struct grail *ge)
1672-{
1673- return ge->impl->touch;
1674-}
1675-
1676-static void flush_events(struct grail *ge)
1677-{
1678- struct grail_impl *impl = ge->impl;
1679- struct input_event iev;
1680-
1681- grailbuf_clear(&impl->gbuf);
1682- while (!evbuf_empty(&impl->evbuf)) {
1683- evbuf_get(&impl->evbuf, &iev);
1684- if (ge->event)
1685- ge->event(ge, &iev);
1686- }
1687-}
1688-
1689-static int skip_event(const struct input_event *ev, int count)
1690-{
1691- switch (ev->type) {
1692- case EV_ABS:
1693- return 1;
1694- case EV_KEY:
1695- return ev->code >= BTN_DIGI && ev->code < BTN_WHEEL;
1696- case EV_SYN:
1697- switch (ev->code) {
1698- case SYN_MT_REPORT:
1699- return 1;
1700- case SYN_REPORT:
1701- return count == 0;
1702- default:
1703- return 0;
1704- }
1705- default:
1706- return 0;
1707- }
1708-}
1709-
1710-static void flush_gestures(struct grail *ge)
1711-{
1712- struct grail_impl *impl = ge->impl;
1713- struct input_event iev;
1714- struct grail_event gev;
1715- int count = 0;
1716-
1717- while (!evbuf_empty(&impl->evbuf)) {
1718- evbuf_get(&impl->evbuf, &iev);
1719- if (skip_event(&iev, count))
1720- continue;
1721- if (ge->event)
1722- ge->event(ge, &iev);
1723- if (iev.type == EV_SYN && iev.code == SYN_REPORT)
1724- count = 0;
1725- else
1726- count++;
1727- }
1728- while (!grailbuf_empty(&impl->gbuf)) {
1729- grailbuf_get(&impl->gbuf, &gev);
1730- if (ge->gesture)
1731- ge->gesture(ge, &gev);
1732- }
1733-}
1734-
1735-static int gesture_timeout(struct grail *ge, const struct utouch_frame *frame)
1736-{
1737- struct gesture_recognizer *gru = ge->gru;
1738- struct gesture_inserter *gin = ge->gin;
1739-
1740- return grail_mask_count(gin->used, sizeof(gin->used)) == 0 &&
1741- frame->time - frame->mod_time > gru->move.fm[FM_X].hold_ms;
1742-}
1743-
1744-static void report_frame(struct grail *ge,
1745- const struct utouch_frame *touch,
1746- const struct input_event *syn)
1747-{
1748- struct grail_impl *impl = ge->impl;
1749-
1750- impl->touch = touch;
1751-
1752- if (touch->num_active && !touch->prev->num_active) {
1753- impl->ongoing = 1;
1754- impl->gesture = 0;
1755- }
1756-
1757- if (!impl->ongoing)
1758- return;
1759-
1760- gin_frame_begin(ge, touch);
1761- gru_recognize(ge, touch);
1762- gin_frame_end(ge, touch);
1763-
1764- if (!grailbuf_empty(&impl->gbuf))
1765- impl->gesture = 1;
1766-
1767- if (touch->num_active == 0 || gesture_timeout(ge, touch))
1768- impl->ongoing &= impl->gesture;
1769-}
1770-
1771-static void grail_pump_mtdev(struct grail *ge, const struct input_event *ev)
1772-{
1773- struct grail_impl *impl = ge->impl;
1774- const struct utouch_frame *frame;
1775-
1776- evbuf_put(&impl->evbuf, ev);
1777-
1778- if (ev->type == EV_SYN || ev->type == EV_ABS || ev->type == EV_KEY) {
1779- frame = utouch_frame_pump_mtdev(impl->fh, ev);
1780- if (frame)
1781- report_frame(ge, frame, ev);
1782- }
1783-
1784- if (ev->type == EV_SYN) {
1785- if (!impl->ongoing)
1786- flush_events(ge);
1787- if (impl->gesture)
1788- flush_gestures(ge);
1789- }
1790-}
1791-
1792-/**
1793- * Read an event from the given file. If fast_fileread is true,
1794- * return immediately. If it is false, delay between events
1795- * so it looks like they are coming in real time.
1796- */
1797-static int grail_read_evemu_event(FILE *fp, struct input_event *ev,
1798- struct timeval *evtime, int fast_fileread) {
1799- if (fast_fileread)
1800- return evemu_read_event(fp, ev);
1801- return evemu_read_event_realtime(fp, ev, evtime);
1802-}
1803-
1804-
1805-static int grail_pull_fstest(struct grail *ge, int fd)
1806-{
1807- struct grail_impl *impl = ge->impl;
1808- struct input_event ev;
1809- struct timeval evtime;
1810- int count = 0;
1811-
1812- memset(&evtime, 0, sizeof(evtime));
1813- while (grail_read_evemu_event(impl->fptest, &ev, &evtime, impl->fast_fileread) > 0) {
1814- grail_pump_mtdev(ge, &ev);
1815- count++;
1816- }
1817-
1818- fclose(impl->fptest);
1819- impl->fptest = 0;
1820-
1821- return count > 0 ? count : -1;
1822-}
1823-
1824-int GRAIL_PUBLIC grail_pull(struct grail *ge, int fd)
1825-{
1826- struct grail_impl *impl = ge->impl;
1827- struct input_event ev;
1828- int ret, count = 0;
1829-
1830- if (impl->fptest)
1831- return grail_pull_fstest(ge, fd);
1832-
1833- while ((ret = mtdev_get(impl->mtdev, fd, &ev, 1)) > 0) {
1834- grail_pump_mtdev(ge, &ev);
1835- count++;
1836- }
1837-
1838- return count > 0 ? count : ret;
1839-}
1840-
1841-void GRAIL_PUBLIC grail_set_coordinate_transform_callback(struct grail *ge,
1842- utouch_coordinate_transform_cb callback,
1843- void *user_data) {
1844- utouch_frame_set_coordinate_transform_callback(ge->impl->fh, callback, user_data);
1845-}
1846
1847=== removed file 'src/grail-bits.c'
1848--- src/grail-bits.c 2011-04-28 16:53:57 +0000
1849+++ src/grail-bits.c 1970-01-01 00:00:00 +0000
1850@@ -1,93 +0,0 @@
1851-/*****************************************************************************
1852- *
1853- * grail - Gesture Recognition And Instantiation Library
1854- *
1855- * Copyright (C) 2010-2011 Canonical Ltd.
1856- *
1857- * This program is free software: you can redistribute it and/or modify it
1858- * under the terms of the GNU General Public License as published by the
1859- * Free Software Foundation, either version 3 of the License, or (at your
1860- * option) any later version.
1861- *
1862- * This program is distributed in the hope that it will be useful, but
1863- * WITHOUT ANY WARRANTY; without even the implied warranty of
1864- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1865- * General Public License for more details.
1866- *
1867- * You should have received a copy of the GNU General Public License along
1868- * with this program. If not, see <http://www.gnu.org/licenses/>.
1869- *
1870- ****************************************************************************/
1871-
1872-#include "grail-bits.h"
1873-
1874-static const int grail_bits_in_byte[256] =
1875-{
1876- 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
1877- 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1878- 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1879- 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1880- 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1881- 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1882- 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1883- 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
1884-};
1885-
1886-static const int grail_first_set_bit[256] =
1887-{
1888- -1,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
1889- 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
1890- 6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
1891- 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
1892- 7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
1893- 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
1894- 6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
1895- 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
1896-};
1897-
1898-void GRAIL_PUBLIC grail_mask_set_mask(grail_mask_t *a, const grail_mask_t *b,
1899- int bytes)
1900-{
1901- while (bytes--)
1902- *a++ |= *b++;
1903-}
1904-
1905-void GRAIL_PUBLIC grail_mask_clear_mask(grail_mask_t *a, const grail_mask_t *b,
1906- int bytes)
1907-{
1908- while (bytes--)
1909- *a++ &= ~*b++;
1910-}
1911-
1912-int GRAIL_PUBLIC grail_mask_count(const grail_mask_t *mask, int bytes)
1913-{
1914- int count = 0;
1915- while (bytes--)
1916- count += grail_bits_in_byte[*mask++];
1917- return count;
1918-}
1919-
1920-int GRAIL_PUBLIC grail_mask_get_first(const grail_mask_t *mask, int bytes)
1921-{
1922- int k;
1923- for (k = 0; k < bytes; k++)
1924- if (mask[k])
1925- return (k << 3) | grail_first_set_bit[mask[k]];
1926- return -1;
1927-}
1928-
1929-int GRAIL_PUBLIC grail_mask_get_next(int i, const grail_mask_t *mask, int bytes)
1930-{
1931- int k = ++i >> 3;
1932- if (k < bytes) {
1933- i = grail_first_set_bit[mask[k] & (~0 << (i & 7))];
1934- if (i >= 0)
1935- return (k << 3) | i;
1936- while (++k < bytes) {
1937- i = grail_first_set_bit[mask[k]];
1938- if (i >= 0)
1939- return (k << 3) | i;
1940- }
1941- }
1942- return -1;
1943-}
1944
1945=== removed file 'src/grail-event.c'
1946--- src/grail-event.c 2011-08-31 17:45:31 +0000
1947+++ src/grail-event.c 1970-01-01 00:00:00 +0000
1948@@ -1,118 +0,0 @@
1949-/*****************************************************************************
1950- *
1951- * grail - Gesture Recognition And Instantiation Library
1952- *
1953- * Copyright (C) 2010-2011 Canonical Ltd.
1954- *
1955- * This program is free software: you can redistribute it and/or modify it
1956- * under the terms of the GNU General Public License as published by the
1957- * Free Software Foundation, either version 3 of the License, or (at your
1958- * option) any later version.
1959- *
1960- * This program is distributed in the hope that it will be useful, but
1961- * WITHOUT ANY WARRANTY; without even the implied warranty of
1962- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1963- * General Public License for more details.
1964- *
1965- * You should have received a copy of the GNU General Public License along
1966- * with this program. If not, see <http://www.gnu.org/licenses/>.
1967- *
1968- ****************************************************************************/
1969-
1970-#include "grail-inserter.h"
1971-#include "grail-impl.h"
1972-#include <malloc.h>
1973-#include <string.h>
1974-#include <errno.h>
1975-#include <math.h>
1976-
1977-static void compute_bbox(struct grail_coord *min, struct grail_coord *max,
1978- const struct utouch_frame *frame)
1979-{
1980- float x, y;
1981- int i;
1982- if (frame->num_active < 1)
1983- return;
1984- x = frame->active[0]->x;
1985- y = frame->active[0]->y;
1986- min->x = max->x = x;
1987- min->y = max->y = y;
1988- for (i = 1; i < frame->num_active; i++) {
1989- x = frame->active[i]->x;
1990- y = frame->active[i]->y;
1991- if (x < min->x)
1992- min->x = x;
1993- if (y < min->y)
1994- min->y = y;
1995- if (x > max->x)
1996- max->x = x;
1997- if (y > max->y)
1998- max->y = y;
1999- }
2000-}
2001-
2002-int gin_add_contact_props(const struct gesture_inserter *gin,
2003- grail_prop_t *prop, const struct utouch_frame *frame)
2004-{
2005- struct grail_coord min = { 0, 0 };
2006- struct grail_coord max = { 0, 0 };
2007- int i, n = 0, ntouch = frame->num_active;
2008- if (!ntouch)
2009- return n;
2010- if (ntouch > 5)
2011- ntouch = 5;
2012- compute_bbox(&min, &max, frame);
2013- prop[n++] = min.x;
2014- prop[n++] = min.y;
2015- prop[n++] = max.x;
2016- prop[n++] = max.y;
2017- for (i = 0; i < ntouch; i++) {
2018- const struct utouch_contact *ct = frame->active[i];
2019- prop[n++] = ct->id;
2020- prop[n++] = ct->x;
2021- prop[n++] = ct->y;
2022- }
2023- return n;
2024-}
2025-
2026-int gin_get_clients(struct grail *ge,
2027- struct grail_client_info *info, int maxinfo,
2028- const grail_mask_t* types, int btypes,
2029- const grail_mask_t* span, int bspan,
2030- const struct utouch_frame *frame)
2031-{
2032- struct grail_coord pos[DIM_TOUCH];
2033- int i, npos = 0;
2034- if (!ge->get_clients)
2035- return 0;
2036- grail_mask_foreach(i, span, bspan) {
2037- pos[npos].x = frame->slots[i]->x;
2038- pos[npos].y = frame->slots[i]->y;
2039- npos++;
2040- }
2041- return ge->get_clients(ge, info, maxinfo, pos, npos, types, btypes);
2042-}
2043-
2044-void gin_send_event(struct grail *ge, struct slot_state *s,
2045- const struct gesture_event *ev,
2046- const struct utouch_frame *frame)
2047-{
2048- struct grail_impl *impl = ge->impl;
2049- struct grail_event gev;
2050- int i;
2051- if (!ge->gesture)
2052- return;
2053- gev.type = s->type;
2054- gev.id = s->id;
2055- gev.status = ev->status;
2056- gev.ntouch = ev->ntouch;
2057- gev.nprop = ev->nprop;
2058- gev.time = ev->time;
2059- gev.pos.x = ev->pos.x;
2060- gev.pos.y = ev->pos.y;
2061- memcpy(gev.prop, ev->prop, ev->nprop * sizeof(grail_prop_t));
2062- for (i = 0; i < s->nclient; i++) {
2063- gev.client_id = s->client_id[i];
2064- grailbuf_put(&impl->gbuf, &gev);
2065- }
2066-}
2067
2068=== removed file 'src/grail-frame.c'
2069--- src/grail-frame.c 2011-08-31 17:20:48 +0000
2070+++ src/grail-frame.c 1970-01-01 00:00:00 +0000
2071@@ -1,410 +0,0 @@
2072-/*****************************************************************************
2073- *
2074- * grail - Gesture Recognition And Instantiation Library
2075- *
2076- * Copyright (C) 2010-2011 Canonical Ltd.
2077- *
2078- * This program is free software: you can redistribute it and/or modify it
2079- * under the terms of the GNU General Public License as published by the
2080- * Free Software Foundation, either version 3 of the License, or (at your
2081- * option) any later version.
2082- *
2083- * This program is distributed in the hope that it will be useful, but
2084- * WITHOUT ANY WARRANTY; without even the implied warranty of
2085- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2086- * General Public License for more details.
2087- *
2088- * You should have received a copy of the GNU General Public License along
2089- * with this program. If not, see <http://www.gnu.org/licenses/>.
2090- *
2091- ****************************************************************************/
2092-
2093-#include "grail-impl.h"
2094-#include <stdlib.h>
2095-#include <string.h>
2096-#include <math.h>
2097-
2098-static void set_center_velocity_and_radius(struct grail_impl *impl,
2099- struct grail_element *slot)
2100-{
2101- const struct utouch_contact **tc = slot->touches;
2102- double x, y, vx, vy, r2, dx, dy;
2103- int i;
2104-
2105- switch (slot->num_touches) {
2106- case 1:
2107- x = tc[0]->x;
2108- y = tc[0]->y;
2109- vx = tc[0]->vx;
2110- vy = tc[0]->vy;
2111- r2 = 0;
2112- break;
2113- case 2:
2114- dx = 0.5 * (tc[1]->x - tc[0]->x);
2115- dy = 0.5 * (tc[1]->y - tc[0]->y);
2116- x = tc[0]->x + dx;
2117- y = tc[0]->y + dy;
2118- vx = 0.5 * (tc[0]->vx + tc[1]->vx);
2119- vy = 0.5 * (tc[0]->vy + tc[1]->vy);
2120- r2 = dx * dx + dy * dy;
2121- break;
2122- default:
2123- x = y = vx = vy = r2 = 0;
2124- for (i = 0; i < slot->num_touches; i++) {
2125- x += tc[i]->x;
2126- y += tc[i]->y;
2127- vx += tc[i]->vx;
2128- vy += tc[i]->vy;
2129- }
2130- x /= slot->num_touches;
2131- y /= slot->num_touches;
2132- vx /= slot->num_touches;
2133- vy /= slot->num_touches;
2134- for (i = 0; i < slot->num_touches; i++) {
2135- dx = tc[i]->x - x;
2136- dy = tc[i]->y - y;
2137- r2 += dx * dx + dy * dy;
2138- }
2139- r2 /= slot->num_touches;
2140- break;
2141- }
2142-
2143- slot->center.x = x;
2144- slot->center.y = y;
2145- slot->velocity.x = 1000 * vx;
2146- slot->velocity.y = 1000 * vy;
2147- slot->radius2 = r2;
2148-}
2149-
2150-static void set_transform(struct grail_impl *impl, struct grail_element *slot,
2151- double ds, double dc)
2152-{
2153- const struct grail_element *pslot = slot->prev;
2154- double dx = slot->center.x - pslot->center.x;
2155- double dy = slot->center.y - pslot->center.y;
2156- float *T = slot->transform;
2157-
2158- T[0] = dc;
2159- T[1] = ds;
2160- T[2] = dx;
2161- T[3] = -ds;
2162- T[4] = dc;
2163- T[5] = dy;
2164-
2165- slot->drag.x = pslot->drag.x + dx;
2166- slot->drag.y = pslot->drag.y + dy;
2167-}
2168-
2169-static void start_slot(struct grail_impl *impl,
2170- struct grail_element *slot,
2171- const struct utouch_frame *touch)
2172-{
2173- float *T = slot->transform;
2174-
2175- slot->id = impl->seqid++ & GRAIL_ID_MAX;
2176- slot->expect_mask = GRAIL_EXPECT_MASK;
2177- slot->active_mask = 0;
2178- slot->start_time = touch->time;
2179- set_center_velocity_and_radius(impl, slot);
2180- T[0] = T[4] = 1;
2181- T[1] = T[2] = T[3] = T[5] = 0;
2182- slot->drag.x = 0;
2183- slot->drag.y = 0;
2184- slot->scale2 = 1;
2185- slot->angle = 0;
2186-}
2187-
2188-static void update_slot(struct grail_impl *impl,
2189- struct grail_element *slot,
2190- double ds, double dc)
2191-{
2192- const struct grail_element *pslot = slot->prev;
2193-
2194- slot->id = pslot->id;
2195- slot->start_time = pslot->start_time;
2196- slot->expect_mask = pslot->expect_mask;
2197- slot->active_mask = pslot->active_mask;
2198-
2199- set_center_velocity_and_radius(impl, slot);
2200- set_transform(impl, slot, ds, dc);
2201-
2202- slot->scale2 = pslot->scale2 * (ds * ds + dc * dc);
2203- slot->angle = pslot->angle + ds / dc; /* atan2(ds, dc) */
2204-}
2205-
2206-static void stop_slot(struct grail_impl *impl,
2207- struct grail_element *slot)
2208-{
2209- const struct grail_element *pslot = slot->prev;
2210- float *T = slot->transform;
2211-
2212- slot->id = -1;
2213- slot->num_touches = 0;
2214- slot->start_time = pslot->start_time;
2215- slot->expect_mask = 0;
2216- slot->active_mask = pslot->active_mask;
2217- slot->center = pslot->center;
2218- slot->velocity = pslot->velocity;
2219- slot->radius2 = pslot->radius2;
2220- T[0] = T[4] = 1;
2221- T[1] = T[2] = T[3] = T[5] = 0;
2222- slot->drag = pslot->drag;
2223- slot->scale2 = pslot->scale2;
2224- slot->angle = pslot->angle;
2225-}
2226-
2227-static void set_slot_one(struct grail_impl *impl,
2228- struct grail_element *slot,
2229- const struct utouch_frame *touch,
2230- const struct utouch_contact *t1)
2231-{
2232- const struct grail_element *pslot = slot->prev;
2233- const struct utouch_contact *p1 = pslot->touches[0];
2234-
2235- if (!t1->active) {
2236- stop_slot(impl, slot);
2237- return;
2238- }
2239-
2240- slot->touches[0] = t1;
2241- slot->num_touches = 1;
2242-
2243- if (pslot->num_touches != slot->num_touches || t1->id != p1->id) {
2244- start_slot(impl, slot, touch);
2245- return;
2246- }
2247-
2248- update_slot(impl, slot, 0, 1);
2249-}
2250-
2251-static void set_slot_two(struct grail_impl *impl,
2252- struct grail_element *slot,
2253- const struct utouch_frame *touch,
2254- const struct utouch_contact *t1,
2255- const struct utouch_contact *t2)
2256-{
2257- const struct grail_element *pslot = slot->prev;
2258- const struct utouch_contact *p1 = pslot->touches[0];
2259- const struct utouch_contact *p2 = pslot->touches[1];
2260- double tx, ty, px, py, d2;
2261-
2262- if (!t1->active || !t2->active) {
2263- stop_slot(impl, slot);
2264- return;
2265- }
2266-
2267- slot->touches[0] = t1;
2268- slot->touches[1] = t2;
2269- slot->num_touches = 2;
2270-
2271- if (pslot->num_touches != slot->num_touches ||
2272- t1->id != p1->id || t2->id != p2->id) {
2273- start_slot(impl, slot, touch);
2274- return;
2275- }
2276-
2277- tx = t2->x - t1->x;
2278- ty = t2->y - t1->y;
2279- px = p2->x - p1->x;
2280- py = p2->y - p1->y;
2281-
2282- d2 = px * px + py * py;
2283- if (d2 > 0) {
2284- px /= d2;
2285- py /= d2;
2286- }
2287-
2288- update_slot(impl, slot, tx * py - ty * px, tx * px + ty * py);
2289-}
2290-
2291-static void set_slot_multi(struct grail_impl *impl,
2292- struct grail_element *slot,
2293- struct grail_frame *frame,
2294- const struct utouch_frame *touch)
2295-{
2296- const struct grail_element *pslot = slot->prev;
2297- struct grail_element **slots = frame->slots;
2298- int i, j, n = impl->num_touches;
2299- struct grail_element *best = 0;
2300-
2301- if (touch->num_active < 3) {
2302- stop_slot(impl, slot);
2303- return;
2304- }
2305-
2306- memcpy(slot->touches, touch->active,
2307- touch->num_active * sizeof(slot->touches[0]));
2308- slot->num_touches = touch->num_active;
2309-
2310- if (pslot->num_touches != slot->num_touches) {
2311- start_slot(impl, slot, touch);
2312- return;
2313- }
2314-
2315- for (i = 0; i < slot->num_touches; i++) {
2316- if (slot->touches[i]->id != pslot->touches[i]->id) {
2317- start_slot(impl, slot, touch);
2318- return;
2319- }
2320- }
2321-
2322- for (i = 0; i < impl->num_touches; i++) {
2323- for (j = i + 1; j < impl->num_touches; j++) {
2324- struct grail_element *s = slots[n++];
2325- if (!s->num_touches)
2326- continue;
2327- if (!best || s->radius2 > best->radius2)
2328- best = s;
2329- }
2330- }
2331-
2332- update_slot(impl, slot, best->transform[1], best->transform[0]);
2333-}
2334-
2335-/**
2336- * Determine the center of rotation point.
2337- *
2338- * For any given point q that is transformed by a 2D affine transformation
2339- * matrix T about anchor point P the new point q' may be determined by the
2340- * following equation:
2341- *
2342- * q' = T * (q - P) + P
2343- *
2344- * T and P are dependent, so we can modify one and find a new value for the
2345- * other. We will label the original T and P as T0 and P0, and the new values
2346- * will be labeled T1 and P1. We can find new values by solving the following
2347- * equation:
2348- *
2349- * q' = T0 * (q - P0) + P0 = T1 * (q - P1) + P1
2350- *
2351- * In the calculations below, we use variables for the scalar values
2352- * that make up T0, P0, T1, and P1:
2353- *
2354- * T0: [ a -b c ] P0: [ x0 ] T1: [ a -b 0 ] P1: [ x1 ]
2355- * [ b a d ] [ y0 ] [ b a 0 ] [ y1 ]
2356- * [ 0 0 1 ] [ 0 ] [ 0 0 1 ] [ 0 ]
2357- *
2358- * Note that rotation and scaling are independent of the anchor point, so a and
2359- * b are equivalent between the transformation matrices.
2360- *
2361- * Since we know all the values of T0, P0, and T1, we can calculate the values
2362- * x1 and y1 in P1.
2363- */
2364-static inline int set_center_of_rotation(struct grail_element *e)
2365-{
2366- float a = e->transform[0];
2367- float b = e->transform[3];
2368- float c = e->transform[2];
2369- float d = e->transform[5];
2370- float x0 = e->center.x;
2371- float y0 = e->center.y;
2372- float x1;
2373- float y1;
2374-
2375- float div = a*a - 2*a + b*b + 1;
2376-
2377- if (fabsf(div) < 1e-5)
2378- return 0;
2379-
2380- x1 = (a*a*x0 - a*(2*x0+c) + b*b*x0 - b*d + c + x0) / div;
2381- y1 = (a*a*y0 - a*(2*y0+d) + b*b*y0 + b*c + d + y0) / div;
2382-
2383- e->rotation_center.x = x1;
2384- e->rotation_center.y = y1;
2385-
2386- return 1;
2387-}
2388-
2389-static void set_slots(struct grail_impl *impl,
2390- struct grail_frame *frame,
2391- const struct utouch_frame *touch)
2392-{
2393- struct grail_element **slots = frame->slots;
2394- struct utouch_contact *const *tc = touch->slots;
2395- int i, j, n = 0;
2396-
2397- for (i = 0; i < impl->num_touches; i++)
2398- set_slot_one(impl, slots[n++], touch, tc[i]);
2399-
2400- for (i = 0; i < impl->num_touches; i++)
2401- for (j = i + 1; j < impl->num_touches; j++)
2402- set_slot_two(impl, slots[n++], touch, tc[i], tc[j]);
2403-
2404- set_slot_multi(impl, slots[n++], frame, touch);
2405-}
2406-
2407-static void collect_transforms(struct grail_impl *impl,
2408- struct grail_frame *frame,
2409- const struct utouch_frame *touch)
2410-{
2411- const struct utouch_surface *s = utouch_frame_get_surface(impl->fh);
2412- const struct grail_control *ctl = impl->ctl;
2413- float d_x = ctl->bar_drag_x * (s->mapped_max_x - s->mapped_min_x);
2414- float d_y = ctl->bar_drag_y * (s->mapped_max_y - s->mapped_min_y);
2415- float ds2 = ctl->bar_scale * ctl->bar_scale;
2416- float dt;
2417- int i;
2418-
2419- for (i = 0; i < impl->num_slots; i++) {
2420- struct grail_element *s = frame->slots[i];
2421-
2422- if (!s->num_touches)
2423- continue;
2424-
2425- set_center_of_rotation(s);
2426-
2427- dt = touch->time - s->start_time;
2428- if (dt > ctl->glue_ms) {
2429- unsigned int mask = s->active_mask;
2430-
2431- if (fabs(s->drag.x) > d_x)
2432- mask |= GRAIL_EXPECT_DRAG_X;
2433- if (fabs(s->drag.y) > d_y)
2434- mask |= GRAIL_EXPECT_DRAG_Y;
2435- if (fabs(s->scale2 - 1) > ds2)
2436- mask |= GRAIL_EXPECT_SCALE;
2437- if (fabs(s->angle) > ctl->bar_angle)
2438- mask |= GRAIL_EXPECT_ANGLE;
2439-
2440- s->active_mask = mask;
2441-
2442- if (dt < ctl->drop_x_ms)
2443- mask |= GRAIL_EXPECT_DRAG_X;
2444- if (dt < ctl->drop_y_ms)
2445- mask |= GRAIL_EXPECT_DRAG_Y;
2446- if (dt < ctl->drop_scale_ms)
2447- mask |= GRAIL_EXPECT_SCALE;
2448- if (dt < ctl->drop_angle_ms)
2449- mask |= GRAIL_EXPECT_ANGLE;
2450-
2451- s->expect_mask &= mask;
2452- }
2453-
2454- frame->ongoing[frame->num_ongoing++] = s;
2455- }
2456-}
2457-
2458-const struct grail_frame GRAIL_PUBLIC *
2459-grail_pump_frame(grail_handle ge, const struct utouch_frame *touch)
2460-{
2461- struct grail_impl *impl = ge->impl;
2462- struct grail_frame *frame = impl->frames[impl->nextframe];
2463- const struct grail_frame *prev = frame->prev;
2464- int i;
2465-
2466- if (touch->slot_revision == touch->prev->slot_revision &&
2467- !prev->num_ongoing)
2468- return 0;
2469-
2470- frame->touch = touch;
2471- frame->num_ongoing = 0;
2472- for (i = 0; i < impl->num_slots; i++)
2473- frame->slots[i]->prev = prev->slots[i];
2474-
2475- set_slots(impl, frame, touch);
2476- collect_transforms(impl, frame, touch);
2477-
2478- impl->nextframe = (impl->nextframe + 1) % impl->num_frames;
2479-
2480- return frame;
2481-}
2482
2483=== renamed file 'src/grail-gestures.c' => 'src/grail-gestures.c.THIS'
2484=== removed file 'src/grail-gestures.h'
2485--- src/grail-gestures.h 2011-05-17 14:15:22 +0000
2486+++ src/grail-gestures.h 1970-01-01 00:00:00 +0000
2487@@ -1,115 +0,0 @@
2488-/*****************************************************************************
2489- *
2490- * grail - Gesture Recognition And Instantiation Library
2491- *
2492- * Copyright (C) 2010-2011 Canonical Ltd.
2493- *
2494- * This program is free software: you can redistribute it and/or modify it
2495- * under the terms of the GNU General Public License as published by the
2496- * Free Software Foundation, either version 3 of the License, or (at your
2497- * option) any later version.
2498- *
2499- * This program is distributed in the hope that it will be useful, but
2500- * WITHOUT ANY WARRANTY; without even the implied warranty of
2501- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2502- * General Public License for more details.
2503- *
2504- * You should have received a copy of the GNU General Public License along
2505- * with this program. If not, see <http://www.gnu.org/licenses/>.
2506- *
2507- ****************************************************************************/
2508-
2509-#ifndef GRAIL_GESTURES_H
2510-#define GRAIL_GESTURES_H
2511-
2512-#include "grail-inserter.h"
2513-
2514-#define PRIO_POINTER 1
2515-#define PRIO_GESTURE 2
2516-#define PRIO_ENV 3
2517-#define PRIO_META 4
2518-#define PRIO_TAP 5
2519-
2520-#define DIM_FM 4
2521-
2522-#define FM_X 0
2523-#define FM_Y 1
2524-#define FM_R 2
2525-#define FM_A 3
2526-
2527-struct filter_model {
2528- float raw_delta;
2529- float action_delta;
2530- float velocity;
2531- float value;
2532- float original;
2533- float sample;
2534- float fuzz;
2535- float bar;
2536- grail_time_t original_ms;
2537- grail_time_t sample_ms;
2538- grail_time_t hold_ms;
2539- grail_time_t bar_ms;
2540-};
2541-
2542-struct move_model {
2543- struct filter_model fm[DIM_FM];
2544- int tickle, active, timeout;
2545- int single, multi, ntouch;
2546- grail_time_t time;
2547-};
2548-
2549-void gru_init_motion(struct grail *ge);
2550-void gru_motion(struct grail *ge,
2551- const struct utouch_frame *frame);
2552-void gru_event(struct grail *ge, int gid,
2553- const struct move_model *move,
2554- const grail_prop_t *prop, int nprop);
2555-void gru_end(struct grail *ge, int gid,
2556- const struct move_model *move,
2557- const grail_prop_t *prop, int nprop);
2558-
2559-struct combo_model {
2560- int active, gid;
2561- int mintouch, maxtouch;
2562- int nprop;
2563- grail_prop_t prop[DIM_GRAIL_PROP];
2564-};
2565-
2566-int gru_touch(struct grail *ge,
2567- const struct utouch_frame *frame);
2568-int gru_drag(struct grail *ge,
2569- const struct utouch_frame *frame);
2570-int gru_pinch(struct grail *ge,
2571- const struct utouch_frame *frame);
2572-int gru_rotate(struct grail *ge,
2573- const struct utouch_frame *frame);
2574-
2575-static inline int out_of_bounds(const struct combo_model *s,
2576- const struct move_model *m)
2577-{
2578- return m->ntouch < s->mintouch || m->ntouch > s->maxtouch;
2579-}
2580-
2581-int gru_wintouch(struct grail *ge,
2582- const struct utouch_frame *frame);
2583-int gru_windrag(struct grail *ge,
2584- const struct utouch_frame *frame);
2585-int gru_winpinch(struct grail *ge,
2586- const struct utouch_frame *frame);
2587-int gru_winrotate(struct grail *ge,
2588- const struct utouch_frame *frame);
2589-
2590-struct tapping_model {
2591- grail_time_t start;
2592- int mintouch, maxtouch;
2593- int active, gid, tap;
2594- int nprop;
2595- grail_prop_t prop[DIM_GRAIL_PROP];
2596-};
2597-
2598-int gru_tapping(struct grail *ge,
2599- const struct utouch_frame *frame);
2600-
2601-#endif
2602-
2603
2604=== removed file 'src/grail-impl.h'
2605--- src/grail-impl.h 2011-08-30 15:10:16 +0000
2606+++ src/grail-impl.h 1970-01-01 00:00:00 +0000
2607@@ -1,88 +0,0 @@
2608-/*****************************************************************************
2609- *
2610- * grail - Gesture Recognition And Instantiation Library
2611- *
2612- * Copyright (C) 2010-2011 Canonical Ltd.
2613- *
2614- * This program is free software: you can redistribute it and/or modify it
2615- * under the terms of the GNU General Public License as published by the
2616- * Free Software Foundation, either version 3 of the License, or (at your
2617- * option) any later version.
2618- *
2619- * This program is distributed in the hope that it will be useful, but
2620- * WITHOUT ANY WARRANTY; without even the implied warranty of
2621- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2622- * General Public License for more details.
2623- *
2624- * You should have received a copy of the GNU General Public License along
2625- * with this program. If not, see <http://www.gnu.org/licenses/>.
2626- *
2627- ****************************************************************************/
2628-
2629-#ifndef GRAIL_IMPL_H
2630-#define GRAIL_IMPL_H
2631-
2632-#define MTDEV_NO_LEGACY_API
2633-#define GRAIL_NO_LEGACY_API
2634-
2635-#include <grail.h>
2636-#include <utouch/frame-mtdev.h>
2637-#include "evbuf.h"
2638-#include "grailbuf.h"
2639-
2640-#define DIM_TOUCH 32
2641-#define DIM_TOUCH_BYTES ((DIM_TOUCH + 7) >> 3)
2642-#define GRAIL_ID_MAX 0xffff
2643-
2644-#define MIN(a, b) ((a) < (b) ? (a) : (b))
2645-#define MAX(a, b) ((a) > (b) ? (a) : (b))
2646-
2647-typedef void *grail_select_callback;
2648-
2649-/*
2650- * In this implementation, there can be N one-gestures, N (N - 1) / 2
2651- * two-gestures, and one global gesture.
2652- */
2653-static inline int get_slot_count(int n)
2654-{
2655- return n + n * (n - 1) / 2 + 1;
2656-}
2657-
2658-int create_grail2(struct grail_impl *x,
2659- utouch_frame_handle fh,
2660- unsigned int num_frames,
2661- void *select,
2662- unsigned int version,
2663- unsigned int control_size,
2664- unsigned int frame_size,
2665- unsigned int slot_size);
2666-
2667-void destroy_grail2(struct grail_impl *x);
2668-
2669-struct grail_impl {
2670- struct evemu_device *evemu;
2671- struct mtdev *mtdev;
2672- utouch_frame_handle fh;
2673- const struct utouch_frame *touch;
2674- struct evbuf evbuf;
2675- struct grailbuf gbuf;
2676- int filter_abs;
2677- int ongoing;
2678- int gesture;
2679- FILE *fptest;
2680- int fast_fileread;
2681- /* new stuff below */
2682- struct grail_control *ctl;
2683- grail_select_callback select;
2684- int num_frames;
2685- int num_slots;
2686- int num_touches;
2687- int nextframe;
2688- int seqid;
2689- unsigned int control_size;
2690- unsigned int frame_size;
2691- unsigned int slot_size;
2692- struct grail_frame **frames;
2693-};
2694-
2695-#endif
2696
2697=== removed file 'src/grail-init.c'
2698--- src/grail-init.c 2011-08-31 17:20:48 +0000
2699+++ src/grail-init.c 1970-01-01 00:00:00 +0000
2700@@ -1,236 +0,0 @@
2701-/*****************************************************************************
2702- *
2703- * grail - Gesture Recognition And Instantiation Library
2704- *
2705- * Copyright (C) 2010-2011 Canonical Ltd.
2706- *
2707- * This program is free software: you can redistribute it and/or modify it
2708- * under the terms of the GNU General Public License as published by the
2709- * Free Software Foundation, either version 3 of the License, or (at your
2710- * option) any later version.
2711- *
2712- * This program is distributed in the hope that it will be useful, but
2713- * WITHOUT ANY WARRANTY; without even the implied warranty of
2714- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2715- * General Public License for more details.
2716- *
2717- * You should have received a copy of the GNU General Public License along
2718- * with this program. If not, see <http://www.gnu.org/licenses/>.
2719- *
2720- ****************************************************************************/
2721-
2722-#include "grail-impl.h"
2723-#include <stdlib.h>
2724-#include <string.h>
2725-#include <math.h>
2726-
2727-static struct grail_control *create_control(int size)
2728-{
2729- struct grail_control *c = calloc(1, size);
2730-
2731- if (!c)
2732- return 0;
2733-
2734- c->glue_ms = 60;
2735- c->bar_drag_x = 0.03;
2736- c->bar_drag_y = 0.03;
2737- c->bar_scale = 0.3;
2738- c->bar_angle = 0.1;
2739- c->drop_x_ms = 300;
2740- c->drop_y_ms = 300;
2741- c->drop_scale_ms = 300;
2742- c->drop_angle_ms = 300;
2743-
2744- return c;
2745-}
2746-
2747-static void destroy_slots(struct grail_element **slots, int nslot)
2748-{
2749- int i;
2750-
2751- if (slots) {
2752- for (i = nslot - 1; i >= 0; i--)
2753- free(slots[i]);
2754- free(slots);
2755- }
2756-}
2757-
2758-static void destroy_frame(struct grail_frame *frame, int nslot)
2759-{
2760- if (frame) {
2761- destroy_slots(frame->slots, nslot);
2762- free(frame->ongoing);
2763- free(frame);
2764- }
2765-}
2766-
2767-static void destroy_frames(struct grail_frame **frames, int nframe, int nslot)
2768-{
2769- int i;
2770-
2771- if (frames) {
2772- for (i = nframe - 1; i >= 0; i--)
2773- destroy_frame(frames[i], nslot);
2774- free(frames);
2775- }
2776-}
2777-
2778-static struct grail_element **create_slots(int nslot, int ntouch, int size)
2779-{
2780- struct grail_element **slots;
2781- struct grail_element *s;
2782- int i;
2783-
2784- slots = calloc(nslot, sizeof(slots[0]));
2785- if (!slots)
2786- return 0;
2787-
2788- for (i = 0; i < nslot; i++) {
2789- s = calloc(1, size + ntouch * sizeof(void *));
2790- if (!s)
2791- goto out;
2792- s->slot = i;
2793- s->id = -1;
2794- s->touches = (void *)((char *)s + size);
2795- slots[i] = s;
2796- }
2797-
2798- return slots;
2799- out:
2800- destroy_slots(slots, nslot);
2801- return 0;
2802-}
2803-
2804-static struct grail_frame *create_frame(int nslot, int ntouch,
2805- int frame_size, int slot_size)
2806-{
2807- struct grail_frame *frame;
2808-
2809- frame = calloc(1, frame_size);
2810- if (!frame)
2811- return 0;
2812-
2813- frame->ongoing = calloc(nslot, sizeof(frame->ongoing[0]));
2814- frame->slots = create_slots(nslot, ntouch, slot_size);
2815- if (!frame->ongoing || !frame->slots)
2816- goto out;
2817-
2818- return frame;
2819- out:
2820- destroy_frame(frame, nslot);
2821- return 0;
2822-}
2823-
2824-static struct grail_frame **create_frames(int nframe, int nslot, int ntouch,
2825- int frame_size, int slot_size)
2826-{
2827- struct grail_frame **frames;
2828- struct grail_frame *f;
2829- int i;
2830-
2831- frames = calloc(nframe, sizeof(frames[0]));
2832- if (!frames)
2833- return 0;
2834-
2835- for (i = 0; i < nframe; i++) {
2836- f = create_frame(nslot, ntouch, frame_size, slot_size);
2837- if (!f)
2838- goto out;
2839- frames[i] = f;
2840- }
2841-
2842- return frames;
2843- out:
2844- destroy_frames(frames, nframe, nslot);
2845- return 0;
2846-}
2847-
2848-int create_grail2(struct grail_impl *x,
2849- utouch_frame_handle fh,
2850- unsigned int num_frames,
2851- grail_select_callback select,
2852- unsigned int version,
2853- unsigned int control_size,
2854- unsigned int frame_size,
2855- unsigned int slot_size)
2856-{
2857- unsigned int ntouch = utouch_frame_get_num_slots(fh);
2858- unsigned int nslot = get_slot_count(ntouch);
2859- int i;
2860-
2861- x->select = select;
2862- x->control_size = MAX(control_size, sizeof(struct grail_control));
2863- x->frame_size = MAX(frame_size, sizeof(struct grail_frame));
2864- x->slot_size = MAX(slot_size, sizeof(struct grail_element));
2865-
2866- x->num_frames = num_frames;
2867- x->num_slots = nslot;
2868- x->num_touches = ntouch;
2869-
2870- x->ctl = create_control(x->control_size);
2871- if (!x->ctl)
2872- goto freemem;
2873-
2874- x->frames = create_frames(num_frames, nslot, ntouch,
2875- x->frame_size, x->slot_size);
2876- if (!x->frames)
2877- goto freemem;
2878-
2879- for (i = 0; i < num_frames; i++)
2880- x->frames[(i + 1) % num_frames]->prev = x->frames[i];
2881-
2882- return 0;
2883-
2884- freemem:
2885- destroy_grail2(x);
2886- return -ENOMEM;
2887-}
2888-
2889-void destroy_grail2(struct grail_impl *x)
2890-{
2891- destroy_frames(x->frames, x->num_frames, x->num_slots);
2892- free(x->ctl);
2893-}
2894-
2895-grail_handle GRAIL_PUBLIC grail_new_raw(utouch_frame_handle fh,
2896- unsigned int num_frames,
2897- grail_select_callback select,
2898- unsigned int version,
2899- unsigned int control_size,
2900- unsigned int frame_size,
2901- unsigned int slot_size)
2902-{
2903- struct grail *ge;
2904- struct grail_impl *x;
2905-
2906- ge = calloc(1, sizeof(*ge));
2907- if (!ge)
2908- return 0;
2909- x = calloc(1, sizeof(*x));
2910- if (!x)
2911- goto out;
2912- x->fh = fh;
2913- if (create_grail2(x, fh, num_frames, select,
2914- version, control_size, frame_size, slot_size))
2915- goto out;
2916-
2917- ge->impl = x;
2918- return ge;
2919-
2920- out:
2921- free(x);
2922- free(ge);
2923- return 0;
2924-}
2925-
2926-void GRAIL_PUBLIC grail_delete(grail_handle ge)
2927-{
2928- destroy_grail2(ge->impl);
2929- free(ge->impl);
2930- free(ge);
2931-}
2932-
2933-struct grail_control GRAIL_PUBLIC *grail_get_control(grail_handle ge)
2934-{
2935- return ge->impl->ctl;
2936-}
2937
2938=== removed file 'src/grail-inserter.c'
2939--- src/grail-inserter.c 2011-08-31 17:20:48 +0000
2940+++ src/grail-inserter.c 1970-01-01 00:00:00 +0000
2941@@ -1,304 +0,0 @@
2942-/*****************************************************************************
2943- *
2944- * grail - Gesture Recognition And Instantiation Library
2945- *
2946- * Copyright (C) 2010-2011 Canonical Ltd.
2947- *
2948- * This program is free software: you can redistribute it and/or modify it
2949- * under the terms of the GNU General Public License as published by the
2950- * Free Software Foundation, either version 3 of the License, or (at your
2951- * option) any later version.
2952- *
2953- * This program is distributed in the hope that it will be useful, but
2954- * WITHOUT ANY WARRANTY; without even the implied warranty of
2955- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2956- * General Public License for more details.
2957- *
2958- * You should have received a copy of the GNU General Public License along
2959- * with this program. If not, see <http://www.gnu.org/licenses/>.
2960- *
2961- ****************************************************************************/
2962-
2963-#include "grail-gestures.h"
2964-#include "grail-inserter.h"
2965-#include "grail-impl.h"
2966-#include <malloc.h>
2967-#include <string.h>
2968-#include <errno.h>
2969-#include <math.h>
2970-
2971-static const int MAX_GESTURE_ID = 0xfff;
2972-
2973-static int find_gslot(const struct gesture_inserter *gin, int gid)
2974-{
2975- int i;
2976- grail_mask_foreach(i, gin->used, sizeof(gin->used))
2977- if (gin->state[i].id == gid)
2978- return i;
2979- return -1;
2980-}
2981-
2982-static int mask_overlap(const grail_mask_t *a, const grail_mask_t *b,
2983- int bytes)
2984-{
2985- int i;
2986-
2987- for (i = 0; i < bytes; i++)
2988- if (a[i] & b[i])
2989- return 1;
2990-
2991- return 0;
2992-}
2993-
2994-// todo: spanning tree for multi-user case
2995-static void setup_new_gestures(struct grail *ge,
2996- const struct utouch_frame *frame)
2997-{
2998- struct gesture_inserter *gin = ge->gin;
2999- grail_mask_t types[DIM_GRAIL_TYPE_BYTES];
3000- grail_mask_t span[DIM_TOUCH_BYTES];
3001- struct grail_client_info info[DIM_CLIENT];
3002- int i, j, nclient = 0;
3003- int nfresh = grail_mask_count(gin->fresh, sizeof(gin->fresh));
3004- if (!nfresh)
3005- return;
3006-
3007- memset(types, 0, sizeof(types));
3008- memset(span, 0, sizeof(span));
3009-
3010- grail_mask_foreach(i, gin->fresh, sizeof(gin->fresh)) {
3011- struct slot_state *s = &gin->state[i];
3012- grail_mask_set(types, s->type);
3013- grail_mask_set_mask(span, s->span, sizeof(span));
3014- }
3015-
3016- nclient = gin_get_clients(ge, info, DIM_CLIENT, types, sizeof(types),
3017- span, sizeof(span), frame);
3018-
3019- grail_mask_foreach(i, gin->fresh, sizeof(gin->fresh)) {
3020- struct slot_state *s = &gin->state[i];
3021- s->nclient = 0;
3022- for (j = 0; j < nclient; j++) {
3023- if (!grail_mask_get(info[j].mask, s->type))
3024- continue;
3025- if (gin->grab_active &&
3026- info[j].id.client != gin->grab_client)
3027- continue;
3028- if (grail_mask_get(info[j].mask, GRAIL_TYPE_SYSFLAG1)) {
3029- gin->grab_active = 1;
3030- gin->grab_client = info[j].id.client;
3031- }
3032- s->client_id[s->nclient++] = info[j].id;
3033- }
3034- }
3035-
3036- memset(gin->fresh, 0, sizeof(gin->fresh));
3037-}
3038-
3039-int gin_init(struct grail *ge)
3040-{
3041- struct gesture_inserter *gin;
3042- int i;
3043- gin = calloc(1, sizeof(*gin));
3044- if (!gin)
3045- return -ENOMEM;
3046- for (i = 0; i < DIM_INSTANCE; i++)
3047- grail_mask_set(gin->unused, i);
3048- ge->gin = gin;
3049- return 0;
3050-}
3051-
3052-void gin_destroy(struct grail *ge)
3053-{
3054- free(ge->gin);
3055- ge->gin = NULL;
3056-}
3057-
3058-void gin_frame_begin(struct grail *ge, const struct utouch_frame *frame)
3059-{
3060- struct gesture_inserter *gin = ge->gin;
3061- memset(gin->types, 0, sizeof(gin->types));
3062- gin->time = frame->time;
3063- if (frame->num_active && !frame->prev->num_active)
3064- gin->grab_active = 0;
3065-}
3066-
3067-void gin_frame_end(struct grail *ge, const struct utouch_frame *frame)
3068-{
3069- struct gesture_inserter *gin = ge->gin;
3070- grail_mask_t keep[DIM_TOUCH_BYTES];
3071- int i, hold[2] = { 0, 0 }, discard[2] = { 0, 0 };
3072-
3073- memset(keep, 0, sizeof(keep));
3074- setup_new_gestures(ge, frame);
3075-
3076- grail_mask_foreach(i, gin->used, sizeof(gin->used)) {
3077- struct slot_state *s = &gin->state[i];
3078- if (!s->nclient)
3079- continue;
3080- if (s->priority > hold[s->slice])
3081- hold[s->slice] = s->priority;
3082- if (s->status != GRAIL_STATUS_UPDATE)
3083- continue;
3084- if (s->priority > discard[s->slice])
3085- discard[s->slice] = s->priority;
3086- }
3087-
3088- grail_mask_foreach(i, gin->used, sizeof(gin->used)) {
3089- struct slot_state *s = &gin->state[i];
3090- if (!s->nclient || (s->priority < discard[s->slice] && !s->sent))
3091- gin_gid_discard(ge, s->id);
3092- }
3093-
3094- grail_mask_foreach(i, gin->used, sizeof(gin->used)) {
3095- struct slot_state *s = &gin->state[i];
3096- if (s->slice == 1)
3097- grail_mask_set_mask(keep, s->span, sizeof(keep));
3098- }
3099-
3100- grail_mask_foreach(i, gin->used, sizeof(gin->used)) {
3101- struct slot_state *s = &gin->state[i];
3102- if (!s->timeout)
3103- continue;
3104- if (mask_overlap(keep, s->span, sizeof(keep)))
3105- continue;
3106- gin_gid_discard(ge, s->id);
3107- }
3108-
3109- grail_mask_foreach(i, gin->used, sizeof(gin->used)) {
3110- struct slot_state *s = &gin->state[i];
3111- struct gesture_event ev;
3112- grail_mask_set(gin->types, s->type);
3113- if (s->priority < hold[s->slice] && !s->sent)
3114- continue;
3115- while (!gebuf_empty(&s->buf)) {
3116- gebuf_get(&s->buf, &ev);
3117- gin_send_event(ge, s, &ev, frame);
3118- }
3119- s->sent = 1;
3120- }
3121-
3122- grail_mask_foreach(i, gin->used, sizeof(gin->used)) {
3123- struct slot_state *s = &gin->state[i];
3124- if (s->status == GRAIL_STATUS_END)
3125- gin_gid_discard(ge, s->id);
3126- }
3127-}
3128-
3129-int gin_gid_begin(struct grail *ge, int type, int priority,
3130- const struct utouch_frame *frame)
3131-{
3132- struct gesture_inserter *gin = ge->gin;
3133- struct slot_state *s;
3134- int slot;
3135- int i = grail_mask_get_first(gin->unused, sizeof(gin->unused));
3136- if (i < 0)
3137- return -1;
3138- s = &gin->state[i];
3139- s->type = type;
3140- if (priority < 0) {
3141- s->priority = -priority;
3142- s->slice = 1;
3143- } else {
3144- s->priority = priority;
3145- s->slice = 0;
3146- }
3147- s->timeout = 0;
3148- s->sent = 0;
3149- s->id = gin->gestureid++ & MAX_GESTURE_ID;
3150- s->status = GRAIL_STATUS_BEGIN;
3151- s->nclient = 0;
3152- for (slot = 0; slot < DIM_TOUCH; slot++)
3153- grail_mask_modify(s->span, slot, frame->slots[slot]->active);
3154- gebuf_clear(&s->buf);
3155- grail_mask_clear(gin->unused, i);
3156- grail_mask_set(gin->fresh, i);
3157- grail_mask_set(gin->used, i);
3158- return s->id;
3159-}
3160-
3161-void gin_gid_discard(struct grail *ge, int gid)
3162-{
3163- struct gesture_inserter *gin = ge->gin;
3164- struct slot_state *s;
3165- int i = find_gslot(gin, gid);
3166- if (i < 0)
3167- return;
3168- s = &gin->state[i];
3169- gebuf_clear(&s->buf);
3170- s->status = GRAIL_STATUS_END;
3171- grail_mask_clear(gin->used, i);
3172- grail_mask_set(gin->unused, i);
3173-}
3174-
3175-void gin_gid_timeout(struct grail *ge, int gid)
3176-{
3177- int i = find_gslot(ge->gin, gid);
3178- if (i >= 0)
3179- ge->gin->state[i].timeout = 1;
3180-}
3181-
3182-void gin_gid_event(struct grail *ge, int gid,
3183- float x, float y, int ntouch,
3184- const grail_prop_t *prop, int nprop,
3185- int transient)
3186-{
3187- struct gesture_inserter *gin = ge->gin;
3188- struct gesture_event ev;
3189- struct slot_state *s;
3190- int i = find_gslot(gin, gid);
3191- if (i < 0)
3192- return;
3193- s = &gin->state[i];
3194- ev.status = transient ? GRAIL_STATUS_UPDATE : s->status;
3195- ev.ntouch = ntouch;
3196- ev.nprop = nprop;
3197- ev.time = gin->time;
3198- ev.pos.x = x;
3199- ev.pos.y = y;
3200- memcpy(ev.prop, prop, nprop * sizeof(grail_prop_t));
3201- gebuf_put(&s->buf, &ev);
3202- if (transient)
3203- s->status = GRAIL_STATUS_END;
3204- else if (s->status == GRAIL_STATUS_BEGIN)
3205- s->status = GRAIL_STATUS_UPDATE;
3206-}
3207-
3208-void gin_gid_end(struct grail *ge, int gid,
3209- float x, float y, int ntouch,
3210- const grail_prop_t *prop, int nprop)
3211-{
3212- struct gesture_inserter *gin = ge->gin;
3213- struct gesture_event ev;
3214- struct slot_state *s;
3215- int i = find_gslot(gin, gid);
3216- if (i < 0)
3217- return;
3218- s = &gin->state[i];
3219- if (s->status != GRAIL_STATUS_BEGIN) {
3220- ev.status = GRAIL_STATUS_END;
3221- ev.ntouch = ntouch;
3222- ev.nprop = nprop;
3223- ev.time = gin->time;
3224- ev.pos.x = x;
3225- ev.pos.y = y;
3226- memcpy(ev.prop, prop, nprop * sizeof(grail_prop_t));
3227- gebuf_put(&s->buf, &ev);
3228- }
3229- s->status = GRAIL_STATUS_END;
3230-}
3231-
3232-void GRAIL_PUBLIC grail_set_bbox(struct grail *ge,
3233- const struct grail_coord *tmin,
3234- const struct grail_coord *tmax)
3235-{
3236- struct utouch_surface *s = utouch_frame_get_surface(ge->impl->fh);
3237-
3238- s->mapped_min_x = tmin->x;
3239- s->mapped_min_y = tmin->y;
3240- s->mapped_max_x = tmax->x;
3241- s->mapped_max_y = tmax->y;
3242-
3243- if (ge->gru)
3244- gru_init_motion(ge);
3245-}
3246
3247=== removed file 'src/grail-inserter.h'
3248--- src/grail-inserter.h 2011-05-17 14:15:22 +0000
3249+++ src/grail-inserter.h 1970-01-01 00:00:00 +0000
3250@@ -1,93 +0,0 @@
3251-/*****************************************************************************
3252- *
3253- * grail - Gesture Recognition And Instantiation Library
3254- *
3255- * Copyright (C) 2010-2011 Canonical Ltd.
3256- *
3257- * This program is free software: you can redistribute it and/or modify it
3258- * under the terms of the GNU General Public License as published by the
3259- * Free Software Foundation, either version 3 of the License, or (at your
3260- * option) any later version.
3261- *
3262- * This program is distributed in the hope that it will be useful, but
3263- * WITHOUT ANY WARRANTY; without even the implied warranty of
3264- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3265- * General Public License for more details.
3266- *
3267- * You should have received a copy of the GNU General Public License along
3268- * with this program. If not, see <http://www.gnu.org/licenses/>.
3269- *
3270- ****************************************************************************/
3271-
3272-#ifndef GRAIL_INSERTER_H
3273-#define GRAIL_INSERTER_H
3274-
3275-#include "grail-impl.h"
3276-#include "gebuf.h"
3277-
3278-#define DIM_EV_TYPE EV_CNT
3279-#define DIM_EV_TYPE_BYTES ((DIM_EV_TYPE + 7) >> 3)
3280-
3281-#define DIM_INSTANCE 32
3282-#define DIM_INSTANCE_BYTES ((DIM_INSTANCE + 7) >> 3)
3283-
3284-#define DIM_CLIENT 32
3285-
3286-struct slot_state {
3287- int type;
3288- int priority;
3289- int slice;
3290- int timeout;
3291- int sent;
3292- int id;
3293- int status;
3294- int nclient;
3295- struct grail_client_id client_id[DIM_CLIENT];
3296- grail_mask_t span[DIM_TOUCH_BYTES];
3297- struct gebuf buf;
3298-};
3299-
3300-struct gesture_inserter {
3301- struct slot_state state[DIM_INSTANCE];
3302- grail_mask_t types[DIM_GRAIL_TYPE_BYTES];
3303- grail_mask_t unused[DIM_INSTANCE_BYTES];
3304- grail_mask_t fresh[DIM_INSTANCE_BYTES];
3305- grail_mask_t used[DIM_INSTANCE_BYTES];
3306- grail_time_t time;
3307- int gestureid;
3308- int grab_active;
3309- int grab_client;
3310-};
3311-
3312-int gin_add_contact_props(const struct gesture_inserter *gin,
3313- grail_prop_t *prop, const struct utouch_frame *frame);
3314-
3315-int gin_get_clients(struct grail *ge,
3316- struct grail_client_info *info, int maxinfo,
3317- const grail_mask_t* types, int btypes,
3318- const grail_mask_t* span, int bspan,
3319- const struct utouch_frame *frame);
3320-void gin_send_event(struct grail *ge, struct slot_state *s,
3321- const struct gesture_event *ev,
3322- const struct utouch_frame *frame);
3323-
3324-int gin_init(struct grail *ge);
3325-void gin_destroy(struct grail *ge);
3326-
3327-void gin_frame_begin(struct grail *ge, const struct utouch_frame *frame);
3328-void gin_frame_end(struct grail *ge, const struct utouch_frame *frame);
3329-
3330-int gin_gid_begin(struct grail *ge, int type, int priority,
3331- const struct utouch_frame *frame);
3332-void gin_gid_discard(struct grail *ge, int gid);
3333-void gin_gid_timeout(struct grail *ge, int gid);
3334-
3335-void gin_gid_event(struct grail *ge, int gid,
3336- float x, float y, int ntouch,
3337- const grail_prop_t *prop, int nprop,
3338- int transient);
3339-void gin_gid_end(struct grail *ge, int gid,
3340- float x, float y, int ntouch,
3341- const grail_prop_t *prop, int nprop);
3342-
3343-#endif
3344
3345=== removed file 'src/grail-legacy.c'
3346--- src/grail-legacy.c 2011-08-31 17:20:48 +0000
3347+++ src/grail-legacy.c 1970-01-01 00:00:00 +0000
3348@@ -1,64 +0,0 @@
3349-/*****************************************************************************
3350- *
3351- * grail - Gesture Recognition And Instantiation Library
3352- *
3353- * Copyright (C) 2010-2011 Canonical Ltd.
3354- *
3355- * This program is free software: you can redistribute it and/or modify it
3356- * under the terms of the GNU General Public License as published by the
3357- * Free Software Foundation, either version 3 of the License, or (at your
3358- * option) any later version.
3359- *
3360- * This program is distributed in the hope that it will be useful, but
3361- * WITHOUT ANY WARRANTY; without even the implied warranty of
3362- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3363- * General Public License for more details.
3364- *
3365- * You should have received a copy of the GNU General Public License along
3366- * with this program. If not, see <http://www.gnu.org/licenses/>.
3367- *
3368- ****************************************************************************/
3369-
3370-#include <grail.h>
3371-#include "grail-inserter.h"
3372-#include <string.h>
3373-#include <stdio.h>
3374-#include <unistd.h>
3375-#include <fcntl.h>
3376-#include <malloc.h>
3377-#include <errno.h>
3378-#include <stdlib.h>
3379-
3380-#ifndef GRAIL_NO_LEGACY_ABI
3381-
3382-void GRAIL_PUBLIC grail_filter_abs_events(struct grail *ge, int usage)
3383-{
3384- struct grail_impl *x = ge->impl;
3385- x->filter_abs = usage;
3386-}
3387-
3388-int GRAIL_PUBLIC grail_get_contacts(const struct grail *ge,
3389- struct grail_contact *touch, int max_touch)
3390-{
3391- const struct utouch_frame *frame = ge->impl->touch;
3392- int i;
3393- if (frame->num_active < max_touch)
3394- max_touch = frame->num_active;
3395- for (i = 0; i < max_touch; i++) {
3396- struct grail_contact *t = &touch[i];
3397- const struct utouch_contact *ct = frame->active[i];
3398- t->id = ct->id;
3399- t->tool_type = ct->tool_type;
3400- t->pos.x = ct->x;
3401- t->pos.y = ct->y;
3402- t->touch_major = ct->touch_major;
3403- t->touch_minor = ct->touch_minor;
3404- t->width_major = ct->width_major;
3405- t->width_minor = ct->width_minor;
3406- t->angle = ct->orientation;
3407- t->pressure = ct->pressure;
3408- }
3409- return max_touch;
3410-}
3411-
3412-#endif
3413
3414=== removed file 'src/grail-recognizer.c'
3415--- src/grail-recognizer.c 2011-04-28 16:53:57 +0000
3416+++ src/grail-recognizer.c 1970-01-01 00:00:00 +0000
3417@@ -1,58 +0,0 @@
3418-/*****************************************************************************
3419- *
3420- * grail - Gesture Recognition And Instantiation Library
3421- *
3422- * Copyright (C) 2010-2011 Canonical Ltd.
3423- *
3424- * This program is free software: you can redistribute it and/or modify it
3425- * under the terms of the GNU General Public License as published by the
3426- * Free Software Foundation, either version 3 of the License, or (at your
3427- * option) any later version.
3428- *
3429- * This program is distributed in the hope that it will be useful, but
3430- * WITHOUT ANY WARRANTY; without even the implied warranty of
3431- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3432- * General Public License for more details.
3433- *
3434- * You should have received a copy of the GNU General Public License along
3435- * with this program. If not, see <http://www.gnu.org/licenses/>.
3436- *
3437- ****************************************************************************/
3438-
3439-#include "grail-recognizer.h"
3440-#include <string.h>
3441-#include <malloc.h>
3442-#include <errno.h>
3443-
3444-int gru_init(struct grail *ge)
3445-{
3446- struct gesture_recognizer *gru;
3447- gru = calloc(1, sizeof(struct gesture_recognizer));
3448- if (!gru)
3449- return -ENOMEM;
3450- ge->gru = gru;
3451- gru_init_motion(ge);
3452- return 0;
3453-}
3454-
3455-void gru_destroy(struct grail *ge)
3456-{
3457- free(ge->gru);
3458- ge->gru = NULL;
3459-}
3460-
3461-void gru_recognize(struct grail *ge, const struct utouch_frame *frame)
3462-{
3463- if (!ge->gin || !ge->gru)
3464- return;
3465- gru_motion(ge, frame);
3466- gru_touch(ge, frame);
3467- gru_drag(ge, frame);
3468- gru_pinch(ge, frame);
3469- gru_rotate(ge, frame);
3470- gru_wintouch(ge, frame);
3471- gru_windrag(ge, frame);
3472- gru_winpinch(ge, frame);
3473- gru_winrotate(ge, frame);
3474- gru_tapping(ge, frame);
3475-}
3476
3477=== removed file 'src/grail-recognizer.h'
3478--- src/grail-recognizer.h 2011-05-17 14:15:22 +0000
3479+++ src/grail-recognizer.h 1970-01-01 00:00:00 +0000
3480@@ -1,44 +0,0 @@
3481-/*****************************************************************************
3482- *
3483- * grail - Gesture Recognition And Instantiation Library
3484- *
3485- * Copyright (C) 2010-2011 Canonical Ltd.
3486- *
3487- * This program is free software: you can redistribute it and/or modify it
3488- * under the terms of the GNU General Public License as published by the
3489- * Free Software Foundation, either version 3 of the License, or (at your
3490- * option) any later version.
3491- *
3492- * This program is distributed in the hope that it will be useful, but
3493- * WITHOUT ANY WARRANTY; without even the implied warranty of
3494- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3495- * General Public License for more details.
3496- *
3497- * You should have received a copy of the GNU General Public License along
3498- * with this program. If not, see <http://www.gnu.org/licenses/>.
3499- *
3500- ****************************************************************************/
3501-
3502-#ifndef GRAIL_RECOGNIZER_H
3503-#define GRAIL_RECOGNIZER_H
3504-
3505-#include "grail-gestures.h"
3506-
3507-struct gesture_recognizer {
3508- struct move_model move;
3509- struct combo_model touch;
3510- struct combo_model drag;
3511- struct combo_model pinch;
3512- struct combo_model rotate;
3513- struct combo_model wintouch;
3514- struct combo_model windrag;
3515- struct combo_model winpinch;
3516- struct combo_model winrotate;
3517- struct tapping_model tapping;
3518-};
3519-
3520-int gru_init(struct grail *ge);
3521-void gru_recognize(struct grail *ge, const struct utouch_frame *frame);
3522-void gru_destroy(struct grail *ge);
3523-
3524-#endif
3525
3526=== removed file 'src/grailbuf.h'
3527--- src/grailbuf.h 2011-05-17 14:15:22 +0000
3528+++ src/grailbuf.h 1970-01-01 00:00:00 +0000
3529@@ -1,59 +0,0 @@
3530-/*****************************************************************************
3531- *
3532- * grail - Gesture Recognition And Instantiation Library
3533- *
3534- * Copyright (C) 2010-2011 Canonical Ltd.
3535- *
3536- * This program is free software: you can redistribute it and/or modify it
3537- * under the terms of the GNU General Public License as published by the
3538- * Free Software Foundation, either version 3 of the License, or (at your
3539- * option) any later version.
3540- *
3541- * This program is distributed in the hope that it will be useful, but
3542- * WITHOUT ANY WARRANTY; without even the implied warranty of
3543- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3544- * General Public License for more details.
3545- *
3546- * You should have received a copy of the GNU General Public License along
3547- * with this program. If not, see <http://www.gnu.org/licenses/>.
3548- *
3549- ****************************************************************************/
3550-
3551-#ifndef GRAIL_BUFFER_H
3552-#define GRAIL_BUFFER_H
3553-
3554-#include <grail.h>
3555-
3556-#define DIM_GRAIL_EVENTS 512
3557-
3558-struct grailbuf {
3559- int head;
3560- int tail;
3561- struct grail_event buffer[DIM_GRAIL_EVENTS];
3562-};
3563-
3564-static inline void grailbuf_clear(struct grailbuf *buf)
3565-{
3566- buf->head = buf->tail = 0;
3567-}
3568-
3569-static inline int grailbuf_empty(const struct grailbuf *buf)
3570-{
3571- return buf->head == buf->tail;
3572-}
3573-
3574-static inline void grailbuf_put(struct grailbuf *buf,
3575- const struct grail_event *ev)
3576-{
3577- buf->buffer[buf->head++] = *ev;
3578- buf->head &= DIM_GRAIL_EVENTS - 1;
3579-}
3580-
3581-static inline void grailbuf_get(struct grailbuf *buf,
3582- struct grail_event *ev)
3583-{
3584- *ev = buf->buffer[buf->tail++];
3585- buf->tail &= DIM_GRAIL_EVENTS - 1;
3586-}
3587-
3588-#endif
3589
3590=== added directory 'src/v2'
3591=== added file 'src/v2/evbuf.h'
3592--- src/v2/evbuf.h 1970-01-01 00:00:00 +0000
3593+++ src/v2/evbuf.h 2011-11-01 19:17:00 +0000
3594@@ -0,0 +1,57 @@
3595+/*****************************************************************************
3596+ *
3597+ * grail - Gesture Recognition And Instantiation Library
3598+ *
3599+ * Copyright (C) 2010-2011 Canonical Ltd.
3600+ *
3601+ * This program is free software: you can redistribute it and/or modify it
3602+ * under the terms of the GNU General Public License as published by the
3603+ * Free Software Foundation, either version 3 of the License, or (at your
3604+ * option) any later version.
3605+ *
3606+ * This program is distributed in the hope that it will be useful, but
3607+ * WITHOUT ANY WARRANTY; without even the implied warranty of
3608+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3609+ * General Public License for more details.
3610+ *
3611+ * You should have received a copy of the GNU General Public License along
3612+ * with this program. If not, see <http://www.gnu.org/licenses/>.
3613+ *
3614+ ****************************************************************************/
3615+
3616+#ifndef GRAIL_EVBUF_H
3617+#define GRAIL_EVBUF_H
3618+
3619+#define DIM_EVENTS 4096
3620+
3621+struct evbuf {
3622+ int head;
3623+ int tail;
3624+ struct input_event buffer[DIM_EVENTS];
3625+};
3626+
3627+static inline void evbuf_clear(struct evbuf *evbuf)
3628+{
3629+ evbuf->head = evbuf->tail = 0;
3630+}
3631+
3632+static inline int evbuf_empty(const struct evbuf *evbuf)
3633+{
3634+ return evbuf->head == evbuf->tail;
3635+}
3636+
3637+static inline void evbuf_put(struct evbuf *evbuf,
3638+ const struct input_event *ev)
3639+{
3640+ evbuf->buffer[evbuf->head++] = *ev;
3641+ evbuf->head &= DIM_EVENTS - 1;
3642+}
3643+
3644+static inline void evbuf_get(struct evbuf *evbuf,
3645+ struct input_event *ev)
3646+{
3647+ *ev = evbuf->buffer[evbuf->tail++];
3648+ evbuf->tail &= DIM_EVENTS - 1;
3649+}
3650+
3651+#endif
3652
3653=== added file 'src/v2/gebuf.h'
3654--- src/v2/gebuf.h 1970-01-01 00:00:00 +0000
3655+++ src/v2/gebuf.h 2011-11-01 19:17:00 +0000
3656@@ -0,0 +1,68 @@
3657+/*****************************************************************************
3658+ *
3659+ * grail - Gesture Recognition And Instantiation Library
3660+ *
3661+ * Copyright (C) 2010-2011 Canonical Ltd.
3662+ *
3663+ * This program is free software: you can redistribute it and/or modify it
3664+ * under the terms of the GNU General Public License as published by the
3665+ * Free Software Foundation, either version 3 of the License, or (at your
3666+ * option) any later version.
3667+ *
3668+ * This program is distributed in the hope that it will be useful, but
3669+ * WITHOUT ANY WARRANTY; without even the implied warranty of
3670+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3671+ * General Public License for more details.
3672+ *
3673+ * You should have received a copy of the GNU General Public License along
3674+ * with this program. If not, see <http://www.gnu.org/licenses/>.
3675+ *
3676+ ****************************************************************************/
3677+
3678+#ifndef GRAIL_GESTURE_BUFFER_H
3679+#define GRAIL_GESTURE_BUFFER_H
3680+
3681+#include "grail-impl.h"
3682+
3683+#define DIM_GESTURE_EVENTS 512
3684+
3685+struct gesture_event {
3686+ int status;
3687+ int ntouch;
3688+ int nprop;
3689+ utouch_frame_time_t time;
3690+ struct grail_coord pos;
3691+ grail_prop_t prop[DIM_GRAIL_PROP];
3692+};
3693+
3694+struct gebuf {
3695+ int head;
3696+ int tail;
3697+ struct gesture_event buffer[DIM_GESTURE_EVENTS];
3698+};
3699+
3700+static inline void gebuf_clear(struct gebuf *gebuf)
3701+{
3702+ gebuf->head = gebuf->tail = 0;
3703+}
3704+
3705+static inline int gebuf_empty(const struct gebuf *gebuf)
3706+{
3707+ return gebuf->head == gebuf->tail;
3708+}
3709+
3710+static inline void gebuf_put(struct gebuf *gebuf,
3711+ const struct gesture_event *ev)
3712+{
3713+ gebuf->buffer[gebuf->head++] = *ev;
3714+ gebuf->head &= DIM_GESTURE_EVENTS - 1;
3715+}
3716+
3717+static inline void gebuf_get(struct gebuf *gebuf,
3718+ struct gesture_event *ev)
3719+{
3720+ *ev = gebuf->buffer[gebuf->tail++];
3721+ gebuf->tail &= DIM_GESTURE_EVENTS - 1;
3722+}
3723+
3724+#endif
3725
3726=== added file 'src/v2/gestures-drag.c'
3727--- src/v2/gestures-drag.c 1970-01-01 00:00:00 +0000
3728+++ src/v2/gestures-drag.c 2011-11-01 19:17:00 +0000
3729@@ -0,0 +1,135 @@
3730+/*****************************************************************************
3731+ *
3732+ * grail - Gesture Recognition And Instantiation Library
3733+ *
3734+ * Copyright (C) 2010-2011 Canonical Ltd.
3735+ *
3736+ * This program is free software: you can redistribute it and/or modify it
3737+ * under the terms of the GNU General Public License as published by the
3738+ * Free Software Foundation, either version 3 of the License, or (at your
3739+ * option) any later version.
3740+ *
3741+ * This program is distributed in the hope that it will be useful, but
3742+ * WITHOUT ANY WARRANTY; without even the implied warranty of
3743+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3744+ * General Public License for more details.
3745+ *
3746+ * You should have received a copy of the GNU General Public License along
3747+ * with this program. If not, see <http://www.gnu.org/licenses/>.
3748+ *
3749+ ****************************************************************************/
3750+
3751+#include "grail-recognizer.h"
3752+#include <math.h>
3753+#include <stdio.h>
3754+
3755+static const int getype[DIM_TOUCH + 1] = {
3756+ -1,
3757+ GRAIL_TYPE_DRAG1,
3758+ GRAIL_TYPE_DRAG2,
3759+ GRAIL_TYPE_DRAG3,
3760+ GRAIL_TYPE_DRAG4,
3761+ GRAIL_TYPE_DRAG5,
3762+};
3763+
3764+static void set_props(const struct gesture_inserter *gin,
3765+ struct combo_model *s, const struct move_model *m,
3766+ const struct utouch_frame *frame)
3767+{
3768+ if (m->single) {
3769+ s->prop[GRAIL_PROP_DRAG_DX] = m->fm[FM_X].raw_delta;
3770+ s->prop[GRAIL_PROP_DRAG_DY] = m->fm[FM_Y].raw_delta;
3771+ } else {
3772+ s->prop[GRAIL_PROP_DRAG_DX] = m->fm[FM_X].action_delta;
3773+ s->prop[GRAIL_PROP_DRAG_DY] = m->fm[FM_Y].action_delta;
3774+ }
3775+ s->prop[GRAIL_PROP_DRAG_VX] = m->fm[FM_X].velocity;
3776+ s->prop[GRAIL_PROP_DRAG_VY] = m->fm[FM_Y].velocity;
3777+ s->prop[GRAIL_PROP_DRAG_X] = m->fm[FM_X].value;
3778+ s->prop[GRAIL_PROP_DRAG_Y] = m->fm[FM_Y].value;
3779+ s->nprop = 6;
3780+ s->nprop += gin_add_contact_props(gin, s->prop + s->nprop, frame);
3781+}
3782+
3783+static const int fm_mask = 0x03;
3784+
3785+int gru_drag(struct grail *ge,
3786+ const struct utouch_frame *frame)
3787+{
3788+ struct gesture_recognizer *gru = ge->gru;
3789+ struct combo_model *state = &gru->drag;
3790+ struct move_model *move = &gru->move;
3791+ int mask = state->active ? (move->active & fm_mask) : fm_mask;
3792+ if (!move->multi && !move->single) {
3793+ if (state->active) {
3794+ gru_end(ge, state->gid, move,
3795+ state->prop, state->nprop);
3796+ state->active = 0;
3797+ }
3798+ }
3799+ if ((move->timeout & fm_mask) == fm_mask) {
3800+ if (state->active) {
3801+ gin_gid_timeout(ge, state->gid);
3802+ }
3803+ }
3804+ if (!state->active) {
3805+ int type = getype[move->ntouch];
3806+ if (type < 0)
3807+ return 0;
3808+ state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
3809+ state->active = 1;
3810+ }
3811+ if (!(move->tickle & mask))
3812+ return 0;
3813+ if (!(move->active & fm_mask))
3814+ return 0;
3815+ set_props(ge->gin, state, move, frame);
3816+ gru_event(ge, state->gid, move, state->prop, state->nprop);
3817+ return 1;
3818+}
3819+
3820+int gru_windrag(struct grail *ge,
3821+ const struct utouch_frame *frame)
3822+{
3823+ struct gesture_recognizer *gru = ge->gru;
3824+ struct combo_model *state = &gru->windrag;
3825+ struct move_model *move = &gru->move;
3826+ int mask = state->active ? (move->active & fm_mask) : fm_mask;
3827+ if (!move->multi && !move->single) {
3828+ if (state->active && out_of_bounds(state, move)) {
3829+ gru_end(ge, state->gid, move,
3830+ state->prop, state->nprop);
3831+ state->active = 0;
3832+ }
3833+ }
3834+ if ((move->timeout & fm_mask) == fm_mask) {
3835+ if (state->active) {
3836+ gin_gid_timeout(ge, state->gid);
3837+ }
3838+ }
3839+ if (!state->active) {
3840+ if (move->ntouch == 4) {
3841+ state->gid = gin_gid_begin(ge, GRAIL_TYPE_MDRAG,
3842+ PRIO_META, frame);
3843+ state->mintouch = 1;
3844+ state->maxtouch = 4;
3845+ state->active = 1;
3846+ } else if (move->ntouch == 3) {
3847+ state->gid = gin_gid_begin(ge, GRAIL_TYPE_EDRAG,
3848+ PRIO_ENV, frame);
3849+ state->mintouch = 1;
3850+ state->maxtouch = 3;
3851+ state->active = 1;
3852+ } else {
3853+ return 0;
3854+ }
3855+ }
3856+ if (!(move->tickle & mask))
3857+ return 0;
3858+ if (!(move->active & fm_mask))
3859+ return 0;
3860+ set_props(ge->gin, state, move, frame);
3861+ gru_event(ge, state->gid, move, state->prop, state->nprop);
3862+ return 1;
3863+}
3864+
3865
3866=== added file 'src/v2/gestures-pinch.c'
3867--- src/v2/gestures-pinch.c 1970-01-01 00:00:00 +0000
3868+++ src/v2/gestures-pinch.c 2011-11-01 19:17:00 +0000
3869@@ -0,0 +1,131 @@
3870+/*****************************************************************************
3871+ *
3872+ * grail - Gesture Recognition And Instantiation Library
3873+ *
3874+ * Copyright (C) 2010-2011 Canonical Ltd.
3875+ *
3876+ * This program is free software: you can redistribute it and/or modify it
3877+ * under the terms of the GNU General Public License as published by the
3878+ * Free Software Foundation, either version 3 of the License, or (at your
3879+ * option) any later version.
3880+ *
3881+ * This program is distributed in the hope that it will be useful, but
3882+ * WITHOUT ANY WARRANTY; without even the implied warranty of
3883+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3884+ * General Public License for more details.
3885+ *
3886+ * You should have received a copy of the GNU General Public License along
3887+ * with this program. If not, see <http://www.gnu.org/licenses/>.
3888+ *
3889+ ****************************************************************************/
3890+
3891+#include "grail-recognizer.h"
3892+#include <math.h>
3893+#include <stdio.h>
3894+
3895+static const int getype[DIM_TOUCH + 1] = {
3896+ 0,
3897+ 0,
3898+ GRAIL_TYPE_PINCH2,
3899+ GRAIL_TYPE_PINCH3,
3900+ GRAIL_TYPE_PINCH4,
3901+ GRAIL_TYPE_PINCH5,
3902+};
3903+
3904+static const int fm_mask = 0x04;
3905+
3906+static void set_props(const struct gesture_inserter *gin,
3907+ struct combo_model *s,
3908+ const struct move_model *m,
3909+ const struct utouch_frame *frame)
3910+{
3911+ s->prop[GRAIL_PROP_PINCH_DR] = m->fm[FM_R].action_delta;
3912+ s->prop[GRAIL_PROP_PINCH_VR] = m->fm[FM_R].velocity;
3913+ s->prop[GRAIL_PROP_PINCH_R] = m->fm[FM_R].value;
3914+ s->prop[GRAIL_PROP_PINCH_X] = m->fm[FM_X].value;
3915+ s->prop[GRAIL_PROP_PINCH_Y] = m->fm[FM_Y].value;
3916+ s->nprop = 5;
3917+ s->nprop += gin_add_contact_props(gin, s->prop + s->nprop, frame);
3918+}
3919+
3920+int gru_pinch(struct grail *ge,
3921+ const struct utouch_frame *frame)
3922+{
3923+ struct gesture_recognizer *gru = ge->gru;
3924+ struct combo_model *state = &gru->pinch;
3925+ struct move_model *move = &gru->move;
3926+ int mask = state->active ? (move->active & fm_mask) : fm_mask;
3927+ if (!move->multi && !move->single) {
3928+ if (state->active) {
3929+ gru_end(ge, state->gid, move,
3930+ state->prop, state->nprop);
3931+ state->active = 0;
3932+ }
3933+ return 0;
3934+ }
3935+ if ((move->timeout & fm_mask) == fm_mask) {
3936+ if (state->active) {
3937+ gin_gid_timeout(ge, state->gid);
3938+ }
3939+ }
3940+ if (!(move->tickle & mask))
3941+ return 0;
3942+ if (!state->active) {
3943+ int type = getype[move->ntouch];
3944+ if (!type)
3945+ return 0;
3946+ state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
3947+ state->active = 1;
3948+ }
3949+ if (!(move->active & fm_mask))
3950+ return 0;
3951+ set_props(ge->gin, state, move, frame);
3952+ gru_event(ge, state->gid, move, state->prop, state->nprop);
3953+ return 1;
3954+}
3955+
3956+int gru_winpinch(struct grail *ge,
3957+ const struct utouch_frame *frame)
3958+{
3959+ struct gesture_recognizer *gru = ge->gru;
3960+ struct combo_model *state = &gru->winpinch;
3961+ struct move_model *move = &gru->move;
3962+ int mask = state->active ? (move->active & fm_mask) : fm_mask;
3963+ if (!move->multi) {
3964+ if (state->active && out_of_bounds(state, move)) {
3965+ gru_end(ge, state->gid, move,
3966+ state->prop, state->nprop);
3967+ state->active = 0;
3968+ }
3969+ return 0;
3970+ }
3971+ if ((move->timeout & fm_mask) == fm_mask) {
3972+ if (state->active) {
3973+ gin_gid_timeout(ge, state->gid);
3974+ }
3975+ }
3976+ if (!(move->tickle & mask))
3977+ return 0;
3978+ if (!state->active) {
3979+ if (move->ntouch == 4) {
3980+ state->gid = gin_gid_begin(ge, GRAIL_TYPE_MPINCH,
3981+ PRIO_META, frame);
3982+ state->mintouch = 2;
3983+ state->maxtouch = 4;
3984+ state->active = 1;
3985+ } else if (move->ntouch == 3) {
3986+ state->gid = gin_gid_begin(ge, GRAIL_TYPE_EPINCH,
3987+ PRIO_ENV, frame);
3988+ state->mintouch = 2;
3989+ state->maxtouch = 3;
3990+ state->active = 1;
3991+ } else {
3992+ return 0;
3993+ }
3994+ }
3995+ if (!(move->active & fm_mask))
3996+ return 0;
3997+ set_props(ge->gin, state, move, frame);
3998+ gru_event(ge, state->gid, move, state->prop, state->nprop);
3999+ return 1;
4000+}
4001
4002=== added file 'src/v2/gestures-rotate.c'
4003--- src/v2/gestures-rotate.c 1970-01-01 00:00:00 +0000
4004+++ src/v2/gestures-rotate.c 2011-11-01 19:17:00 +0000
4005@@ -0,0 +1,130 @@
4006+/*****************************************************************************
4007+ *
4008+ * grail - Gesture Recognition And Instantiation Library
4009+ *
4010+ * Copyright (C) 2010-2011 Canonical Ltd.
4011+ *
4012+ * This program is free software: you can redistribute it and/or modify it
4013+ * under the terms of the GNU General Public License as published by the
4014+ * Free Software Foundation, either version 3 of the License, or (at your
4015+ * option) any later version.
4016+ *
4017+ * This program is distributed in the hope that it will be useful, but
4018+ * WITHOUT ANY WARRANTY; without even the implied warranty of
4019+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4020+ * General Public License for more details.
4021+ *
4022+ * You should have received a copy of the GNU General Public License along
4023+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4024+ *
4025+ ****************************************************************************/
4026+
4027+#include "grail-recognizer.h"
4028+#include <math.h>
4029+#include <stdio.h>
4030+
4031+static const int getype[DIM_TOUCH + 1] = {
4032+ 0,
4033+ 0,
4034+ GRAIL_TYPE_ROTATE2,
4035+ GRAIL_TYPE_ROTATE3,
4036+ GRAIL_TYPE_ROTATE4,
4037+ GRAIL_TYPE_ROTATE5,
4038+};
4039+
4040+static const int fm_mask = 0x08;
4041+
4042+static void set_props(const struct gesture_inserter *gin,
4043+ struct combo_model *s, const struct move_model *m,
4044+ const struct utouch_frame *frame)
4045+{
4046+ s->prop[GRAIL_PROP_ROTATE_DA] = m->fm[FM_A].action_delta;
4047+ s->prop[GRAIL_PROP_ROTATE_VA] = m->fm[FM_A].velocity;
4048+ s->prop[GRAIL_PROP_ROTATE_A] = m->fm[FM_A].value;
4049+ s->prop[GRAIL_PROP_ROTATE_X] = m->fm[FM_X].value;
4050+ s->prop[GRAIL_PROP_ROTATE_Y] = m->fm[FM_Y].value;
4051+ s->nprop = 5;
4052+ s->nprop += gin_add_contact_props(gin, s->prop + s->nprop, frame);
4053+}
4054+
4055+int gru_rotate(struct grail *ge,
4056+ const struct utouch_frame *frame)
4057+{
4058+ struct gesture_recognizer *gru = ge->gru;
4059+ struct combo_model *state = &gru->rotate;
4060+ struct move_model *move = &gru->move;
4061+ int mask = state->active ? (move->active & fm_mask) : fm_mask;
4062+ if (!move->multi && !move->single) {
4063+ if (state->active) {
4064+ gru_end(ge, state->gid, move,
4065+ state->prop, state->nprop);
4066+ state->active = 0;
4067+ }
4068+ return 0;
4069+ }
4070+ if ((move->timeout & fm_mask) == fm_mask) {
4071+ if (state->active) {
4072+ gin_gid_timeout(ge, state->gid);
4073+ }
4074+ }
4075+ if (!(move->tickle & mask))
4076+ return 0;
4077+ if (!state->active) {
4078+ int type = getype[move->ntouch];
4079+ if (!type)
4080+ return 0;
4081+ state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
4082+ state->active = 1;
4083+ }
4084+ if (!(move->active & fm_mask))
4085+ return 0;
4086+ set_props(ge->gin, state, move, frame);
4087+ gru_event(ge, state->gid, move, state->prop, state->nprop);
4088+ return 1;
4089+}
4090+
4091+int gru_winrotate(struct grail *ge,
4092+ const struct utouch_frame *frame)
4093+{
4094+ struct gesture_recognizer *gru = ge->gru;
4095+ struct combo_model *state = &gru->winrotate;
4096+ struct move_model *move = &gru->move;
4097+ int mask = state->active ? (move->active & fm_mask) : fm_mask;
4098+ if (!move->multi) {
4099+ if (state->active && out_of_bounds(state, move)) {
4100+ gru_end(ge, state->gid, move,
4101+ state->prop, state->nprop);
4102+ state->active = 0;
4103+ }
4104+ return 0;
4105+ }
4106+ if ((move->timeout & fm_mask) == fm_mask) {
4107+ if (state->active) {
4108+ gin_gid_timeout(ge, state->gid);
4109+ }
4110+ }
4111+ if (!(move->tickle & mask))
4112+ return 0;
4113+ if (!state->active) {
4114+ if (move->ntouch == 4) {
4115+ state->gid = gin_gid_begin(ge, GRAIL_TYPE_MROTATE,
4116+ PRIO_META, frame);
4117+ state->mintouch = 2;
4118+ state->maxtouch = 4;
4119+ state->active = 1;
4120+ } else if (move->ntouch == 3) {
4121+ state->gid = gin_gid_begin(ge, GRAIL_TYPE_EROTATE,
4122+ PRIO_ENV, frame);
4123+ state->mintouch = 2;
4124+ state->maxtouch = 3;
4125+ state->active = 1;
4126+ } else {
4127+ return 0;
4128+ }
4129+ }
4130+ if (!(move->active & fm_mask))
4131+ return 0;
4132+ set_props(ge->gin, state, move, frame);
4133+ gru_event(ge, state->gid, move, state->prop, state->nprop);
4134+ return 1;
4135+}
4136
4137=== added file 'src/v2/gestures-tapping.c'
4138--- src/v2/gestures-tapping.c 1970-01-01 00:00:00 +0000
4139+++ src/v2/gestures-tapping.c 2011-11-01 19:17:00 +0000
4140@@ -0,0 +1,100 @@
4141+/*****************************************************************************
4142+ *
4143+ * grail - Gesture Recognition And Instantiation Library
4144+ *
4145+ * Copyright (C) 2010-2011 Canonical Ltd.
4146+ *
4147+ * This program is free software: you can redistribute it and/or modify it
4148+ * under the terms of the GNU General Public License as published by the
4149+ * Free Software Foundation, either version 3 of the License, or (at your
4150+ * option) any later version.
4151+ *
4152+ * This program is distributed in the hope that it will be useful, but
4153+ * WITHOUT ANY WARRANTY; without even the implied warranty of
4154+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4155+ * General Public License for more details.
4156+ *
4157+ * You should have received a copy of the GNU General Public License along
4158+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4159+ *
4160+ ****************************************************************************/
4161+
4162+#include "grail-recognizer.h"
4163+#include <math.h>
4164+
4165+static const int fm_mask = 0x07;
4166+
4167+static void set_props(const struct gesture_inserter *gin,
4168+ struct tapping_model *s, const struct move_model *m,
4169+ const struct utouch_frame *frame)
4170+{
4171+ s->prop[GRAIL_PROP_TAP_DT] = m->time - s->start;
4172+ s->prop[GRAIL_PROP_TAP_X] = m->fm[FM_X].value;
4173+ s->prop[GRAIL_PROP_TAP_Y] = m->fm[FM_Y].value;
4174+ s->nprop = 3;
4175+ s->nprop += gin_add_contact_props(gin, s->prop + s->nprop, frame);
4176+}
4177+
4178+int gru_tapping(struct grail *ge,
4179+ const struct utouch_frame *frame)
4180+{
4181+ struct gesture_recognizer *gru = ge->gru;
4182+ struct tapping_model *state = &gru->tapping;
4183+ struct move_model *move = &gru->move;
4184+ state->tap = 0;
4185+ if (frame->num_active && !frame->prev->num_active) {
4186+ state->mintouch = 0;
4187+ state->maxtouch = 0;
4188+ }
4189+ if (move->ntouch > state->maxtouch) {
4190+ if (state->active) {
4191+ gin_gid_discard(ge, state->gid);
4192+ state->active = 0;
4193+ }
4194+ state->start = move->time;
4195+ state->maxtouch = move->ntouch;
4196+ set_props(ge->gin, state, move, frame);
4197+ if (state->maxtouch <= 5) {
4198+ int type = GRAIL_TYPE_TAP1 + state->maxtouch - 1;
4199+ state->gid = gin_gid_begin(ge, type, PRIO_TAP, frame);
4200+ state->active = 1;
4201+ }
4202+ return 0;
4203+ }
4204+ if (!state->active) {
4205+ state->mintouch = move->ntouch;
4206+ state->maxtouch = move->ntouch;
4207+ return 0;
4208+ }
4209+ if (move->ntouch <= state->mintouch) {
4210+ int x = state->prop[GRAIL_PROP_TAP_X];
4211+ int y = state->prop[GRAIL_PROP_TAP_Y];
4212+ int t = move->time - state->start;
4213+ if (t > move->fm[FM_X].bar_ms) {
4214+ gin_gid_discard(ge, state->gid);
4215+ state->mintouch = move->ntouch;
4216+ state->maxtouch = move->ntouch;
4217+ state->active = 0;
4218+ return 0;
4219+ }
4220+ state->tap = state->maxtouch;
4221+ state->prop[GRAIL_PROP_TAP_DT] = t;
4222+ gin_gid_event(ge, state->gid, x, y, state->maxtouch,
4223+ state->prop, state->nprop, 1);
4224+ state->mintouch = move->ntouch;
4225+ state->maxtouch = move->ntouch;
4226+ state->active = 0;
4227+ return 1;
4228+ }
4229+ if (!move->ntouch)
4230+ return 0;
4231+ state->prop[GRAIL_PROP_TAP_DT] = move->time - state->start;
4232+ if ((move->active & fm_mask) ||
4233+ move->time - state->start > move->fm[FM_X].bar_ms) {
4234+ gin_gid_discard(ge, state->gid);
4235+ state->mintouch = move->ntouch;
4236+ state->maxtouch = move->ntouch;
4237+ state->active = 0;
4238+ }
4239+ return 0;
4240+}
4241
4242=== added file 'src/v2/gestures-touch.c'
4243--- src/v2/gestures-touch.c 1970-01-01 00:00:00 +0000
4244+++ src/v2/gestures-touch.c 2011-11-01 19:17:00 +0000
4245@@ -0,0 +1,98 @@
4246+/*****************************************************************************
4247+ *
4248+ * grail - Gesture Recognition And Instantiation Library
4249+ *
4250+ * Copyright (C) 2010 Canonical Ltd.
4251+ * Copyright (C) 2010 Henrik Rydberg <rydberg@bitmath.org>
4252+ *
4253+ * This program is free software: you can redistribute it and/or modify it
4254+ * under the terms of the GNU General Public License as published by the
4255+ * Free Software Foundation, either version 3 of the License, or (at your
4256+ * option) any later version.
4257+ *
4258+ * This program is distributed in the hope that it will be useful, but
4259+ * WITHOUT ANY WARRANTY; without even the implied warranty of
4260+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4261+ * General Public License for more details.
4262+ *
4263+ * You should have received a copy of the GNU General Public License along
4264+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4265+ *
4266+ ****************************************************************************/
4267+
4268+#include "grail-recognizer.h"
4269+#include <math.h>
4270+#include <stdio.h>
4271+
4272+static const int getype[DIM_TOUCH + 1] = {
4273+ -1,
4274+ GRAIL_TYPE_TOUCH1,
4275+ GRAIL_TYPE_TOUCH2,
4276+ GRAIL_TYPE_TOUCH3,
4277+ GRAIL_TYPE_TOUCH4,
4278+ GRAIL_TYPE_TOUCH5,
4279+};
4280+
4281+int gru_touch(struct grail *ge,
4282+ const struct utouch_frame *frame)
4283+{
4284+ struct gesture_recognizer *gru = ge->gru;
4285+ struct combo_model *state = &gru->touch;
4286+ struct move_model *move = &gru->move;
4287+ if (frame->slot_revision != frame->prev->slot_revision) {
4288+ if (state->active) {
4289+ gru_end(ge, state->gid, move,
4290+ state->prop, state->nprop);
4291+ state->active = 0;
4292+ }
4293+ }
4294+ if (!state->active) {
4295+ int type = getype[move->ntouch];
4296+ if (type <= 0)
4297+ return 0;
4298+ state->gid = gin_gid_begin(ge, type, -PRIO_GESTURE, frame);
4299+ state->active = 1;
4300+ }
4301+ if (move->time - move->fm[FM_X].original_ms <= move->fm[FM_X].hold_ms)
4302+ return 0;
4303+ state->nprop = gin_add_contact_props(ge->gin, state->prop, frame);
4304+ gru_event(ge, state->gid, move, state->prop, state->nprop);
4305+ return 1;
4306+}
4307+
4308+int gru_wintouch(struct grail *ge,
4309+ const struct utouch_frame *frame)
4310+{
4311+ struct gesture_recognizer *gru = ge->gru;
4312+ struct combo_model *state = &gru->wintouch;
4313+ struct move_model *move = &gru->move;
4314+ if (frame->slot_revision != frame->prev->slot_revision) {
4315+ if (state->active && out_of_bounds(state, move)) {
4316+ gru_end(ge, state->gid, move,
4317+ state->prop, state->nprop);
4318+ state->active = 0;
4319+ }
4320+ }
4321+ if (!state->active) {
4322+ if (move->ntouch == 4) {
4323+ state->gid = gin_gid_begin(ge, GRAIL_TYPE_MTOUCH,
4324+ -PRIO_META, frame);
4325+ state->mintouch = 1;
4326+ state->maxtouch = 4;
4327+ state->active = 1;
4328+ } else if (move->ntouch == 3) {
4329+ state->gid = gin_gid_begin(ge, GRAIL_TYPE_ETOUCH,
4330+ -PRIO_ENV, frame);
4331+ state->mintouch = 1;
4332+ state->maxtouch = 3;
4333+ state->active = 1;
4334+ } else {
4335+ return 0;
4336+ }
4337+ }
4338+ if (move->time - move->fm[FM_X].original_ms <= move->fm[FM_X].hold_ms)
4339+ return 0;
4340+ state->nprop = gin_add_contact_props(ge->gin, state->prop, frame);
4341+ gru_event(ge, state->gid, move, state->prop, state->nprop);
4342+ return 1;
4343+}
4344
4345=== added file 'src/v2/grail-api.c'
4346--- src/v2/grail-api.c 1970-01-01 00:00:00 +0000
4347+++ src/v2/grail-api.c 2011-11-01 19:17:00 +0000
4348@@ -0,0 +1,328 @@
4349+/*****************************************************************************
4350+ *
4351+ * grail - Gesture Recognition And Instantiation Library
4352+ *
4353+ * Copyright (C) 2010-2011 Canonical Ltd.
4354+ *
4355+ * This program is free software: you can redistribute it and/or modify it
4356+ * under the terms of the GNU General Public License as published by the
4357+ * Free Software Foundation, either version 3 of the License, or (at your
4358+ * option) any later version.
4359+ *
4360+ * This program is distributed in the hope that it will be useful, but
4361+ * WITHOUT ANY WARRANTY; without even the implied warranty of
4362+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4363+ * General Public License for more details.
4364+ *
4365+ * You should have received a copy of the GNU General Public License along
4366+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4367+ *
4368+ ****************************************************************************/
4369+
4370+#include "grail-impl.h"
4371+#include "grail-inserter.h"
4372+#include "grail-recognizer.h"
4373+#include <string.h>
4374+#include <stdio.h>
4375+#include <unistd.h>
4376+#include <fcntl.h>
4377+#include <malloc.h>
4378+#include <errno.h>
4379+#include <stdlib.h>
4380+#include <sys/stat.h>
4381+
4382+#define DIM_FRAMES 100
4383+#define FRAME_RATE 100
4384+
4385+unsigned int GRAIL_PUBLIC grail_get_version(void)
4386+{
4387+ return GRAIL_VERSION;
4388+}
4389+
4390+int GRAIL_PUBLIC grail_open(struct grail *ge, int fd)
4391+{
4392+ struct grail_impl *x;
4393+ struct stat fs;
4394+ int ret;
4395+
4396+ ret = fstat(fd, &fs);
4397+ if (ret)
4398+ return ret;
4399+
4400+ x = calloc(1, sizeof(*x));
4401+ if (!x)
4402+ return -ENOMEM;
4403+
4404+ if (!fs.st_rdev)
4405+ x->fptest = fdopen(fd, "r");
4406+
4407+ x->evemu = evemu_new(x->fptest ? "fptest" : 0);
4408+ if (!x->evemu) {
4409+ ret = -ENOMEM;
4410+ goto freemem;
4411+ }
4412+ if (x->fptest)
4413+ ret = evemu_read(x->evemu, x->fptest) <= 0;
4414+ else
4415+ ret = evemu_extract(x->evemu, fd);
4416+ if (ret)
4417+ goto freemem;
4418+ if (!utouch_frame_is_supported_mtdev(x->evemu)) {
4419+ ret = -ENODEV;
4420+ goto freemem;
4421+ }
4422+
4423+ if (!x->fptest) {
4424+ x->mtdev = mtdev_new_open(fd);
4425+ if (!x->mtdev) {
4426+ ret = -ENOMEM;
4427+ goto freemem;
4428+ }
4429+ }
4430+ x->fh = utouch_frame_new_engine(DIM_FRAMES, DIM_TOUCH, FRAME_RATE);
4431+ if (!x->fh) {
4432+ ret = -ENOMEM;
4433+ goto freedev;
4434+ }
4435+ ret = utouch_frame_init_mtdev(x->fh, x->evemu);
4436+ if (ret)
4437+ goto freeframe;
4438+
4439+ ge->impl = x;
4440+
4441+ ret = gin_init(ge);
4442+ if (ret)
4443+ goto freeframe;
4444+
4445+ ret = gru_init(ge);
4446+ if (ret)
4447+ goto freegin;
4448+
4449+ return 0;
4450+ freegin:
4451+ gin_destroy(ge);
4452+ freeframe:
4453+ utouch_frame_delete_engine(x->fh);
4454+ freedev:
4455+ if (x->mtdev)
4456+ mtdev_close_delete(x->mtdev);
4457+ freemem:
4458+ evemu_delete(x->evemu);
4459+ if (x->fptest)
4460+ fclose(x->fptest);
4461+ free(x);
4462+ ge->impl = 0;
4463+ return ret;
4464+}
4465+
4466+void GRAIL_PUBLIC grail_close(struct grail *ge, int fd)
4467+{
4468+ struct grail_impl *x = ge->impl;
4469+ gru_destroy(ge);
4470+ gin_destroy(ge);
4471+ utouch_frame_delete_engine(x->fh);
4472+ if (x->mtdev)
4473+ mtdev_close_delete(x->mtdev);
4474+ evemu_delete(x->evemu);
4475+ if (x->fptest)
4476+ fclose(x->fptest);
4477+ free(x);
4478+ ge->impl = 0;
4479+}
4480+
4481+int GRAIL_PUBLIC grail_idle(struct grail *ge, int fd, int ms)
4482+{
4483+ struct grail_impl *x = ge->impl;
4484+ if (x->fptest)
4485+ return 0;
4486+ if (x->mtdev)
4487+ return mtdev_idle(x->mtdev, fd, ms);
4488+ return 1;
4489+}
4490+
4491+void GRAIL_PUBLIC grail_get_units(const struct grail *ge,
4492+ struct grail_coord *min, struct grail_coord *max)
4493+{
4494+ struct utouch_surface *s = utouch_frame_get_surface(ge->impl->fh);
4495+ min->x = s->min_x;
4496+ min->y = s->min_y;
4497+ max->x = s->max_x;
4498+ max->y = s->max_y;
4499+}
4500+
4501+const struct utouch_frame GRAIL_PUBLIC *
4502+grail_get_contact_frame(const struct grail *ge)
4503+{
4504+ return ge->impl->touch;
4505+}
4506+
4507+static void flush_events(struct grail *ge)
4508+{
4509+ struct grail_impl *impl = ge->impl;
4510+ struct input_event iev;
4511+
4512+ grailbuf_clear(&impl->gbuf);
4513+ while (!evbuf_empty(&impl->evbuf)) {
4514+ evbuf_get(&impl->evbuf, &iev);
4515+ if (ge->event)
4516+ ge->event(ge, &iev);
4517+ }
4518+}
4519+
4520+static int skip_event(const struct input_event *ev, int count)
4521+{
4522+ switch (ev->type) {
4523+ case EV_ABS:
4524+ return 1;
4525+ case EV_KEY:
4526+ return ev->code >= BTN_DIGI && ev->code < BTN_WHEEL;
4527+ case EV_SYN:
4528+ switch (ev->code) {
4529+ case SYN_MT_REPORT:
4530+ return 1;
4531+ case SYN_REPORT:
4532+ return count == 0;
4533+ default:
4534+ return 0;
4535+ }
4536+ default:
4537+ return 0;
4538+ }
4539+}
4540+
4541+static void flush_gestures(struct grail *ge)
4542+{
4543+ struct grail_impl *impl = ge->impl;
4544+ struct input_event iev;
4545+ struct grail_event gev;
4546+ int count = 0;
4547+
4548+ while (!evbuf_empty(&impl->evbuf)) {
4549+ evbuf_get(&impl->evbuf, &iev);
4550+ if (skip_event(&iev, count))
4551+ continue;
4552+ if (ge->event)
4553+ ge->event(ge, &iev);
4554+ if (iev.type == EV_SYN && iev.code == SYN_REPORT)
4555+ count = 0;
4556+ else
4557+ count++;
4558+ }
4559+ while (!grailbuf_empty(&impl->gbuf)) {
4560+ grailbuf_get(&impl->gbuf, &gev);
4561+ if (ge->gesture)
4562+ ge->gesture(ge, &gev);
4563+ }
4564+}
4565+
4566+static int gesture_timeout(struct grail *ge, const struct utouch_frame *frame)
4567+{
4568+ struct gesture_recognizer *gru = ge->gru;
4569+ struct gesture_inserter *gin = ge->gin;
4570+
4571+ return grail_mask_count(gin->used, sizeof(gin->used)) == 0 &&
4572+ frame->time - frame->mod_time > gru->move.fm[FM_X].hold_ms;
4573+}
4574+
4575+static void report_frame(struct grail *ge,
4576+ const struct utouch_frame *touch,
4577+ const struct input_event *syn)
4578+{
4579+ struct grail_impl *impl = ge->impl;
4580+
4581+ impl->touch = touch;
4582+
4583+ if (touch->num_active && !touch->prev->num_active) {
4584+ impl->ongoing = 1;
4585+ impl->gesture = 0;
4586+ }
4587+
4588+ if (!impl->ongoing)
4589+ return;
4590+
4591+ gin_frame_begin(ge, touch);
4592+ gru_recognize(ge, touch);
4593+ gin_frame_end(ge, touch);
4594+
4595+ if (!grailbuf_empty(&impl->gbuf))
4596+ impl->gesture = 1;
4597+
4598+ if (touch->num_active == 0 || gesture_timeout(ge, touch))
4599+ impl->ongoing &= impl->gesture;
4600+}
4601+
4602+static void grail_pump_mtdev(struct grail *ge, const struct input_event *ev)
4603+{
4604+ struct grail_impl *impl = ge->impl;
4605+ const struct utouch_frame *frame;
4606+
4607+ evbuf_put(&impl->evbuf, ev);
4608+
4609+ if (ev->type == EV_SYN || ev->type == EV_ABS || ev->type == EV_KEY) {
4610+ frame = utouch_frame_pump_mtdev(impl->fh, ev);
4611+ if (frame)
4612+ report_frame(ge, frame, ev);
4613+ }
4614+
4615+ if (ev->type == EV_SYN) {
4616+ if (!impl->ongoing)
4617+ flush_events(ge);
4618+ if (impl->gesture)
4619+ flush_gestures(ge);
4620+ }
4621+}
4622+
4623+/**
4624+ * Read an event from the given file. If fast_fileread is true,
4625+ * return immediately. If it is false, delay between events
4626+ * so it looks like they are coming in real time.
4627+ */
4628+static int grail_read_evemu_event(FILE *fp, struct input_event *ev,
4629+ struct timeval *evtime, int fast_fileread) {
4630+ if (fast_fileread)
4631+ return evemu_read_event(fp, ev);
4632+ return evemu_read_event_realtime(fp, ev, evtime);
4633+}
4634+
4635+
4636+static int grail_pull_fstest(struct grail *ge, int fd)
4637+{
4638+ struct grail_impl *impl = ge->impl;
4639+ struct input_event ev;
4640+ struct timeval evtime;
4641+ int count = 0;
4642+
4643+ memset(&evtime, 0, sizeof(evtime));
4644+ while (grail_read_evemu_event(impl->fptest, &ev, &evtime, impl->fast_fileread) > 0) {
4645+ grail_pump_mtdev(ge, &ev);
4646+ count++;
4647+ }
4648+
4649+ fclose(impl->fptest);
4650+ impl->fptest = 0;
4651+
4652+ return count > 0 ? count : -1;
4653+}
4654+
4655+int GRAIL_PUBLIC grail_pull(struct grail *ge, int fd)
4656+{
4657+ struct grail_impl *impl = ge->impl;
4658+ struct input_event ev;
4659+ int ret, count = 0;
4660+
4661+ if (impl->fptest)
4662+ return grail_pull_fstest(ge, fd);
4663+
4664+ while ((ret = mtdev_get(impl->mtdev, fd, &ev, 1)) > 0) {
4665+ grail_pump_mtdev(ge, &ev);
4666+ count++;
4667+ }
4668+
4669+ return count > 0 ? count : ret;
4670+}
4671+
4672+void GRAIL_PUBLIC grail_set_coordinate_transform_callback(struct grail *ge,
4673+ utouch_coordinate_transform_cb callback,
4674+ void *user_data) {
4675+ utouch_frame_set_coordinate_transform_callback(ge->impl->fh, callback, user_data);
4676+}
4677
4678=== added file 'src/v2/grail-bits.c'
4679--- src/v2/grail-bits.c 1970-01-01 00:00:00 +0000
4680+++ src/v2/grail-bits.c 2011-11-01 19:17:00 +0000
4681@@ -0,0 +1,93 @@
4682+/*****************************************************************************
4683+ *
4684+ * grail - Gesture Recognition And Instantiation Library
4685+ *
4686+ * Copyright (C) 2010-2011 Canonical Ltd.
4687+ *
4688+ * This program is free software: you can redistribute it and/or modify it
4689+ * under the terms of the GNU General Public License as published by the
4690+ * Free Software Foundation, either version 3 of the License, or (at your
4691+ * option) any later version.
4692+ *
4693+ * This program is distributed in the hope that it will be useful, but
4694+ * WITHOUT ANY WARRANTY; without even the implied warranty of
4695+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4696+ * General Public License for more details.
4697+ *
4698+ * You should have received a copy of the GNU General Public License along
4699+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4700+ *
4701+ ****************************************************************************/
4702+
4703+#include "grail-bits.h"
4704+
4705+static const int grail_bits_in_byte[256] =
4706+{
4707+ 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
4708+ 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
4709+ 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
4710+ 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
4711+ 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
4712+ 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
4713+ 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
4714+ 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
4715+};
4716+
4717+static const int grail_first_set_bit[256] =
4718+{
4719+ -1,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
4720+ 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
4721+ 6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
4722+ 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
4723+ 7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
4724+ 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
4725+ 6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
4726+ 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
4727+};
4728+
4729+void GRAIL_PUBLIC grail_mask_set_mask(grail_mask_t *a, const grail_mask_t *b,
4730+ int bytes)
4731+{
4732+ while (bytes--)
4733+ *a++ |= *b++;
4734+}
4735+
4736+void GRAIL_PUBLIC grail_mask_clear_mask(grail_mask_t *a, const grail_mask_t *b,
4737+ int bytes)
4738+{
4739+ while (bytes--)
4740+ *a++ &= ~*b++;
4741+}
4742+
4743+int GRAIL_PUBLIC grail_mask_count(const grail_mask_t *mask, int bytes)
4744+{
4745+ int count = 0;
4746+ while (bytes--)
4747+ count += grail_bits_in_byte[*mask++];
4748+ return count;
4749+}
4750+
4751+int GRAIL_PUBLIC grail_mask_get_first(const grail_mask_t *mask, int bytes)
4752+{
4753+ int k;
4754+ for (k = 0; k < bytes; k++)
4755+ if (mask[k])
4756+ return (k << 3) | grail_first_set_bit[mask[k]];
4757+ return -1;
4758+}
4759+
4760+int GRAIL_PUBLIC grail_mask_get_next(int i, const grail_mask_t *mask, int bytes)
4761+{
4762+ int k = ++i >> 3;
4763+ if (k < bytes) {
4764+ i = grail_first_set_bit[mask[k] & (~0 << (i & 7))];
4765+ if (i >= 0)
4766+ return (k << 3) | i;
4767+ while (++k < bytes) {
4768+ i = grail_first_set_bit[mask[k]];
4769+ if (i >= 0)
4770+ return (k << 3) | i;
4771+ }
4772+ }
4773+ return -1;
4774+}
4775
4776=== added file 'src/v2/grail-event.c'
4777--- src/v2/grail-event.c 1970-01-01 00:00:00 +0000
4778+++ src/v2/grail-event.c 2011-11-01 19:17:00 +0000
4779@@ -0,0 +1,118 @@
4780+/*****************************************************************************
4781+ *
4782+ * grail - Gesture Recognition And Instantiation Library
4783+ *
4784+ * Copyright (C) 2010-2011 Canonical Ltd.
4785+ *
4786+ * This program is free software: you can redistribute it and/or modify it
4787+ * under the terms of the GNU General Public License as published by the
4788+ * Free Software Foundation, either version 3 of the License, or (at your
4789+ * option) any later version.
4790+ *
4791+ * This program is distributed in the hope that it will be useful, but
4792+ * WITHOUT ANY WARRANTY; without even the implied warranty of
4793+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4794+ * General Public License for more details.
4795+ *
4796+ * You should have received a copy of the GNU General Public License along
4797+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4798+ *
4799+ ****************************************************************************/
4800+
4801+#include "grail-inserter.h"
4802+#include "grail-impl.h"
4803+#include <malloc.h>
4804+#include <string.h>
4805+#include <errno.h>
4806+#include <math.h>
4807+
4808+static void compute_bbox(struct grail_coord *min, struct grail_coord *max,
4809+ const struct utouch_frame *frame)
4810+{
4811+ float x, y;
4812+ int i;
4813+ if (frame->num_active < 1)
4814+ return;
4815+ x = frame->active[0]->x;
4816+ y = frame->active[0]->y;
4817+ min->x = max->x = x;
4818+ min->y = max->y = y;
4819+ for (i = 1; i < frame->num_active; i++) {
4820+ x = frame->active[i]->x;
4821+ y = frame->active[i]->y;
4822+ if (x < min->x)
4823+ min->x = x;
4824+ if (y < min->y)
4825+ min->y = y;
4826+ if (x > max->x)
4827+ max->x = x;
4828+ if (y > max->y)
4829+ max->y = y;
4830+ }
4831+}
4832+
4833+int gin_add_contact_props(const struct gesture_inserter *gin,
4834+ grail_prop_t *prop, const struct utouch_frame *frame)
4835+{
4836+ struct grail_coord min = { 0, 0 };
4837+ struct grail_coord max = { 0, 0 };
4838+ int i, n = 0, ntouch = frame->num_active;
4839+ if (!ntouch)
4840+ return n;
4841+ if (ntouch > 5)
4842+ ntouch = 5;
4843+ compute_bbox(&min, &max, frame);
4844+ prop[n++] = min.x;
4845+ prop[n++] = min.y;
4846+ prop[n++] = max.x;
4847+ prop[n++] = max.y;
4848+ for (i = 0; i < ntouch; i++) {
4849+ const struct utouch_contact *ct = frame->active[i];
4850+ prop[n++] = ct->id;
4851+ prop[n++] = ct->x;
4852+ prop[n++] = ct->y;
4853+ }
4854+ return n;
4855+}
4856+
4857+int gin_get_clients(struct grail *ge,
4858+ struct grail_client_info *info, int maxinfo,
4859+ const grail_mask_t* types, int btypes,
4860+ const grail_mask_t* span, int bspan,
4861+ const struct utouch_frame *frame)
4862+{
4863+ struct grail_coord pos[DIM_TOUCH];
4864+ int i, npos = 0;
4865+ if (!ge->get_clients)
4866+ return 0;
4867+ grail_mask_foreach(i, span, bspan) {
4868+ pos[npos].x = frame->slots[i]->x;
4869+ pos[npos].y = frame->slots[i]->y;
4870+ npos++;
4871+ }
4872+ return ge->get_clients(ge, info, maxinfo, pos, npos, types, btypes);
4873+}
4874+
4875+void gin_send_event(struct grail *ge, struct slot_state *s,
4876+ const struct gesture_event *ev,
4877+ const struct utouch_frame *frame)
4878+{
4879+ struct grail_impl *impl = ge->impl;
4880+ struct grail_event gev;
4881+ int i;
4882+ if (!ge->gesture)
4883+ return;
4884+ gev.type = s->type;
4885+ gev.id = s->id;
4886+ gev.status = ev->status;
4887+ gev.ntouch = ev->ntouch;
4888+ gev.nprop = ev->nprop;
4889+ gev.time = ev->time;
4890+ gev.pos.x = ev->pos.x;
4891+ gev.pos.y = ev->pos.y;
4892+ memcpy(gev.prop, ev->prop, ev->nprop * sizeof(grail_prop_t));
4893+ for (i = 0; i < s->nclient; i++) {
4894+ gev.client_id = s->client_id[i];
4895+ grailbuf_put(&impl->gbuf, &gev);
4896+ }
4897+}
4898
4899=== added file 'src/v2/grail-frame.c'
4900--- src/v2/grail-frame.c 1970-01-01 00:00:00 +0000
4901+++ src/v2/grail-frame.c 2011-11-01 19:17:00 +0000
4902@@ -0,0 +1,410 @@
4903+/*****************************************************************************
4904+ *
4905+ * grail - Gesture Recognition And Instantiation Library
4906+ *
4907+ * Copyright (C) 2010-2011 Canonical Ltd.
4908+ *
4909+ * This program is free software: you can redistribute it and/or modify it
4910+ * under the terms of the GNU General Public License as published by the
4911+ * Free Software Foundation, either version 3 of the License, or (at your
4912+ * option) any later version.
4913+ *
4914+ * This program is distributed in the hope that it will be useful, but
4915+ * WITHOUT ANY WARRANTY; without even the implied warranty of
4916+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4917+ * General Public License for more details.
4918+ *
4919+ * You should have received a copy of the GNU General Public License along
4920+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4921+ *
4922+ ****************************************************************************/
4923+
4924+#include "grail-impl.h"
4925+#include <stdlib.h>
4926+#include <string.h>
4927+#include <math.h>
4928+
4929+static void set_center_velocity_and_radius(struct grail_impl *impl,
4930+ struct grail_element *slot)
4931+{
4932+ const struct utouch_contact **tc = slot->touches;
4933+ double x, y, vx, vy, r2, dx, dy;
4934+ int i;
4935+
4936+ switch (slot->num_touches) {
4937+ case 1:
4938+ x = tc[0]->x;
4939+ y = tc[0]->y;
4940+ vx = tc[0]->vx;
4941+ vy = tc[0]->vy;
4942+ r2 = 0;
4943+ break;
4944+ case 2:
4945+ dx = 0.5 * (tc[1]->x - tc[0]->x);
4946+ dy = 0.5 * (tc[1]->y - tc[0]->y);
4947+ x = tc[0]->x + dx;
4948+ y = tc[0]->y + dy;
4949+ vx = 0.5 * (tc[0]->vx + tc[1]->vx);
4950+ vy = 0.5 * (tc[0]->vy + tc[1]->vy);
4951+ r2 = dx * dx + dy * dy;
4952+ break;
4953+ default:
4954+ x = y = vx = vy = r2 = 0;
4955+ for (i = 0; i < slot->num_touches; i++) {
4956+ x += tc[i]->x;
4957+ y += tc[i]->y;
4958+ vx += tc[i]->vx;
4959+ vy += tc[i]->vy;
4960+ }
4961+ x /= slot->num_touches;
4962+ y /= slot->num_touches;
4963+ vx /= slot->num_touches;
4964+ vy /= slot->num_touches;
4965+ for (i = 0; i < slot->num_touches; i++) {
4966+ dx = tc[i]->x - x;
4967+ dy = tc[i]->y - y;
4968+ r2 += dx * dx + dy * dy;
4969+ }
4970+ r2 /= slot->num_touches;
4971+ break;
4972+ }
4973+
4974+ slot->center.x = x;
4975+ slot->center.y = y;
4976+ slot->velocity.x = 1000 * vx;
4977+ slot->velocity.y = 1000 * vy;
4978+ slot->radius2 = r2;
4979+}
4980+
4981+static void set_transform(struct grail_impl *impl, struct grail_element *slot,
4982+ double ds, double dc)
4983+{
4984+ const struct grail_element *pslot = slot->prev;
4985+ double dx = slot->center.x - pslot->center.x;
4986+ double dy = slot->center.y - pslot->center.y;
4987+ float *T = slot->transform;
4988+
4989+ T[0] = dc;
4990+ T[1] = ds;
4991+ T[2] = dx;
4992+ T[3] = -ds;
4993+ T[4] = dc;
4994+ T[5] = dy;
4995+
4996+ slot->drag.x = pslot->drag.x + dx;
4997+ slot->drag.y = pslot->drag.y + dy;
4998+}
4999+
5000+static void start_slot(struct grail_impl *impl,
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches