2019-05-31 20:55:11 +08:00
|
|
|
#ifndef CONTROLMSG_H
|
|
|
|
#define CONTROLMSG_H
|
|
|
|
|
2021-01-09 02:24:51 +08:00
|
|
|
#include "common.h"
|
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "android/input.h"
|
|
|
|
#include "android/keycodes.h"
|
2021-01-09 02:15:29 +08:00
|
|
|
#include "coords.h"
|
2019-05-31 20:55:11 +08:00
|
|
|
|
2020-06-05 05:23:09 +08:00
|
|
|
#define CONTROL_MSG_MAX_SIZE (1 << 18) // 256k
|
2020-06-05 03:09:42 +08:00
|
|
|
|
2020-04-14 01:37:34 +08:00
|
|
|
#define CONTROL_MSG_INJECT_TEXT_MAX_LENGTH 300
|
2020-06-05 03:42:09 +08:00
|
|
|
// type: 1 byte; paste flag: 1 byte; length: 4 bytes
|
|
|
|
#define CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH (CONTROL_MSG_MAX_SIZE - 6)
|
2019-05-31 20:55:11 +08:00
|
|
|
|
2021-06-20 06:32:55 +08:00
|
|
|
#define POINTER_ID_MOUSE UINT64_C(-1)
|
|
|
|
#define POINTER_ID_VIRTUAL_FINGER UINT64_C(-2)
|
2019-10-04 02:14:12 +08:00
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
enum control_msg_type {
|
|
|
|
CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
|
|
|
CONTROL_MSG_TYPE_INJECT_TEXT,
|
2019-09-15 22:16:17 +08:00
|
|
|
CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
2019-05-31 20:55:11 +08:00
|
|
|
CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
|
|
|
CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
|
|
|
CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
2021-04-17 20:32:18 +08:00
|
|
|
CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL,
|
2021-04-17 20:26:54 +08:00
|
|
|
CONTROL_MSG_TYPE_COLLAPSE_PANELS,
|
2019-05-31 20:55:11 +08:00
|
|
|
CONTROL_MSG_TYPE_GET_CLIPBOARD,
|
|
|
|
CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
2019-03-16 03:23:30 +08:00
|
|
|
CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE,
|
2019-12-05 02:55:28 +08:00
|
|
|
CONTROL_MSG_TYPE_ROTATE_DEVICE,
|
2019-03-16 03:23:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum screen_power_mode {
|
|
|
|
// see <https://android.googlesource.com/platform/frameworks/base.git/+/pie-release-2/core/java/android/view/SurfaceControl.java#305>
|
|
|
|
SCREEN_POWER_MODE_OFF = 0,
|
|
|
|
SCREEN_POWER_MODE_NORMAL = 2,
|
2019-05-31 20:55:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct control_msg {
|
|
|
|
enum control_msg_type type;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
enum android_keyevent_action action;
|
|
|
|
enum android_keycode keycode;
|
2020-06-11 16:40:52 +08:00
|
|
|
uint32_t repeat;
|
2019-05-31 20:55:11 +08:00
|
|
|
enum android_metastate metastate;
|
|
|
|
} inject_keycode;
|
|
|
|
struct {
|
2021-01-24 22:14:53 +08:00
|
|
|
char *text; // owned, to be freed by free()
|
2019-05-31 20:55:11 +08:00
|
|
|
} inject_text;
|
|
|
|
struct {
|
|
|
|
enum android_motionevent_action action;
|
|
|
|
enum android_motionevent_buttons buttons;
|
2019-09-15 22:16:17 +08:00
|
|
|
uint64_t pointer_id;
|
|
|
|
struct position position;
|
|
|
|
float pressure;
|
|
|
|
} inject_touch_event;
|
2019-05-31 20:55:11 +08:00
|
|
|
struct {
|
|
|
|
struct position position;
|
|
|
|
int32_t hscroll;
|
|
|
|
int32_t vscroll;
|
|
|
|
} inject_scroll_event;
|
2021-04-17 00:37:50 +08:00
|
|
|
struct {
|
|
|
|
enum android_keyevent_action action; // action for the BACK key
|
|
|
|
// screen may only be turned on on ACTION_DOWN
|
|
|
|
} back_or_screen_on;
|
2019-05-31 20:55:11 +08:00
|
|
|
struct {
|
2021-01-24 22:14:53 +08:00
|
|
|
char *text; // owned, to be freed by free()
|
2020-05-26 02:58:24 +08:00
|
|
|
bool paste;
|
2019-05-31 20:55:11 +08:00
|
|
|
} set_clipboard;
|
2019-03-16 03:23:30 +08:00
|
|
|
struct {
|
|
|
|
enum screen_power_mode mode;
|
|
|
|
} set_screen_power_mode;
|
2019-05-31 20:55:11 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-06-05 03:26:38 +08:00
|
|
|
// buf size must be at least CONTROL_MSG_MAX_SIZE
|
2019-05-31 20:55:11 +08:00
|
|
|
// return the number of bytes written
|
|
|
|
size_t
|
|
|
|
control_msg_serialize(const struct control_msg *msg, unsigned char *buf);
|
|
|
|
|
2021-06-09 00:14:20 +08:00
|
|
|
void
|
|
|
|
control_msg_log(const struct control_msg *msg);
|
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
void
|
|
|
|
control_msg_destroy(struct control_msg *msg);
|
|
|
|
|
|
|
|
#endif
|