Track mouse position on device screen

This commit is contained in:
DomenGaber 2020-02-04 15:39:06 +01:00
parent 0a370910a6
commit 8d8251ddcb
4 changed files with 34 additions and 0 deletions

View File

@ -866,6 +866,21 @@ select:active {
ime-mode: disabled; 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.*/ /*Default noVNC logo.*/
/* From: http://fonts.googleapis.com/css?family=Orbitron:700 */ /* From: http://fonts.googleapis.com/css?family=Orbitron:700 */
@font-face { @font-face {

View File

@ -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 * /VISUAL
* ============== * ==============
@ -1036,6 +1047,8 @@ const UI = {
UI.rfb.resizeSession = UI.getSetting('resize') === 'remote'; UI.rfb.resizeSession = UI.getSetting('resize') === 'remote';
UI.rfb.showDotCursor = UI.getSetting('show_dot'); UI.rfb.showDotCursor = UI.getSetting('show_dot');
UI.trackMouse();
UI.updateViewOnly(); // requires UI.rfb UI.updateViewOnly(); // requires UI.rfb
}, },

View File

@ -271,6 +271,8 @@ export default class RFB extends EventTargetMixin {
} }
} }
get canvas() { return this._canvas; }
get capabilities() { return this._capabilities; } get capabilities() { return this._capabilities; }
get touchButton() { return this._mouse.touchButton; } get touchButton() { return this._mouse.touchButton; }

View File

@ -332,5 +332,9 @@
<source src="app/sounds/bell.oga" type="audio/ogg"> <source src="app/sounds/bell.oga" type="audio/ogg">
<source src="app/sounds/bell.mp3" type="audio/mpeg"> <source src="app/sounds/bell.mp3" type="audio/mpeg">
</audio> </audio>
<div id="noVNC_mouse_coordinates">
(0, 0)
</div>
</body> </body>
</html> </html>