diff options
Diffstat (limited to 'web/share/js/kvm/mouse.js')
-rw-r--r-- | web/share/js/kvm/mouse.js | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/web/share/js/kvm/mouse.js b/web/share/js/kvm/mouse.js index 3ac7935e..2893a5ae 100644 --- a/web/share/js/kvm/mouse.js +++ b/web/share/js/kvm/mouse.js @@ -40,8 +40,8 @@ export function Mouse(record_callback) { var __keypad = null; - var __current_pos = {x: 0, y:0}; - var __sent_pos = {x: 0, y:0}; + var __current_pos = {x: 0, y: 0}; + var __sent_pos = {x: 0, y: 0}; var __wheel_delta = {x: 0, y: 0}; var __relative_deltas = []; @@ -210,15 +210,16 @@ export function Mouse(record_callback) { if (__absolute) { let pos = __current_pos; if (pos.x !== __sent_pos.x || pos.y !== __sent_pos.y) { - let el_stream_image = $("stream-image"); - let to = { - x: __translate(pos.x, 0, el_stream_image.clientWidth, -32768, 32767), - y: __translate(pos.y, 0, el_stream_image.clientHeight, -32768, 32767), - }; - - tools.debug("Mouse: moved:", to); - __sendEvent("mouse_move", {"to": to}); - __sent_pos = pos; + let geometry = $("stream-box").stream_geometry; + if (geometry) { + let to = { + x: __translate(pos.x, geometry.x, geometry.width, -32768, 32767), + y: __translate(pos.y, geometry.y, geometry.height, -32768, 32767), + }; + tools.debug("Mouse: moved:", to); + __sendEvent("mouse_move", {"to": to}); + __sent_pos = pos; + } } } else if (__relative_deltas.length) { tools.debug("Mouse: relative:", __relative_deltas); @@ -228,7 +229,13 @@ export function Mouse(record_callback) { }; var __translate = function(x, a, b, c, d) { - return Math.round((x - a) / (b - a) * (d - c) + c); + let translated = Math.round((x - a) / b * (d - c) + c); + if (translated < c) { + return c; + } else if (translated > d) { + return d; + } + return translated; }; var __streamWheelHandler = function(event) { |