|
|
|
@ -33,99 +33,26 @@ convert_mouse_buttons(uint32_t state) {
|
|
|
|
|
return buttons;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
convert_mouse_action(enum sc_action from, enum android_motionevent_action *to) {
|
|
|
|
|
static const struct sc_intmap_entry actions[] = {
|
|
|
|
|
{SC_ACTION_DOWN, AMOTION_EVENT_ACTION_DOWN},
|
|
|
|
|
{SC_ACTION_UP, AMOTION_EVENT_ACTION_UP},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const struct sc_intmap_entry *entry = SC_INTMAP_FIND_ENTRY(actions, from);
|
|
|
|
|
if (entry) {
|
|
|
|
|
*to = entry->value;
|
|
|
|
|
return true;
|
|
|
|
|
static enum android_motionevent_action
|
|
|
|
|
convert_mouse_action(enum sc_action action) {
|
|
|
|
|
if (action == SC_ACTION_DOWN) {
|
|
|
|
|
return AMOTION_EVENT_ACTION_DOWN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
assert(action == SC_ACTION_UP);
|
|
|
|
|
return AMOTION_EVENT_ACTION_UP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
convert_touch_action(enum sc_touch_action from,
|
|
|
|
|
enum android_motionevent_action *to) {
|
|
|
|
|
static const struct sc_intmap_entry actions[] = {
|
|
|
|
|
{SC_TOUCH_ACTION_MOVE, AMOTION_EVENT_ACTION_MOVE},
|
|
|
|
|
{SC_TOUCH_ACTION_DOWN, AMOTION_EVENT_ACTION_DOWN},
|
|
|
|
|
{SC_TOUCH_ACTION_UP, AMOTION_EVENT_ACTION_UP},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const struct sc_intmap_entry *entry = SC_INTMAP_FIND_ENTRY(actions, from);
|
|
|
|
|
if (entry) {
|
|
|
|
|
*to = entry->value;
|
|
|
|
|
return true;
|
|
|
|
|
static enum android_motionevent_action
|
|
|
|
|
convert_touch_action(enum sc_touch_action action) {
|
|
|
|
|
switch (action) {
|
|
|
|
|
case SC_TOUCH_ACTION_MOVE:
|
|
|
|
|
return AMOTION_EVENT_ACTION_MOVE;
|
|
|
|
|
case SC_TOUCH_ACTION_DOWN:
|
|
|
|
|
return AMOTION_EVENT_ACTION_DOWN;
|
|
|
|
|
default:
|
|
|
|
|
assert(action == SC_TOUCH_ACTION_UP);
|
|
|
|
|
return AMOTION_EVENT_ACTION_UP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
convert_mouse_motion(const struct sc_mouse_motion_event *event,
|
|
|
|
|
struct control_msg *msg) {
|
|
|
|
|
msg->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
|
|
|
|
msg->inject_touch_event.action = AMOTION_EVENT_ACTION_MOVE;
|
|
|
|
|
msg->inject_touch_event.pointer_id = POINTER_ID_MOUSE;
|
|
|
|
|
msg->inject_touch_event.position = event->position;
|
|
|
|
|
msg->inject_touch_event.pressure = 1.f;
|
|
|
|
|
msg->inject_touch_event.buttons =
|
|
|
|
|
convert_mouse_buttons(event->buttons_state);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
convert_touch(const struct sc_touch_event *event,
|
|
|
|
|
struct control_msg *msg) {
|
|
|
|
|
msg->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
|
|
|
|
|
|
|
|
|
if (!convert_touch_action(event->action, &msg->inject_touch_event.action)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msg->inject_touch_event.pointer_id = event->pointer_id;
|
|
|
|
|
msg->inject_touch_event.position = event->position;
|
|
|
|
|
msg->inject_touch_event.pressure = event->pressure;
|
|
|
|
|
msg->inject_touch_event.buttons = 0;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
convert_mouse_click(const struct sc_mouse_click_event *event,
|
|
|
|
|
struct control_msg *msg) {
|
|
|
|
|
msg->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
|
|
|
|
|
|
|
|
|
if (!convert_mouse_action(event->action, &msg->inject_touch_event.action)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msg->inject_touch_event.pointer_id = POINTER_ID_MOUSE;
|
|
|
|
|
msg->inject_touch_event.position = event->position;
|
|
|
|
|
msg->inject_touch_event.pressure = event->action == SC_ACTION_DOWN
|
|
|
|
|
? 1.f : 0.f;
|
|
|
|
|
msg->inject_touch_event.buttons =
|
|
|
|
|
convert_mouse_buttons(event->buttons_state);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
convert_mouse_scroll(const struct sc_mouse_scroll_event *event,
|
|
|
|
|
struct control_msg *msg) {
|
|
|
|
|
msg->type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT;
|
|
|
|
|
msg->inject_scroll_event.position = event->position;
|
|
|
|
|
msg->inject_scroll_event.hscroll = event->hscroll;
|
|
|
|
|
msg->inject_scroll_event.vscroll = event->vscroll;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
@ -133,10 +60,16 @@ sc_mouse_processor_process_mouse_motion(struct sc_mouse_processor *mp,
|
|
|
|
|
const struct sc_mouse_motion_event *event) {
|
|
|
|
|
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
|
|
|
|
|
|
|
|
|
struct control_msg msg;
|
|
|
|
|
if (!convert_mouse_motion(event, &msg)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
struct control_msg msg = {
|
|
|
|
|
.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
|
|
|
|
.inject_touch_event = {
|
|
|
|
|
.action = AMOTION_EVENT_ACTION_MOVE,
|
|
|
|
|
.pointer_id = POINTER_ID_MOUSE,
|
|
|
|
|
.position = event->position,
|
|
|
|
|
.pressure = 1.f,
|
|
|
|
|
.buttons = convert_mouse_buttons(event->buttons_state),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!controller_push_msg(mi->controller, &msg)) {
|
|
|
|
|
LOGW("Could not request 'inject mouse motion event'");
|
|
|
|
@ -148,11 +81,19 @@ sc_mouse_processor_process_touch(struct sc_mouse_processor *mp,
|
|
|
|
|
const struct sc_touch_event *event) {
|
|
|
|
|
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
|
|
|
|
|
|
|
|
|
struct control_msg msg;
|
|
|
|
|
if (convert_touch(event, &msg)) {
|
|
|
|
|
if (!controller_push_msg(mi->controller, &msg)) {
|
|
|
|
|
LOGW("Could not request 'inject touch event'");
|
|
|
|
|
}
|
|
|
|
|
struct control_msg msg = {
|
|
|
|
|
.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
|
|
|
|
.inject_touch_event = {
|
|
|
|
|
.action = convert_touch_action(event->action),
|
|
|
|
|
.pointer_id = event->pointer_id,
|
|
|
|
|
.position = event->position,
|
|
|
|
|
.pressure = event->pressure,
|
|
|
|
|
.buttons = 0,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!controller_push_msg(mi->controller, &msg)) {
|
|
|
|
|
LOGW("Could not request 'inject touch event'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -161,11 +102,19 @@ sc_mouse_processor_process_mouse_click(struct sc_mouse_processor *mp,
|
|
|
|
|
const struct sc_mouse_click_event *event) {
|
|
|
|
|
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
|
|
|
|
|
|
|
|
|
struct control_msg msg;
|
|
|
|
|
if (convert_mouse_click(event, &msg)) {
|
|
|
|
|
if (!controller_push_msg(mi->controller, &msg)) {
|
|
|
|
|
LOGW("Could not request 'inject mouse click event'");
|
|
|
|
|
}
|
|
|
|
|
struct control_msg msg = {
|
|
|
|
|
.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
|
|
|
|
.inject_touch_event = {
|
|
|
|
|
.action = convert_mouse_action(event->action),
|
|
|
|
|
.pointer_id = POINTER_ID_MOUSE,
|
|
|
|
|
.position = event->position,
|
|
|
|
|
.pressure = event->action == SC_ACTION_DOWN ? 1.f : 0.f,
|
|
|
|
|
.buttons = convert_mouse_buttons(event->buttons_state),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!controller_push_msg(mi->controller, &msg)) {
|
|
|
|
|
LOGW("Could not request 'inject mouse click event'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -174,11 +123,17 @@ sc_mouse_processor_process_mouse_scroll(struct sc_mouse_processor *mp,
|
|
|
|
|
const struct sc_mouse_scroll_event *event) {
|
|
|
|
|
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
|
|
|
|
|
|
|
|
|
struct control_msg msg;
|
|
|
|
|
if (convert_mouse_scroll(event, &msg)) {
|
|
|
|
|
if (!controller_push_msg(mi->controller, &msg)) {
|
|
|
|
|
LOGW("Could not request 'inject mouse scroll event'");
|
|
|
|
|
}
|
|
|
|
|
struct control_msg msg = {
|
|
|
|
|
.type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
|
|
|
|
.inject_scroll_event = {
|
|
|
|
|
.position = event->position,
|
|
|
|
|
.hscroll = event->hscroll,
|
|
|
|
|
.vscroll = event->vscroll,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!controller_push_msg(mi->controller, &msg)) {
|
|
|
|
|
LOGW("Could not request 'inject mouse scroll event'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|