summaryrefslogtreecommitdiffstats
path: root/uwac/libuwac/uwac-tools.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:24:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:24:41 +0000
commita9bcc81f821d7c66f623779fa5147e728eb3c388 (patch)
tree98676963bcdd537ae5908a067a8eb110b93486a6 /uwac/libuwac/uwac-tools.c
parentInitial commit. (diff)
downloadfreerdp3-a9bcc81f821d7c66f623779fa5147e728eb3c388.tar.xz
freerdp3-a9bcc81f821d7c66f623779fa5147e728eb3c388.zip
Adding upstream version 3.3.0+dfsg1.upstream/3.3.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'uwac/libuwac/uwac-tools.c')
-rw-r--r--uwac/libuwac/uwac-tools.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/uwac/libuwac/uwac-tools.c b/uwac/libuwac/uwac-tools.c
new file mode 100644
index 0000000..760970e
--- /dev/null
+++ b/uwac/libuwac/uwac-tools.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright © 2015 David FORT <contact@hardening-consulting.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include <wayland-util.h>
+#include <string.h>
+#include <uwac/uwac-tools.h>
+
+struct uwac_touch_automata
+{
+ struct wl_array tp;
+};
+
+void UwacTouchAutomataInit(UwacTouchAutomata* automata)
+{
+ wl_array_init(&automata->tp);
+}
+
+void UwacTouchAutomataReset(UwacTouchAutomata* automata)
+{
+ automata->tp.size = 0;
+}
+
+bool UwacTouchAutomataInjectEvent(UwacTouchAutomata* automata, UwacEvent* event)
+{
+
+ UwacTouchPoint* tp = NULL;
+
+ switch (event->type)
+ {
+ case UWAC_EVENT_TOUCH_FRAME_BEGIN:
+ break;
+
+ case UWAC_EVENT_TOUCH_UP:
+ {
+ UwacTouchUp* touchUp = &event->touchUp;
+ size_t toMove = automata->tp.size - sizeof(UwacTouchPoint);
+
+ wl_array_for_each(tp, &automata->tp)
+ {
+ if ((int64_t)tp->id == touchUp->id)
+ {
+ if (toMove)
+ memmove(tp, tp + 1, toMove);
+ return true;
+ }
+
+ toMove -= sizeof(UwacTouchPoint);
+ }
+ break;
+ }
+
+ case UWAC_EVENT_TOUCH_DOWN:
+ {
+ UwacTouchDown* touchDown = &event->touchDown;
+
+ wl_array_for_each(tp, &automata->tp)
+ {
+ if ((int64_t)tp->id == touchDown->id)
+ {
+ tp->x = touchDown->x;
+ tp->y = touchDown->y;
+ return true;
+ }
+ }
+
+ tp = wl_array_add(&automata->tp, sizeof(UwacTouchPoint));
+ if (!tp)
+ return false;
+
+ if (touchDown->id < 0)
+ return false;
+
+ tp->id = (uint32_t)touchDown->id;
+ tp->x = touchDown->x;
+ tp->y = touchDown->y;
+ break;
+ }
+
+ case UWAC_EVENT_TOUCH_FRAME_END:
+ break;
+
+ default:
+ break;
+ }
+
+ return true;
+}