From 8d8251ddcb9e70d1b0282d0e4e37b9473f03db35 Mon Sep 17 00:00:00 2001 From: DomenGaber Date: Tue, 4 Feb 2020 15:39:06 +0100 Subject: [PATCH] Track mouse position on device screen --- app/styles/base.css | 15 +++++++++++++++ app/ui.js | 13 +++++++++++++ core/rfb.js | 2 ++ vnc.html | 4 ++++ 4 files changed, 34 insertions(+) diff --git a/app/styles/base.css b/app/styles/base.css index 9db83bf6..320df9f0 100644 --- a/app/styles/base.css +++ b/app/styles/base.css @@ -866,6 +866,21 @@ select:active { ime-mode: disabled; } +#noVNC_mouse_coordinates { + position: fixed; + top: 0; + right: 0; + padding: 20px; + min-width: 150px; + font-size: 20px; + font-weight: 600; + text-align: center; + background-color: #fff; + border: 2px solid #E0E0E0; + border-radius: 0 0 0 5px; + box-shadow: 6px 6px 0px rgba(0, 0, 0, 0.5); +} + /*Default noVNC logo.*/ /* From: http://fonts.googleapis.com/css?family=Orbitron:700 */ @font-face { diff --git a/app/ui.js b/app/ui.js index 9c5e922f..b4e588db 100644 --- a/app/ui.js +++ b/app/ui.js @@ -707,6 +707,17 @@ const UI = { } }, + trackMouse() { + UI.rfb.canvas.addEventListener('mousemove', function(e) { + let scaleRatioX = UI.rfb.canvas.width / UI.rfb.canvas.clientWidth; + let scaleRatioY = UI.rfb.canvas.height / UI.rfb.canvas.clientHeight; + let x = Math.floor(e.offsetX * scaleRatioX); + let y = Math.floor(e.offsetY * scaleRatioY); + document.getElementById('noVNC_mouse_coordinates').innerText = "(" + x + ", " + y + ")" + }); + }, + + /* ------^------- * /VISUAL * ============== @@ -1036,6 +1047,8 @@ const UI = { UI.rfb.resizeSession = UI.getSetting('resize') === 'remote'; UI.rfb.showDotCursor = UI.getSetting('show_dot'); + UI.trackMouse(); + UI.updateViewOnly(); // requires UI.rfb }, diff --git a/core/rfb.js b/core/rfb.js index 49a16bb6..82ed141d 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -271,6 +271,8 @@ export default class RFB extends EventTargetMixin { } } + get canvas() { return this._canvas; } + get capabilities() { return this._capabilities; } get touchButton() { return this._mouse.touchButton; } diff --git a/vnc.html b/vnc.html index d1e6c683..96746f8b 100644 --- a/vnc.html +++ b/vnc.html @@ -332,5 +332,9 @@ + +
+ (0, 0) +