diff --git a/kernel/include/kernel/Input/InputDevice.h b/kernel/include/kernel/Input/InputDevice.h index fe3f3ca714..6cb69e961f 100644 --- a/kernel/include/kernel/Input/InputDevice.h +++ b/kernel/include/kernel/Input/InputDevice.h @@ -35,6 +35,8 @@ namespace Kernel const dev_t m_rdev; const BAN::String m_name; + const Type m_type; + mutable SpinLock m_event_lock; Semaphore m_event_semaphore; diff --git a/kernel/kernel/Input/InputDevice.cpp b/kernel/kernel/Input/InputDevice.cpp index 95b9a61648..68d2c3c587 100644 --- a/kernel/kernel/Input/InputDevice.cpp +++ b/kernel/kernel/Input/InputDevice.cpp @@ -53,6 +53,7 @@ namespace Kernel : CharacterDevice(0440, 0, 901) , m_rdev(get_rdev(type)) , m_name(MUST(BAN::String::formatted(get_name_format(type), minor(m_rdev)))) + , m_type(type) , m_event_size(get_event_size(type)) { MUST(m_event_buffer.resize(m_event_size * m_max_event_count, 0)); @@ -63,6 +64,25 @@ namespace Kernel SpinLockGuard _(m_event_lock); ASSERT(event.size() == m_event_size); + if (m_type == Type::Mouse && m_event_count > 0) + { + const size_t last_index = (m_event_head + m_max_event_count - 1) % m_max_event_count; + + auto& last_event = *reinterpret_cast(&m_event_buffer[last_index * m_event_size]); + auto& curr_event = event.as(); + if (last_event.type == LibInput::MouseEventType::MouseMoveEvent && curr_event.type == LibInput::MouseEventType::MouseMoveEvent) + { + last_event.move_event.rel_x += curr_event.move_event.rel_x; + last_event.move_event.rel_y += curr_event.move_event.rel_y; + return; + } + if (last_event.type == LibInput::MouseEventType::MouseScrollEvent && curr_event.type == LibInput::MouseEventType::MouseScrollEvent) + { + last_event.scroll_event.scroll += curr_event.scroll_event.scroll; + return; + } + } + if (m_event_count == m_max_event_count) { m_event_tail = (m_event_tail + 1) % m_max_event_count;