diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-07 08:07:37 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-07 08:08:08 +0100 |
commit | e29060620fcc1fc5878b5c2d9731d79cfb5c9f95 (patch) | |
tree | c0d47c2bd94b1982d9fcfbf6ad121bb9406d292b /WindowServer/WSMessageLoop.cpp | |
parent | a537d78ac0ea5845dab9eb4a94a740d4a1e7e2b1 (diff) | |
download | serenity-e29060620fcc1fc5878b5c2d9731d79cfb5c9f95.zip |
WindowServer: Improve parsing of mouse packets.
Diffstat (limited to 'WindowServer/WSMessageLoop.cpp')
-rw-r--r-- | WindowServer/WSMessageLoop.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/WindowServer/WSMessageLoop.cpp b/WindowServer/WSMessageLoop.cpp index 3d5a505b3b..224595a7e1 100644 --- a/WindowServer/WSMessageLoop.cpp +++ b/WindowServer/WSMessageLoop.cpp @@ -159,8 +159,23 @@ void WSMessageLoop::drain_mouse() ASSERT(nread == sizeof(data)); bool left_button = data[0] & 1; bool right_button = data[0] & 2; - dx += data[1] ? (int)data[1] - (int)((data[0] << 4) & 0x100) : 0; - dy += data[2] ? (int)((data[0] << 3) & 0x100) - (int)data[2] : 0; + bool x_overflow = data[0] & 0x40; + bool y_overflow = data[0] & 0x80; + bool x_sign = data[0] & 0x10; + bool y_sign = data[0] & 0x20; + + if (x_overflow || y_overflow) + continue; + + int x = data[1]; + int y = data[2]; + if (x && x_sign) + x -= 0x100; + if (y && y_sign) + y -= 0x100; + + dx += x; + dy += -y; if (left_button != prev_left_button || right_button != prev_right_button || !mouse.can_read(*m_server_process)) { prev_left_button = left_button; prev_right_button = right_button; |