[vdagent-win PATCH] handle_mouse_event: fix off-by-one when normalizing mouse coordinates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Mouse coordinates can be 0..(width-1) and 0..(height-1)

Normalization of mouse coordinates (for SendInput) was done
against w,h and thus right-most and down-most coordinates
could never be reached.

Fix it by normalizing against (w-1) and (h-1).

Also added protection against a case of 0 or 1 (for any of w,h)
Fixes rhbz#1032037
---
 vdagent/vdagent.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index c976665..595db85 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -567,13 +567,15 @@ bool VDAgent::handle_mouse_event(VDAgentMouseState* state)
     ZeroMemory(&_input, sizeof(INPUT));
     _input.type = INPUT_MOUSE;
     if (state->x != _mouse_x || state->y != _mouse_y) {
+        DWORD w = _desktop_layout->get_total_width();
+        DWORD h = _desktop_layout->get_total_height();
+        w = (w > 1) ? w-1 : 1; /* coordinates are 0..w-1, protect w==0 */
+        h = (h > 1) ? h-1 : 1; /* coordinates are 0..h-1, protect h==0 */
         _mouse_x = state->x;
         _mouse_y = state->y;
         mouse_move = MOUSEEVENTF_MOVE;
-        _input.mi.dx = (mode->get_pos_x() + _mouse_x) * 0xffff /
-                       _desktop_layout->get_total_width();
-        _input.mi.dy = (mode->get_pos_y() + _mouse_y) * 0xffff /
-                       _desktop_layout->get_total_height();
+        _input.mi.dx = (mode->get_pos_x() + _mouse_x) * 0xffff / w;
+        _input.mi.dy = (mode->get_pos_y() + _mouse_y) * 0xffff / h;
     }
     if (state->buttons != _buttons_state) {
         buttons_change = get_buttons_change(_buttons_state, state->buttons, VD_AGENT_LBUTTON_MASK,
-- 
2.5.0

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]