Display and control your Android device
Move input event helpers
Romain Vimont36aaf702791b
diff --git a/app/src/input_events.h b/app/src/input_events.hindex 4a4cf356..9bf3c421 100644--- a/app/src/input_events.h+++ b/app/src/input_events.h@@ -377,4 +377,76 @@ struct sc_touch_event {float pressure;};+static inline uint16_t+sc_mods_state_from_sdl(uint16_t mods_state) {+ return mods_state;+}++static inline enum sc_keycode+sc_keycode_from_sdl(SDL_Keycode keycode) {+ return (enum sc_keycode) keycode;+}++static inline enum sc_scancode+sc_scancode_from_sdl(SDL_Scancode scancode) {+ return (enum sc_scancode) scancode;+}++static inline enum sc_action+sc_action_from_sdl_keyboard_type(uint32_t type) {+ assert(type == SDL_KEYDOWN || type == SDL_KEYUP);+ if (type == SDL_KEYDOWN) {+ return SC_ACTION_DOWN;+ }+ return SC_ACTION_UP;+}++static inline enum sc_action+sc_action_from_sdl_mousebutton_type(uint32_t type) {+ assert(type == SDL_MOUSEBUTTONDOWN || type == SDL_MOUSEBUTTONUP);+ if (type == SDL_MOUSEBUTTONDOWN) {+ return SC_ACTION_DOWN;+ }+ return SC_ACTION_UP;+}++static inline enum sc_touch_action+sc_touch_action_from_sdl(uint32_t type) {+ assert(type == SDL_FINGERMOTION || type == SDL_FINGERDOWN ||+ type == SDL_FINGERUP);+ if (type == SDL_FINGERMOTION) {+ return SC_TOUCH_ACTION_MOVE;+ }+ if (type == SDL_FINGERDOWN) {+ return SC_TOUCH_ACTION_DOWN;+ }+ return SC_TOUCH_ACTION_UP;+}++static inline enum sc_mouse_button+sc_mouse_button_from_sdl(uint8_t button) {+ if (button >= SDL_BUTTON_LEFT && button <= SDL_BUTTON_X2) {+ // SC_MOUSE_BUTTON_* constants are initialized from SDL_BUTTON(index)+ return SDL_BUTTON(button);+ }++ return SC_MOUSE_BUTTON_UNKNOWN;+}++static inline uint8_t+sc_mouse_buttons_state_from_sdl(uint32_t buttons_state,+ bool forward_all_clicks) {+ assert(buttons_state < 0x100); // fits in uint8_t++ uint8_t mask = SC_MOUSE_BUTTON_LEFT;+ if (forward_all_clicks) {+ mask |= SC_MOUSE_BUTTON_RIGHT+ | SC_MOUSE_BUTTON_MIDDLE+ | SC_MOUSE_BUTTON_X1+ | SC_MOUSE_BUTTON_X2;+ }++ return buttons_state & mask;+}+#endifdiff --git a/app/src/input_manager.c b/app/src/input_manager.cindex d623c5ae..63842d35 100644--- a/app/src/input_manager.c+++ b/app/src/input_manager.c@@ -7,78 +7,6 @@#include "screen.h"#include "util/log.h"-static inline uint16_t-sc_mods_state_from_sdl(uint16_t mods_state) {- return mods_state;-}--static inline enum sc_keycode-sc_keycode_from_sdl(SDL_Keycode keycode) {- return (enum sc_keycode) keycode;-}--static inline enum sc_scancode-sc_scancode_from_sdl(SDL_Scancode scancode) {- return (enum sc_scancode) scancode;-}--static inline enum sc_action-sc_action_from_sdl_keyboard_type(uint32_t type) {- assert(type == SDL_KEYDOWN || type == SDL_KEYUP);- if (type == SDL_KEYDOWN) {- return SC_ACTION_DOWN;- }- return SC_ACTION_UP;-}--static inline enum sc_action-sc_action_from_sdl_mousebutton_type(uint32_t type) {- assert(type == SDL_MOUSEBUTTONDOWN || type == SDL_MOUSEBUTTONUP);- if (type == SDL_MOUSEBUTTONDOWN) {- return SC_ACTION_DOWN;- }- return SC_ACTION_UP;-}--static inline enum sc_touch_action-sc_touch_action_from_sdl(uint32_t type) {- assert(type == SDL_FINGERMOTION || type == SDL_FINGERDOWN ||- type == SDL_FINGERUP);- if (type == SDL_FINGERMOTION) {- return SC_TOUCH_ACTION_MOVE;- }- if (type == SDL_FINGERDOWN) {- return SC_TOUCH_ACTION_DOWN;- }- return SC_TOUCH_ACTION_UP;-}--static inline enum sc_mouse_button-sc_mouse_button_from_sdl(uint8_t button) {- if (button >= SDL_BUTTON_LEFT && button <= SDL_BUTTON_X2) {- // SC_MOUSE_BUTTON_* constants are initialized from SDL_BUTTON(index)- return SDL_BUTTON(button);- }-- return SC_MOUSE_BUTTON_UNKNOWN;-}--static inline uint8_t-sc_mouse_buttons_state_from_sdl(uint32_t buttons_state,- bool forward_all_clicks) {- assert(buttons_state < 0x100); // fits in uint8_t-- uint8_t mask = SC_MOUSE_BUTTON_LEFT;- if (forward_all_clicks) {- mask |= SC_MOUSE_BUTTON_RIGHT- | SC_MOUSE_BUTTON_MIDDLE- | SC_MOUSE_BUTTON_X1- | SC_MOUSE_BUTTON_X2;- }-- return buttons_state & mask;-}-#define SC_SDL_SHORTCUT_MODS_MASK (KMOD_CTRL | KMOD_ALT | KMOD_GUI)static inline uint16_t