提交 33696837 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!75 platform: fix modstate problem

Merge pull request !75 from Night/master
......@@ -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();
......
......@@ -125,6 +125,7 @@ class Platform : public std::enable_shared_from_this<Platform>,
void push_finger_motion(int x, int y, int finger_id, std::vector<input::Event> &touch_events);
int user_window_event = 0;
std::uint32_t key_mod_{ KMOD_NONE };
};
} // namespace sdl
} // namespace platform
......
......@@ -57,7 +57,7 @@ const std::map<std::string, Window::mini_size>Window::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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册