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/>.
22
#include <geis/geis.h>
25
#include <sys/select.h>
28
void print_attr(GeisAttr attr)
30
GeisString attr_name = geis_attr_name(attr);
31
switch (geis_attr_type(attr))
33
case GEIS_ATTR_TYPE_BOOLEAN:
34
printf(" \"%s\": %s\n", attr_name,
35
geis_attr_value_to_boolean(attr) ? "true" : "false");
37
case GEIS_ATTR_TYPE_FLOAT:
38
printf(" \"%s\": %g\n", attr_name, geis_attr_value_to_float(attr));
40
case GEIS_ATTR_TYPE_INTEGER:
41
printf(" \"%s\": %d\n", attr_name, geis_attr_value_to_integer(attr));
43
case GEIS_ATTR_TYPE_STRING:
44
printf(" \"%s\": %s\n", attr_name, geis_attr_value_to_string(attr));
53
dump_device_event(GeisEvent event)
58
GeisInputDeviceId device_id = 0;
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);
91
for (j=0; j < geis_group_frame_count(group); ++j)
94
GeisFrame frame = geis_group_frame(group, j);
95
GeisSize attr_count = geis_frame_attr_count(frame);
97
for (k = 0; k < attr_count; ++k)
99
print_attr(geis_frame_attr(frame, k));
102
for (k = 0; k < geis_frame_touchid_count(frame); ++k)
104
GeisSize touchid = geis_frame_touchid(frame, k);
105
GeisTouch touch = geis_touchset_touch_by_id(touchset, touchid);
107
printf("+touch %lu\n", k);
108
for (n = 0; n < geis_touch_attr_count(touch); ++n)
110
print_attr(geis_touch_attr(touch, n));
119
main(int argc, char* argv[])
123
GeisSubscription subscription;
127
geis = geis_new(GEIS_INIT_UTOUCH_XCB,
128
GEIS_INIT_TRACK_DEVICES,
130
subscription = geis_subscription_new(geis, "example", GEIS_SUBSCRIPTION_CONT);
131
filter = geis_filter_new(geis, "filter");
133
geis_filter_add_term(filter,
135
GEIS_GESTURE_ATTRIBUTE_TOUCHES, GEIS_FILTER_OP_EQ, 2,
138
status = geis_subscription_add_filter(subscription, filter);
139
status = geis_subscription_activate(subscription);
141
geis_get_configuration(geis, GEIS_CONFIGURATION_FD, &fd);
147
FD_SET(0, &read_fds);
148
FD_SET(fd, &read_fds);
149
int sstat = select(fd+1, &read_fds, NULL, NULL, NULL);
152
fprintf(stderr, "error %d in select(): %s\n", errno, strerror(errno));
156
if (FD_ISSET(fd, &read_fds))
159
status = geis_dispatch_events(geis);
160
status = geis_next_event(geis, &event);
161
while (status == GEIS_STATUS_CONTINUE || status == GEIS_STATUS_SUCCESS)
163
switch (geis_event_type(event))
165
case GEIS_EVENT_DEVICE_AVAILABLE:
166
case GEIS_EVENT_DEVICE_UNAVAILABLE:
167
dump_device_event(event);
170
case GEIS_EVENT_GESTURE_BEGIN:
171
case GEIS_EVENT_GESTURE_UPDATE:
172
case GEIS_EVENT_GESTURE_END:
173
dump_gesture_event(event);
176
geis_event_delete(event);
177
status = geis_next_event(geis, &event);
181
if (FD_ISSET(0, &read_fds))
187
geis_subscription_delete(subscription);