diff options
author | Maxim Devaev <[email protected]> | 2021-08-17 15:01:04 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2021-08-17 15:01:04 +0300 |
commit | 586c7d20778e1e30ea802f489a71c2d2dd0b18f6 (patch) | |
tree | 4cfa698e07142f9cadef94fc3b24d5f510be5b82 /web/share/js/kvm/mouse.js | |
parent | b7cf7b4523c28bed43346bb593add7ff4bc993e1 (diff) |
pikvm/pikvm#281: adjustable relative mouse sensitivity
Diffstat (limited to 'web/share/js/kvm/mouse.js')
-rw-r--r-- | web/share/js/kvm/mouse.js | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/web/share/js/kvm/mouse.js b/web/share/js/kvm/mouse.js index cfc70bff..1c33e4c0 100644 --- a/web/share/js/kvm/mouse.js +++ b/web/share/js/kvm/mouse.js @@ -42,6 +42,7 @@ export function Mouse(__getResolution, __recordWsEvent) { var __sent_pos = {x: 0, y: 0}; var __wheel_delta = {x: 0, y: 0}; var __relative_deltas = []; + var __relative_sens = 1.0; var __stream_hovered = false; @@ -61,6 +62,12 @@ export function Mouse(__getResolution, __recordWsEvent) { $("stream-box").onwheel = __streamWheelHandler; $("stream-box").ontouchstart = (event) => __streamTouchMoveHandler(event); + let sens_slider = $("hid-mouse-sens-slider"); + tools.slider.setParams(sens_slider, 0.1, 1.9, 0.1, 1); + sens_slider.oninput = sens_slider.onchange = __updateRelativeSens; + sens_slider.value = tools.storage.get("hid.mouse.sens", 1.0); + __updateRelativeSens(); + tools.storage.bindSimpleSwitch($("hid-mouse-squash-switch"), "hid.mouse.squash", true); setInterval(__sendMove, 100); @@ -97,6 +104,12 @@ export function Mouse(__getResolution, __recordWsEvent) { __keypad.releaseAll(); }; + var __updateRelativeSens = function() { + __relative_sens = parseFloat($("hid-mouse-sens-slider").value); + $("hid-mouse-sens-value").innerHTML = __relative_sens.toFixed(1); + tools.storage.set("hid.mouse.sens", __relative_sens); + }; + var __streamHoveredHandler = function(hovered) { if (__absolute) { __stream_hovered = hovered; @@ -188,8 +201,8 @@ export function Mouse(__getResolution, __recordWsEvent) { }; } else if (__isRelativeCaptured()) { let delta = { - x: Math.min(Math.max(-127, event.movementX), 127), - y: Math.min(Math.max(-127, event.movementY), 127), + x: Math.min(Math.max(-127, Math.floor(event.movementX * __relative_sens)), 127), + y: Math.min(Math.max(-127, Math.floor(event.movementY * __relative_sens)), 127), }; if (__isRelativeSquashed()) { __relative_deltas.push(delta); |