FreeRDP
Loading...
Searching...
No Matches
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#include <winpr/wtypes.h>
27
28struct uwac_touch_automata
29{
30 struct wl_array tp;
31};
32
33void UwacTouchAutomataInit(UwacTouchAutomata* automata)
34{
35 wl_array_init(&automata->tp);
36}
37
38void UwacTouchAutomataReset(UwacTouchAutomata* automata)
39{
40 automata->tp.size = 0;
41}
42
43bool UwacTouchAutomataInjectEvent(UwacTouchAutomata* automata, UwacEvent* event)
44{
45
46 UwacTouchPoint* tp = nullptr;
47
48 switch (event->type)
49 {
50 case UWAC_EVENT_TOUCH_FRAME_BEGIN:
51 break;
52
53 case UWAC_EVENT_TOUCH_UP:
54 {
55 UwacTouchUp* touchUp = &event->touchUp;
56 size_t toMove = automata->tp.size - sizeof(UwacTouchPoint);
57
58 wl_array_for_each(tp, &automata->tp)
59 {
60 if ((int64_t)tp->id == touchUp->id)
61 {
62 if (toMove)
63 memmove(tp, tp + 1, toMove);
64 return true;
65 }
66
67 toMove -= sizeof(UwacTouchPoint);
68 }
69 break;
70 }
71
72 case UWAC_EVENT_TOUCH_DOWN:
73 {
74 UwacTouchDown* touchDown = &event->touchDown;
75
76 wl_array_for_each(tp, &automata->tp)
77 {
78 if ((int64_t)tp->id == touchDown->id)
79 {
80 tp->x = touchDown->x;
81 tp->y = touchDown->y;
82 return true;
83 }
84 }
85
86 tp = wl_array_add(&automata->tp, sizeof(UwacTouchPoint));
87 if (!tp)
88 return false;
89
90 if (touchDown->id < 0)
91 return false;
92
93 tp->id = (uint32_t)touchDown->id;
94 tp->x = touchDown->x;
95 tp->y = touchDown->y;
96 break;
97 }
98
99 case UWAC_EVENT_TOUCH_FRAME_END:
100 break;
101
102 default:
103 break;
104 }
105
106 return true;
107}