tizen 2.3 release
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / common / xdbg_evlog_gesture.c
1 /**************************************************************************
2
3 xdbg
4
5 Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
6
7 Contact: Boram Park <boram1288.park@samsung.com>
8          Sangjin LEE <lsj119@samsung.com>
9
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
20 of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 **************************************************************************/
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <strings.h>
39 #include <sys/types.h>
40 #include <sys/fcntl.h>
41 #include <unistd.h>
42 #include <stdarg.h>
43 #include <fcntl.h>
44 #include <unistd.h>
45
46 #include <dix.h>
47 #define XREGISTRY
48 #include <registry.h>
49 #include <xace.h>
50 #include <xacestr.h>
51 #include <X11/Xatom.h>
52 #include <X11/Xlib.h>
53 #include <windowstr.h>
54 #include <X11/extensions/gesture.h>
55 #include <X11/extensions/gestureproto.h>
56
57
58 #include "xdbg_types.h"
59 #include "xdbg_evlog_gesture.h"
60 #include "xdbg_evlog.h"
61
62 static char *
63 _EvlogRequestGesture(EvlogInfo *evinfo, int detail_level, char *reply, int *len)
64 {
65     xReq *req = evinfo->req.ptr;
66
67     switch (req->data)
68     {
69     case X_GestureSelectEvents:
70         {
71             xGestureSelectEventsReq *stuff = (xGestureSelectEventsReq *)req;
72             REPLY (": XID(0x%x)",
73                 (unsigned int)stuff->window);
74
75             if (detail_level >= EVLOG_PRINT_DETAIL)
76             {
77                 REPLY (" mask(0x%x)",
78                     (unsigned int)stuff->mask);
79             }
80
81             return reply;
82         }
83
84     case X_GestureGetSelectedEvents:
85         {
86             xGestureGetSelectedEventsReq *stuff = (xGestureGetSelectedEventsReq *)req;
87             REPLY (": XID(0x%x)",
88                 (unsigned int)stuff->window);
89
90             return reply;
91         }
92
93     case X_GestureGrabEvent:
94         {
95             xGestureGrabEventReq *stuff = (xGestureGrabEventReq *)req;
96             REPLY (": XID(0x%x)",
97                 (unsigned int)stuff->window);
98
99             if (detail_level >= EVLOG_PRINT_DETAIL)
100             {
101                 const char *event_type;
102                 char devent_type[10];
103
104                 switch (stuff->eventType)
105                 {
106                     case GestureNotifyFlick:  event_type = "GestureNotifyFlick"; break;
107                     case GestureNotifyPan:  event_type = "GestureNotifyPan"; break;
108                     case GestureNotifyPinchRotation:  event_type = "GestureNotifyPinchRotation"; break;
109                     case GestureNotifyTap:  event_type = "GestureNotifyTap"; break;
110                     case GestureNotifyTapNHold:  event_type = "GestureNotifyTapNHold"; break;
111                     case GestureNotifyHold:  event_type = "GestureNotifyHold"; break;
112                     case GestureNotifyGroup:  event_type = "GestureNotifyGroup"; break;
113                     default:  event_type = devent_type; sprintf (devent_type, "%ld", (long int)stuff->eventType); break;
114                 }
115
116                 REPLY (" event_type(%s) num_finger(%d) time(%lums)",
117                     event_type,
118                     stuff->num_finger,
119                     (unsigned long)stuff->time);
120             }
121
122             return reply;
123         }
124
125     case X_GestureUngrabEvent:
126         {
127             xGestureUngrabEventReq *stuff = (xGestureUngrabEventReq *)req;
128             REPLY (": XID(0x%x)",
129                 (unsigned int)stuff->window);
130
131             if (detail_level >= EVLOG_PRINT_DETAIL)
132             {
133                 const char *event_type;
134                 char devent_type[10];
135
136                 switch (stuff->eventType)
137                 {
138                     case GestureNotifyFlick:  event_type = "GestureNotifyFlick"; break;
139                     case GestureNotifyPan:  event_type = "GestureNotifyPan"; break;
140                     case GestureNotifyPinchRotation:  event_type = "GestureNotifyPinchRotation"; break;
141                     case GestureNotifyTap:  event_type = "GestureNotifyTap"; break;
142                     case GestureNotifyTapNHold:  event_type = "GestureNotifyTapNHold"; break;
143                     case GestureNotifyHold:  event_type = "GestureNotifyHold"; break;
144                     case GestureNotifyGroup:  event_type = "GestureNotifyGroup"; break;
145                     default:  event_type = devent_type; sprintf (devent_type, "%ld", (long int)stuff->eventType); break;
146                 }
147
148                 REPLY (" event_type(%s) num_finger(%d) time(%lums)",
149                     event_type,
150                     stuff->num_finger,
151                     (unsigned long)stuff->time);
152             }
153
154             return reply;
155         }
156
157     default:
158             break;
159     }
160
161     return reply;
162 }
163
164 static char *
165 _EvlogEventGesture (EvlogInfo *evinfo, int first_base, int detail_level, char *reply, int *len)
166 {
167     xEvent *evt = evinfo->evt.ptr;
168
169     switch ((evt->u.u.type & 0x7F) - first_base)
170     {
171     case GestureNotifyFlick:
172         {
173             xGestureNotifyFlickEvent *stuff = (xGestureNotifyFlickEvent *) evt;
174             REPLY (": XID(0x%x)",
175                 (unsigned int)stuff->window);
176
177             if (detail_level >= EVLOG_PRINT_DETAIL)
178             {
179                 const char *kind;
180                 char dkind[10];
181
182                 switch (stuff->kind)
183                 {
184                     case GestureEnd:  kind = "GestureEnd"; break;
185                     case GestureBegin:  kind = "GestureBegin"; break;
186                     case GestureUpdate:  kind = "GestureUpdate"; break;
187                     case GestureDone:  kind = "GestureDone"; break;
188                     default:  kind = dkind; snprintf (dkind, 10, "%d", stuff->kind); break;
189                 }
190
191                 REPLY (" kind(%s) time(%lums) num_finger(%d) direction(%d) distance(%d)",
192                     kind,
193                     (unsigned long)stuff->time,
194                     stuff->num_finger,
195                     stuff->direction,
196                     stuff->distance);
197
198                 REPLY ("\n");
199                 REPLY ("%67s duration(%lums) angle(%ld)",
200                     " ",
201                     (unsigned long)stuff->duration,
202                     (long int)stuff->angle);
203             }
204
205             return reply;
206         }
207
208     case GestureNotifyPan:
209         {
210             xGestureNotifyPanEvent *stuff = (xGestureNotifyPanEvent *) evt;
211             REPLY (": XID(0x%x)",
212                 (unsigned int)stuff->window);
213
214             if (detail_level >= EVLOG_PRINT_DETAIL)
215             {
216                 const char *kind;
217                 char dkind[10];
218
219                 switch (stuff->kind)
220                 {
221                     case GestureEnd:  kind = "GestureEnd"; break;
222                     case GestureBegin:  kind = "GestureBegin"; break;
223                     case GestureUpdate:  kind = "GestureUpdate"; break;
224                     case GestureDone:  kind = "GestureDone"; break;
225                     default:  kind = dkind; snprintf (dkind, 10, "%d", stuff->kind); break;
226                 }
227
228                 REPLY (" kind(%s) sequence_num(%d) time(%lums) num_finger(%d) direction(%d) ",
229                     kind,
230                     stuff->sequenceNumber,
231                     (unsigned long)stuff->time,
232                     stuff->num_finger,
233                     stuff->direction);
234
235                 REPLY ("\n");
236                 REPLY ("%67s distance(%d) duration(%ldms) coord(%d,%d)",
237                     " ",
238                     stuff->distance,
239                     (long int)stuff->duration,
240                     stuff->dx,
241                     stuff->dy);
242             }
243
244             return reply;
245         }
246
247     case GestureNotifyPinchRotation:
248         {
249             xGestureNotifyPinchRotationEvent *stuff = (xGestureNotifyPinchRotationEvent *) evt;
250             REPLY (": XID(0x%x)",
251                 (unsigned int)stuff->window);
252
253             if (detail_level >= EVLOG_PRINT_DETAIL)
254             {
255                 const char *kind;
256                 char dkind[10];
257
258                 switch (stuff->kind)
259                 {
260                     case GestureEnd:  kind = "GestureEnd"; break;
261                     case GestureBegin:  kind = "GestureBegin"; break;
262                     case GestureUpdate:  kind = "GestureUpdate"; break;
263                     case GestureDone:  kind = "GestureDone"; break;
264                     default:  kind = dkind; snprintf (dkind, 10, "%d", stuff->kind); break;
265                 }
266
267                 REPLY (" kind(%s) sequence_num(%d) time(%lums) num_finger(%d) distance(%d)",
268                     kind,
269                     stuff->sequenceNumber,
270                     (unsigned long)stuff->time,
271                     stuff->num_finger,
272                     stuff->distance);
273
274                 REPLY ("\n");
275                 REPLY ("%67s coord(%d,%d) zoom(%ld) angle(%ld)",
276                     " ",
277                     stuff->cx,
278                     stuff->cy,
279                     (long int)stuff->zoom,
280                     (long int)stuff->angle);
281             }
282
283             return reply;
284         }
285
286     case GestureNotifyTap:
287         {
288             xGestureNotifyTapEvent *stuff = (xGestureNotifyTapEvent *) evt;
289             REPLY (": XID(0x%x)",
290                 (unsigned int)stuff->window);
291
292             if (detail_level >= EVLOG_PRINT_DETAIL)
293             {
294                 const char *kind;
295                 char dkind[10];
296
297                 switch (stuff->kind)
298                 {
299                     case GestureEnd:  kind = "GestureEnd"; break;
300                     case GestureBegin:  kind = "GestureBegin"; break;
301                     case GestureUpdate:  kind = "GestureUpdate"; break;
302                     case GestureDone:  kind = "GestureDone"; break;
303                     default:  kind = dkind; snprintf (dkind, 10, "%d", stuff->kind); break;
304                 }
305
306                 REPLY (" kind(%s) sequence_num(%d) time(%lums) num_finger(%d) coord(%d,%d)",
307                     kind,
308                     stuff->sequenceNumber,
309                     (unsigned long)stuff->time,
310                     stuff->num_finger,
311                     stuff->cx,
312                     stuff->cy);
313
314                 REPLY ("\n");
315                 REPLY ("%67s tap_repeat(%d) interval(%lums)",
316                     " ",
317                     stuff->tap_repeat,
318                     (unsigned long)stuff->interval);
319             }
320
321             return reply;
322         }
323
324     case GestureNotifyTapNHold:
325         {
326             xGestureNotifyTapNHoldEvent *stuff = (xGestureNotifyTapNHoldEvent *) evt;
327             REPLY (": XID(0x%x)",
328                 (unsigned int)stuff->window);
329
330             if (detail_level >= EVLOG_PRINT_DETAIL)
331             {
332                 const char *kind;
333                 char dkind[10];
334
335                 switch (stuff->kind)
336                 {
337                     case GestureEnd:  kind = "GestureEnd"; break;
338                     case GestureBegin:  kind = "GestureBegin"; break;
339                     case GestureUpdate:  kind = "GestureUpdate"; break;
340                     case GestureDone:  kind = "GestureDone"; break;
341                     default:  kind = dkind; snprintf (dkind, 10, "%d", stuff->kind); break;
342                 }
343
344                 REPLY (" kind(%s) sequence_num(%d) time(%lums) num_finger(%d) coord(%d,%d)",
345                     kind,
346                     stuff->sequenceNumber,
347                     (unsigned long)stuff->time,
348                     stuff->num_finger,
349                     stuff->cx,
350                     stuff->cy);
351
352                 REPLY ("\n");
353                 REPLY ("%67s interval(%lums) hold_time(%lums)",
354                     " ",
355                     (unsigned long)stuff->interval,
356                     (unsigned long)stuff->holdtime);
357             }
358
359             return reply;
360         }
361
362     case GestureNotifyHold:
363         {
364             xGestureNotifyHoldEvent *stuff = (xGestureNotifyHoldEvent *) evt;
365             REPLY (": XID(0x%x)",
366                 (unsigned int)stuff->window);
367
368             if (detail_level >= EVLOG_PRINT_DETAIL)
369             {
370                 const char *kind;
371                 char dkind[10];
372
373                 switch (stuff->kind)
374                 {
375                     case GestureEnd:  kind = "GestureEnd"; break;
376                     case GestureBegin:  kind = "GestureBegin"; break;
377                     case GestureUpdate:  kind = "GestureUpdate"; break;
378                     case GestureDone:  kind = "GestureDone"; break;
379                     default:  kind = dkind; snprintf (dkind, 10, "%d", stuff->kind); break;
380                 }
381
382                 REPLY (" kind(%s) sequence_num(%d) time(%lums) num_finger(%d) coord(%d,%d) ",
383                     kind,
384                     stuff->sequenceNumber,
385                     (unsigned long)stuff->time,
386                     stuff->num_finger,
387                     stuff->cx,
388                     stuff->cy);
389
390                 REPLY ("\n");
391                 REPLY ("%67s hold_time(%lums)",
392                     " ",
393                     (unsigned long)stuff->holdtime);
394             }
395
396             return reply;
397         }
398
399     case GestureNotifyGroup:
400         {
401             xGestureNotifyGroupEvent *stuff = (xGestureNotifyGroupEvent *) evt;
402             REPLY (": XID(0x%x) groupID(%d) groupNum(%d)",
403                 (unsigned int)stuff->window,
404                 stuff->groupid,
405                 stuff->num_group);
406
407             if (detail_level >= EVLOG_PRINT_DETAIL)
408             {
409                 const char *kind;
410                 char dkind[10];
411
412                 switch (stuff->kind)
413                 {
414                     case GestureGroupRemoved:  kind = "GestureGroupRemoved"; break;
415                     case GestureGroupAdded:  kind = "GestureGroupAdded"; break;
416                     case GestureGroupCurrent:  kind = "GestureGroupCurrent"; break;
417                     default:  kind = dkind; snprintf (dkind, 10, "%d", stuff->kind); break;
418                 }
419
420                 REPLY ("\n");
421                 REPLY ("%67s kind(%s) sequence_num(%d) time(%lums) group_id(%d) num_group(%d)",
422                     " ",
423                     kind,
424                     stuff->sequenceNumber,
425                     (unsigned long)stuff->time,
426                     stuff->groupid,
427                     stuff->num_group);
428             }
429
430             return reply;
431         }
432
433     default:
434             break;
435     }
436
437     return reply;
438 }
439
440 static char *
441 _EvlogReplyGesture (EvlogInfo *evinfo, int detail_level, char *reply, int *len)
442 {
443 #if 0
444     xGenericReply *rep = evinfo->rep.ptr;
445
446     switch (evinfo->rep.reqData)
447     {
448
449     default:
450             break;
451     }
452 #endif
453     return reply;
454 }
455
456 void
457 xDbgEvlogGestureGetBase (ExtensionInfo *extinfo)
458 {
459 #ifdef XDBG_CLIENT
460     RETURN_IF_FAIL (extinfo != NULL);
461
462     extinfo->req_func = _EvlogRequestGesture;
463     extinfo->evt_func = _EvlogEventGesture;
464     extinfo->rep_func = _EvlogReplyGesture;
465 #else
466     ExtensionEntry *xext = CheckExtension (GESTURE_EXT_NAME);
467     RETURN_IF_FAIL (xext != NULL);
468     RETURN_IF_FAIL (extinfo != NULL);
469
470     extinfo->opcode = xext->base;
471     extinfo->evt_base = xext->eventBase;
472     extinfo->err_base = xext->errorBase;
473     extinfo->req_func = _EvlogRequestGesture;
474     extinfo->evt_func = _EvlogEventGesture;
475     extinfo->rep_func = _EvlogReplyGesture;
476 #endif
477 }