2018-08-15 23:01:54 +08:00
|
|
|
#include "input_manager.h"
|
2018-02-09 01:14:50 +08:00
|
|
|
|
2018-09-09 22:31:41 +08:00
|
|
|
#include <SDL2/SDL_assert.h>
|
2018-02-09 01:14:50 +08:00
|
|
|
#include "convert.h"
|
2018-08-15 23:01:54 +08:00
|
|
|
#include "lock_util.h"
|
2018-02-13 17:10:18 +08:00
|
|
|
#include "log.h"
|
2018-02-09 01:14:50 +08:00
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
// Convert window coordinates (as provided by SDL_GetMouseState() to renderer
|
|
|
|
// coordinates (as provided in SDL mouse events)
|
2018-03-05 21:54:12 +08:00
|
|
|
//
|
|
|
|
// See my question:
|
|
|
|
// <https://stackoverflow.com/questions/49111054/how-to-get-mouse-position-on-mouse-wheel-event>
|
2019-03-03 03:09:56 +08:00
|
|
|
static void
|
|
|
|
convert_to_renderer_coordinates(SDL_Renderer *renderer, int *x, int *y) {
|
2018-03-05 21:54:12 +08:00
|
|
|
SDL_Rect viewport;
|
|
|
|
float scale_x, scale_y;
|
|
|
|
SDL_RenderGetViewport(renderer, &viewport);
|
|
|
|
SDL_RenderGetScale(renderer, &scale_x, &scale_y);
|
|
|
|
*x = (int) (*x / scale_x) - viewport.x;
|
|
|
|
*y = (int) (*y / scale_y) - viewport.y;
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static struct point
|
|
|
|
get_mouse_point(struct screen *screen) {
|
2018-11-27 15:54:31 +08:00
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
SDL_GetMouseState(&x, &y);
|
|
|
|
convert_to_renderer_coordinates(screen->renderer, &x, &y);
|
|
|
|
return (struct point) {
|
|
|
|
.x = x,
|
|
|
|
.y = y,
|
|
|
|
};
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
|
2018-06-25 03:09:23 +08:00
|
|
|
static const int ACTION_DOWN = 1;
|
|
|
|
static const int ACTION_UP = 1 << 1;
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static void
|
|
|
|
send_keycode(struct controller *controller, enum android_keycode keycode,
|
|
|
|
int actions, const char *name) {
|
2018-02-09 01:14:50 +08:00
|
|
|
// send DOWN event
|
2019-05-31 20:55:11 +08:00
|
|
|
struct control_msg msg;
|
|
|
|
msg.type = CONTROL_MSG_TYPE_INJECT_KEYCODE;
|
|
|
|
msg.inject_keycode.keycode = keycode;
|
|
|
|
msg.inject_keycode.metastate = 0;
|
2018-02-09 01:14:50 +08:00
|
|
|
|
2018-06-25 03:09:23 +08:00
|
|
|
if (actions & ACTION_DOWN) {
|
2019-05-31 20:55:11 +08:00
|
|
|
msg.inject_keycode.action = AKEY_EVENT_ACTION_DOWN;
|
|
|
|
if (!controller_push_msg(controller, &msg)) {
|
|
|
|
LOGW("Cannot request 'inject %s (DOWN)'", name);
|
2018-06-25 03:09:23 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
|
2018-06-25 03:09:23 +08:00
|
|
|
if (actions & ACTION_UP) {
|
2019-05-31 20:55:11 +08:00
|
|
|
msg.inject_keycode.action = AKEY_EVENT_ACTION_UP;
|
|
|
|
if (!controller_push_msg(controller, &msg)) {
|
|
|
|
LOGW("Cannot request 'inject %s (UP)'", name);
|
2018-06-25 03:09:23 +08:00
|
|
|
}
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static inline void
|
|
|
|
action_home(struct controller *controller, int actions) {
|
2018-06-25 03:09:23 +08:00
|
|
|
send_keycode(controller, AKEYCODE_HOME, actions, "HOME");
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static inline void
|
|
|
|
action_back(struct controller *controller, int actions) {
|
2018-06-25 03:09:23 +08:00
|
|
|
send_keycode(controller, AKEYCODE_BACK, actions, "BACK");
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static inline void
|
|
|
|
action_app_switch(struct controller *controller, int actions) {
|
2018-06-25 03:09:23 +08:00
|
|
|
send_keycode(controller, AKEYCODE_APP_SWITCH, actions, "APP_SWITCH");
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static inline void
|
|
|
|
action_power(struct controller *controller, int actions) {
|
2018-06-25 03:09:23 +08:00
|
|
|
send_keycode(controller, AKEYCODE_POWER, actions, "POWER");
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static inline void
|
|
|
|
action_volume_up(struct controller *controller, int actions) {
|
2018-06-25 03:09:23 +08:00
|
|
|
send_keycode(controller, AKEYCODE_VOLUME_UP, actions, "VOLUME_UP");
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static inline void
|
|
|
|
action_volume_down(struct controller *controller, int actions) {
|
2018-06-25 03:09:23 +08:00
|
|
|
send_keycode(controller, AKEYCODE_VOLUME_DOWN, actions, "VOLUME_DOWN");
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static inline void
|
|
|
|
action_menu(struct controller *controller, int actions) {
|
2018-06-25 03:09:23 +08:00
|
|
|
send_keycode(controller, AKEYCODE_MENU, actions, "MENU");
|
2018-03-21 09:04:40 +08:00
|
|
|
}
|
|
|
|
|
2018-03-10 07:11:52 +08:00
|
|
|
// turn the screen on if it was off, press BACK otherwise
|
2019-03-03 03:09:56 +08:00
|
|
|
static void
|
|
|
|
press_back_or_turn_screen_on(struct controller *controller) {
|
2019-05-31 20:55:11 +08:00
|
|
|
struct control_msg msg;
|
|
|
|
msg.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON;
|
2018-03-07 21:46:31 +08:00
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
if (!controller_push_msg(controller, &msg)) {
|
|
|
|
LOGW("Cannot request 'turn screen on'");
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static void
|
|
|
|
expand_notification_panel(struct controller *controller) {
|
2019-05-31 20:55:11 +08:00
|
|
|
struct control_msg msg;
|
|
|
|
msg.type = CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL;
|
2019-02-27 03:35:37 +08:00
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
if (!controller_push_msg(controller, &msg)) {
|
|
|
|
LOGW("Cannot request 'expand notification panel'");
|
2019-02-27 03:35:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static void
|
|
|
|
collapse_notification_panel(struct controller *controller) {
|
2019-05-31 20:55:11 +08:00
|
|
|
struct control_msg msg;
|
|
|
|
msg.type = CONTROL_MSG_TYPE_COLLAPSE_NOTIFICATION_PANEL;
|
2019-02-27 03:35:37 +08:00
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
if (!controller_push_msg(controller, &msg)) {
|
|
|
|
LOGW("Cannot request 'collapse notification panel'");
|
2019-02-27 03:35:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 21:23:01 +08:00
|
|
|
static void
|
|
|
|
request_device_clipboard(struct controller *controller) {
|
2019-05-31 20:55:11 +08:00
|
|
|
struct control_msg msg;
|
|
|
|
msg.type = CONTROL_MSG_TYPE_GET_CLIPBOARD;
|
2019-05-30 21:23:01 +08:00
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
if (!controller_push_msg(controller, &msg)) {
|
|
|
|
LOGW("Cannot request device clipboard");
|
2019-05-30 21:23:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 02:25:23 +08:00
|
|
|
static void
|
|
|
|
set_device_clipboard(struct controller *controller) {
|
|
|
|
char *text = SDL_GetClipboardText();
|
|
|
|
if (!text) {
|
|
|
|
LOGW("Cannot get clipboard text: %s", SDL_GetError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!*text) {
|
|
|
|
// empty text
|
|
|
|
SDL_free(text);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
struct control_msg msg;
|
|
|
|
msg.type = CONTROL_MSG_TYPE_SET_CLIPBOARD;
|
|
|
|
msg.set_clipboard.text = text;
|
2019-05-31 02:25:23 +08:00
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
if (!controller_push_msg(controller, &msg)) {
|
2019-05-31 02:25:23 +08:00
|
|
|
SDL_free(text);
|
2019-05-31 20:55:11 +08:00
|
|
|
LOGW("Cannot request 'set device clipboard'");
|
2019-05-31 02:25:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-16 03:23:30 +08:00
|
|
|
static void
|
|
|
|
set_screen_power_mode(struct controller *controller,
|
|
|
|
enum screen_power_mode mode) {
|
|
|
|
struct control_msg msg;
|
|
|
|
msg.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
|
|
|
|
msg.set_screen_power_mode.mode = mode;
|
|
|
|
|
|
|
|
if (!controller_push_msg(controller, &msg)) {
|
|
|
|
LOGW("Cannot request 'set screen power mode'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static void
|
2019-06-07 22:55:19 +08:00
|
|
|
switch_fps_counter_state(struct fps_counter *fps_counter) {
|
|
|
|
// the started state can only be written from the current thread, so there
|
|
|
|
// is no ToCToU issue
|
|
|
|
if (fps_counter_is_started(fps_counter)) {
|
|
|
|
fps_counter_stop(fps_counter);
|
2018-02-15 19:24:16 +08:00
|
|
|
LOGI("FPS counter stopped");
|
|
|
|
} else {
|
2019-06-07 22:55:19 +08:00
|
|
|
if (fps_counter_start(fps_counter)) {
|
|
|
|
LOGI("FPS counter started");
|
|
|
|
} else {
|
|
|
|
LOGE("FPS counter starting failed");
|
|
|
|
}
|
2018-02-15 19:24:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static void
|
|
|
|
clipboard_paste(struct controller *controller) {
|
2018-03-07 22:29:33 +08:00
|
|
|
char *text = SDL_GetClipboardText();
|
|
|
|
if (!text) {
|
|
|
|
LOGW("Cannot get clipboard text: %s", SDL_GetError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!*text) {
|
|
|
|
// empty text
|
|
|
|
SDL_free(text);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
struct control_msg msg;
|
|
|
|
msg.type = CONTROL_MSG_TYPE_INJECT_TEXT;
|
|
|
|
msg.inject_text.text = text;
|
|
|
|
if (!controller_push_msg(controller, &msg)) {
|
2018-03-07 22:29:33 +08:00
|
|
|
SDL_free(text);
|
2019-05-31 20:55:11 +08:00
|
|
|
LOGW("Cannot request 'paste clipboard'");
|
2018-03-07 22:29:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
input_manager_process_text_input(struct input_manager *input_manager,
|
|
|
|
const SDL_TextInputEvent *event) {
|
2018-09-09 22:31:41 +08:00
|
|
|
char c = event->text[0];
|
|
|
|
if (isalpha(c) || c == ' ') {
|
|
|
|
SDL_assert(event->text[1] == '\0');
|
|
|
|
// letters and space are handled as raw key event
|
|
|
|
return;
|
|
|
|
}
|
2019-05-31 20:55:11 +08:00
|
|
|
struct control_msg msg;
|
|
|
|
msg.type = CONTROL_MSG_TYPE_INJECT_TEXT;
|
|
|
|
msg.inject_text.text = SDL_strdup(event->text);
|
|
|
|
if (!msg.inject_text.text) {
|
2018-03-07 22:29:33 +08:00
|
|
|
LOGW("Cannot strdup input text");
|
|
|
|
return;
|
|
|
|
}
|
2019-05-31 20:55:11 +08:00
|
|
|
if (!controller_push_msg(input_manager->controller, &msg)) {
|
|
|
|
SDL_free(msg.inject_text.text);
|
|
|
|
LOGW("Cannot request 'inject text'");
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
input_manager_process_key(struct input_manager *input_manager,
|
2019-03-03 18:05:26 +08:00
|
|
|
const SDL_KeyboardEvent *event,
|
|
|
|
bool control) {
|
2019-06-01 05:25:41 +08:00
|
|
|
// control: indicates the state of the command-line option --no-control
|
|
|
|
// ctrl: the Ctrl key
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool ctrl = event->keysym.mod & (KMOD_LCTRL | KMOD_RCTRL);
|
|
|
|
bool alt = event->keysym.mod & (KMOD_LALT | KMOD_RALT);
|
|
|
|
bool meta = event->keysym.mod & (KMOD_LGUI | KMOD_RGUI);
|
2018-10-25 00:51:02 +08:00
|
|
|
|
2018-10-25 01:03:07 +08:00
|
|
|
if (alt) {
|
2018-10-25 00:51:02 +08:00
|
|
|
// no shortcut involves Alt or Meta, and they should not be forwarded
|
|
|
|
// to the device
|
|
|
|
return;
|
|
|
|
}
|
2018-02-09 01:14:50 +08:00
|
|
|
|
2019-06-01 05:25:41 +08:00
|
|
|
struct controller *controller = input_manager->controller;
|
|
|
|
|
2018-02-09 01:14:50 +08:00
|
|
|
// capture all Ctrl events
|
2018-10-25 01:03:07 +08:00
|
|
|
if (ctrl | meta) {
|
2018-03-06 18:11:07 +08:00
|
|
|
SDL_Keycode keycode = event->keysym.sym;
|
2019-06-01 05:25:41 +08:00
|
|
|
bool down = event->type == SDL_KEYDOWN;
|
|
|
|
int action = down ? ACTION_DOWN : ACTION_UP;
|
2019-03-03 06:52:22 +08:00
|
|
|
bool repeat = event->repeat;
|
|
|
|
bool shift = event->keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT);
|
2018-02-09 01:14:50 +08:00
|
|
|
switch (keycode) {
|
|
|
|
case SDLK_h:
|
2019-03-03 05:40:51 +08:00
|
|
|
if (control && ctrl && !meta && !shift && !repeat) {
|
2019-06-01 05:25:41 +08:00
|
|
|
action_home(controller, action);
|
2018-06-25 03:48:34 +08:00
|
|
|
}
|
2018-02-09 01:14:50 +08:00
|
|
|
return;
|
|
|
|
case SDLK_b: // fall-through
|
|
|
|
case SDLK_BACKSPACE:
|
2019-03-03 05:40:51 +08:00
|
|
|
if (control && ctrl && !meta && !shift && !repeat) {
|
2019-06-01 05:25:41 +08:00
|
|
|
action_back(controller, action);
|
2018-06-25 03:48:34 +08:00
|
|
|
}
|
2018-02-09 01:14:50 +08:00
|
|
|
return;
|
2018-03-23 17:10:24 +08:00
|
|
|
case SDLK_s:
|
2019-03-03 05:40:51 +08:00
|
|
|
if (control && ctrl && !meta && !shift && !repeat) {
|
2019-06-01 05:25:41 +08:00
|
|
|
action_app_switch(controller, action);
|
2018-06-25 03:48:34 +08:00
|
|
|
}
|
2018-02-09 01:14:50 +08:00
|
|
|
return;
|
2018-03-23 17:10:24 +08:00
|
|
|
case SDLK_m:
|
2019-03-03 05:40:51 +08:00
|
|
|
if (control && ctrl && !meta && !shift && !repeat) {
|
2019-06-01 05:25:41 +08:00
|
|
|
action_menu(controller, action);
|
2018-06-25 03:48:34 +08:00
|
|
|
}
|
2018-03-21 09:04:40 +08:00
|
|
|
return;
|
2018-02-09 01:14:50 +08:00
|
|
|
case SDLK_p:
|
2019-03-03 05:40:51 +08:00
|
|
|
if (control && ctrl && !meta && !shift && !repeat) {
|
2019-06-01 05:25:41 +08:00
|
|
|
action_power(controller, action);
|
2018-06-25 03:48:34 +08:00
|
|
|
}
|
2018-02-09 01:14:50 +08:00
|
|
|
return;
|
2019-03-16 03:23:30 +08:00
|
|
|
case SDLK_o:
|
2019-06-03 17:44:39 +08:00
|
|
|
if (control && ctrl && !shift && !meta && down) {
|
|
|
|
set_screen_power_mode(controller, SCREEN_POWER_MODE_OFF);
|
2019-03-16 03:23:30 +08:00
|
|
|
}
|
|
|
|
return;
|
2018-04-03 20:20:33 +08:00
|
|
|
case SDLK_DOWN:
|
2018-10-25 01:05:34 +08:00
|
|
|
#ifdef __APPLE__
|
2019-03-03 05:40:51 +08:00
|
|
|
if (control && !ctrl && meta && !shift) {
|
2018-10-25 01:05:34 +08:00
|
|
|
#else
|
2019-03-03 05:40:51 +08:00
|
|
|
if (control && ctrl && !meta && !shift) {
|
2018-10-25 01:05:34 +08:00
|
|
|
#endif
|
2018-10-25 01:03:07 +08:00
|
|
|
// forward repeated events
|
2019-06-01 05:25:41 +08:00
|
|
|
action_volume_down(controller, action);
|
2018-10-25 01:03:07 +08:00
|
|
|
}
|
2018-04-03 20:20:33 +08:00
|
|
|
return;
|
|
|
|
case SDLK_UP:
|
2018-10-25 01:05:34 +08:00
|
|
|
#ifdef __APPLE__
|
2019-03-03 05:40:51 +08:00
|
|
|
if (control && !ctrl && meta && !shift) {
|
2018-10-25 01:05:34 +08:00
|
|
|
#else
|
2019-03-03 05:40:51 +08:00
|
|
|
if (control && ctrl && !meta && !shift) {
|
2018-10-25 01:05:34 +08:00
|
|
|
#endif
|
2018-10-25 01:03:07 +08:00
|
|
|
// forward repeated events
|
2019-06-01 05:25:41 +08:00
|
|
|
action_volume_up(controller, action);
|
2018-10-25 01:03:07 +08:00
|
|
|
}
|
2018-04-03 20:20:33 +08:00
|
|
|
return;
|
2019-05-30 21:23:01 +08:00
|
|
|
case SDLK_c:
|
2019-06-01 05:25:41 +08:00
|
|
|
if (control && ctrl && !meta && !shift && !repeat && down) {
|
|
|
|
request_device_clipboard(controller);
|
2019-05-30 21:23:01 +08:00
|
|
|
}
|
|
|
|
return;
|
2018-03-07 22:29:33 +08:00
|
|
|
case SDLK_v:
|
2019-06-01 05:25:41 +08:00
|
|
|
if (control && ctrl && !meta && !repeat && down) {
|
2019-05-31 02:25:23 +08:00
|
|
|
if (shift) {
|
|
|
|
// store the text in the device clipboard
|
2019-06-01 05:25:41 +08:00
|
|
|
set_device_clipboard(controller);
|
2019-05-31 02:25:23 +08:00
|
|
|
} else {
|
|
|
|
// inject the text as input events
|
2019-06-01 05:25:41 +08:00
|
|
|
clipboard_paste(controller);
|
2019-05-31 02:25:23 +08:00
|
|
|
}
|
2018-06-25 03:09:23 +08:00
|
|
|
}
|
2018-03-07 22:29:33 +08:00
|
|
|
return;
|
2018-02-09 01:14:50 +08:00
|
|
|
case SDLK_f:
|
2019-06-01 05:25:41 +08:00
|
|
|
if (ctrl && !meta && !shift && !repeat && down) {
|
2018-06-25 03:09:23 +08:00
|
|
|
screen_switch_fullscreen(input_manager->screen);
|
|
|
|
}
|
2018-02-09 01:14:50 +08:00
|
|
|
return;
|
|
|
|
case SDLK_x:
|
2019-06-01 05:25:41 +08:00
|
|
|
if (ctrl && !meta && !shift && !repeat && down) {
|
2018-06-25 03:09:23 +08:00
|
|
|
screen_resize_to_fit(input_manager->screen);
|
|
|
|
}
|
2018-02-09 01:14:50 +08:00
|
|
|
return;
|
|
|
|
case SDLK_g:
|
2019-06-01 05:25:41 +08:00
|
|
|
if (ctrl && !meta && !shift && !repeat && down) {
|
2018-06-25 03:09:23 +08:00
|
|
|
screen_resize_to_pixel_perfect(input_manager->screen);
|
|
|
|
}
|
2018-02-09 01:14:50 +08:00
|
|
|
return;
|
2018-02-15 19:24:16 +08:00
|
|
|
case SDLK_i:
|
2019-06-01 05:25:41 +08:00
|
|
|
if (ctrl && !meta && !shift && !repeat && down) {
|
2019-06-07 22:55:19 +08:00
|
|
|
struct fps_counter *fps_counter =
|
|
|
|
input_manager->video_buffer->fps_counter;
|
|
|
|
switch_fps_counter_state(fps_counter);
|
2018-06-25 03:09:23 +08:00
|
|
|
}
|
2019-02-27 03:35:37 +08:00
|
|
|
return;
|
|
|
|
case SDLK_n:
|
2019-06-01 05:25:41 +08:00
|
|
|
if (control && ctrl && !meta && !repeat && down) {
|
2019-02-27 03:35:37 +08:00
|
|
|
if (shift) {
|
2019-06-01 05:25:41 +08:00
|
|
|
collapse_notification_panel(controller);
|
2019-02-27 03:35:37 +08:00
|
|
|
} else {
|
2019-06-01 05:25:41 +08:00
|
|
|
expand_notification_panel(controller);
|
2019-02-27 03:35:37 +08:00
|
|
|
}
|
|
|
|
}
|
2018-02-15 19:24:16 +08:00
|
|
|
return;
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-03 05:40:51 +08:00
|
|
|
if (!control) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
struct control_msg msg;
|
|
|
|
if (input_key_from_sdl_to_android(event, &msg)) {
|
2019-06-01 05:25:41 +08:00
|
|
|
if (!controller_push_msg(controller, &msg)) {
|
2019-05-31 20:55:11 +08:00
|
|
|
LOGW("Cannot request 'inject keycode'");
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
input_manager_process_mouse_motion(struct input_manager *input_manager,
|
|
|
|
const SDL_MouseMotionEvent *event) {
|
2018-02-09 01:14:50 +08:00
|
|
|
if (!event->state) {
|
|
|
|
// do not send motion events when no button is pressed
|
|
|
|
return;
|
|
|
|
}
|
2019-05-31 20:55:11 +08:00
|
|
|
struct control_msg msg;
|
2019-03-03 03:09:56 +08:00
|
|
|
if (mouse_motion_from_sdl_to_android(event,
|
|
|
|
input_manager->screen->frame_size,
|
2019-05-31 20:55:11 +08:00
|
|
|
&msg)) {
|
|
|
|
if (!controller_push_msg(input_manager->controller, &msg)) {
|
|
|
|
LOGW("Cannot request 'inject mouse motion event'");
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
static bool
|
2019-03-03 03:09:56 +08:00
|
|
|
is_outside_device_screen(struct input_manager *input_manager, int x, int y)
|
2018-11-19 04:20:21 +08:00
|
|
|
{
|
|
|
|
return x < 0 || x >= input_manager->screen->frame_size.width ||
|
|
|
|
y < 0 || y >= input_manager->screen->frame_size.height;
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
input_manager_process_mouse_button(struct input_manager *input_manager,
|
2019-03-03 18:05:26 +08:00
|
|
|
const SDL_MouseButtonEvent *event,
|
|
|
|
bool control) {
|
2018-03-10 07:40:55 +08:00
|
|
|
if (event->type == SDL_MOUSEBUTTONDOWN) {
|
2019-03-03 05:40:51 +08:00
|
|
|
if (control && event->button == SDL_BUTTON_RIGHT) {
|
2018-03-10 07:40:55 +08:00
|
|
|
press_back_or_turn_screen_on(input_manager->controller);
|
|
|
|
return;
|
|
|
|
}
|
2019-03-03 05:40:51 +08:00
|
|
|
if (control && event->button == SDL_BUTTON_MIDDLE) {
|
2018-06-25 03:09:23 +08:00
|
|
|
action_home(input_manager->controller, ACTION_DOWN | ACTION_UP);
|
2018-03-10 07:40:55 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-03-13 15:32:48 +08:00
|
|
|
// double-click on black borders resize to fit the device screen
|
2018-11-27 15:54:31 +08:00
|
|
|
if (event->button == SDL_BUTTON_LEFT && event->clicks == 2) {
|
2019-05-31 20:55:11 +08:00
|
|
|
bool outside =
|
|
|
|
is_outside_device_screen(input_manager, event->x, event->y);
|
2018-11-27 15:54:31 +08:00
|
|
|
if (outside) {
|
|
|
|
screen_resize_to_fit(input_manager->screen);
|
2019-01-18 20:21:25 +08:00
|
|
|
return;
|
2018-11-27 15:54:31 +08:00
|
|
|
}
|
2018-03-13 15:32:48 +08:00
|
|
|
}
|
2018-11-19 04:20:21 +08:00
|
|
|
// otherwise, send the click event to the device
|
2018-08-11 21:06:38 +08:00
|
|
|
}
|
2018-11-19 04:20:21 +08:00
|
|
|
|
2019-03-03 05:40:51 +08:00
|
|
|
if (!control) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
struct control_msg msg;
|
2019-03-03 03:09:56 +08:00
|
|
|
if (mouse_button_from_sdl_to_android(event,
|
|
|
|
input_manager->screen->frame_size,
|
2019-05-31 20:55:11 +08:00
|
|
|
&msg)) {
|
|
|
|
if (!controller_push_msg(input_manager->controller, &msg)) {
|
|
|
|
LOGW("Cannot request 'inject mouse button event'");
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
input_manager_process_mouse_wheel(struct input_manager *input_manager,
|
|
|
|
const SDL_MouseWheelEvent *event) {
|
2018-02-09 01:14:50 +08:00
|
|
|
struct position position = {
|
2018-02-15 19:07:47 +08:00
|
|
|
.screen_size = input_manager->screen->frame_size,
|
2018-11-27 15:54:31 +08:00
|
|
|
.point = get_mouse_point(input_manager->screen),
|
2018-02-09 01:14:50 +08:00
|
|
|
};
|
2019-05-31 20:55:11 +08:00
|
|
|
struct control_msg msg;
|
|
|
|
if (mouse_wheel_from_sdl_to_android(event, position, &msg)) {
|
|
|
|
if (!controller_push_msg(input_manager->controller, &msg)) {
|
|
|
|
LOGW("Cannot request 'inject mouse wheel event'");
|
2018-02-09 01:14:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|