summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--COPYING674
-rw-r--r--INSTALL32
-rw-r--r--Makefile.am14
-rw-r--r--README4
-rwxr-xr-xautogen.sh11
-rw-r--r--configure.ac31
-rw-r--r--docs/grail-problems.txt60
-rw-r--r--grail.pc.in9
-rw-r--r--include/grail-bits.h65
-rw-r--r--include/grail-touch.h107
-rw-r--r--include/grail-types.h56
-rw-r--r--include/grail.h94
-rw-r--r--src/Makefile.am36
-rw-r--r--src/evbuf.h64
-rw-r--r--src/gebuf.h70
-rw-r--r--src/gestures-combo.c71
-rw-r--r--src/gestures-pan.c68
-rw-r--r--src/gestures-pinch.c68
-rw-r--r--src/gestures-rotate.c66
-rw-r--r--src/gestures-tapping.c101
-rw-r--r--src/grail-api.c115
-rw-r--r--src/grail-bits.c94
-rw-r--r--src/grail-gestures.c188
-rw-r--r--src/grail-gestures.h77
-rw-r--r--src/grail-inserter.c282
-rw-r--r--src/grail-inserter.h71
-rw-r--r--src/grail-recognizer.c58
-rw-r--r--src/grail-recognizer.h44
-rw-r--r--src/touch-dev.c218
-rw-r--r--src/touch-engine.c137
-rw-r--r--test/Makefile.am9
-rw-r--r--test/grail-gesture.c111
-rw-r--r--test/grail-touch.c88
34 files changed, 3194 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0a7ae96
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
.bzr
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..5581f8b
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
1grail - Gesture Recognition And Instantiation Library (GPLv3 license)
2
3 Copyright (C) 2010 Canonical Ltd.
4
5Authors:
6 Henrik Rydberg <rydberg@bitmath.org>
7
8 Preamble
9
10 The GNU General Public License is a free, copyleft license for
11software and other kinds of works.
12
13 The licenses for most software and other practical works are designed
14to take away your freedom to share and change the works. By contrast,
15the GNU General Public License is intended to guarantee your freedom to
16share and change all versions of a program--to make sure it remains free
17software for all its users. We, the Free Software Foundation, use the
18GNU General Public License for most of our software; it applies also to
19any other work released this way by its authors. You can apply it to
20your programs, too.
21
22 When we speak of free software, we are referring to freedom, not
23price. Our General Public Licenses are designed to make sure that you
24have the freedom to distribute copies of free software (and charge for
25them if you wish), that you receive source code or can get it if you
26want it, that you can change the software or use pieces of it in new
27free programs, and that you know you can do these things.
28
29 To protect your rights, we need to prevent others from denying you
30these rights or asking you to surrender the rights. Therefore, you have
31certain responsibilities if you distribute copies of the software, or if
32you modify it: responsibilities to respect the freedom of others.
33
34 For example, if you distribute copies of such a program, whether
35gratis or for a fee, you must pass on to the recipients the same
36freedoms that you received. You must make sure that they, too, receive
37or can get the source code. And you must show them these terms so they
38know their rights.
39
40 Developers that use the GNU GPL protect your rights with two steps:
41(1) assert copyright on the software, and (2) offer you this License
42giving you legal permission to copy, distribute and/or modify it.
43
44 For the developers' and authors' protection, the GPL clearly explains
45that there is no warranty for this free software. For both users' and
46authors' sake, the GPL requires that modified versions be marked as
47changed, so that their problems will not be attributed erroneously to
48authors of previous versions.
49
50 Some devices are designed to deny users access to install or run
51modified versions of the software inside them, although the manufacturer
52can do so. This is fundamentally incompatible with the aim of
53protecting users' freedom to change the software. The systematic
54pattern of such abuse occurs in the area of products for individuals to
55use, which is precisely where it is most unacceptable. Therefore, we
56have designed this version of the GPL to prohibit the practice for those
57products. If such problems arise substantially in other domains, we
58stand ready to extend this provision to those domains in future versions
59of the GPL, as needed to protect the freedom of users.
60
61 Finally, every program is threatened constantly by software patents.
62States should not allow patents to restrict development and use of
63software on general-purpose computers, but in those that do, we wish to
64avoid the special danger that patents applied to a free program could
65make it effectively proprietary. To prevent this, the GPL assures that
66patents cannot be used to render the program non-free.
67
68 The precise terms and conditions for copying, distribution and
69modification follow.
70
71 TERMS AND CONDITIONS
72
73 0. Definitions.
74
75 "This License" refers to version 3 of the GNU General Public License.
76
77 "Copyright" also means copyright-like laws that apply to other kinds of
78works, such as semiconductor masks.
79
80 "The Program" refers to any copyrightable work licensed under this
81License. Each licensee is addressed as "you". "Licensees" and
82"recipients" may be individuals or organizations.
83
84 To "modify" a work means to copy from or adapt all or part of the work
85in a fashion requiring copyright permission, other than the making of an
86exact copy. The resulting work is called a "modified version" of the
87earlier work or a work "based on" the earlier work.
88
89 A "covered work" means either the unmodified Program or a work based
90on the Program.
91
92 To "propagate" a work means to do anything with it that, without
93permission, would make you directly or secondarily liable for
94infringement under applicable copyright law, except executing it on a
95computer or modifying a private copy. Propagation includes copying,
96distribution (with or without modification), making available to the
97public, and in some countries other activities as well.
98
99 To "convey" a work means any kind of propagation that enables other
100parties to make or receive copies. Mere interaction with a user through
101a computer network, with no transfer of a copy, is not conveying.
102
103 An interactive user interface displays "Appropriate Legal Notices"
104to the extent that it includes a convenient and prominently visible
105feature that (1) displays an appropriate copyright notice, and (2)
106tells the user that there is no warranty for the work (except to the
107extent that warranties are provided), that licensees may convey the
108work under this License, and how to view a copy of this License. If
109the interface presents a list of user commands or options, such as a
110menu, a prominent item in the list meets this criterion.
111
112 1. Source Code.
113
114 The "source code" for a work means the preferred form of the work
115for making modifications to it. "Object code" means any non-source
116form of a work.
117
118 A "Standard Interface" means an interface that either is an official
119standard defined by a recognized standards body, or, in the case of
120interfaces specified for a particular programming language, one that
121is widely used among developers working in that language.
122
123 The "System Libraries" of an executable work include anything, other
124than the work as a whole, that (a) is included in the normal form of
125packaging a Major Component, but which is not part of that Major
126Component, and (b) serves only to enable use of the work with that
127Major Component, or to implement a Standard Interface for which an
128implementation is available to the public in source code form. A
129"Major Component", in this context, means a major essential component
130(kernel, window system, and so on) of the specific operating system
131(if any) on which the executable work runs, or a compiler used to
132produce the work, or an object code interpreter used to run it.
133
134 The "Corresponding Source" for a work in object code form means all
135the source code needed to generate, install, and (for an executable
136work) run the object code and to modify the work, including scripts to
137control those activities. However, it does not include the work's
138System Libraries, or general-purpose tools or generally available free
139programs which are used unmodified in performing those activities but
140which are not part of the work. For example, Corresponding Source
141includes interface definition files associated with source files for
142the work, and the source code for shared libraries and dynamically
143linked subprograms that the work is specifically designed to require,
144such as by intimate data communication or control flow between those
145subprograms and other parts of the work.
146
147 The Corresponding Source need not include anything that users
148can regenerate automatically from other parts of the Corresponding
149Source.
150
151 The Corresponding Source for a work in source code form is that
152same work.
153
154 2. Basic Permissions.
155
156 All rights granted under this License are granted for the term of
157copyright on the Program, and are irrevocable provided the stated
158conditions are met. This License explicitly affirms your unlimited
159permission to run the unmodified Program. The output from running a
160covered work is covered by this License only if the output, given its
161content, constitutes a covered work. This License acknowledges your
162rights of fair use or other equivalent, as provided by copyright law.
163
164 You may make, run and propagate covered works that you do not
165convey, without conditions so long as your license otherwise remains
166in force. You may convey covered works to others for the sole purpose
167of having them make modifications exclusively for you, or provide you
168with facilities for running those works, provided that you comply with
169the terms of this License in conveying all material for which you do
170not control copyright. Those thus making or running the covered works
171for you must do so exclusively on your behalf, under your direction
172and control, on terms that prohibit them from making any copies of
173your copyrighted material outside their relationship with you.
174
175 Conveying under any other circumstances is permitted solely under
176the conditions stated below. Sublicensing is not allowed; section 10
177makes it unnecessary.
178
179 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
181 No covered work shall be deemed part of an effective technological
182measure under any applicable law fulfilling obligations under article
18311 of the WIPO copyright treaty adopted on 20 December 1996, or
184similar laws prohibiting or restricting circumvention of such
185measures.
186
187 When you convey a covered work, you waive any legal power to forbid
188circumvention of technological measures to the extent such circumvention
189is effected by exercising rights under this License with respect to
190the covered work, and you disclaim any intention to limit operation or
191modification of the work as a means of enforcing, against the work's
192users, your or third parties' legal rights to forbid circumvention of
193technological measures.
194
195 4. Conveying Verbatim Copies.
196
197 You may convey verbatim copies of the Program's source code as you
198receive it, in any medium, provided that you conspicuously and
199appropriately publish on each copy an appropriate copyright notice;
200keep intact all notices stating that this License and any
201non-permissive terms added in accord with section 7 apply to the code;
202keep intact all notices of the absence of any warranty; and give all
203recipients a copy of this License along with the Program.
204
205 You may charge any price or no price for each copy that you convey,
206and you may offer support or warranty protection for a fee.
207
208 5. Conveying Modified Source Versions.
209
210 You may convey a work based on the Program, or the modifications to
211produce it from the Program, in the form of source code under the
212terms of section 4, provided that you also meet all of these conditions:
213
214 a) The work must carry prominent notices stating that you modified
215 it, and giving a relevant date.
216
217 b) The work must carry prominent notices stating that it is
218 released under this License and any conditions added under section
219 7. This requirement modifies the requirement in section 4 to
220 "keep intact all notices".
221
222 c) You must license the entire work, as a whole, under this
223 License to anyone who comes into possession of a copy. This
224 License will therefore apply, along with any applicable section 7
225 additional terms, to the whole of the work, and all its parts,
226 regardless of how they are packaged. This License gives no
227 permission to license the work in any other way, but it does not
228 invalidate such permission if you have separately received it.
229
230 d) If the work has interactive user interfaces, each must display
231 Appropriate Legal Notices; however, if the Program has interactive
232 interfaces that do not display Appropriate Legal Notices, your
233 work need not make them do so.
234
235 A compilation of a covered work with other separate and independent
236works, which are not by their nature extensions of the covered work,
237and which are not combined with it such as to form a larger program,
238in or on a volume of a storage or distribution medium, is called an
239"aggregate" if the compilation and its resulting copyright are not
240used to limit the access or legal rights of the compilation's users
241beyond what the individual works permit. Inclusion of a covered work
242in an aggregate does not cause this License to apply to the other
243parts of the aggregate.
244
245 6. Conveying Non-Source Forms.
246
247 You may convey a covered work in object code form under the terms
248of sections 4 and 5, provided that you also convey the
249machine-readable Corresponding Source under the terms of this License,
250in one of these ways:
251
252 a) Convey the object code in, or embodied in, a physical product
253 (including a physical distribution medium), accompanied by the
254 Corresponding Source fixed on a durable physical medium
255 customarily used for software interchange.
256
257 b) Convey the object code in, or embodied in, a physical product
258 (including a physical distribution medium), accompanied by a
259 written offer, valid for at least three years and valid for as
260 long as you offer spare parts or customer support for that product
261 model, to give anyone who possesses the object code either (1) a
262 copy of the Corresponding Source for all the software in the
263 product that is covered by this License, on a durable physical
264 medium customarily used for software interchange, for a price no
265 more than your reasonable cost of physically performing this
266 conveying of source, or (2) access to copy the
267 Corresponding Source from a network server at no charge.
268
269 c) Convey individual copies of the object code with a copy of the
270 written offer to provide the Corresponding Source. This
271 alternative is allowed only occasionally and noncommercially, and
272 only if you received the object code with such an offer, in accord
273 with subsection 6b.
274
275 d) Convey the object code by offering access from a designated
276 place (gratis or for a charge), and offer equivalent access to the
277 Corresponding Source in the same way through the same place at no
278 further charge. You need not require recipients to copy the
279 Corresponding Source along with the object code. If the place to
280 copy the object code is a network server, the Corresponding Source
281 may be on a different server (operated by you or a third party)
282 that supports equivalent copying facilities, provided you maintain
283 clear directions next to the object code saying where to find the
284 Corresponding Source. Regardless of what server hosts the
285 Corresponding Source, you remain obligated to ensure that it is
286 available for as long as needed to satisfy these requirements.
287
288 e) Convey the object code using peer-to-peer transmission, provided
289 you inform other peers where the object code and Corresponding
290 Source of the work are being offered to the general public at no
291 charge under subsection 6d.
292
293 A separable portion of the object code, whose source code is excluded
294from the Corresponding Source as a System Library, need not be
295included in conveying the object code work.
296
297 A "User Product" is either (1) a "consumer product", which means any
298tangible personal property which is normally used for personal, family,
299or household purposes, or (2) anything designed or sold for incorporation
300into a dwelling. In determining whether a product is a consumer product,
301doubtful cases shall be resolved in favor of coverage. For a particular
302product received by a particular user, "normally used" refers to a
303typical or common use of that class of product, regardless of the status
304of the particular user or of the way in which the particular user
305actually uses, or expects or is expected to use, the product. A product
306is a consumer product regardless of whether the product has substantial
307commercial, industrial or non-consumer uses, unless such uses represent
308the only significant mode of use of the product.
309
310 "Installation Information" for a User Product means any methods,
311procedures, authorization keys, or other information required to install
312and execute modified versions of a covered work in that User Product from
313a modified version of its Corresponding Source. The information must
314suffice to ensure that the continued functioning of the modified object
315code is in no case prevented or interfered with solely because
316modification has been made.
317
318 If you convey an object code work under this section in, or with, or
319specifically for use in, a User Product, and the conveying occurs as
320part of a transaction in which the right of possession and use of the
321User Product is transferred to the recipient in perpetuity or for a
322fixed term (regardless of how the transaction is characterized), the
323Corresponding Source conveyed under this section must be accompanied
324by the Installation Information. But this requirement does not apply
325if neither you nor any third party retains the ability to install
326modified object code on the User Product (for example, the work has
327been installed in ROM).
328
329 The requirement to provide Installation Information does not include a
330requirement to continue to provide support service, warranty, or updates
331for a work that has been modified or installed by the recipient, or for
332the User Product in which it has been modified or installed. Access to a
333network may be denied when the modification itself materially and
334adversely affects the operation of the network or violates the rules and
335protocols for communication across the network.
336
337 Corresponding Source conveyed, and Installation Information provided,
338in accord with this section must be in a format that is publicly
339documented (and with an implementation available to the public in
340source code form), and must require no special password or key for
341unpacking, reading or copying.
342
343 7. Additional Terms.
344
345 "Additional permissions" are terms that supplement the terms of this
346License by making exceptions from one or more of its conditions.
347Additional permissions that are applicable to the entire Program shall
348be treated as though they were included in this License, to the extent
349that they are valid under applicable law. If additional permissions
350apply only to part of the Program, that part may be used separately
351under those permissions, but the entire Program remains governed by
352this License without regard to the additional permissions.
353
354 When you convey a copy of a covered work, you may at your option
355remove any additional permissions from that copy, or from any part of
356it. (Additional permissions may be written to require their own
357removal in certain cases when you modify the work.) You may place
358additional permissions on material, added by you to a covered work,
359for which you have or can give appropriate copyright permission.
360
361 Notwithstanding any other provision of this License, for material you
362add to a covered work, you may (if authorized by the copyright holders of
363that material) supplement the terms of this License with terms:
364
365 a) Disclaiming warranty or limiting liability differently from the
366 terms of sections 15 and 16 of this License; or
367
368 b) Requiring preservation of specified reasonable legal notices or
369 author attributions in that material or in the Appropriate Legal
370 Notices displayed by works containing it; or
371
372 c) Prohibiting misrepresentation of the origin of that material, or
373 requiring that modified versions of such material be marked in
374 reasonable ways as different from the original version; or
375
376 d) Limiting the use for publicity purposes of names of licensors or
377 authors of the material; or
378
379 e) Declining to grant rights under trademark law for use of some
380 trade names, trademarks, or service marks; or
381
382 f) Requiring indemnification of licensors and authors of that
383 material by anyone who conveys the material (or modified versions of
384 it) with contractual assumptions of liability to the recipient, for
385 any liability that these contractual assumptions directly impose on
386 those licensors and authors.
387
388 All other non-permissive additional terms are considered "further
389restrictions" within the meaning of section 10. If the Program as you
390received it, or any part of it, contains a notice stating that it is
391governed by this License along with a term that is a further
392restriction, you may remove that term. If a license document contains
393a further restriction but permits relicensing or conveying under this
394License, you may add to a covered work material governed by the terms
395of that license document, provided that the further restriction does
396not survive such relicensing or conveying.
397
398 If you add terms to a covered work in accord with this section, you
399must place, in the relevant source files, a statement of the
400additional terms that apply to those files, or a notice indicating
401where to find the applicable terms.
402
403 Additional terms, permissive or non-permissive, may be stated in the
404form of a separately written license, or stated as exceptions;
405the above requirements apply either way.
406
407 8. Termination.
408
409 You may not propagate or modify a covered work except as expressly
410provided under this License. Any attempt otherwise to propagate or
411modify it is void, and will automatically terminate your rights under
412this License (including any patent licenses granted under the third
413paragraph of section 11).
414
415 However, if you cease all violation of this License, then your
416license from a particular copyright holder is reinstated (a)
417provisionally, unless and until the copyright holder explicitly and
418finally terminates your license, and (b) permanently, if the copyright
419holder fails to notify you of the violation by some reasonable means
420prior to 60 days after the cessation.
421
422 Moreover, your license from a particular copyright holder is
423reinstated permanently if the copyright holder notifies you of the
424violation by some reasonable means, this is the first time you have
425received notice of violation of this License (for any work) from that
426copyright holder, and you cure the violation prior to 30 days after
427your receipt of the notice.
428
429 Termination of your rights under this section does not terminate the
430licenses of parties who have received copies or rights from you under
431this License. If your rights have been terminated and not permanently
432reinstated, you do not qualify to receive new licenses for the same
433material under section 10.
434
435 9. Acceptance Not Required for Having Copies.
436
437 You are not required to accept this License in order to receive or
438run a copy of the Program. Ancillary propagation of a covered work
439occurring solely as a consequence of using peer-to-peer transmission
440to receive a copy likewise does not require acceptance. However,
441nothing other than this License grants you permission to propagate or
442modify any covered work. These actions infringe copyright if you do
443not accept this License. Therefore, by modifying or propagating a
444covered work, you indicate your acceptance of this License to do so.
445
446 10. Automatic Licensing of Downstream Recipients.
447
448 Each time you convey a covered work, the recipient automatically
449receives a license from the original licensors, to run, modify and
450propagate that work, subject to this License. You are not responsible
451for enforcing compliance by third parties with this License.
452
453 An "entity transaction" is a transaction transferring control of an
454organization, or substantially all assets of one, or subdividing an
455organization, or merging organizations. If propagation of a covered
456work results from an entity transaction, each party to that
457transaction who receives a copy of the work also receives whatever
458licenses to the work the party's predecessor in interest had or could
459give under the previous paragraph, plus a right to possession of the
460Corresponding Source of the work from the predecessor in interest, if
461the predecessor has it or can get it with reasonable efforts.
462
463 You may not impose any further restrictions on the exercise of the
464rights granted or affirmed under this License. For example, you may
465not impose a license fee, royalty, or other charge for exercise of
466rights granted under this License, and you may not initiate litigation
467(including a cross-claim or counterclaim in a lawsuit) alleging that
468any patent claim is infringed by making, using, selling, offering for
469sale, or importing the Program or any portion of it.
470
471 11. Patents.
472
473 A "contributor" is a copyright holder who authorizes use under this
474License of the Program or a work on which the Program is based. The
475work thus licensed is called the contributor's "contributor version".
476
477 A contributor's "essential patent claims" are all patent claims
478owned or controlled by the contributor, whether already acquired or
479hereafter acquired, that would be infringed by some manner, permitted
480by this License, of making, using, or selling its contributor version,
481but do not include claims that would be infringed only as a
482consequence of further modification of the contributor version. For
483purposes of this definition, "control" includes the right to grant
484patent sublicenses in a manner consistent with the requirements of
485this License.
486
487 Each contributor grants you a non-exclusive, worldwide, royalty-free
488patent license under the contributor's essential patent claims, to
489make, use, sell, offer for sale, import and otherwise run, modify and
490propagate the contents of its contributor version.
491
492 In the following three paragraphs, a "patent license" is any express
493agreement or commitment, however denominated, not to enforce a patent
494(such as an express permission to practice a patent or covenant not to
495sue for patent infringement). To "grant" such a patent license to a
496party means to make such an agreement or commitment not to enforce a
497patent against the party.
498
499 If you convey a covered work, knowingly relying on a patent license,
500and the Corresponding Source of the work is not available for anyone
501to copy, free of charge and under the terms of this License, through a
502publicly available network server or other readily accessible means,
503then you must either (1) cause the Corresponding Source to be so
504available, or (2) arrange to deprive yourself of the benefit of the
505patent license for this particular work, or (3) arrange, in a manner
506consistent with the requirements of this License, to extend the patent
507license to downstream recipients. "Knowingly relying" means you have
508actual knowledge that, but for the patent license, your conveying the
509covered work in a country, or your recipient's use of the covered work
510in a country, would infringe one or more identifiable patents in that
511country that you have reason to believe are valid.
512
513 If, pursuant to or in connection with a single transaction or
514arrangement, you convey, or propagate by procuring conveyance of, a
515covered work, and grant a patent license to some of the parties
516receiving the covered work authorizing them to use, propagate, modify
517or convey a specific copy of the covered work, then the patent license
518you grant is automatically extended to all recipients of the covered
519work and works based on it.
520
521 A patent license is "discriminatory" if it does not include within
522the scope of its coverage, prohibits the exercise of, or is
523conditioned on the non-exercise of one or more of the rights that are
524specifically granted under this License. You may not convey a covered
525work if you are a party to an arrangement with a third party that is
526in the business of distributing software, under which you make payment
527to the third party based on the extent of your activity of conveying
528the work, and under which the third party grants, to any of the
529parties who would receive the covered work from you, a discriminatory
530patent license (a) in connection with copies of the covered work
531conveyed by you (or copies made from those copies), or (b) primarily
532for and in connection with specific products or compilations that
533contain the covered work, unless you entered into that arrangement,
534or that patent license was granted, prior to 28 March 2007.
535
536 Nothing in this License shall be construed as excluding or limiting
537any implied license or other defenses to infringement that may
538otherwise be available to you under applicable patent law.
539
540 12. No Surrender of Others' Freedom.
541
542 If conditions are imposed on you (whether by court order, agreement or
543otherwise) that contradict the conditions of this License, they do not
544excuse you from the conditions of this License. If you cannot convey a
545covered work so as to satisfy simultaneously your obligations under this
546License and any other pertinent obligations, then as a consequence you may
547not convey it at all. For example, if you agree to terms that obligate you
548to collect a royalty for further conveying from those to whom you convey
549the Program, the only way you could satisfy both those terms and this
550License would be to refrain entirely from conveying the Program.
551
552 13. Use with the GNU Affero General Public License.
553
554 Notwithstanding any other provision of this License, you have
555permission to link or combine any covered work with a work licensed
556under version 3 of the GNU Affero General Public License into a single
557combined work, and to convey the resulting work. The terms of this
558License will continue to apply to the part which is the covered work,
559but the special requirements of the GNU Affero General Public License,
560section 13, concerning interaction through a network will apply to the
561combination as such.
562
563 14. Revised Versions of this License.
564
565 The Free Software Foundation may publish revised and/or new versions of
566the GNU General Public License from time to time. Such new versions will
567be similar in spirit to the present version, but may differ in detail to
568address new problems or concerns.
569
570 Each version is given a distinguishing version number. If the
571Program specifies that a certain numbered version of the GNU General
572Public License "or any later version" applies to it, you have the
573option of following the terms and conditions either of that numbered
574version or of any later version published by the Free Software
575Foundation. If the Program does not specify a version number of the
576GNU General Public License, you may choose any version ever published
577by the Free Software Foundation.
578
579 If the Program specifies that a proxy can decide which future
580versions of the GNU General Public License can be used, that proxy's
581public statement of acceptance of a version permanently authorizes you
582to choose that version for the Program.
583
584 Later license versions may give you additional or different
585permissions. However, no additional obligations are imposed on any
586author or copyright holder as a result of your choosing to follow a
587later version.
588
589 15. Disclaimer of Warranty.
590
591 THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
600 16. Limitation of Liability.
601
602 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610SUCH DAMAGES.
611
612 17. Interpretation of Sections 15 and 16.
613
614 If the disclaimer of warranty and limitation of liability provided
615above cannot be given local legal effect according to their terms,
616reviewing courts shall apply local law that most closely approximates
617an absolute waiver of all civil liability in connection with the
618Program, unless a warranty or assumption of liability accompanies a
619copy of the Program in return for a fee.
620
621 END OF TERMS AND CONDITIONS
622
623 How to Apply These Terms to Your New Programs
624
625 If you develop a new program, and you want it to be of the greatest
626possible use to the public, the best way to achieve this is to make it
627free software which everyone can redistribute and change under these terms.
628
629 To do so, attach the following notices to the program. It is safest
630to attach them to the start of each source file to most effectively
631state the exclusion of warranty; and each file should have at least
632the "copyright" line and a pointer to where the full notice is found.
633
634 <one line to give the program's name and a brief idea of what it does.>
635 Copyright (C) <year> <name of author>
636
637 This program is free software: you can redistribute it and/or modify
638 it under the terms of the GNU General Public License as published by
639 the Free Software Foundation, either version 3 of the License, or
640 (at your option) any later version.
641
642 This program is distributed in the hope that it will be useful,
643 but WITHOUT ANY WARRANTY; without even the implied warranty of
644 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 GNU General Public License for more details.
646
647 You should have received a copy of the GNU General Public License
648 along with this program. If not, see <http://www.gnu.org/licenses/>.
649
650Also add information on how to contact you by electronic and paper mail.
651
652 If the program does terminal interaction, make it output a short
653notice like this when it starts in an interactive mode:
654
655 <program> Copyright (C) <year> <name of author>
656 This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 This is free software, and you are welcome to redistribute it
658 under certain conditions; type `show c' for details.
659
660The hypothetical commands `show w' and `show c' should show the appropriate
661parts of the General Public License. Of course, your program's commands
662might be different; for a GUI interface, you would use an "about box".
663
664 You should also get your employer (if you work as a programmer) or school,
665if any, to sign a "copyright disclaimer" for the program, if necessary.
666For more information on this, and how to apply and follow the GNU GPL, see
667<http://www.gnu.org/licenses/>.
668
669 The GNU General Public License does not permit incorporating your program
670into proprietary programs. If your program is a subroutine library, you
671may consider it more useful to permit linking proprietary applications with
672the library. If this is what you want to do, use the GNU Lesser General
673Public License instead of this License. But first, please read
674<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..4e42ff7
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,32 @@
1grail - Gesture Recognition And Instantiation Library
2
3To build, you need to have the autoconf, libtool and mtdev-dev packages
4installed. Then, do
5
6 ./autogen.sh
7 ./configure
8 make
9
10To test the touch properties of an MT device at /dev/input/eventX, do
11
12 sudo ./test/grail-touch /dev/input/eventX
13
14You should be able to see touch events in the terminal. After five
15seconds of inactivity, the program exits.
16
17To test gestures, do
18
19 sudo ./test/grail-gesture 0xffffffff /dev/input/eventX
20
21You should be able to see gesture events in the terminal. After five
22seconds of inactivity, the program exits.
23
24To install grail, do
25
26 sudo make install
27
28By default, grail installs to /usr/local. To change, use the --prefix
29configure option.
30
31Enjoy,
32Henrik
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..14279f4
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,14 @@
1SUBDIRS = src test
2
3pkgconfigdir = $(libdir)/pkgconfig
4pkgconfig_DATA = grail.pc
5
6INCLUDES = $(top_srcdir)/include/
7
8.PHONY: ChangeLog INSTALL
9INSTALL:
10 $(INSTALL_CMD)
11ChangeLog:
12 bzr log > ChangeLog
13
14dist-hook: ChangeLog INSTALL
diff --git a/README b/README
new file mode 100644
index 0000000..05a40e1
--- /dev/null
+++ b/README
@@ -0,0 +1,4 @@
1grail - Gesture Recognition And Instantiation Library
2
3This code defines an interface and tools for handling recognized
4gestures.
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..a08311b
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,11 @@
1#! /bin/sh
2
3srcdir=`dirname $0`
4test -z "$srcdir" && srcdir=.
5
6ORIGDIR=`pwd`
7cd $srcdir
8
9autoreconf -v --install || exit 1
10cd $ORIGDIR || exit $?
11
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..6d8a72b
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,31 @@
1# Initialize Autoconf
2AC_PREREQ([2.60])
3AC_INIT([Gesture Recognition And Instantiation Library],
4 [1.0.3],
5 [],
6 [grail])
7AC_CONFIG_SRCDIR([Makefile.am])
8AC_CONFIG_HEADERS([config.h])
9AC_CONFIG_AUX_DIR([config-aux])
10
11# Initialize Automake
12AM_INIT_AUTOMAKE([foreign dist-bzip2])
13AM_MAINTAINER_MODE
14
15LIB_VERSION=1:0:0
16AC_SUBST([LIB_VERSION])
17
18# Initialize libtool
19AC_PROG_LIBTOOL
20
21# Checks for programs.
22AC_PROG_CC
23AC_PROG_INSTALL
24
25PKG_CHECK_MODULES([MTDEV], [mtdev >= 1.0])
26
27AC_CONFIG_FILES([Makefile
28 src/Makefile
29 test/Makefile
30 grail.pc])
31AC_OUTPUT
diff --git a/docs/grail-problems.txt b/docs/grail-problems.txt
new file mode 100644
index 0000000..0713288
--- /dev/null
+++ b/docs/grail-problems.txt
@@ -0,0 +1,60 @@
1Split gestures into recognition and application
2-----------------------------------------------
3
4Gesture detection is not an exact science, but the algorithms
5inevitably involve decisions influenced by what gestures are available
6to choose from. Therefore, the recognition should be considered an
7inherent property of the device itself, regardless of user interaction
8context. Just imagine having a keyboard that resized slightly
9everytime you switched from chrome to gimp.
10
11
12Tag events as being part of a gesture
13-------------------------------------
14
15One of the problems faced when replacing one set of events with
16another is where and how this filtering should take place. One window
17might listen for spiral gestures, whereas another window is a paint
18program where you actually want to draw a spiral. By introducing a
19relation between a gesture and an event, filtering becomes something
20simple that can be performed close to the window. The relation can be
21implemented as a bitmask representing what gestures the event is part
22of.
23
24
25Help the client to keep track of active gestures
26------------------------------------------------
27
28A gesture starts, continues, and either completes or aborts.
29A client that listens to a subset of gestures will have to keep track.
30Compatible to Qt approach.
31
32
33Allow clients to listen to different gestures
34---------------------------------------------
35
36Clients listening on certain gestures will get those gesture events that
37apply to the client, which makes it possible for different clients to
38listen to different types of gestures. For instance, having an MT drawing
39program next to a web browser, a two finger stroke in the drawing program
40will result in two lines, whereas in the web browser, it will scroll the
41text.
42
43
44Propagate gesture events based on the focus point
45-------------------------------------------------
46
47Like pointer events, a gesture applies to a window or a window manager,
48based on where it is performed on the screen. In order to route the gesture
49events to the right window, we propagate them through the window hierarchy
50based on the gesture focus points. Based on the target windows, their
51respective gesture type masks, and the active set of gestures, final
52gesture events are emitted to the right windows.
53
54
55Allow Window Manager to grab system-wide gestures
56-------------------------------------------------
57
58Even if clients are not listening to global window-manager gestures, it
59could well be that no other gestures should be displayed while the global
60gesture is taking place.
diff --git a/grail.pc.in b/grail.pc.in
new file mode 100644
index 0000000..6d69ddc
--- /dev/null
+++ b/grail.pc.in
@@ -0,0 +1,9 @@
1prefix=@prefix@
2exec_prefix=@exec_prefix@
3libdir=@libdir@
4includedir=@includedir@
5
6Name: grail
7Description: Gesture Recognition And Instantiation Library
8Version: @PACKAGE_VERSION@
9Libs: -L${libdir} -lgrail
diff --git a/include/grail-bits.h b/include/grail-bits.h
new file mode 100644
index 0000000..ca04c3f
--- /dev/null
+++ b/include/grail-bits.h
@@ -0,0 +1,65 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#ifndef _GRAIL_BITS_H
26#define _GRAIL_BITS_H
27
28typedef unsigned char grail_mask_t;
29
30static inline void grail_mask_set(grail_mask_t *mask, int i)
31{
32 mask[i >> 3] |= (1 << (i & 7));
33}
34
35static inline void grail_mask_clear(grail_mask_t *mask, int i)
36{
37 mask[i >> 3] &= ~(1 << (i & 7));
38}
39
40static inline void grail_mask_modify(grail_mask_t *mask, int i, int v)
41{
42 if (v)
43 grail_mask_set(mask, i);
44 else
45 grail_mask_clear(mask, i);
46}
47
48static inline int grail_mask_get(const grail_mask_t *mask, int i)
49{
50 return (mask[i >> 3] >> (i & 7)) & 1;
51}
52
53void grail_mask_set_mask(grail_mask_t *a, const grail_mask_t *b, int bytes);
54void grail_mask_clear_mask(grail_mask_t *a, const grail_mask_t *b, int bytes);
55
56int grail_mask_count(const grail_mask_t *mask, int bytes);
57int grail_mask_get_first(const grail_mask_t *mask, int bytes);
58int grail_mask_get_next(int i, const grail_mask_t *mask, int bytes);
59
60#define grail_mask_foreach(i, mask, bytes) \
61 for (i = grail_mask_get_first(mask, bytes); \
62 i >= 0; \
63 i = grail_mask_get_next(i, mask, bytes))
64
65#endif
diff --git a/include/grail-touch.h b/include/grail-touch.h
new file mode 100644
index 0000000..5c2fab0
--- /dev/null
+++ b/include/grail-touch.h
@@ -0,0 +1,107 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#ifndef _GRAIL_TOUCH_H
26#define _GRAIL_TOUCH_H
27
28#include <grail-bits.h>
29#include <mtdev.h>
30
31#define DIM_TOUCH 32
32#define DIM_TOUCH_BYTES ((DIM_TOUCH + 7) >> 3)
33
34typedef int touch_prop_t;
35typedef __u64 touch_time_t;
36
37enum touch_prop_list {
38 TP_POS_X,
39 TP_POS_Y,
40 TP_TOUCH_MAJOR,
41 TP_TOUCH_MINOR,
42 TP_WIDTH_MAJOR,
43 TP_WIDTH_MINOR,
44 TP_ORIENTATION,
45 TP_PRESSURE,
46 DIM_TOUCH_PROP
47};
48
49#define DIM_TOUCH_PROP_BYTES ((DIM_TOUCH_PROP + 7) >> 3)
50
51struct touch {
52 int active;
53 int slot;
54 touch_prop_t prop[DIM_TOUCH_PROP];
55};
56
57struct touch_frame {
58 int nactive;
59 int ncreate, nmodify, ndestroy;
60 touch_time_t time;
61 grail_mask_t touches[DIM_TOUCH_BYTES];
62 struct touch *active[DIM_TOUCH];
63 struct touch touch[DIM_TOUCH];
64};
65
66struct touch_dev_caps {
67 grail_mask_t mask[DIM_TOUCH_PROP_BYTES];
68 struct input_absinfo info[DIM_TOUCH_PROP];
69};
70
71struct touch_dev {
72 void (*event)(struct touch_dev *dev, const struct input_event *ev);
73 void (*create)(struct touch_dev *dev, int slot,
74 const grail_mask_t *mask, const touch_prop_t *prop);
75 void (*modify)(struct touch_dev *dev, int slot,
76 const grail_mask_t *mask, const touch_prop_t *prop);
77 void (*destroy)(struct touch_dev *dev, int slot);
78 void (*sync)(struct touch_dev *dev, const struct input_event *syn);
79 struct touch_dev_caps caps;
80 struct touch_dev_impl *impl;
81 void *priv;
82};
83
84struct touch_engine {
85 void (*event)(struct touch_engine *engine,
86 const struct input_event *ev);
87 void (*sync)(struct touch_engine *engine,
88 const struct input_event *syn);
89 struct touch_frame frame;
90 void *priv;
91};
92
93int touch_dev_open(struct touch_dev *dev, int fd);
94int touch_dev_idle(struct touch_dev *dev, int fd, int ms);
95int touch_dev_pull(struct touch_dev *dev, int fd);
96void touch_dev_close(struct touch_dev *dev, int fd);
97
98void touch_engine_init(struct touch_engine *engine,
99 void (*event)(struct touch_engine *engine,
100 const struct input_event *ev),
101 void (*sync)(struct touch_engine *engine,
102 const struct input_event *ev),
103 void *priv);
104void touch_engine_attach(struct touch_engine *engine, struct touch_dev *dev);
105void touch_engine_detach(struct touch_engine *engine, struct touch_dev *dev);
106
107#endif
diff --git a/include/grail-types.h b/include/grail-types.h
new file mode 100644
index 0000000..7de3d9a
--- /dev/null
+++ b/include/grail-types.h
@@ -0,0 +1,56 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#ifndef _GRAIL_TYPES_H
26#define _GRAIL_TYPES_H
27
28#define GRAIL_TYPE_POINTER 0 /* reserved */
29
30#define GRAIL_TYPE_PAN 1 /* two-finger pan/scroll */
31#define GRAIL_TYPE_PINCH 2 /* two-finger pinch-to-zoom */
32#define GRAIL_TYPE_ROTATE 3 /* two-finger rotation */
33#define GRAIL_TYPE_COMBO2 4 /* two-finger combo */
34
35#define GRAIL_TYPE_SWIPE 5 /* three-finger pan */
36#define GRAIL_TYPE_SCALE 6 /* three-finger pinch */
37#define GRAIL_TYPE_TURN 7 /* three-finger rotate */
38#define GRAIL_TYPE_COMBO3 8 /* three-finger combo */
39
40#define GRAIL_TYPE_BRUSH 9 /* four-finger pan */
41#define GRAIL_TYPE_PICK 10 /* four-finger pinch */
42#define GRAIL_TYPE_WHIRL 11 /* four-finger rotate */
43#define GRAIL_TYPE_COMBO4 12 /* four-finger combo */
44
45#define GRAIL_TYPE_HAND 13 /* five-finger pan */
46#define GRAIL_TYPE_GRAB 14 /* five-finger pinch */
47#define GRAIL_TYPE_REVOLVE 15 /* five-finger rotate */
48#define GRAIL_TYPE_COMBO5 16 /* five-finger combo */
49
50#define GRAIL_TYPE_TAP1 17 /* single one-finger tap */
51#define GRAIL_TYPE_TAP2 18 /* single two-finger tap */
52#define GRAIL_TYPE_TAP3 19 /* single three-finger tap */
53#define GRAIL_TYPE_TAP4 20 /* single four-finger tap */
54#define GRAIL_TYPE_TAP5 21 /* single five-finger tap */
55
56#endif
diff --git a/include/grail.h b/include/grail.h
new file mode 100644
index 0000000..0fa4473
--- /dev/null
+++ b/include/grail.h
@@ -0,0 +1,94 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#ifndef _GRAIL_H
26#define _GRAIL_H
27
28#include <grail-bits.h>
29#include <grail-types.h>
30#include <linux/input.h>
31
32#define DIM_GRAIL_TYPE 64
33#define DIM_GRAIL_TYPE_BYTES ((DIM_GRAIL_TYPE + 7) >> 3)
34
35#define DIM_GRAIL_PROP 16
36#define DIM_GRAIL_PROP_BYTES ((DIM_GRAIL_PROP + 7) >> 3)
37
38#define GRAIL_STATUS_BEGIN 0
39#define GRAIL_STATUS_UPDATE 1
40#define GRAIL_STATUS_END 2
41
42typedef float grail_prop_t;
43typedef __u64 grail_time_t;
44
45struct grail_coord {
46 float x, y;
47};
48
49struct grail_client_id {
50 int client;
51 int root, event, child;
52};
53
54struct grail_client_info {
55 struct grail_client_id id;
56 grail_mask_t mask[DIM_GRAIL_TYPE_BYTES];
57};
58
59struct grail_event {
60 int type;
61 int id;
62 int status;
63 int ntouch;
64 int nprop;
65 struct grail_coord pos;
66 struct grail_client_id client_id;
67 grail_time_t time;
68 grail_prop_t prop[DIM_GRAIL_PROP];
69};
70
71struct grail {
72 int (*get_clients)(struct grail *ge,
73 struct grail_client_info *client, int max_clients,
74 const struct grail_coord *coords, int num_coords,
75 const grail_mask_t *types, int type_bytes);
76 void (*event)(struct grail *ge,
77 const struct input_event *ev);
78 void (*gesture)(struct grail *ge,
79 const struct grail_event *ev);
80 struct grail_impl *impl;
81 struct gesture_inserter *gin;
82 struct gesture_recognizer *gru;
83 void *priv;
84};
85
86int grail_open(struct grail *ge, int fd);
87int grail_idle(struct grail *ge, int fd, int ms);
88int grail_pull(struct grail *ge, int fd);
89void grail_close(struct grail *ge, int fd);
90
91void grail_get_units(struct grail_coord *min, struct grail_coord *max,
92 const struct grail *ge);
93
94#endif
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..7dc3ac2
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,36 @@
1lib_LTLIBRARIES = libgrail.la
2
3libgrail_la_LDFLAGS = \
4 -version-info @LIB_VERSION@ \
5 -lm \
6 $(MTDEV_LIBS)
7
8libgrail_la_SOURCES = \
9 evbuf.h \
10 gebuf.h \
11 touch-dev.c \
12 touch-engine.c \
13 grail-bits.c \
14 grail-inserter.c \
15 grail-inserter.h \
16 grail-gestures.c \
17 grail-gestures.h \
18 gestures-pan.c \
19 gestures-pinch.c \
20 gestures-rotate.c \
21 gestures-combo.c \
22 gestures-tapping.c \
23 grail-recognizer.c \
24 grail-recognizer.h \
25 grail-api.c
26
27AM_CFLAGS = $(CWARNFLAGS)
28
29INCLUDES = -I$(top_srcdir)/include/
30
31libgrailincludedir = $(includedir)
32libgrailinclude_HEADERS = \
33 $(top_srcdir)/include/grail-bits.h \
34 $(top_srcdir)/include/grail-types.h \
35 $(top_srcdir)/include/grail-touch.h \
36 $(top_srcdir)/include/grail.h
diff --git a/src/evbuf.h b/src/evbuf.h
new file mode 100644
index 0000000..dc5ad1e
--- /dev/null
+++ b/src/evbuf.h
@@ -0,0 +1,64 @@
1/*****************************************************************************
2 *
3 * mtdev - Multitouch Protocol Translation Library (MIT license)
4 *
5 * Copyright (C) 2010 Henrik Rydberg <rydberg@bitmath.org>
6 * Copyright (C) 2010 Canonical Ltd.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 ****************************************************************************/
28
29#ifndef GRAIL_EVBUF_H
30#define GRAIL_EVBUF_H
31
32#define DIM_EVENTS 512
33
34struct evbuf {
35 int head;
36 int tail;
37 struct input_event buffer[DIM_EVENTS];
38};
39
40static inline void evbuf_clear(struct evbuf *evbuf)
41{
42 evbuf->head = evbuf->tail = 0;
43}
44
45static inline int evbuf_empty(const struct evbuf *evbuf)
46{
47 return evbuf->head == evbuf->tail;
48}
49
50static inline void evbuf_put(struct evbuf *evbuf,
51 const struct input_event *ev)
52{
53 evbuf->buffer[evbuf->head++] = *ev;
54 evbuf->head &= DIM_EVENTS - 1;
55}
56
57static inline void evbuf_get(struct evbuf *evbuf,
58 struct input_event *ev)
59{
60 *ev = evbuf->buffer[evbuf->tail++];
61 evbuf->tail &= DIM_EVENTS - 1;
62}
63
64#endif
diff --git a/src/gebuf.h b/src/gebuf.h
new file mode 100644
index 0000000..3f71ab5
--- /dev/null
+++ b/src/gebuf.h
@@ -0,0 +1,70 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#ifndef _GRAIL_GESTURE_BUFFER_H
26#define _GRAIL_GESTURE_BUFFER_H
27
28#include <grail.h>
29
30#define DIM_GESTURE_EVENTS 512
31
32struct gesture_event {
33 int ntouch;
34 int nprop;
35 touch_time_t time;
36 struct grail_coord pos;
37 grail_prop_t prop[DIM_GRAIL_PROP];
38};
39
40struct gebuf {
41 int head;
42 int tail;
43 struct gesture_event buffer[DIM_GESTURE_EVENTS];
44};
45
46static inline void gebuf_clear(struct gebuf *gebuf)
47{
48 gebuf->head = gebuf->tail = 0;
49}
50
51static inline int gebuf_empty(const struct gebuf *gebuf)
52{
53 return gebuf->head == gebuf->tail;
54}
55
56static inline void gebuf_put(struct gebuf *gebuf,
57 const struct gesture_event *ev)
58{
59 gebuf->buffer[gebuf->head++] = *ev;
60 gebuf->head &= DIM_GESTURE_EVENTS - 1;
61}
62
63static inline void gebuf_get(struct gebuf *gebuf,
64 struct gesture_event *ev)
65{
66 *ev = gebuf->buffer[gebuf->tail++];
67 gebuf->tail &= DIM_GESTURE_EVENTS - 1;
68}
69
70#endif
diff --git a/src/gestures-combo.c b/src/gestures-combo.c
new file mode 100644
index 0000000..7b8dbd5
--- /dev/null
+++ b/src/gestures-combo.c
@@ -0,0 +1,71 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include "grail-recognizer.h"
26#include <math.h>
27#include <stdio.h>
28
29static const int getype[DIM_TOUCH + 1] = {
30 0,
31 0,
32 GRAIL_TYPE_COMBO2,
33 GRAIL_TYPE_COMBO3,
34 GRAIL_TYPE_COMBO4,
35 GRAIL_TYPE_COMBO5,
36};
37
38int gru_combo(struct grail *ge,
39 const struct touch_frame *frame)
40{
41 struct gesture_recognizer *gru = ge->gru;
42 struct combo_model *state = &gru->combo;
43 struct move_model *move = &gru->move;
44 grail_prop_t prop[DIM_GRAIL_PROP];
45 if (!move->multi) {
46 if (state->active) {
47 gru_end(ge, state->gid, move);
48 state->active = 0;
49 }
50 return 0;
51 }
52 if (!move->x.tickle && !move->y.tickle &&
53 !move->r.tickle && !move->a.tickle)
54 return 0;
55 if (!state->active) {
56 int type = getype[move->ntouch];
57 if (!type)
58 return 0;
59 state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
60 state->active = 1;
61 }
62 if (!move->x.active && !move->y.active &&
63 !move->r.active && !move->a.active)
64 return 0;
65 prop[0] = move->x.active ? move->x.delta : 0;
66 prop[1] = move->y.active ? move->y.delta : 0;
67 prop[2] = move->r.active ? move->r.delta : 0;
68 prop[3] = move->a.active ? move->a.delta : 0;
69 gru_event(ge, state->gid, move, prop, 4);
70 return 1;
71}
diff --git a/src/gestures-pan.c b/src/gestures-pan.c
new file mode 100644
index 0000000..3094007
--- /dev/null
+++ b/src/gestures-pan.c
@@ -0,0 +1,68 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include "grail-recognizer.h"
26#include <math.h>
27#include <stdio.h>
28
29static const int getype[DIM_TOUCH + 1] = {
30 0,
31 0,
32 GRAIL_TYPE_PAN,
33 GRAIL_TYPE_SWIPE,
34 GRAIL_TYPE_BRUSH,
35 GRAIL_TYPE_HAND,
36};
37
38int gru_pan(struct grail *ge,
39 const struct touch_frame *frame)
40{
41 struct gesture_recognizer *gru = ge->gru;
42 struct combo_model *state = &gru->pan;
43 struct move_model *move = &gru->move;
44 grail_prop_t prop[DIM_GRAIL_PROP];
45 if (!move->multi) {
46 if (state->active) {
47 gru_end(ge, state->gid, move);
48 state->active = 0;
49 }
50 return 0;
51 }
52 if (!move->x.tickle && !move->y.tickle)
53 return 0;
54 if (!state->active) {
55 int type = getype[move->ntouch];
56 if (!type)
57 return 0;
58 state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
59 state->active = 1;
60 }
61 if (!move->x.active && !move->y.active)
62 return 0;
63 prop[0] = move->x.active ? move->x.delta : 0;
64 prop[1] = move->y.active ? move->y.delta : 0;
65 gru_event(ge, state->gid, move, prop, 2);
66 return 1;
67}
68
diff --git a/src/gestures-pinch.c b/src/gestures-pinch.c
new file mode 100644
index 0000000..0721e02
--- /dev/null
+++ b/src/gestures-pinch.c
@@ -0,0 +1,68 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include "grail-recognizer.h"
26#include <math.h>
27#include <stdio.h>
28
29static const int getype[DIM_TOUCH + 1] = {
30 0,
31 0,
32 GRAIL_TYPE_PINCH,
33 GRAIL_TYPE_SCALE,
34 GRAIL_TYPE_PICK,
35 GRAIL_TYPE_GRAB,
36};
37
38int gru_pinch(struct grail *ge,
39 const struct touch_frame *frame)
40{
41 struct gesture_recognizer *gru = ge->gru;
42 struct combo_model *state = &gru->pinch;
43 struct move_model *move = &gru->move;
44 grail_prop_t prop[DIM_GRAIL_PROP];
45 if (!move->multi) {
46 if (state->active) {
47 gru_end(ge, state->gid, move);
48 state->active = 0;
49 }
50 return 0;
51 }
52 if (!move->a.tickle)
53 return 0;
54 if (!move->r.tickle)
55 return 0;
56 if (!state->active) {
57 int type = getype[move->ntouch];
58 if (!type)
59 return 0;
60 state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
61 state->active = 1;
62 }
63 if (!move->r.active)
64 return 0;
65 prop[0] = move->r.delta;
66 gru_event(ge, state->gid, move, prop, 1);
67 return 1;
68}
diff --git a/src/gestures-rotate.c b/src/gestures-rotate.c
new file mode 100644
index 0000000..6c496d2
--- /dev/null
+++ b/src/gestures-rotate.c
@@ -0,0 +1,66 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include "grail-recognizer.h"
26#include <math.h>
27#include <stdio.h>
28
29static const int getype[DIM_TOUCH + 1] = {
30 0,
31 0,
32 GRAIL_TYPE_ROTATE,
33 GRAIL_TYPE_TURN,
34 GRAIL_TYPE_WHIRL,
35 GRAIL_TYPE_REVOLVE,
36};
37
38int gru_rotate(struct grail *ge,
39 const struct touch_frame *frame)
40{
41 struct gesture_recognizer *gru = ge->gru;
42 struct combo_model *state = &gru->rotate;
43 struct move_model *move = &gru->move;
44 grail_prop_t prop[DIM_GRAIL_PROP];
45 if (!move->multi) {
46 if (state->active) {
47 gru_end(ge, state->gid, move);
48 state->active = 0;
49 }
50 return 0;
51 }
52 if (!move->a.tickle)
53 return 0;
54 if (!state->active) {
55 int type = getype[move->ntouch];
56 if (!type)
57 return 0;
58 state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
59 state->active = 1;
60 }
61 if (!move->a.active)
62 return 0;
63 prop[0] = move->a.delta;
64 gru_event(ge, state->gid, move, prop, 1);
65 return 1;
66}
diff --git a/src/gestures-tapping.c b/src/gestures-tapping.c
new file mode 100644
index 0000000..cc0e685
--- /dev/null
+++ b/src/gestures-tapping.c
@@ -0,0 +1,101 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include "grail-recognizer.h"
26#include <math.h>
27
28static const int TAP_BEGIN = 0;
29static const int TAP_END = 1;
30static const int TAP_CANCEL = 2;
31
32static const int TAP_MIN_GAP_MS = 25;
33static const int TAP_MAX_GAP_MS = 300;
34
35int gru_tapping(struct grail *ge,
36 const struct touch_frame *frame)
37{
38 struct gesture_recognizer *gru = ge->gru;
39 struct tapping_model *state = &gru->tapping;
40 struct move_model *move = &gru->move;
41 grail_prop_t prop[DIM_GRAIL_PROP];
42 if (move->ntouch) {
43 if (state->status == TAP_CANCEL)
44 return 0;
45 state->status = TAP_BEGIN;
46 if (!state->ntouch)
47 state->start = move->time;
48 if (move->ntouch > state->ntouch) {
49 state->ntouch = move->ntouch;
50 if (state->active) {
51 gin_gid_discard(ge, state->gid);
52 state->active = 0;
53 }
54 state->x = move->x.val;
55 state->y = move->y.val;
56 } else if (state->ntouch == 1) {
57 if (fabs(move->x.val - state->x) > move->y.bar ||
58 fabs(move->y.val - state->y) > move->y.bar)
59 state->status = TAP_CANCEL;
60 }
61 if (!state->active) {
62 int type = GRAIL_TYPE_TAP1 + state->ntouch - 1;
63 state->gid = gin_gid_begin(ge, type, PRIO_TAP, frame);
64 state->active = 1;
65 }
66 } else if (state->status == TAP_BEGIN && state->ntouch) {
67 state->status = TAP_END;
68 } else {
69 state->status = TAP_BEGIN;
70 state->ntouch = 0;
71 return 0;
72 }
73 if (state->ntouch < 1 || state->ntouch > 5)
74 state->status = TAP_CANCEL;
75 if (move->time - state->start > TAP_MAX_GAP_MS)
76 state->status = TAP_CANCEL;
77 if (state->status == TAP_END &&
78 move->time - state->start < TAP_MIN_GAP_MS)
79 state->status = TAP_CANCEL;
80 if (move->x.active || move->y.active)
81 state->status = TAP_CANCEL;
82 if (state->status == TAP_CANCEL) {
83 if (state->active) {
84 gin_gid_discard(ge, state->gid);
85 state->active = 0;
86 }
87 state->ntouch = 0;
88 return 0;
89 }
90 if (state->status != TAP_END ||
91 move->time - state->start < TAP_MIN_GAP_MS)
92 return 0;
93 prop[0] = move->time - state->start;
94 gin_gid_event(ge, state->gid,
95 move->x.val, move->y.val, state->ntouch,
96 prop, 1, GRAIL_STATUS_END);
97 state->status = TAP_BEGIN;
98 state->ntouch = 0;
99 state->active = 0;
100 return 1;
101}
diff --git a/src/grail-api.c b/src/grail-api.c
new file mode 100644
index 0000000..9ceb1e7
--- /dev/null
+++ b/src/grail-api.c
@@ -0,0 +1,115 @@
1#include "grail-inserter.h"
2#include "grail-recognizer.h"
3#include <grail.h>
4#include <string.h>
5#include <stdio.h>
6#include <unistd.h>
7#include <fcntl.h>
8#include <malloc.h>
9#include <errno.h>
10#include "evbuf.h"
11
12struct grail_impl {
13 struct touch_dev dev;
14 struct touch_engine engine;
15 struct evbuf evbuf;
16};
17
18static void tp_event(struct touch_engine *engine,
19 const struct input_event *ev)
20{
21 struct grail *ge = engine->priv;
22 struct grail_impl *x = ge->impl;
23 evbuf_put(&x->evbuf, ev);
24}
25
26static void tp_sync(struct touch_engine *engine,
27 const struct input_event *syn)
28{
29 struct input_event ev;
30 struct grail *ge = engine->priv;
31 struct grail_impl *x = ge->impl;
32 struct touch_frame *frame = &engine->frame;
33 grail_mask_t filtered[DIM_EV_TYPE_BYTES];
34 int nevent = 0;
35 gin_frame_begin(ge, frame);
36 gru_recognize(ge, frame);
37 gin_frame_end(ge, filtered, sizeof(filtered), frame);
38 if (!ge->event) {
39 evbuf_clear(&x->evbuf);
40 return;
41 }
42 while (!evbuf_empty(&x->evbuf)) {
43 evbuf_get(&x->evbuf, &ev);
44 if (grail_mask_get(filtered, ev.type))
45 continue;
46 ge->event(ge, &ev);
47 nevent++;
48 }
49 if (nevent)
50 ge->event(ge, syn);
51}
52
53int grail_open(struct grail *ge, int fd)
54{
55 struct grail_impl *x;
56 int ret;
57 x = calloc(1, sizeof(*x));
58 if (!x)
59 return -ENOMEM;
60 ge->impl = x;
61 ret = gin_init(ge);
62 if (ret)
63 goto freemem;
64 ret = touch_dev_open(&x->dev, fd);
65 if (ret)
66 goto freegin;
67 ret = gru_init(ge);
68 if (ret)
69 goto freedev;
70 touch_engine_init(&x->engine, tp_event, tp_sync, ge);
71 touch_engine_attach(&x->engine, &x->dev);
72 return 0;
73 freedev:
74 touch_dev_close(&x->dev, fd);
75 freegin:
76 gin_destroy(ge);
77 freemem:
78 free(x);
79 ge->impl = 0;
80 return ret;
81}
82
83void grail_close(struct grail *ge, int fd)
84{
85 struct grail_impl *x = ge->impl;
86 void *status;
87 touch_engine_detach(&x->engine, &x->dev);
88 gru_destroy(ge);
89 touch_dev_close(&x->dev, fd);
90 gin_destroy(ge);
91 free(ge->impl);
92 ge->impl = 0;
93}
94
95int grail_idle(struct grail *ge, int fd, int ms)
96{
97 struct grail_impl *x = ge->impl;
98 return touch_dev_idle(&x->dev, fd, ms);
99}
100
101int grail_pull(struct grail *ge, int fd)
102{
103 struct grail_impl *x = ge->impl;
104 return touch_dev_pull(&x->dev, fd);
105}
106
107void grail_get_units(struct grail_coord *min, struct grail_coord *max,
108 const struct grail *ge)
109{
110 const struct touch_dev_caps *caps = &ge->impl->dev.caps;
111 min->x = caps->info[TP_POS_X].minimum;
112 min->y = caps->info[TP_POS_Y].minimum;
113 max->x = caps->info[TP_POS_X].maximum;
114 max->y = caps->info[TP_POS_Y].maximum;
115}
diff --git a/src/grail-bits.c b/src/grail-bits.c
new file mode 100644
index 0000000..1b38d58
--- /dev/null
+++ b/src/grail-bits.c
@@ -0,0 +1,94 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include "grail-bits.h"
26
27static const int grail_bits_in_byte[256] =
28{
29 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,
30 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,
31 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,
32 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,
33 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,
34 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,
35 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,
36 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,
37};
38
39static const int grail_first_set_bit[256] =
40{
41 -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,
42 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,
43 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,
44 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,
45 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,
46 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,
47 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,
48 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,
49};
50
51void grail_mask_set_mask(grail_mask_t *a, const grail_mask_t *b, int bytes)
52{
53 while (bytes--)
54 *a++ |= *b++;
55}
56
57void grail_mask_clear_mask(grail_mask_t *a, const grail_mask_t *b, int bytes)
58{
59 while (bytes--)
60 *a++ &= ~*b++;
61}
62
63int grail_mask_count(const grail_mask_t *mask, int bytes)
64{
65 int count = 0;
66 while (bytes--)
67 count += grail_bits_in_byte[*mask++];
68 return count;
69}
70
71int grail_mask_get_first(const grail_mask_t *mask, int bytes)
72{
73 int k;
74 for (k = 0; k < bytes; k++)
75 if (mask[k])
76 return (k << 3) | grail_first_set_bit[mask[k]];
77 return -1;
78}
79
80int grail_mask_get_next(int i, const grail_mask_t *mask, int bytes)
81{
82 int k = ++i >> 3;
83 if (k < bytes) {
84 i = grail_first_set_bit[mask[k] & (~0 << (i & 7))];
85 if (i >= 0)
86 return (k << 3) | i;
87 while (++k < bytes) {
88 i = grail_first_set_bit[mask[k]];
89 if (i >= 0)
90 return (k << 3) | i;
91 }
92 }
93 return -1;
94}
diff --git a/src/grail-gestures.c b/src/grail-gestures.c
new file mode 100644
index 0000000..e1bf622
--- /dev/null
+++ b/src/grail-gestures.c
@@ -0,0 +1,188 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include "grail-recognizer.h"
26#include <math.h>
27
28static const float SN_MOVE = 200;
29static const float SN_ZOOM = 200;
30static const float SN_ROTATE = 200;
31static const float BAR_MOVE = 4;
32static const float BAR_ZOOM = 12;
33static const float BAR_ROTATE = 12;
34
35static void compute_position(float *x, float *y,
36 const struct touch_frame *frame)
37{
38 int i, n = frame->nactive;
39 *x = 0;
40 *y = 0;
41 if (n < 1)
42 return;
43 for (i = 0; i < n; i++) {
44 const struct touch *t = frame->active[i];
45 *x += t->prop[TP_POS_X];
46 *y += t->prop[TP_POS_Y];
47 }
48 *x /= n;
49 *y /= n;
50}
51
52static float compute_radius(float x, float y,
53 const struct touch_frame *frame)
54{
55 int i, n = frame->nactive;
56 float r = 0, r2 = 0;
57 if (n < 2)
58 return r;
59 for (i = 0; i < n; i++) {
60 const struct touch *t = frame->active[i];
61 float dx = t->prop[TP_POS_X] - x;
62 float dy = t->prop[TP_POS_Y] - y;
63 r2 += dx * dx + dy * dy;
64 }
65 r2 /= n;
66 r = sqrt(r2);
67 return r;
68}
69
70static float compute_rotation(float x, float y, float r,
71 const struct touch_frame *prev,
72 const struct touch_frame *frame)
73{
74 int i, n = frame->nactive;
75 float da = 0, da2 = 0;
76 if (n < 2)
77 return da;
78 for (i = 0; i < n; i++) {
79 const struct touch *t = frame->active[i];
80 const struct touch *ot = &prev->touch[t->slot];
81 float dx = t->prop[TP_POS_X] - x;
82 float dy = t->prop[TP_POS_Y] - y;
83 float mx = t->prop[TP_POS_X] - ot->prop[TP_POS_X];
84 float my = t->prop[TP_POS_Y] - ot->prop[TP_POS_Y];
85 da2 += dx * my - dy * mx;
86 }
87 da2 /= n;
88 da = da2 / r;
89 return da;
90}
91
92static float move_filter(const struct filter_model *m, float val)
93{
94 if (val > m->val - m->fuzz / 2 && val < m->val + m->fuzz / 2)
95 return m->val;
96 if (val > m->val - m->fuzz && val < m->val + m->fuzz)
97 return (m->val * 3 + val) / 4;
98 if (val > m->val - m->fuzz * 2 && val < m->val + m->fuzz * 2)
99 return (m->val + val) / 2;
100 return val;
101}
102
103static int move_reset(struct filter_model *m, float val)
104{
105 m->delta = 0;
106 m->tickle = 0;
107 m->active = 0;
108 m->val = val;
109 m->orig = val;
110}
111
112static int move_update(struct filter_model *m, float val)
113{
114 m->delta = val - m->val;
115 m->tickle = fabs(m->delta) > 0;
116 m->val = val;
117 if (!m->active && fabs(val - m->orig) > m->bar)
118 m->active = 1;
119 return m->active;
120}
121
122void gru_init_motion(struct grail *ge)
123{
124 struct gesture_recognizer *gru = ge->gru;
125 struct move_model *state = &gru->move;
126 struct grail_coord min, max;
127 grail_get_units(&min, &max, ge);
128 float x = max.x - min.x;
129 float y = max.y - min.y;
130 float r = sqrt(x * x + y * y);
131 state->x.fuzz = x / SN_MOVE;
132 state->y.fuzz = y / SN_MOVE;
133 state->r.fuzz = r / SN_ZOOM;
134 state->a.fuzz = r / SN_ROTATE;
135 state->x.bar = BAR_MOVE * state->x.fuzz;
136 state->y.bar = BAR_MOVE * state->y.fuzz;
137 state->r.bar = BAR_ZOOM * state->r.fuzz;
138 state->a.bar = BAR_ROTATE * state->a.fuzz;
139 state->multi = 0;
140}
141
142void gru_motion(struct grail *ge,
143 const struct touch_frame *frame)
144{
145 struct gesture_recognizer *gru = ge->gru;
146 struct move_model *state = &gru->move;
147 float x, y, r, a;
148 compute_position(&x, &y, frame);
149 if (frame->nactive < 2 || frame->ncreate || frame->ndestroy) {
150 r = compute_radius(x, y, frame);
151 a = 0;
152 move_reset(&state->x, x);
153 move_reset(&state->y, y);
154 move_reset(&state->r, r);
155 move_reset(&state->a, a);
156 state->multi = 0;
157 } else {
158 x = move_filter(&state->x, x);
159 y = move_filter(&state->y, y);
160 r = compute_radius(x, y, frame);
161 r = move_filter(&state->r, r);
162 a = state->a.val + compute_rotation(x, y, r, &gru->frame, frame);
163 //a = move_filter(&state->a, a);
164 move_update(&state->x, x);
165 move_update(&state->y, y);
166 move_update(&state->r, r);
167 move_update(&state->a, a);
168 state->multi = 1;
169 }
170 state->ntouch = frame->nactive;
171 state->time = frame->time;
172}
173
174void gru_event(struct grail *ge, int gid,
175 const struct move_model *move,
176 const grail_prop_t *prop, int nprop)
177{
178 gin_gid_event(ge, gid,
179 move->x.val, move->y.val, move->ntouch,
180 prop, nprop,
181 GRAIL_STATUS_UPDATE);
182}
183
184void gru_end(struct grail *ge, int gid, const struct move_model *move)
185{
186 gin_gid_end(ge, gid, move->x.val, move->y.val, move->ntouch);
187}
188
diff --git a/src/grail-gestures.h b/src/grail-gestures.h
new file mode 100644
index 0000000..663d357
--- /dev/null
+++ b/src/grail-gestures.h
@@ -0,0 +1,77 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#ifndef _GRAIL_GESTURES_H
26#define _GRAIL_GESTURES_H
27
28#include "grail-inserter.h"
29
30#define PRIO_POINTER 1
31#define PRIO_GESTURE 2
32#define PRIO_TAP 3
33
34struct filter_model {
35 float delta, val, orig, fuzz, bar;
36 int tickle, active;
37};
38
39struct move_model {
40 struct filter_model x, y, r, a;
41 int multi, ntouch;
42 float dx, dy, dr, da;
43 grail_time_t time;
44};
45
46void gru_init_motion(struct grail *ge);
47void gru_motion(struct grail *ge,
48 const struct touch_frame *frame);
49void gru_event(struct grail *ge, int gid,
50 const struct move_model *move,
51 const grail_prop_t *prop, int nprop);
52
53struct combo_model {
54 int active, gid;
55};
56
57int gru_pan(struct grail *ge,
58 const struct touch_frame *frame);
59int gru_pinch(struct grail *ge,
60 const struct touch_frame *frame);
61int gru_rotate(struct grail *ge,
62 const struct touch_frame *frame);
63int gru_combo(struct grail *ge,
64 const struct touch_frame *frame);
65
66struct tapping_model {
67 grail_time_t start;
68 float x, y;
69 int status, ntouch;
70 int active, gid;
71};
72
73int gru_tapping(struct grail *ge,
74 const struct touch_frame *frame);
75
76#endif
77
diff --git a/src/grail-inserter.c b/src/grail-inserter.c
new file mode 100644
index 0000000..724052c
--- /dev/null
+++ b/src/grail-inserter.c
@@ -0,0 +1,282 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include "grail-inserter.h"
26#include <malloc.h>
27#include <string.h>
28#include <errno.h>
29
30static const int MAX_GESTURE_ID = 0xfff;
31
32struct gesture_inserter {
33 struct slot_state state[DIM_INSTANCE];
34 grail_mask_t unused[DIM_INSTANCE_BYTES];
35 grail_mask_t fresh[DIM_INSTANCE_BYTES];
36 grail_mask_t used[DIM_INSTANCE_BYTES];
37 grail_time_t time;
38 int gestureid;
39};
40
41static int find_gslot(const struct gesture_inserter *gin, int gid)
42{
43 int i;
44 grail_mask_foreach(i, gin->used, sizeof(gin->used))
45 if (gin->state[i].id == gid)
46 return i;
47 return -1;
48}
49
50static void send_event(struct grail *ge, struct slot_state *s,
51 const struct gesture_event *ev)
52{
53 struct grail_event gev;
54 int i;
55 if (!ge->gesture)
56 return;
57 gev.type = s->type;
58 gev.id = s->id;
59 gev.status = s->status;
60 gev.ntouch = ev->ntouch;
61 gev.nprop = ev->nprop;
62 gev.time = ev->time;
63 gev.pos = ev->pos;
64 memcpy(gev.prop, ev->prop, ev->nprop * sizeof(grail_prop_t));
65 for (i = 0; i < s->nclient; i++) {
66 gev.client_id = s->client_id[i];
67 ge->gesture(ge, &gev);
68 }
69}
70
71// todo: spanning tree for multi-user case
72static void setup_new_gestures(struct grail *ge,
73 const struct touch_frame *frame)
74{
75 struct gesture_inserter *gin = ge->gin;
76 grail_mask_t types[DIM_GRAIL_TYPE_BYTES];
77 grail_mask_t span[DIM_TOUCH_BYTES];
78 struct grail_client_info info[DIM_CLIENT];
79 int i, j, nclient = 0;
80 int nfresh = grail_mask_count(gin->fresh, sizeof(gin->fresh));
81 if (!nfresh)
82 return;
83
84 memset(types, 0, sizeof(types));
85 memset(span, 0, sizeof(span));
86
87 grail_mask_foreach(i, gin->fresh, sizeof(gin->fresh)) {
88 struct slot_state *s = &gin->state[i];
89 grail_mask_set(types, s->type);
90 grail_mask_set_mask(span, s->span, sizeof(span));
91 }
92
93 if (ge->get_clients) {
94 struct grail_coord coord[DIM_CLIENT];
95 int ncoord = 0;
96 grail_mask_foreach(i, span, sizeof(span)) {
97 const struct touch *t = &frame->touch[i];
98 coord[ncoord].x = t->prop[TP_POS_X];
99 coord[ncoord].y = t->prop[TP_POS_Y];
100 ncoord++;
101 }
102 nclient = ge->get_clients(ge, info, DIM_CLIENT,
103 coord, ncoord, types, sizeof(types));
104 }
105
106 grail_mask_foreach(i, gin->fresh, sizeof(gin->fresh)) {
107 struct slot_state *s = &gin->state[i];
108 s->nclient = 0;
109 for (j = 0; j < nclient; j++) {
110 if (!grail_mask_get(info[j].mask, s->type))
111 continue;
112 s->client_id[s->nclient++] = info[j].id;
113 }
114 }
115
116 memset(gin->fresh, 0, sizeof(gin->fresh));
117}
118
119int gin_init(struct grail *ge)
120{
121 struct gesture_inserter *gin;
122 int i;
123 gin = calloc(1, sizeof(*gin));
124 if (!gin)
125 return -ENOMEM;
126 for (i = 0; i < DIM_INSTANCE; i++)
127 grail_mask_set(gin->unused, i);
128 ge->gin = gin;
129 return 0;
130}
131
132void gin_destroy(struct grail *ge)
133{
134 free(ge->gin);
135 ge->gin = NULL;
136}
137
138void gin_frame_begin(struct grail *ge, const struct touch_frame *frame)
139{
140 struct gesture_inserter *gin = ge->gin;
141 gin->time = frame->time;
142}
143
144void gin_frame_end(struct grail *ge,
145 grail_mask_t *filtered, int max_filtered,
146 const struct touch_frame *frame)
147{
148 struct gesture_inserter *gin = ge->gin;
149 grail_mask_t span[DIM_INSTANCE_BYTES];
150 int i, hold = 0, discard = 0;
151
152 memset(filtered, 0, max_filtered);
153 memset(span, 0, sizeof(span));
154
155 setup_new_gestures(ge, frame);
156
157 grail_mask_foreach(i, gin->used, sizeof(gin->used)) {
158 struct slot_state *s = &gin->state[i];
159 if (!s->nclient)
160 continue;
161 if (s->priority > hold)
162 hold = s->priority;
163 if (s->status == GRAIL_STATUS_BEGIN)
164 continue;
165 if (s->priority > discard)
166 discard = s->priority;
167 }
168
169 grail_mask_foreach(i, gin->used, sizeof(gin->used)) {
170 struct slot_state *s = &gin->state[i];
171 if (!s->nclient || s->priority < discard)
172 gin_gid_discard(ge, s->id);
173 }
174
175 grail_mask_foreach(i, gin->used, sizeof(gin->used)) {
176 struct slot_state *s = &gin->state[i];
177 struct gesture_event ev;
178 grail_mask_set_mask(span, s->span, sizeof(span));
179 if (s->priority < hold)
180 continue;
181 while (!gebuf_empty(&s->buf)) {
182 gebuf_get(&s->buf, &ev);
183 send_event(ge, s, &ev);
184 }
185 }
186
187 grail_mask_foreach(i, gin->used, sizeof(gin->used)) {
188 struct slot_state *s = &gin->state[i];
189 if (s->status == GRAIL_STATUS_END)
190 gin_gid_discard(ge, s->id);
191 }
192
193 if (grail_mask_count(span, sizeof(span)))
194 grail_mask_set(filtered, EV_ABS);
195}
196
197int gin_gid_begin_select(struct grail *ge, int type, int priority,
198 const grail_mask_t *span, int nspan)
199{
200 struct gesture_inserter *gin = ge->gin;
201 struct slot_state *s;
202 int i = grail_mask_get_first(gin->unused, sizeof(gin->unused));
203 if (i < 0)
204 return -1;
205 s = &gin->state[i];
206 s->type = type;
207 s->priority = priority;
208 s->id = gin->gestureid++ & MAX_GESTURE_ID;
209 s->status = GRAIL_STATUS_BEGIN;
210 s->nclient = 0;
211 memcpy(s->span, span, nspan);
212 gebuf_clear(&s->buf);
213 grail_mask_clear(gin->unused, i);
214 grail_mask_set(gin->fresh, i);
215 grail_mask_set(gin->used, i);
216 return s->id;
217}
218
219int gin_gid_begin(struct grail *ge, int type, int priority,
220 const struct touch_frame *frame)
221{
222 return gin_gid_begin_select(ge, type, priority,
223 frame->touches, sizeof(frame->touches));
224}
225
226void gin_gid_discard(struct grail *ge, int gid)
227{
228 struct gesture_inserter *gin = ge->gin;
229 struct slot_state *s;
230 int i = find_gslot(gin, gid);
231 if (i < 0)
232 return;
233 s = &gin->state[i];
234 gebuf_clear(&s->buf);
235 s->status = GRAIL_STATUS_END;
236 grail_mask_clear(gin->used, i);
237 grail_mask_set(gin->unused, i);
238}
239
240void gin_gid_event(struct grail *ge, int gid,
241 float x, float y, int ntouch,
242 const grail_prop_t *prop, int nprop,
243 int status)
244{
245 struct gesture_inserter *gin = ge->gin;
246 struct gesture_event ev;
247 struct slot_state *s;
248 int i = find_gslot(gin, gid);
249 if (i < 0)
250 return;
251 s = &gin->state[i];
252 ev.ntouch = ntouch;
253 ev.nprop = nprop;
254 ev.time = gin->time;
255 ev.pos.x = x;
256 ev.pos.y = y;
257 memcpy(ev.prop, prop, nprop * sizeof(grail_prop_t));
258 gebuf_put(&s->buf, &ev);
259 if (s->status == GRAIL_STATUS_BEGIN)
260 s->status = status;
261}
262
263void gin_gid_end(struct grail *ge, int gid,
264 float x, float y, int ntouch)
265{
266 struct gesture_inserter *gin = ge->gin;
267 struct gesture_event ev;
268 struct slot_state *s;
269 int i = find_gslot(gin, gid);
270 if (i < 0)
271 return;
272 s = &gin->state[i];
273 if (s->status != GRAIL_STATUS_BEGIN) {
274 ev.ntouch = ntouch;
275 ev.nprop = 0;
276 ev.time = gin->time;
277 ev.pos.x = x;
278 ev.pos.y = y;
279 gebuf_put(&s->buf, &ev);
280 }
281 s->status = GRAIL_STATUS_END;
282}
diff --git a/src/grail-inserter.h b/src/grail-inserter.h
new file mode 100644
index 0000000..3ffacec
--- /dev/null
+++ b/src/grail-inserter.h
@@ -0,0 +1,71 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#ifndef _GRAIL_INSERTER_H
26#define _GRAIL_INSERTER_H
27
28#include <grail-touch.h>
29#include <grail.h>
30#include "gebuf.h"
31
32#define DIM_EV_TYPE EV_CNT
33#define DIM_EV_TYPE_BYTES ((DIM_EV_TYPE + 7) >> 3)
34
35#define DIM_INSTANCE 32
36#define DIM_INSTANCE_BYTES ((DIM_INSTANCE + 7) >> 3)
37
38#define DIM_CLIENT 32
39
40struct slot_state {
41 int type;
42 int priority;
43 int id;
44 int status;
45 int nclient;
46 struct grail_client_id client_id[DIM_CLIENT];
47 grail_mask_t span[DIM_TOUCH_BYTES];
48 struct gebuf buf;
49};
50
51int gin_init(struct grail *ge);
52void gin_destroy(struct grail *ge);
53
54void gin_frame_begin(struct grail *ge, const struct touch_frame *frame);
55void gin_frame_end(struct grail *ge, grail_mask_t *filtered, int max_filtered,
56 const struct touch_frame *frame);
57
58int gin_gid_begin_select(struct grail *ge, int type, int priority,
59 const grail_mask_t *span, int nspan);
60int gin_gid_begin(struct grail *ge, int type, int priority,
61 const struct touch_frame *frame);
62void gin_gid_discard(struct grail *ge, int gid);
63
64void gin_gid_event(struct grail *ge, int gid,
65 float x, float y, int ntouch,
66 const grail_prop_t *prop, int nprop,
67 int status);
68void gin_gid_end(struct grail *ge, int gid,
69 float x, float y, int ntouch);
70
71#endif
diff --git a/src/grail-recognizer.c b/src/grail-recognizer.c
new file mode 100644
index 0000000..587a12a
--- /dev/null
+++ b/src/grail-recognizer.c
@@ -0,0 +1,58 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include "grail-recognizer.h"
26#include <string.h>
27#include <malloc.h>
28#include <errno.h>
29
30int gru_init(struct grail *ge)
31{
32 struct gesture_recognizer *gru;
33 gru = calloc(1, sizeof(struct gesture_recognizer));
34 if (!gru)
35 return -ENOMEM;
36 ge->gru = gru;
37 gru_init_motion(ge);
38 return 0;
39}
40
41void gru_destroy(struct grail *ge)
42{
43 free(ge->gru);
44 ge->gru = NULL;
45}
46
47void gru_recognize(struct grail *ge, const struct touch_frame *frame)
48{
49 if (!ge->gin || !ge->gru)
50 return;
51 gru_motion(ge, frame);
52 gru_pan(ge, frame);
53 gru_pinch(ge, frame);
54 gru_rotate(ge, frame);
55 gru_combo(ge, frame);
56 gru_tapping(ge, frame);
57 ge->gru->frame = *frame;
58}
diff --git a/src/grail-recognizer.h b/src/grail-recognizer.h
new file mode 100644
index 0000000..8a5ac80
--- /dev/null
+++ b/src/grail-recognizer.h
@@ -0,0 +1,44 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#ifndef _GRAIL_RECOGNIZER_H
26#define _GRAIL_RECOGNIZER_H
27
28#include "grail-gestures.h"
29
30struct gesture_recognizer {
31 struct touch_frame frame;
32 struct move_model move;
33 struct combo_model pan;
34 struct combo_model pinch;
35 struct combo_model rotate;
36 struct combo_model combo;
37 struct tapping_model tapping;
38};
39
40int gru_init(struct grail *ge);
41void gru_recognize(struct grail *ge, const struct touch_frame *frame);
42void gru_destroy(struct grail *ge);
43
44#endif
diff --git a/src/touch-dev.c b/src/touch-dev.c
new file mode 100644
index 0000000..4cc8d55
--- /dev/null
+++ b/src/touch-dev.c
@@ -0,0 +1,218 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include <grail-touch.h>
26#include <malloc.h>
27#include <string.h>
28#include <errno.h>
29
30/* from mtdev-mapping.h */
31#define MT_TOUCH_MAJOR 0
32#define MT_TOUCH_MINOR 1
33#define MT_WIDTH_MAJOR 2
34#define MT_WIDTH_MINOR 3
35#define MT_ORIENTATION 4
36#define MT_POSITION_X 5
37#define MT_POSITION_Y 6
38#define MT_TRACKING_ID 9
39#define MT_PRESSURE 10
40
41int mtdev_fetch_event(struct mtdev *dev, int fd, struct input_event *ev);
42void mtdev_put_event(struct mtdev *dev, const struct input_event *ev);
43int mtdev_empty(struct mtdev *dev);
44void mtdev_get_event(struct mtdev *dev, struct input_event* ev);
45
46struct touch_dev_impl {
47 int id[DIM_TOUCH];
48 int slot;
49 int status;
50 grail_mask_t mask[DIM_TOUCH_BYTES];
51 touch_prop_t prop[DIM_TOUCH_PROP];
52 struct mtdev mtdev;
53};
54
55static inline void set_info(struct touch_dev_caps *caps, int code,
56 const struct input_absinfo *info)
57{
58 grail_mask_set(caps->mask, code);
59 caps->info[code] = *info;
60}
61
62static void set_caps(struct touch_dev_caps *caps,
63 const struct mtdev_caps *mtcaps)
64{
65 if (mtcaps->has_abs[MT_POSITION_X])
66 set_info(caps, TP_POS_X, &mtcaps->abs[MT_POSITION_X]);
67 if (mtcaps->has_abs[MT_POSITION_Y])
68 set_info(caps, TP_POS_Y, &mtcaps->abs[MT_POSITION_Y]);
69 if (mtcaps->has_abs[MT_TOUCH_MAJOR])
70 set_info(caps, TP_TOUCH_MAJOR, &mtcaps->abs[MT_TOUCH_MAJOR]);
71 if (mtcaps->has_abs[MT_TOUCH_MINOR])
72 set_info(caps, TP_TOUCH_MINOR, &mtcaps->abs[MT_TOUCH_MINOR]);
73 if (mtcaps->has_abs[MT_WIDTH_MAJOR])
74 set_info(caps, TP_WIDTH_MAJOR, &mtcaps->abs[MT_WIDTH_MAJOR]);
75 if (mtcaps->has_abs[MT_WIDTH_MINOR])
76 set_info(caps, TP_WIDTH_MINOR, &mtcaps->abs[MT_WIDTH_MINOR]);
77 if (mtcaps->has_abs[MT_ORIENTATION])
78 set_info(caps, TP_ORIENTATION, &mtcaps->abs[MT_ORIENTATION]);
79 if (mtcaps->has_abs[MT_PRESSURE])
80 set_info(caps, TP_PRESSURE, &mtcaps->abs[MT_PRESSURE]);
81}
82
83static inline void set_prop(struct touch_dev_impl *x, int code, int value)
84{
85 grail_mask_set(x->mask, code);
86 x->prop[code] = value;
87}
88
89static void finish_touch(struct touch_dev *dev,
90 struct touch_dev_impl *x)
91{
92 if (x->status < 0 && dev->destroy)
93 dev->destroy(dev, x->slot);
94 if (x->status > 0 && dev->create)
95 dev->create(dev, x->slot, x->mask, x->prop);
96 if (x->status == 0 && dev->modify &&
97 grail_mask_count(x->mask, sizeof(x->mask)))
98 dev->modify(dev, x->slot, x->mask, x->prop);
99 x->status = 0;
100 memset(x->mask, 0, sizeof(x->mask));
101}
102
103static void finish_packet(struct touch_dev *dev,
104 const struct input_event *syn)
105{
106 finish_touch(dev, dev->impl);
107 if (dev->sync)
108 dev->sync(dev, syn);
109}
110
111static int handle_abs_event(struct touch_dev *dev,
112 const struct input_event *ev)
113{
114 struct touch_dev_impl *x = dev->impl;
115 switch (ev->code) {
116 case ABS_MT_SLOT:
117 if (ev->value >= 0 && ev->value < DIM_TOUCH) {
118 if (x->slot != ev->value)
119 finish_touch(dev, x);
120 x->slot = ev->value;
121 }
122 return 1;
123 case ABS_MT_POSITION_X:
124 set_prop(x, TP_POS_X, ev->value);
125 return 1;
126 case ABS_MT_POSITION_Y:
127 set_prop(x, TP_POS_Y, ev->value);
128 return 1;
129 case ABS_MT_TOUCH_MAJOR:
130 set_prop(x, TP_TOUCH_MAJOR, ev->value);
131 return 1;
132 case ABS_MT_TOUCH_MINOR:
133 set_prop(x, TP_TOUCH_MINOR, ev->value);
134 return 1;
135 case ABS_MT_WIDTH_MAJOR:
136 set_prop(x, TP_WIDTH_MAJOR, ev->value);
137 return 1;
138 case ABS_MT_WIDTH_MINOR:
139 set_prop(x, TP_WIDTH_MINOR, ev->value);
140 return 1;
141 case ABS_MT_ORIENTATION:
142 set_prop(x, TP_ORIENTATION, ev->value);
143 return 1;
144 case ABS_MT_PRESSURE:
145 set_prop(x, TP_PRESSURE, ev->value);
146 return 1;
147 case ABS_MT_TRACKING_ID:
148 if (x->id[x->slot] != ev->value) {
149 if (x->id[x->slot] != MT_ID_NULL) {
150 x->status = -1;
151 finish_touch(dev, x);
152 }
153 if (ev->value != MT_ID_NULL)
154 x->status = 1;
155 }
156 x->id[x->slot] = ev->value;
157 return 1;
158 default:
159 return 0;
160 }
161}
162
163int touch_dev_open(struct touch_dev *dev, int fd)
164{
165 struct touch_dev_impl *x;
166 int ret, i;
167 memset(dev, 0, sizeof(*dev));
168 x = calloc(1, sizeof(*x));
169 if (!x)
170 return -ENOMEM;
171 ret = mtdev_open(&x->mtdev, fd);
172 if (!ret && !x->mtdev.caps.has_mtdata)
173 ret = -ENODEV;
174 if (ret)
175 goto error;
176 for (i = 0; i < DIM_TOUCH; i++)
177 x->id[i] = MT_ID_NULL;
178 set_caps(&dev->caps, &x->mtdev.caps);
179 dev->impl = x;
180 return 0;
181 error:
182 free(x);
183 return ret;
184}
185
186int touch_dev_idle(struct touch_dev *dev, int fd, int ms)
187{
188 return mtdev_idle(&dev->impl->mtdev, fd, ms);
189}
190
191int touch_dev_pull(struct touch_dev *dev, int fd)
192{
193 struct touch_dev_impl *x = dev->impl;
194 struct input_event ev;
195 int ret, count = 0, consumed;
196 while ((ret = mtdev_get(&x->mtdev, fd, &ev, 1)) > 0) {
197 consumed = 0;
198 if (ev.type == EV_SYN) {
199 if (ev.code == SYN_REPORT)
200 finish_packet(dev, &ev);
201 consumed++;
202 } else if (ev.type == EV_ABS) {
203 consumed += handle_abs_event(dev, &ev);
204 }
205 if (!consumed && dev->event)
206 dev->event(dev, &ev);
207 count++;
208 }
209 return count > 0 ? count : ret;
210}
211
212void touch_dev_close(struct touch_dev *dev, int fd)
213{
214 struct touch_dev_impl *x = dev->impl;
215 mtdev_close(&x->mtdev);
216 free(x);
217 memset(dev, 0, sizeof(*dev));
218}
diff --git a/src/touch-engine.c b/src/touch-engine.c
new file mode 100644
index 0000000..3e6870e
--- /dev/null
+++ b/src/touch-engine.c
@@ -0,0 +1,137 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include <grail-touch.h>
26#include <string.h>
27
28static void tp_event(struct touch_dev *dev, const struct input_event *ev)
29{
30 struct touch_engine *engine = dev->priv;
31 if (engine && engine->event)
32 engine->event(engine, ev);
33}
34
35static void update_frame(struct touch_frame *frame,
36 int slot, int active,
37 const grail_mask_t *mask,
38 const touch_prop_t *prop)
39{
40 struct touch *t = &frame->touch[slot];
41 int i;
42 t->active = active;
43 grail_mask_modify(frame->touches, slot, active);
44 if (mask && prop)
45 grail_mask_foreach(i, mask, DIM_TOUCH_PROP_BYTES)
46 t->prop[i] = prop[i];
47}
48
49static void finalize_frame(struct touch_frame *frame, touch_time_t time)
50{
51 int i, nslot = 0;
52 grail_mask_foreach(i, frame->touches, DIM_TOUCH_BYTES)
53 frame->active[nslot++] = &frame->touch[i];
54 frame->nactive = nslot;
55 frame->time = time;
56}
57
58static void tp_create(struct touch_dev *dev, int slot,
59 const grail_mask_t *mask, const touch_prop_t *prop)
60{
61 struct touch_engine *engine = dev->priv;
62 if (engine) {
63 engine->frame.ncreate++;
64 update_frame(&engine->frame, slot, 1, mask, prop);
65 }
66}
67
68static void tp_modify(struct touch_dev *dev, int slot,
69 const grail_mask_t *mask, const touch_prop_t *prop)
70{
71 struct touch_engine *engine = dev->priv;
72 if (engine) {
73 engine->frame.nmodify++;
74 update_frame(&engine->frame, slot, 1, mask, prop);
75 }
76}
77
78static void tp_destroy(struct touch_dev *dev, int slot)
79{
80 struct touch_engine *engine = dev->priv;
81 if (engine) {
82 engine->frame.ndestroy++;
83 update_frame(&engine->frame, slot, 0, 0, 0);
84 }
85}
86
87static void tp_sync(struct touch_dev *dev, const struct input_event *syn)
88{
89 static const touch_time_t ms = 1000;
90 struct touch_engine *engine = dev->priv;
91 touch_time_t time = syn->time.tv_usec / ms + syn->time.tv_sec * ms;
92 if (engine) {
93 finalize_frame(&engine->frame, time);
94 if (engine->sync)
95 engine->sync(engine, syn);
96 engine->frame.ncreate = 0;
97 engine->frame.nmodify = 0;
98 engine->frame.ndestroy = 0;
99 }
100}
101
102void touch_engine_init(struct touch_engine *engine,
103 void (*event)(struct touch_engine *engine,
104 const struct input_event *ev),
105 void (*sync)(struct touch_engine *engine,
106 const struct input_event *ev),
107 void *priv)
108{
109 int i;
110 memset(engine, 0, sizeof(*engine));
111 for (i = 0; i < DIM_TOUCH; i++)
112 engine->frame.touch[i].slot = i;
113 engine->event = event;
114 engine->sync = sync;
115 engine->priv = priv;
116}
117
118void touch_engine_attach(struct touch_engine *engine, struct touch_dev *dev)
119{
120 dev->priv = engine;
121 dev->event = tp_event;
122 dev->create = tp_create;
123 dev->modify = tp_modify;
124 dev->destroy = tp_destroy;
125 dev->sync = tp_sync;
126}
127
128void touch_engine_detach(struct touch_engine *engine, struct touch_dev *dev)
129{
130 dev->sync = 0;
131 dev->destroy = 0;
132 dev->modify = 0;
133 dev->create = 0;
134 dev->event = 0;
135 dev->priv = 0;
136}
137
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..4ccbe0a
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,9 @@
1bin_PROGRAMS = grail-touch grail-gesture
2
3INCLUDES=-I$(top_srcdir)/include/
4
5grail_touch_SOURCES = grail-touch.c
6grail_touch_LDFLAGS = -L$(top_builddir)/src/.libs/ -lgrail -lmtdev -lm
7
8grail_gesture_SOURCES = grail-gesture.c
9grail_gesture_LDFLAGS = -L$(top_builddir)/src/.libs/ -lgrail -lmtdev -lm
diff --git a/test/grail-gesture.c b/test/grail-gesture.c
new file mode 100644
index 0000000..16b33ac
--- /dev/null
+++ b/test/grail-gesture.c
@@ -0,0 +1,111 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include <grail.h>
26#include <string.h>
27#include <stdio.h>
28#include <unistd.h>
29#include <fcntl.h>
30
31static grail_mask_t flag_mask[DIM_GRAIL_TYPE_BYTES];
32
33static int tp_get_clients(struct grail *ge,
34 struct grail_client_info *clients, int max_clients,
35 const struct grail_coord *coords, int num_coords,
36 const grail_mask_t *types, int type_bytes)
37{
38 memset(&clients[0], 0, sizeof(clients[0]));
39 clients[0].id.client = 345;
40 clients[0].id.root = 1;
41 clients[0].id.event = 2;
42 clients[0].id.child = 3;
43 memcpy(clients[0].mask, flag_mask, sizeof(flag_mask));
44 return 1;
45}
46
47static void tp_event(struct grail *ge, const struct input_event *ev)
48{
49 if (!grail_mask_get(flag_mask, GRAIL_TYPE_POINTER))
50 return;
51 fprintf(stderr, "event %d 0x%x %d\n", ev->type, ev->code, ev->value);
52}
53
54static void tp_gesture(struct grail *ge, const struct grail_event *ev)
55{
56 int i;
57 fprintf(stderr, "gesture %d %d %d %d - %f %f %d - %d\n",
58 ev->type, ev->id, ev->client_id.client, ev->client_id.event,
59 ev->pos.x, ev->pos.y, ev->ntouch,
60 ev->status);
61 for (i = 0; i < ev->nprop; i++)
62 fprintf(stderr, "\t%d: %f\n", i, ev->prop[i]);
63}
64
65static void loop_device(struct grail *ge, int fd)
66{
67 while (!grail_idle(ge, fd, 5000))
68 grail_pull(ge, fd);
69}
70
71int main(int argc, char *argv[])
72{
73 struct grail ge;
74 int i, fd;
75
76 if (argc < 3) {
77 fprintf(stderr, "Usage: %s <mask> <device>\n", argv[0]);
78 return -1;
79 }
80
81 memset(&ge, 0, sizeof(ge));
82 ge.get_clients = tp_get_clients;
83 ge.event = tp_event;
84 ge.gesture = tp_gesture;
85
86 unsigned long mask = strtoull(argv[1], 0, 0);
87 for (i = 0; i < DIM_GRAIL_TYPE; i++)
88 if ((mask >> i) & 1)
89 grail_mask_set(flag_mask, i);
90
91 fd = open(argv[2], O_RDONLY | O_NONBLOCK);
92 if (fd < 0) {
93 fprintf(stderr, "error: could not open device\n");
94 return -1;
95 }
96 if (ioctl(fd, EVIOCGRAB, 1)) {
97 fprintf(stderr, "error: could not grab the device\n");
98 return -1;
99 }
100
101 if (grail_open(&ge, fd)) {
102 fprintf(stderr, "error: could not open touch device\n");
103 return -1;
104 }
105 loop_device(&ge, fd);
106 grail_close(&ge, fd);
107
108 ioctl(fd, EVIOCGRAB, 0);
109 close(fd);
110 return 0;
111}
diff --git a/test/grail-touch.c b/test/grail-touch.c
new file mode 100644
index 0000000..bed31c3
--- /dev/null
+++ b/test/grail-touch.c
@@ -0,0 +1,88 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include <grail-touch.h>
26#include <string.h>
27#include <stdio.h>
28#include <unistd.h>
29#include <fcntl.h>
30
31static void tp_event(struct touch_engine *engine,
32 const struct input_event *ev)
33{
34 fprintf(stderr, "event %d 0x%x %d\n", ev->type, ev->code, ev->value);
35}
36
37static void tp_sync(struct touch_engine *engine,
38 const struct input_event *syn)
39{
40 struct touch_frame *frame = &engine->frame;
41 int i, j;
42 for (i = 0; i < frame->nactive; i++) {
43 struct touch *t = frame->active[i];
44 fprintf(stderr, "touch %d %d\n", i, t->slot);
45 for (j = 0; j < DIM_TOUCH_PROP; j++)
46 fprintf(stderr, " %d\n", t->prop[j]);
47 }
48 fprintf(stderr, "sync %d %lld %d %d\n",
49 frame->nactive, frame->time, frame->ncreate, frame->ndestroy);
50}
51
52static void loop_device(struct touch_dev *dev, int fd)
53{
54 struct touch_engine engine;
55 touch_engine_init(&engine, tp_event, tp_sync, 0);
56 touch_engine_attach(&engine, dev);
57 while (!touch_dev_idle(dev, fd, 5000))
58 touch_dev_pull(dev, fd);
59 touch_engine_detach(&engine, dev);
60}
61
62int main(int argc, char *argv[])
63{
64 struct touch_dev dev;
65 int fd;
66 if (argc < 2) {
67 fprintf(stderr, "Usage: %s <device>\n", argv[0]);
68 return -1;
69 }
70 fd = open(argv[1], O_RDONLY | O_NONBLOCK);
71 if (fd < 0) {
72 fprintf(stderr, "error: could not open device\n");
73 return -1;
74 }
75 if (ioctl(fd, EVIOCGRAB, 1)) {
76 fprintf(stderr, "error: could not grab the device\n");
77 return -1;
78 }
79 if (touch_dev_open(&dev, fd)) {
80 fprintf(stderr, "error: could not open touch device\n");
81 return -1;
82 }
83 loop_device(&dev, fd);
84 touch_dev_close(&dev, fd);
85 ioctl(fd, EVIOCGRAB, 0);
86 close(fd);
87 return 0;
88}