pikvm/pikvm#880: Fixed mouse position at edges

This commit is contained in:
Maxim Devaev
2025-05-12 19:26:48 +03:00
parent 5273199e0b
commit df8898684f
5 changed files with 13 additions and 17 deletions

View File

@@ -590,8 +590,8 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
move = (self._width, self._height, to_x, to_y)
if self.__mouse_move != move:
await self._on_mouse_move_event(
tools.remap(to_x, 0, self._width, *MouseRange.RANGE),
tools.remap(to_y, 0, self._height, *MouseRange.RANGE),
tools.remap(to_x, 0, self._width - 1, *MouseRange.RANGE),
tools.remap(to_y, 0, self._height - 1, *MouseRange.RANGE),
)
self.__mouse_move = move

View File

@@ -33,7 +33,8 @@ from typing import TypeVar
# =====
def remap(value: int, in_min: int, in_max: int, out_min: int, out_max: int) -> int:
return int((value - in_min) * (out_max - out_min) // (in_max - in_min) + out_min)
result = int((value - in_min) * (out_max - out_min) // ((in_max - in_min) or 1) + out_min)
return min(max(result, out_min), out_max)
# =====