summaryrefslogtreecommitdiff
path: root/src/grail-event.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-08-19 22:15:55 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-08-19 22:15:55 +0200
commit76f51a7675801acfe8e58c6a21192668d23d3320 (patch)
tree73109e613e93fbb8f20fabdbec9f7e0d5356f4dd /src/grail-event.c
parent8331322a0fec7277366a29a970eafbb795c08432 (diff)
Add contact information to the property list
Add the five first contacts to the property list, and unify the handling of all gesture types in this regard. To avoid duplication, move the scaling of properties closer to the gesture recognizer. Move all gesture event handling code to grail-event.c, simplifying the structure somewhat. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/grail-event.c')
-rw-r--r--src/grail-event.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/grail-event.c b/src/grail-event.c
index 6479cc0..2cf8209 100644
--- a/src/grail-event.c
+++ b/src/grail-event.c
@@ -22,8 +22,101 @@
22 22
23#include "grail-inserter.h" 23#include "grail-inserter.h"
24#include "grail-impl.h" 24#include "grail-impl.h"
25#include <malloc.h>
26#include <string.h>
27#include <errno.h>
25#include <math.h> 28#include <math.h>
26 29
30static void compute_bbox(struct grail_coord *min, struct grail_coord *max,
31 const struct touch_frame *frame)
32{
33 float x, y;
34 int i;
35 if (frame->nactive < 1)
36 return;
37 x = frame->active[0]->x;
38 y = frame->active[0]->y;
39 min->x = max->x = x;
40 min->y = max->y = y;
41 for (i = 1; i < frame->nactive; i++) {
42 x = frame->active[i]->x;
43 y = frame->active[i]->y;
44 if (x < min->x)
45 min->x = x;
46 if (y < min->y)
47 min->y = y;
48 if (x > max->x)
49 max->x = x;
50 if (y > max->y)
51 max->y = y;
52 }
53}
54
55int gin_add_contact_props(const struct gesture_inserter *gin,
56 grail_prop_t *prop, const struct touch_frame *frame)
57{
58 struct grail_coord min, max;
59 int i, n = 0, ntouch = frame->nactive;
60 if (!ntouch)
61 return n;
62 if (ntouch > 5)
63 ntouch = 5;
64 compute_bbox(&min, &max, frame);
65 prop[n++] = gin_prop_x(gin, min.x);
66 prop[n++] = gin_prop_y(gin, min.y);
67 prop[n++] = gin_prop_x(gin, max.x);
68 prop[n++] = gin_prop_y(gin, max.y);
69 for (i = 0; i < ntouch; i++) {
70 const struct touch *ct = frame->active[i];
71 prop[n++] = ct->id;
72 prop[n++] = gin_prop_x(gin, ct->x);
73 prop[n++] = gin_prop_y(gin, ct->y);
74 }
75 return n;
76}
77
78int gin_get_clients(struct grail *ge,
79 struct grail_client_info *info, int maxinfo,
80 const grail_mask_t* types, int btypes,
81 const grail_mask_t* span, int bspan,
82 const struct touch_frame *frame)
83{
84 struct grail_coord pos[DIM_TOUCH];
85 int i, npos = 0;
86 if (!ge->get_clients)
87 return 0;
88 grail_mask_foreach(i, span, bspan) {
89 pos[npos].x = gin_prop_x(ge->gin, frame->touch[i].x);
90 pos[npos].y = gin_prop_y(ge->gin, frame->touch[i].y);
91 npos++;
92 }
93 return ge->get_clients(ge, info, maxinfo, pos, npos, types, btypes);
94}
95
96void gin_send_event(struct grail *ge, struct slot_state *s,
97 const struct gesture_event *ev,
98 const struct touch_frame *frame)
99{
100 const struct gesture_inserter *gin = ge->gin;
101 struct grail_event gev;
102 int i;
103 if (!ge->gesture)
104 return;
105 gev.type = s->type;
106 gev.id = s->id;
107 gev.status = ev->status;
108 gev.ntouch = ev->ntouch;
109 gev.nprop = ev->nprop;
110 gev.time = ev->time;
111 gev.pos.x = gin_prop_x(gin, ev->pos.x);
112 gev.pos.y = gin_prop_y(gin, ev->pos.y);
113 memcpy(gev.prop, ev->prop, ev->nprop * sizeof(grail_prop_t));
114 for (i = 0; i < s->nclient; i++) {
115 gev.client_id = s->client_id[i];
116 ge->gesture(ge, &gev);
117 }
118}
119
27int grail_get_contacts(const struct grail *ge, 120int grail_get_contacts(const struct grail *ge,
28 struct grail_contact *touch, int max_touch) 121 struct grail_contact *touch, int max_touch)
29{ 122{