Kernel: Add mouse move and scroll event merging back

This makes mouse work much faster when reading can't keep up with the
amount of events.
This commit is contained in:
Bananymous 2024-07-15 15:45:20 +03:00
parent 4cd9252ff6
commit 60b396fee5
2 changed files with 22 additions and 0 deletions

View File

@ -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;

View File

@ -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<LibInput::MouseEvent*>(&m_event_buffer[last_index * m_event_size]);
auto& curr_event = event.as<const LibInput::MouseEvent>();
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;