diff --git a/src/anbox/platform/sdl/platform.cpp b/src/anbox/platform/sdl/platform.cpp index 05128a171ea0d35c4dad3a0c742f9655e8cced5f..9594935035566c27de80f0bbcdd550b9fe2b3e2c 100644 --- a/src/anbox/platform/sdl/platform.cpp +++ b/src/anbox/platform/sdl/platform.cpp @@ -391,6 +391,12 @@ void Platform::process_input_event(const SDL_Event &event) { input_key_event(SDL_SCANCODE_AC_BACK, 0); break; } + if (code == KEY_CAPSLOCK) { + key_mod_ ^= KMOD_CAPS; + } + if (code == KEY_NUMLOCK) { + key_mod_ ^= KMOD_NUM; + } keyboard_events.push_back({EV_KEY, code, 0}); break; } @@ -574,7 +580,23 @@ void Platform::window_deleted(const Window::Id &id) { void Platform::window_wants_focus(const Window::Id &id) { auto w = windows_.find(id); - if (w == windows_.end()) return; + if (w == windows_.end()) { + return; + } + + // if window's modstate is not the same as android, send + // capslock or numlock message to android to change it. + auto mod_state = SDL_GetModState(); + if ((key_mod_ & KMOD_NUM) != (mod_state & KMOD_NUM)) { + input_key_event(SDL_SCANCODE_NUMLOCKCLEAR, 1); + input_key_event(SDL_SCANCODE_NUMLOCKCLEAR, 0); + key_mod_ ^= KMOD_NUM; + } + if ((key_mod_ & KMOD_CAPS) != (mod_state & KMOD_CAPS)) { + input_key_event(SDL_SCANCODE_CAPSLOCK, 1); + input_key_event(SDL_SCANCODE_CAPSLOCK, 0); + key_mod_ ^= KMOD_CAPS; + } if (auto window = w->second.lock()) { focused_sdl_window_id_ = window->window_id(); diff --git a/src/anbox/platform/sdl/platform.h b/src/anbox/platform/sdl/platform.h index 6294d59021df2c1c0cea4f17887aa6adeff79eed..9b8af4cd7e1f709b86993da74b891598e5992f67 100644 --- a/src/anbox/platform/sdl/platform.h +++ b/src/anbox/platform/sdl/platform.h @@ -125,6 +125,7 @@ class Platform : public std::enable_shared_from_this, void push_finger_motion(int x, int y, int finger_id, std::vector &touch_events); int user_window_event = 0; + std::uint32_t key_mod_{ KMOD_NONE }; }; } // namespace sdl } // namespace platform diff --git a/src/anbox/platform/sdl/window.cpp b/src/anbox/platform/sdl/window.cpp index e945faa36659dd34092778e3fdd20d1912819be1..0ade5a63b491a2dc5fc172c5939cd078e281d4fa 100755 --- a/src/anbox/platform/sdl/window.cpp +++ b/src/anbox/platform/sdl/window.cpp @@ -57,7 +57,7 @@ const std::mapWindow::custom_window_map = { {"微信", {WX_MINI_WIDTH, MINI_HEIGHT}} }; -Window::Id Window::Invalid{-1}; +Window::Id Window::Invalid{ -1 }; Window::Observer::~Observer() {} @@ -294,7 +294,9 @@ void Window::switch_window_state() { void Window::process_event(const SDL_Event &event) { switch (event.window.event) { case SDL_WINDOWEVENT_FOCUS_GAINED: - if (observer_) observer_->window_wants_focus(id_); + if (observer_) { + observer_->window_wants_focus(id_); + } break; case SDL_WINDOWEVENT_FOCUS_LOST: break;