From ed5952f13ef1baede4101934bc5df952ce66af1b Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Sat, 14 Aug 2021 09:21:04 +0300 Subject: fixed pikvm/pikvm#159: workaround for windows 98 absolute mouse bug --- hid/platformio.ini | 2 ++ hid/src/usb/hid.h | 4 ++++ kvmd/plugins/hid/otg/__init__.py | 9 ++++++++- kvmd/plugins/hid/otg/mouse.py | 7 +++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hid/platformio.ini b/hid/platformio.ini index a8a0988d..ed847afb 100644 --- a/hid/platformio.ini +++ b/hid/platformio.ini @@ -24,6 +24,8 @@ build_flags = -DHID_WITH_USB -DHID_SET_USB_KBD -DHID_SET_USB_MOUSE_ABS +# ----- The USB ABS fix for Windows 98 (https://github.com/pikvm/pikvm/issues/159) ----- +# -DHID_USB_ABS_WIN98_FIX # ----- PS2 keyboard only ----- # -DHID_WITH_PS2 # -DHID_SET_PS2_KBD diff --git a/hid/src/usb/hid.h b/hid/src/usb/hid.h index f40cbf36..51b14b96 100644 --- a/hid/src/usb/hid.h +++ b/hid/src/usb/hid.h @@ -161,7 +161,11 @@ class UsbMouseAbsolute { void sendMove(int x, int y) { CHECK_HID_EP; +#ifdef HID_USB_ABS_WIN98_FIX + _mouse.moveTo(x << 1, y << 1); +#else _mouse.moveTo(x, y); +#endif } void sendWheel(int delta_y) { diff --git a/kvmd/plugins/hid/otg/__init__.py b/kvmd/plugins/hid/otg/__init__.py index 0ba74c88..030c551d 100644 --- a/kvmd/plugins/hid/otg/__init__.py +++ b/kvmd/plugins/hid/otg/__init__.py @@ -72,7 +72,12 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes self.__output_to_mouse: Dict[str, MouseProcess] = {} self.__mouse_to_output: Dict[MouseProcess, str] = {} if mouse_alt["device_path"]: - self.__mouse_alt_proc = MouseProcess(absolute=(not mouse["absolute"]), **common, **mouse_alt) + self.__mouse_alt_proc = MouseProcess( + absolute=(not mouse["absolute"]), + absolute_win98_fix=mouse["absolute_win98_fix"], + **common, + **mouse_alt, + ) self.__output_to_mouse = { "usb": (self.__mouse_proc if mouse["absolute"] else self.__mouse_alt_proc), "usb_rel": (self.__mouse_alt_proc if mouse["absolute"] else self.__mouse_proc), @@ -94,6 +99,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes "queue_timeout": Option(0.1, type=valid_float_f01), "write_retries": Option(150, type=valid_int_f1), "absolute": Option(True, type=valid_bool), + "absolute_win98_fix": Option(False, type=valid_bool), "horizontal_wheel": Option(True, type=valid_bool), }, "mouse_alt": { @@ -102,6 +108,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes "queue_timeout": Option(0.1, type=valid_float_f01), "write_retries": Option(150, type=valid_int_f1), # No absolute option here, initialized by (not mouse.absolute) + # Also no absolute_win98_fix "horizontal_wheel": Option(True, type=valid_bool), }, "noop": Option(False, type=valid_bool), diff --git a/kvmd/plugins/hid/otg/mouse.py b/kvmd/plugins/hid/otg/mouse.py index 620effc5..4ede3277 100644 --- a/kvmd/plugins/hid/otg/mouse.py +++ b/kvmd/plugins/hid/otg/mouse.py @@ -42,6 +42,7 @@ from .events import make_mouse_report class MouseProcess(BaseDeviceProcess): def __init__(self, **kwargs: Any) -> None: self.__absolute: bool = kwargs.pop("absolute") + self.__absolute_win98_fix: bool = kwargs.pop("absolute_win98_fix") self.__horizontal_wheel: bool = kwargs.pop("horizontal_wheel") super().__init__( @@ -143,6 +144,12 @@ class MouseProcess(BaseDeviceProcess): assert relative_event is None move_x = self.__x move_y = self.__y + if self.__absolute_win98_fix: + # https://github.com/pikvm/pikvm/issues/159 + # For some reason, the correct implementation of this fix + # is a shift to the left, and not to the right, as in VirtualBox + move_x <<= 1 + move_y <<= 1 else: assert self.__x == self.__y == 0 if relative_event is not None: -- cgit v1.2.3