|
|
|
|
@ -5,7 +5,7 @@
|
|
|
|
|
#define MAP(FROM, TO) case FROM: *to = TO; return true
|
|
|
|
|
#define FAIL default: return false
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
bool
|
|
|
|
|
convert_keycode_action(SDL_EventType from, enum android_keyevent_action *to) {
|
|
|
|
|
switch (from) {
|
|
|
|
|
MAP(SDL_KEYDOWN, AKEY_EVENT_ACTION_DOWN);
|
|
|
|
|
@ -33,7 +33,7 @@ autocomplete_metastate(enum android_metastate metastate) {
|
|
|
|
|
return metastate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static enum android_metastate
|
|
|
|
|
enum android_metastate
|
|
|
|
|
convert_meta_state(SDL_Keymod mod) {
|
|
|
|
|
enum android_metastate metastate = 0;
|
|
|
|
|
if (mod & KMOD_LSHIFT) {
|
|
|
|
|
@ -74,7 +74,7 @@ convert_meta_state(SDL_Keymod mod) {
|
|
|
|
|
return autocomplete_metastate(metastate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
bool
|
|
|
|
|
convert_keycode(SDL_Keycode from, enum android_keycode *to, uint16_t mod) {
|
|
|
|
|
switch (from) {
|
|
|
|
|
MAP(SDLK_RETURN, AKEYCODE_ENTER);
|
|
|
|
|
@ -128,7 +128,7 @@ convert_keycode(SDL_Keycode from, enum android_keycode *to, uint16_t mod) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static enum android_motionevent_buttons
|
|
|
|
|
enum android_motionevent_buttons
|
|
|
|
|
convert_mouse_buttons(uint32_t state) {
|
|
|
|
|
enum android_motionevent_buttons buttons = 0;
|
|
|
|
|
if (state & SDL_BUTTON_LMASK) {
|
|
|
|
|
@ -150,24 +150,6 @@ convert_mouse_buttons(uint32_t state) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to) {
|
|
|
|
|
to->type = CONTROL_MSG_TYPE_INJECT_KEYCODE;
|
|
|
|
|
|
|
|
|
|
if (!convert_keycode_action(from->type, &to->inject_keycode.action)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t mod = from->keysym.mod;
|
|
|
|
|
if (!convert_keycode(from->keysym.sym, &to->inject_keycode.keycode, mod)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
to->inject_keycode.metastate = convert_meta_state(mod);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
convert_mouse_action(SDL_EventType from, enum android_motionevent_action *to) {
|
|
|
|
|
switch (from) {
|
|
|
|
|
MAP(SDL_MOUSEBUTTONDOWN, AMOTION_EVENT_ACTION_DOWN);
|
|
|
|
|
@ -177,41 +159,6 @@ convert_mouse_action(SDL_EventType from, enum android_motionevent_action *to) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
convert_mouse_button(const SDL_MouseButtonEvent *from, struct size screen_size,
|
|
|
|
|
struct control_msg *to) {
|
|
|
|
|
to->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
|
|
|
|
|
|
|
|
|
if (!convert_mouse_action(from->type, &to->inject_touch_event.action)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
to->inject_touch_event.pointer_id = POINTER_ID_MOUSE;
|
|
|
|
|
to->inject_touch_event.position.screen_size = screen_size;
|
|
|
|
|
to->inject_touch_event.position.point.x = from->x;
|
|
|
|
|
to->inject_touch_event.position.point.y = from->y;
|
|
|
|
|
to->inject_touch_event.pressure = 1.f;
|
|
|
|
|
to->inject_touch_event.buttons =
|
|
|
|
|
convert_mouse_buttons(SDL_BUTTON(from->button));
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
convert_mouse_motion(const SDL_MouseMotionEvent *from, struct size screen_size,
|
|
|
|
|
struct control_msg *to) {
|
|
|
|
|
to->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
|
|
|
|
to->inject_touch_event.action = AMOTION_EVENT_ACTION_MOVE;
|
|
|
|
|
to->inject_touch_event.pointer_id = POINTER_ID_MOUSE;
|
|
|
|
|
to->inject_touch_event.position.screen_size = screen_size;
|
|
|
|
|
to->inject_touch_event.position.point.x = from->x;
|
|
|
|
|
to->inject_touch_event.position.point.y = from->y;
|
|
|
|
|
to->inject_touch_event.pressure = 1.f;
|
|
|
|
|
to->inject_touch_event.buttons = convert_mouse_buttons(from->state);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
convert_touch_action(SDL_EventType from, enum android_motionevent_action *to) {
|
|
|
|
|
switch (from) {
|
|
|
|
|
MAP(SDL_FINGERMOTION, AMOTION_EVENT_ACTION_MOVE);
|
|
|
|
|
@ -220,39 +167,3 @@ convert_touch_action(SDL_EventType from, enum android_motionevent_action *to) {
|
|
|
|
|
FAIL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
convert_touch(const SDL_TouchFingerEvent *from, struct size screen_size,
|
|
|
|
|
struct control_msg *to) {
|
|
|
|
|
to->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
|
|
|
|
|
|
|
|
|
if (!convert_touch_action(from->type, &to->inject_touch_event.action)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
to->inject_touch_event.pointer_id = from->fingerId;
|
|
|
|
|
to->inject_touch_event.position.screen_size = screen_size;
|
|
|
|
|
// SDL touch event coordinates are normalized in the range [0; 1]
|
|
|
|
|
to->inject_touch_event.position.point.x = from->x * screen_size.width;
|
|
|
|
|
to->inject_touch_event.position.point.y = from->y * screen_size.height;
|
|
|
|
|
to->inject_touch_event.pressure = from->pressure;
|
|
|
|
|
to->inject_touch_event.buttons = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
convert_mouse_wheel(const SDL_MouseWheelEvent *from, struct position position,
|
|
|
|
|
struct control_msg *to) {
|
|
|
|
|
to->type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT;
|
|
|
|
|
|
|
|
|
|
to->inject_scroll_event.position = position;
|
|
|
|
|
|
|
|
|
|
int mul = from->direction == SDL_MOUSEWHEEL_NORMAL ? 1 : -1;
|
|
|
|
|
// SDL behavior seems inconsistent between horizontal and vertical scrolling
|
|
|
|
|
// so reverse the horizontal
|
|
|
|
|
// <https://wiki.libsdl.org/SDL_MouseWheelEvent#Remarks>
|
|
|
|
|
to->inject_scroll_event.hscroll = -mul * from->x;
|
|
|
|
|
to->inject_scroll_event.vscroll = mul * from->y;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|