2018-02-08 20:47:31 +08:00
|
|
|
#ifndef CONTROLEVENT_H
|
|
|
|
#define CONTROLEVENT_H
|
2017-12-14 18:38:44 +08:00
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
#include <stdbool.h>
|
2019-05-29 23:26:21 +08:00
|
|
|
#include <stddef.h>
|
2019-03-03 06:52:22 +08:00
|
|
|
#include <stdint.h>
|
2017-12-14 18:38:44 +08:00
|
|
|
|
|
|
|
#include "android/input.h"
|
|
|
|
#include "android/keycodes.h"
|
2018-01-22 23:50:08 +08:00
|
|
|
#include "common.h"
|
2017-12-14 18:38:44 +08:00
|
|
|
|
2019-05-29 14:35:28 +08:00
|
|
|
#define CONTROL_EVENT_TEXT_MAX_LENGTH 300
|
|
|
|
#define CONTROL_EVENT_SERIALIZED_MAX_SIZE (3 + CONTROL_EVENT_TEXT_MAX_LENGTH)
|
2017-12-14 18:38:44 +08:00
|
|
|
|
|
|
|
enum control_event_type {
|
|
|
|
CONTROL_EVENT_TYPE_KEYCODE,
|
|
|
|
CONTROL_EVENT_TYPE_TEXT,
|
|
|
|
CONTROL_EVENT_TYPE_MOUSE,
|
|
|
|
CONTROL_EVENT_TYPE_SCROLL,
|
2018-02-02 21:52:23 +08:00
|
|
|
CONTROL_EVENT_TYPE_COMMAND,
|
2017-12-14 18:38:44 +08:00
|
|
|
};
|
|
|
|
|
2019-02-27 03:35:37 +08:00
|
|
|
enum control_event_command {
|
|
|
|
CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON,
|
|
|
|
CONTROL_EVENT_COMMAND_EXPAND_NOTIFICATION_PANEL,
|
|
|
|
CONTROL_EVENT_COMMAND_COLLAPSE_NOTIFICATION_PANEL,
|
|
|
|
};
|
2018-02-02 21:52:23 +08:00
|
|
|
|
2017-12-14 18:38:44 +08:00
|
|
|
struct control_event {
|
|
|
|
enum control_event_type type;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
enum android_keyevent_action action;
|
|
|
|
enum android_keycode keycode;
|
|
|
|
enum android_metastate metastate;
|
|
|
|
} keycode_event;
|
|
|
|
struct {
|
2018-03-07 22:29:33 +08:00
|
|
|
char *text; // owned, to be freed by SDL_free()
|
2017-12-14 18:38:44 +08:00
|
|
|
} text_event;
|
|
|
|
struct {
|
|
|
|
enum android_motionevent_action action;
|
|
|
|
enum android_motionevent_buttons buttons;
|
2018-01-29 21:52:22 +08:00
|
|
|
struct position position;
|
2017-12-14 18:38:44 +08:00
|
|
|
} mouse_event;
|
|
|
|
struct {
|
2018-01-29 21:52:22 +08:00
|
|
|
struct position position;
|
2019-03-03 06:52:22 +08:00
|
|
|
int32_t hscroll;
|
|
|
|
int32_t vscroll;
|
2017-12-14 18:38:44 +08:00
|
|
|
} scroll_event;
|
2018-02-02 21:52:23 +08:00
|
|
|
struct {
|
2019-02-27 03:35:37 +08:00
|
|
|
enum control_event_command action;
|
2018-02-02 21:52:23 +08:00
|
|
|
} command_event;
|
2017-12-14 18:38:44 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-05-29 14:35:28 +08:00
|
|
|
// buf size must be at least CONTROL_EVENT_SERIALIZED_MAX_SIZE
|
2019-05-29 23:26:21 +08:00
|
|
|
// return the number of bytes written
|
|
|
|
size_t
|
2019-03-03 03:09:56 +08:00
|
|
|
control_event_serialize(const struct control_event *event, unsigned char *buf);
|
2017-12-14 18:38:44 +08:00
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
control_event_destroy(struct control_event *event);
|
2018-03-07 22:29:33 +08:00
|
|
|
|
2017-12-14 18:38:44 +08:00
|
|
|
#endif
|