diff options
author | Devaev Maxim <[email protected]> | 2018-07-13 05:52:22 +0000 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-07-13 05:52:22 +0000 |
commit | 1f02b77f662e3ba6a4d66e7c037dba334874d1db (patch) | |
tree | 6b22b89e7905d3f55ed0eafbd2287e98e4c3c2f0 | |
parent | 2a6883064da7b63bca15e2aaeb9debe584d88bc7 (diff) |
client-side for mouse wheel
-rw-r--r-- | kvmd/kvmd/server.py | 3 | ||||
-rw-r--r-- | kvmd/web/js/kvmd.js | 21 |
2 files changed, 19 insertions, 5 deletions
diff --git a/kvmd/kvmd/server.py b/kvmd/kvmd/server.py index 96304fb3..47badb32 100644 --- a/kvmd/kvmd/server.py +++ b/kvmd/kvmd/server.py @@ -145,9 +145,8 @@ class Server: # pylint: disable=too-many-instance-attributes if key and state in [True, False]: await self.__hid.send_key_event(key, state) continue - elif event.get("event_type") in ["mouse_move", "mouse_button"]: + elif event.get("event_type") in ["mouse_move", "mouse_button", "mouse_wheel"]: pass - # logger.info("Mouse event: %s", event) # TODO else: logger.error("Invalid websocket event: %r", event) await ws.send_str(json.dumps({"msg_type": "echo", "msg": msg.data})) diff --git a/kvmd/web/js/kvmd.js b/kvmd/web/js/kvmd.js index e93a4d88..489d70d1 100644 --- a/kvmd/web/js/kvmd.js +++ b/kvmd/web/js/kvmd.js @@ -47,8 +47,8 @@ function __installHidHandlers(ws) { el_stream_image.onmouseup = (event) => __onMouseButton(ws, event, false); el_stream_image.oncontextmenu = (event) => event.preventDefault(); el_stream_image.onmousemove = __onMouseMove; - runKvmdSession.mouse_timer_id = setInterval(() => __handleMouseMove(ws), 100); - // TODO: https://learn.javascript.ru/mousewheel + el_stream_image.onwheel = (event) => __onMouseWheel(ws, event); + runKvmdSession.mouse_move_timer = setInterval(() => __handleMouseMove(ws), 100); } function __clearHidHandlers() { @@ -60,7 +60,8 @@ function __clearHidHandlers() { el_stream_image.onmouseup = null; el_stream_image.oncontextmenu = null; el_stream_image.onmousemove = null; - clearInterval(runKvmdSession.mouse_timer_id); + el_stream_image.onwheel = null; + clearInterval(runKvmdSession.mouse_move_timer); } function __onKeyEvent(ws, event, state) { @@ -115,6 +116,20 @@ function __handleMouseMove(ws) { } __handleMouseMove.old_pos = {x: 0, y:0}; +function __onMouseWheel(ws, event) { + // https://learn.javascript.ru/mousewheel + if (event.preventDefault) { + event.preventDefault(); + } + ws.send(JSON.stringify({ + event_type: "mouse_wheel", + delta: { + x: event.deltaX, + y: event.deltaY, + }, + })); +} + // ----------------------------------------------------------------------------- function clickPowerButton() { |