diff options
author | Devaev Maxim <[email protected]> | 2020-11-05 13:01:26 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-11-05 13:01:26 +0300 |
commit | ae6d8258af6a800ca2f2107290114c80e326247f (patch) | |
tree | 89f32c5e8bc01260fcd29a5f96d4a86d2c0912b0 | |
parent | dc3259c169a4b1602ee1c7810d67aef16edd9f57 (diff) |
squash relative events
-rw-r--r-- | kvmd/apps/kvmd/api/hid.py | 17 | ||||
-rw-r--r-- | web/share/js/kvm/mouse.js | 4 |
2 files changed, 16 insertions, 5 deletions
diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py index 82d7219d..1f51a0e4 100644 --- a/kvmd/apps/kvmd/api/hid.py +++ b/kvmd/apps/kvmd/api/hid.py @@ -24,7 +24,6 @@ import os import stat import functools -from typing import Tuple from typing import Dict from typing import Set from typing import Callable @@ -159,10 +158,22 @@ class HidApi: (valid_hid_mouse_delta(delta["x"]), valid_hid_mouse_delta(delta["y"])) for delta in (raw_delta if isinstance(raw_delta, list) else [raw_delta]) ] + squash = valid_bool(event.get("squash", False)) except Exception: return - for delta_xy in deltas: - handler(*delta_xy) + if squash: + prev = (0, 0) + for cur in deltas: + if abs(prev[0] + cur[0]) > 127 or abs(prev[1] + cur[1]) > 127: + handler(*prev) + prev = cur + else: + prev = (prev[0] + cur[0], prev[1] + cur[1]) + if prev[0] or prev[1]: + handler(*prev) + else: + for xy in deltas: + handler(*xy) # ===== diff --git a/web/share/js/kvm/mouse.js b/web/share/js/kvm/mouse.js index 37de6226..0f7282e0 100644 --- a/web/share/js/kvm/mouse.js +++ b/web/share/js/kvm/mouse.js @@ -201,9 +201,9 @@ export function Mouse(record_callback) { __sendEvent("mouse_move", {"to": to}); __sent_pos = pos; } - } else if (__relative_deltas) { + } else if (__relative_deltas.length) { tools.debug("Mouse: relative:", __relative_deltas); - __sendEvent("mouse_relative", {"delta": __relative_deltas}); + __sendEvent("mouse_relative", {"delta": __relative_deltas, "squash": true}); __relative_deltas = []; } }; |