FreeRDP/uwac/libuwac/uwac-tools.c

107 lines
2.6 KiB
C
Raw Normal View History

/*
* 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>
2019-11-06 17:24:51 +03:00
struct uwac_touch_automata
{
struct wl_array tp;
};
2019-11-06 17:24:51 +03:00
void UwacTouchAutomataInit(UwacTouchAutomata* automata)
{
wl_array_init(&automata->tp);
}
2019-11-06 17:24:51 +03:00
void UwacTouchAutomataReset(UwacTouchAutomata* automata)
{
automata->tp.size = 0;
}
2019-11-06 17:24:51 +03:00
bool UwacTouchAutomataInjectEvent(UwacTouchAutomata* automata, UwacEvent* event)
{
2019-11-06 17:24:51 +03:00
UwacTouchPoint* tp;
2019-11-06 17:24:51 +03:00
switch (event->type)
{
case UWAC_EVENT_TOUCH_FRAME_BEGIN:
break;
2019-11-06 17:24:51 +03:00
case UWAC_EVENT_TOUCH_UP:
{
UwacTouchUp* touchUp = &event->touchUp;
size_t toMove = automata->tp.size - sizeof(UwacTouchPoint);
2019-11-06 17:24:51 +03:00
wl_array_for_each(tp, &automata->tp)
{
if ((int64_t)tp->id == touchUp->id)
{
if (toMove)
memmove(tp, tp + 1, toMove);
return true;
}
2019-11-06 17:24:51 +03:00
toMove -= sizeof(UwacTouchPoint);
}
break;
}
2019-11-06 17:24:51 +03:00
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;
}
}
2019-11-06 17:24:51 +03:00
tp = wl_array_add(&automata->tp, sizeof(UwacTouchPoint));
if (!tp)
return false;
2019-11-06 17:24:51 +03:00
if (touchDown->id < 0)
return false;
2019-02-07 16:21:04 +03:00
2019-11-06 17:24:51 +03:00
tp->id = (uint32_t)touchDown->id;
tp->x = touchDown->x;
tp->y = touchDown->y;
break;
}
2019-11-06 17:24:51 +03:00
case UWAC_EVENT_TOUCH_FRAME_END:
break;
2019-11-06 17:24:51 +03:00
default:
break;
}
return true;
}