Blame uwac/libuwac/uwac-tools.c

Packit Service fa4841
/*
Packit Service fa4841
 * Copyright © 2015 David FORT <contact@hardening-consulting.com>
Packit Service fa4841
 *
Packit Service fa4841
 * Permission to use, copy, modify, distribute, and sell this software and its
Packit Service fa4841
 * documentation for any purpose is hereby granted without fee, provided that
Packit Service fa4841
 * the above copyright notice appear in all copies and that both that copyright
Packit Service fa4841
 * notice and this permission notice appear in supporting documentation, and
Packit Service fa4841
 * that the name of the copyright holders not be used in advertising or
Packit Service fa4841
 * publicity pertaining to distribution of the software without specific,
Packit Service fa4841
 * written prior permission.  The copyright holders make no representations
Packit Service fa4841
 * about the suitability of this software for any purpose.  It is provided "as
Packit Service fa4841
 * is" without express or implied warranty.
Packit Service fa4841
 *
Packit Service fa4841
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
Packit Service fa4841
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
Packit Service fa4841
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
Packit Service fa4841
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
Packit Service fa4841
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
Packit Service fa4841
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
Packit Service fa4841
 * OF THIS SOFTWARE.
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
#include <wayland-util.h>
Packit Service fa4841
#include <string.h>
Packit Service fa4841
#include <uwac/uwac-tools.h>
Packit Service fa4841
Packit Service fa4841
/** @brief */
Packit Service bb5c11
struct uwac_touch_automata {
Packit Service fa4841
	struct wl_array tp;
Packit Service fa4841
};
Packit Service fa4841
Packit Service bb5c11
void UwacTouchAutomataInit(UwacTouchAutomata *automata) {
Packit Service fa4841
	wl_array_init(&automata->tp);
Packit Service fa4841
}
Packit Service fa4841
Packit Service bb5c11
void UwacTouchAutomataReset(UwacTouchAutomata *automata) {
Packit Service fa4841
	automata->tp.size = 0;
Packit Service fa4841
}
Packit Service fa4841
Packit Service bb5c11
bool UwacTouchAutomataInjectEvent(UwacTouchAutomata *automata, UwacEvent *event) {
Packit Service fa4841
Packit Service bb5c11
	UwacTouchPoint *tp;
Packit Service fa4841
Packit Service bb5c11
	switch (event->type) {
Packit Service bb5c11
	case UWAC_EVENT_TOUCH_FRAME_BEGIN:
Packit Service bb5c11
		break;
Packit Service fa4841
Packit Service bb5c11
	case UWAC_EVENT_TOUCH_UP: {
Packit Service bb5c11
		UwacTouchUp *touchUp = &event->touchUp;
Packit Service bb5c11
		int toMove = automata->tp.size - sizeof(UwacTouchPoint);
Packit Service fa4841
Packit Service bb5c11
		wl_array_for_each(tp, &automata->tp) {
Packit Service bb5c11
			if (tp->id == touchUp->id) {
Packit Service bb5c11
				if (toMove)
Packit Service bb5c11
					memmove(tp, tp+1, toMove);
Packit Service bb5c11
				return true;
Packit Service fa4841
			}
Packit Service bb5c11
Packit Service bb5c11
			toMove -= sizeof(UwacTouchPoint);
Packit Service fa4841
		}
Packit Service bb5c11
		break;
Packit Service bb5c11
	}
Packit Service fa4841
Packit Service bb5c11
	case UWAC_EVENT_TOUCH_DOWN: {
Packit Service bb5c11
		UwacTouchDown *touchDown = &event->touchDown;
Packit Service fa4841
Packit Service bb5c11
		wl_array_for_each(tp, &automata->tp) {
Packit Service bb5c11
			if (tp->id == touchDown->id) {
Packit Service bb5c11
				tp->x = touchDown->x;
Packit Service bb5c11
				tp->y = touchDown->y;
Packit Service bb5c11
				return true;
Packit Service bb5c11
			}
Packit Service bb5c11
		}
Packit Service fa4841
Packit Service bb5c11
		tp = wl_array_add(&automata->tp, sizeof(UwacTouchPoint));
Packit Service bb5c11
		if (!tp)
Packit Service bb5c11
			return false;
Packit Service fa4841
Packit Service bb5c11
		tp->id = touchDown->id;
Packit Service bb5c11
		tp->x = touchDown->x;
Packit Service bb5c11
		tp->y = touchDown->y;
Packit Service bb5c11
		break;
Packit Service bb5c11
	}
Packit Service fa4841
Packit Service bb5c11
	case UWAC_EVENT_TOUCH_FRAME_END:
Packit Service bb5c11
		break;
Packit Service fa4841
Packit Service bb5c11
	default:
Packit Service bb5c11
		break;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	return true;
Packit Service fa4841
}