FreeRDP
uwac-tools.c
1 /*
2  * Copyright © 2015 David FORT <contact@hardening-consulting.com>
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting documentation, and
8  * that the name of the copyright holders not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission. The copyright holders make no representations
11  * about the suitability of this software for any purpose. It is provided "as
12  * is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20  * OF THIS SOFTWARE.
21  */
22 
23 #include <wayland-util.h>
24 #include <string.h>
25 #include <uwac/uwac-tools.h>
26 
27 struct uwac_touch_automata
28 {
29  struct wl_array tp;
30 };
31 
32 void UwacTouchAutomataInit(UwacTouchAutomata* automata)
33 {
34  wl_array_init(&automata->tp);
35 }
36 
37 void UwacTouchAutomataReset(UwacTouchAutomata* automata)
38 {
39  automata->tp.size = 0;
40 }
41 
42 bool UwacTouchAutomataInjectEvent(UwacTouchAutomata* automata, UwacEvent* event)
43 {
44 
45  UwacTouchPoint* tp = NULL;
46 
47  switch (event->type)
48  {
49  case UWAC_EVENT_TOUCH_FRAME_BEGIN:
50  break;
51 
52  case UWAC_EVENT_TOUCH_UP:
53  {
54  UwacTouchUp* touchUp = &event->touchUp;
55  size_t toMove = automata->tp.size - sizeof(UwacTouchPoint);
56 
57  wl_array_for_each(tp, &automata->tp)
58  {
59  if ((int64_t)tp->id == touchUp->id)
60  {
61  if (toMove)
62  memmove(tp, tp + 1, toMove);
63  return true;
64  }
65 
66  toMove -= sizeof(UwacTouchPoint);
67  }
68  break;
69  }
70 
71  case UWAC_EVENT_TOUCH_DOWN:
72  {
73  UwacTouchDown* touchDown = &event->touchDown;
74 
75  wl_array_for_each(tp, &automata->tp)
76  {
77  if ((int64_t)tp->id == touchDown->id)
78  {
79  tp->x = touchDown->x;
80  tp->y = touchDown->y;
81  return true;
82  }
83  }
84 
85  tp = wl_array_add(&automata->tp, sizeof(UwacTouchPoint));
86  if (!tp)
87  return false;
88 
89  if (touchDown->id < 0)
90  return false;
91 
92  tp->id = (uint32_t)touchDown->id;
93  tp->x = touchDown->x;
94  tp->y = touchDown->y;
95  break;
96  }
97 
98  case UWAC_EVENT_TOUCH_FRAME_END:
99  break;
100 
101  default:
102  break;
103  }
104 
105  return true;
106 }