Commit 1bf4f023 authored by Florian Oetke's avatar Florian Oetke
Browse files

fixed hanging keys caused by ui-filtered events

parent 9b89d53e
Pipeline #2812 passed with stage
in 15 minutes and 48 seconds
......@@ -18,6 +18,7 @@
#include <glm/vec2.hpp>
#include <memory>
#include <unordered_map>
#include <unordered_set>
namespace mirrage::asset {
......@@ -51,7 +52,7 @@ namespace mirrage::input {
void enable_context(Context_id id);
void on_key_pressed(Key);
void on_key_released(Key);
void on_key_released(Key, bool filtered);
void on_mouse_pos_change(glm::vec2 rel, glm::vec2 abs);
......@@ -62,7 +63,7 @@ namespace mirrage::input {
void on_pad_button_released(Input_source src, Pad_button);
void on_mouse_button_pressed(Mouse_button, float pressure = 1.f);
void on_mouse_button_released(Mouse_button, int8_t clicks);
void on_mouse_button_released(Mouse_button, int8_t clicks, bool filtered);
void on_pad_stick_change(Input_source src, Pad_stick, glm::vec2 rel, glm::vec2 abs);
......@@ -74,6 +75,9 @@ namespace mirrage::input {
Context_id _active_context_id;
Context* _active_context;
std::unordered_set<Key> _cont_pressed_keys;
std::unordered_set<Mouse_button> _cont_pressed_mouse;
bool _primary_mouse_button_down = false;
bool _is_mouse_drag = false;
};
......
......@@ -212,8 +212,9 @@ namespace mirrage::input {
void Input_manager::_handle_event(SDL_Event& event, bool filtered)
{
if(filtered)
return; // TODO: don't filter key/button-up events if the down event has already been send
if(filtered && event.type != SDL_KEYUP && event.type != SDL_MOUSEBUTTONUP) {
return;
}
switch(event.type) {
case SDL_TEXTINPUT: _mailbox.send<Char_input>(event.text.text); break;
......@@ -224,8 +225,9 @@ namespace mirrage::input {
break;
case SDL_KEYUP:
if(event.key.repeat == 0)
_mapper->on_key_released(from_sdl_keycode(event.key.keysym.sym));
if(event.key.repeat == 0) {
_mapper->on_key_released(from_sdl_keycode(event.key.keysym.sym), filtered);
}
break;
case SDL_MOUSEMOTION: _on_mouse_motion(event.motion); break;
......@@ -236,8 +238,8 @@ namespace mirrage::input {
break;
case SDL_MOUSEBUTTONUP:
_mapper->on_mouse_button_released(event.button.button,
static_cast<int8_t>(event.button.clicks));
_mapper->on_mouse_button_released(
event.button.button, static_cast<int8_t>(event.button.clicks), filtered);
_pointer_active[0] = false;
break;
......@@ -282,7 +284,7 @@ namespace mirrage::input {
if(event.tfinger.type == SDL_FINGERDOWN)
_mapper->on_mouse_button_pressed(1, event.tfinger.pressure);
else if(event.tfinger.type == SDL_FINGERUP)
_mapper->on_mouse_button_released(1, 1);
_mapper->on_mouse_button_released(1, 1, filtered);
}
}
break;
......
......@@ -153,12 +153,21 @@ namespace mirrage::input {
void Input_mapper::on_key_pressed(Key k)
{
_cont_pressed_keys.emplace(k);
find_maybe(_active_context->keys, k).process([&](auto& action) { process_pressed(_bus, action); });
}
void Input_mapper::on_key_released(Key k)
void Input_mapper::on_key_released(Key k, bool filtered)
{
find_maybe(_active_context->keys, k).process([&](auto& action) { process_release(_bus, action); });
auto pressed = _cont_pressed_keys.count(k);
_cont_pressed_keys.erase(k);
find_maybe(_active_context->keys, k).process([&](auto& action) {
if(!filtered || action.type == Reaction_type::continuous) {
if(pressed || action.type != Reaction_type::continuous)
process_release(_bus, action);
}
});
}
void Input_mapper::on_mouse_pos_change(glm::vec2 rel, glm::vec2 abs)
......@@ -213,6 +222,8 @@ namespace mirrage::input {
void Input_mapper::on_mouse_button_pressed(Mouse_button b, float pressure)
{
_cont_pressed_mouse.emplace(b);
find_maybe(_active_context->mouse_buttons, {b, 0}).process([&](auto& action) {
process_pressed(_bus, action, Input_source{0}, pressure);
});
......@@ -221,9 +232,9 @@ namespace mirrage::input {
_primary_mouse_button_down = true;
}
void Input_mapper::on_mouse_button_released(Mouse_button b, int8_t clicks)
void Input_mapper::on_mouse_button_released(Mouse_button b, int8_t clicks, bool filtered)
{
if(b != 1 || !_is_mouse_drag) {
if((b != 1 || !_is_mouse_drag) && !filtered) {
find_maybe(_active_context->mouse_buttons, {b, clicks}).process([&](auto& action) {
process_release(_bus, action);
});
......@@ -236,6 +247,7 @@ namespace mirrage::input {
// call end listerners for continue_click_handlers (clicks==0)
find_maybe(_active_context->mouse_buttons, {b, 0}).process([&](auto& action) {
if(!filtered || (action.type == Reaction_type::continuous && _cont_pressed_mouse.count(b) > 0))
process_release(_bus, action);
});
......@@ -243,6 +255,8 @@ namespace mirrage::input {
_primary_mouse_button_down = false;
_is_mouse_drag = false;
}
_cont_pressed_mouse.erase(b);
}
void Input_mapper::on_pad_stick_change(Input_source src, Pad_stick s, glm::vec2 rel, glm::vec2 abs)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment