3
* @brief A simple example using the GEIS v2 API.
5
* Copyright 2011 Canonical Ltd.
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "geis_config.h"
23
#include <geis/geis.h>
26
#include <sys/select.h>
29
void print_attr(GeisAttr attr)
31
GeisString attr_name = geis_attr_name(attr);
32
switch (geis_attr_type(attr))
34
case GEIS_ATTR_TYPE_BOOLEAN:
35
printf(" \"%s\": %s\n", attr_name,
36
geis_attr_value_to_boolean(attr) ? "true" : "false");
38
case GEIS_ATTR_TYPE_FLOAT:
39
printf(" \"%s\": %g\n", attr_name, geis_attr_value_to_float(attr));
41
case GEIS_ATTR_TYPE_INTEGER:
42
printf(" \"%s\": %d\n", attr_name, geis_attr_value_to_integer(attr));
44
case GEIS_ATTR_TYPE_STRING:
45
printf(" \"%s\": %s\n", attr_name, geis_attr_value_to_string(attr));
54
dump_device_event(GeisEvent event)
60
attr = geis_event_attr_by_name(event, GEIS_EVENT_ATTRIBUTE_DEVICE);
61
device = geis_attr_value_to_pointer(attr);
62
printf("device %02d \"%s\"\n",
63
geis_device_id(device), geis_device_name(device));
64
for (i = 0; i < geis_device_attr_count(device); ++i)
66
print_attr(geis_device_attr(device, i));
72
dump_gesture_event(GeisEvent event)
75
GeisTouchSet touchset;
76
GeisGroupSet groupset;
79
attr = geis_event_attr_by_name(event, GEIS_EVENT_ATTRIBUTE_TOUCHSET);
80
touchset = geis_attr_value_to_pointer(attr);
82
attr = geis_event_attr_by_name(event, GEIS_EVENT_ATTRIBUTE_GROUPSET);
83
groupset = geis_attr_value_to_pointer(attr);
86
for (i= 0; i < geis_groupset_group_count(groupset); ++i)
89
GeisGroup group = geis_groupset_group(groupset, i);
90
printf("+group %u\n", geis_group_id(group));
92
for (j=0; j < geis_group_frame_count(group); ++j)
95
GeisFrame frame = geis_group_frame(group, j);
96
GeisSize attr_count = geis_frame_attr_count(frame);
98
printf("+frame %u\n", geis_frame_id(frame));
99
for (k = 0; k < attr_count; ++k)
101
print_attr(geis_frame_attr(frame, k));
104
for (k = 0; k < geis_frame_touchid_count(frame); ++k)
106
GeisSize touchid = geis_frame_touchid(frame, k);
107
GeisTouch touch = geis_touchset_touch_by_id(touchset, touchid);
109
printf("+touch %u\n", (unsigned)k);
110
for (n = 0; n < geis_touch_attr_count(touch); ++n)
112
print_attr(geis_touch_attr(touch, n));
121
target_subscription(Geis geis, GeisSubscription subscription)
124
GeisFilter filter = geis_filter_new(geis, "filter");
125
geis_filter_add_term(filter,
127
GEIS_GESTURE_ATTRIBUTE_TOUCHES, GEIS_FILTER_OP_EQ, 2,
130
status = geis_subscription_add_filter(subscription, filter);
131
if (status != GEIS_STATUS_SUCCESS)
133
fprintf(stderr, "error adding filter\n");
139
main(int argc GEIS_UNUSED, char* argv[] GEIS_UNUSED)
143
GeisSubscription subscription;
146
geis = geis_new(GEIS_INIT_TRACK_DEVICES,
147
GEIS_INIT_TRACK_GESTURE_CLASSES,
149
geis_get_configuration(geis, GEIS_CONFIGURATION_FD, &fd);
151
subscription = geis_subscription_new(geis, "example", GEIS_SUBSCRIPTION_CONT);
157
FD_SET(0, &read_fds);
158
FD_SET(fd, &read_fds);
159
int sstat = select(fd+1, &read_fds, NULL, NULL, NULL);
162
fprintf(stderr, "error %d in select(): %s\n", errno, strerror(errno));
166
if (FD_ISSET(fd, &read_fds))
169
status = geis_dispatch_events(geis);
170
status = geis_next_event(geis, &event);
171
while (status == GEIS_STATUS_CONTINUE || status == GEIS_STATUS_SUCCESS)
173
switch (geis_event_type(event))
175
case GEIS_EVENT_INIT_COMPLETE:
176
target_subscription(geis, subscription);
177
status = geis_subscription_activate(subscription);
180
case GEIS_EVENT_DEVICE_AVAILABLE:
181
case GEIS_EVENT_DEVICE_UNAVAILABLE:
182
dump_device_event(event);
185
case GEIS_EVENT_GESTURE_BEGIN:
186
case GEIS_EVENT_GESTURE_UPDATE:
187
case GEIS_EVENT_GESTURE_END:
188
dump_gesture_event(event);
194
geis_event_delete(event);
195
status = geis_next_event(geis, &event);
199
if (FD_ISSET(0, &read_fds))
205
geis_subscription_delete(subscription);