aboutsummaryrefslogtreecommitdiffstats
path: root/libterminput_marshal_input.c
blob: 9949838cfe00b7cfb398feb3f29376f46ea5b163 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* See LICENSE file for copyright and license details. */
#include "common.h"


int
libterminput_marshal_input(struct libterminput_marshaller *how, const union libterminput_input *what) /* TODO test */
{
	enum libterminput_type type = what->type;
	if (how->store(how, &type, sizeof(type)))
		return -1;
	if (type == LIBTERMINPUT_NONE) {
		if (what->keypress.key == LIBTERMINPUT_SYMBOL)
			type = LIBTERMINPUT_KEYPRESS;
		if (how->store(how, &type, sizeof(type)))
			return -1;
	}
	if (type == LIBTERMINPUT_KEYPRESS)
		return libterminput_marshal_keypress__(how, &what->keypress);
	else if (type == LIBTERMINPUT_TEXT)
		return libterminput_marshal_text__(how, &what->text);
	else if (type == LIBTERMINPUT_MOUSEEVENT)
		return libterminput_marshal_mouseevent__(how, &what->mouseevent);
	else if (type == LIBTERMINPUT_CURSOR_POSITION)
		return libterminput_marshal_position__(how, &what->position);
	else
		return 0;
}