Simplify mouse injection implementation
The static functions are now so simple that they become unnecessary: the control message may be initialized directly instead.
This commit is contained in:
parent
a1f2f5fbd3
commit
96e0e89740
1 changed files with 38 additions and 53 deletions
|
@ -55,58 +55,21 @@ convert_touch_action(enum sc_touch_action action) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
convert_touch(const struct sc_touch_event *event,
|
|
||||||
struct control_msg *msg) {
|
|
||||||
msg->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
|
||||||
msg->inject_touch_event.action = convert_touch_action(event->action);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
convert_mouse_click(const struct sc_mouse_click_event *event,
|
|
||||||
struct control_msg *msg) {
|
|
||||||
msg->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
|
||||||
msg->inject_touch_event.action = convert_mouse_action(event->action);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sc_mouse_processor_process_mouse_motion(struct sc_mouse_processor *mp,
|
sc_mouse_processor_process_mouse_motion(struct sc_mouse_processor *mp,
|
||||||
const struct sc_mouse_motion_event *event) {
|
const struct sc_mouse_motion_event *event) {
|
||||||
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
||||||
|
|
||||||
struct control_msg msg;
|
struct control_msg msg = {
|
||||||
convert_mouse_motion(event, &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)) {
|
if (!controller_push_msg(mi->controller, &msg)) {
|
||||||
LOGW("Could not request 'inject mouse motion event'");
|
LOGW("Could not request 'inject mouse motion event'");
|
||||||
|
@ -118,8 +81,16 @@ sc_mouse_processor_process_touch(struct sc_mouse_processor *mp,
|
||||||
const struct sc_touch_event *event) {
|
const struct sc_touch_event *event) {
|
||||||
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
||||||
|
|
||||||
struct control_msg msg;
|
struct control_msg msg = {
|
||||||
convert_touch(event, &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)) {
|
if (!controller_push_msg(mi->controller, &msg)) {
|
||||||
LOGW("Could not request 'inject touch event'");
|
LOGW("Could not request 'inject touch event'");
|
||||||
|
@ -131,8 +102,16 @@ sc_mouse_processor_process_mouse_click(struct sc_mouse_processor *mp,
|
||||||
const struct sc_mouse_click_event *event) {
|
const struct sc_mouse_click_event *event) {
|
||||||
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
||||||
|
|
||||||
struct control_msg msg;
|
struct control_msg msg = {
|
||||||
convert_mouse_click(event, &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)) {
|
if (!controller_push_msg(mi->controller, &msg)) {
|
||||||
LOGW("Could not request 'inject mouse click event'");
|
LOGW("Could not request 'inject mouse click event'");
|
||||||
|
@ -144,8 +123,14 @@ sc_mouse_processor_process_mouse_scroll(struct sc_mouse_processor *mp,
|
||||||
const struct sc_mouse_scroll_event *event) {
|
const struct sc_mouse_scroll_event *event) {
|
||||||
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
||||||
|
|
||||||
struct control_msg msg;
|
struct control_msg msg = {
|
||||||
convert_mouse_scroll(event, &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)) {
|
if (!controller_push_msg(mi->controller, &msg)) {
|
||||||
LOGW("Could not request 'inject mouse scroll event'");
|
LOGW("Could not request 'inject mouse scroll event'");
|
||||||
|
|
Loading…
Reference in a new issue