2019-05-31 12:55:11 +00:00
|
|
|
#ifndef CONTROLMSG_H
|
|
|
|
#define CONTROLMSG_H
|
|
|
|
|
2021-01-08 18:24:51 +00:00
|
|
|
#include "common.h"
|
|
|
|
|
2019-05-31 12:55:11 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "android/input.h"
|
|
|
|
#include "android/keycodes.h"
|
2021-01-08 18:15:29 +00:00
|
|
|
#include "coords.h"
|
2019-05-31 12:55:11 +00:00
|
|
|
|
2022-01-26 20:31:30 +00:00
|
|
|
#define SC_CONTROL_MSG_MAX_SIZE (1 << 18) // 256k
|
2020-06-04 19:09:42 +00:00
|
|
|
|
2022-01-26 20:31:30 +00:00
|
|
|
#define SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH 300
|
2021-12-04 03:11:30 +00:00
|
|
|
// type: 1 byte; sequence: 8 bytes; paste flag: 1 byte; length: 4 bytes
|
2022-01-26 20:31:30 +00:00
|
|
|
#define SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH (SC_CONTROL_MSG_MAX_SIZE - 14)
|
2019-05-31 12:55:11 +00:00
|
|
|
|
2021-06-19 22:32:55 +00:00
|
|
|
#define POINTER_ID_MOUSE UINT64_C(-1)
|
|
|
|
#define POINTER_ID_VIRTUAL_FINGER UINT64_C(-2)
|
2019-10-03 18:14:12 +00:00
|
|
|
|
2022-01-14 21:17:30 +00:00
|
|
|
enum sc_control_msg_type {
|
2022-01-26 20:31:30 +00:00
|
|
|
SC_CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
|
|
|
SC_CONTROL_MSG_TYPE_INJECT_TEXT,
|
|
|
|
SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
|
|
|
SC_CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
|
|
|
SC_CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
|
|
|
SC_CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
|
|
|
SC_CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL,
|
|
|
|
SC_CONTROL_MSG_TYPE_COLLAPSE_PANELS,
|
|
|
|
SC_CONTROL_MSG_TYPE_GET_CLIPBOARD,
|
|
|
|
SC_CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
|
|
|
SC_CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE,
|
|
|
|
SC_CONTROL_MSG_TYPE_ROTATE_DEVICE,
|
2019-03-15 19:23:30 +00:00
|
|
|
};
|
|
|
|
|
2022-01-26 20:31:30 +00:00
|
|
|
enum sc_screen_power_mode {
|
2019-03-15 19:23:30 +00:00
|
|
|
// see <https://android.googlesource.com/platform/frameworks/base.git/+/pie-release-2/core/java/android/view/SurfaceControl.java#305>
|
2022-01-26 20:31:30 +00:00
|
|
|
SC_SCREEN_POWER_MODE_OFF = 0,
|
|
|
|
SC_SCREEN_POWER_MODE_NORMAL = 2,
|
2019-05-31 12:55:11 +00:00
|
|
|
};
|
|
|
|
|
2022-01-26 20:31:30 +00:00
|
|
|
enum sc_copy_key {
|
|
|
|
SC_COPY_KEY_NONE,
|
|
|
|
SC_COPY_KEY_COPY,
|
|
|
|
SC_COPY_KEY_CUT,
|
2021-11-29 08:30:57 +00:00
|
|
|
};
|
|
|
|
|
2022-01-14 21:17:30 +00:00
|
|
|
struct sc_control_msg {
|
|
|
|
enum sc_control_msg_type type;
|
2019-05-31 12:55:11 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
enum android_keyevent_action action;
|
|
|
|
enum android_keycode keycode;
|
2020-06-11 08:40:52 +00:00
|
|
|
uint32_t repeat;
|
2019-05-31 12:55:11 +00:00
|
|
|
enum android_metastate metastate;
|
|
|
|
} inject_keycode;
|
|
|
|
struct {
|
2021-01-24 14:14:53 +00:00
|
|
|
char *text; // owned, to be freed by free()
|
2019-05-31 12:55:11 +00:00
|
|
|
} inject_text;
|
|
|
|
struct {
|
|
|
|
enum android_motionevent_action action;
|
|
|
|
enum android_motionevent_buttons buttons;
|
2019-09-15 14:16:17 +00:00
|
|
|
uint64_t pointer_id;
|
2021-10-30 13:20:39 +00:00
|
|
|
struct sc_position position;
|
2019-09-15 14:16:17 +00:00
|
|
|
float pressure;
|
|
|
|
} inject_touch_event;
|
2019-05-31 12:55:11 +00:00
|
|
|
struct {
|
2021-10-30 13:20:39 +00:00
|
|
|
struct sc_position position;
|
2019-05-31 12:55:11 +00:00
|
|
|
int32_t hscroll;
|
|
|
|
int32_t vscroll;
|
2021-12-31 09:38:05 +00:00
|
|
|
enum android_motionevent_buttons buttons;
|
2019-05-31 12:55:11 +00:00
|
|
|
} inject_scroll_event;
|
2021-04-16 16:37:50 +00: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;
|
2021-11-29 08:30:57 +00:00
|
|
|
struct {
|
2022-01-26 20:31:30 +00:00
|
|
|
enum sc_copy_key copy_key;
|
2021-11-29 08:30:57 +00:00
|
|
|
} get_clipboard;
|
2019-05-31 12:55:11 +00:00
|
|
|
struct {
|
2021-11-20 10:50:33 +00:00
|
|
|
uint64_t sequence;
|
2021-01-24 14:14:53 +00:00
|
|
|
char *text; // owned, to be freed by free()
|
2020-05-25 18:58:24 +00:00
|
|
|
bool paste;
|
2019-05-31 12:55:11 +00:00
|
|
|
} set_clipboard;
|
2019-03-15 19:23:30 +00:00
|
|
|
struct {
|
2022-01-26 20:31:30 +00:00
|
|
|
enum sc_screen_power_mode mode;
|
2019-03-15 19:23:30 +00:00
|
|
|
} set_screen_power_mode;
|
2019-05-31 12:55:11 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-06-04 19:26:38 +00:00
|
|
|
// buf size must be at least CONTROL_MSG_MAX_SIZE
|
2019-05-31 12:55:11 +00:00
|
|
|
// return the number of bytes written
|
|
|
|
size_t
|
2022-01-14 21:17:30 +00:00
|
|
|
sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf);
|
2019-05-31 12:55:11 +00:00
|
|
|
|
2021-06-08 16:14:20 +00:00
|
|
|
void
|
2022-01-14 21:17:30 +00:00
|
|
|
sc_control_msg_log(const struct sc_control_msg *msg);
|
2021-06-08 16:14:20 +00:00
|
|
|
|
2019-05-31 12:55:11 +00:00
|
|
|
void
|
2022-01-14 21:17:30 +00:00
|
|
|
sc_control_msg_destroy(struct sc_control_msg *msg);
|
2019-05-31 12:55:11 +00:00
|
|
|
|
|
|
|
#endif
|