[Spice-commits] vdagent/vdagent.cpp
Uri Lublin
uril at kemper.freedesktop.org
Thu May 5 08:52:24 UTC 2016
vdagent/vdagent.cpp | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
New commits:
commit 5edf7433a44174de04243e2c8f493fbc08c554f8
Author: Uri Lublin <uril at redhat.com>
Date: Sun Nov 15 16:24:00 2015 +0200
handle_mouse_event: fix off-by-one when normalizing mouse coordinates
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
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,
More information about the Spice-commits
mailing list