Fix pointer position mismatch issue
In case of big size resolution of host video, mouse pointer
indicates slightly upper left than client GUI pointer. It's caused
by rounding off value below the decimal point on the coordinate
unit. For an example, in 1600x1200 screen size, the x coordinate
unit is 32768 / 1600 = 20.48 but we use 20 after rounding off the
0.48.
To prevent this issue, this commit changes logic of the calculation.
It uses integer operations instead of using floating point
operations for better performance.
Change-Id: Ie1fbb6b41ace997c50982d9542b0b03280b2220f
Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>
diff --git a/ikvm_input.cpp b/ikvm_input.cpp
index ce88f40..71e5b7f 100644
--- a/ikvm_input.cpp
+++ b/ikvm_input.cpp
@@ -138,14 +138,14 @@
if (x >= 0 && (unsigned int)x < video.getWidth())
{
- uint16_t xx = x * ((SHRT_MAX + 1) / video.getWidth());
+ uint16_t xx = (uint16_t)(x * (SHRT_MAX + 1) / video.getWidth());
memcpy(&input->pointerReport[1], &xx, 2);
}
if (y >= 0 && (unsigned int)y < video.getHeight())
{
- uint16_t yy = y * ((SHRT_MAX + 1) / video.getHeight());
+ uint16_t yy = (uint16_t)(y * (SHRT_MAX + 1) / video.getHeight());
memcpy(&input->pointerReport[3], &yy, 2);
}