This commit is contained in:
sravyak 2024-05-18 18:52:25 +03:00 committed by GitHub
commit 9cdefc443c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 13466 additions and 17 deletions

View File

@ -229,8 +229,9 @@ const UI = {
document.getElementById("noVNC_control_bar") document.getElementById("noVNC_control_bar")
.addEventListener('keydown', UI.keepControlbar); .addEventListener('keydown', UI.keepControlbar);
document.getElementById("noVNC_view_drag_button") // // Agilicus Modified
.addEventListener('click', UI.toggleViewDrag); // document.getElementById("noVNC_view_drag_button")
// .addEventListener('click', UI.toggleViewDrag);
document.getElementById("noVNC_control_bar_handle") document.getElementById("noVNC_control_bar_handle")
.addEventListener('mousedown', UI.controlbarHandleMouseDown); .addEventListener('mousedown', UI.controlbarHandleMouseDown);
@ -1058,7 +1059,7 @@ const UI = {
UI.rfb.addEventListener("serververification", UI.serverVerify); UI.rfb.addEventListener("serververification", UI.serverVerify);
UI.rfb.addEventListener("credentialsrequired", UI.credentials); UI.rfb.addEventListener("credentialsrequired", UI.credentials);
UI.rfb.addEventListener("securityfailure", UI.securityFailed); UI.rfb.addEventListener("securityfailure", UI.securityFailed);
UI.rfb.addEventListener("clippingviewport", UI.updateViewDrag); // UI.rfb.addEventListener("clippingviewport", UI.updateViewDrag);
UI.rfb.addEventListener("capabilities", UI.updatePowerButton); UI.rfb.addEventListener("capabilities", UI.updatePowerButton);
UI.rfb.addEventListener("clipboard", UI.clipboardReceive); UI.rfb.addEventListener("clipboard", UI.clipboardReceive);
UI.rfb.addEventListener("bell", UI.bell); UI.rfb.addEventListener("bell", UI.bell);
@ -1112,6 +1113,9 @@ const UI = {
connectFinished(e) { connectFinished(e) {
UI.connected = true; UI.connected = true;
UI.inhibitReconnect = false; UI.inhibitReconnect = false;
// Agilicus modified from original file
// UI.toggleViewDrag();
UI.rfb.dragViewport = true;
let msg; let msg;
if (UI.getSetting('encrypt')) { if (UI.getSetting('encrypt')) {
@ -1363,7 +1367,7 @@ const UI = {
// Changing the viewport may change the state of // Changing the viewport may change the state of
// the dragging button // the dragging button
UI.updateViewDrag(); // UI.updateViewDrag();
}, },
/* ------^------- /* ------^-------
@ -1372,12 +1376,12 @@ const UI = {
* VIEWDRAG * VIEWDRAG
* ------v------*/ * ------v------*/
toggleViewDrag() { // toggleViewDrag() {
if (!UI.rfb) return; // if (!UI.rfb) return;
UI.rfb.dragViewport = !UI.rfb.dragViewport; // UI.rfb.dragViewport = !UI.rfb.dragViewport;
UI.updateViewDrag(); // // UI.updateViewDrag();
}, // },
updateViewDrag() { updateViewDrag() {
if (!UI.connected) return; if (!UI.connected) return;

View File

@ -433,6 +433,10 @@ export default class Display {
this._rescale(scaleRatio); this._rescale(scaleRatio);
} }
customrescale(factor) {
this._rescale(factor);
}
// ===== PRIVATE METHODS ===== // ===== PRIVATE METHODS =====
_rescale(factor) { _rescale(factor) {

View File

@ -34,7 +34,8 @@ const GH_LONGPRESS_TIMEOUT = 1000;
const GH_TWOTOUCH_TIMEOUT = 50; const GH_TWOTOUCH_TIMEOUT = 50;
export default class GestureHandler { export default class GestureHandler {
constructor() { constructor(display) {
this._display = display;
this._target = null; this._target = null;
this._state = GH_INITSTATE; this._state = GH_INITSTATE;
@ -49,6 +50,10 @@ export default class GestureHandler {
this._twoTouchTimeoutId = null; this._twoTouchTimeoutId = null;
this._boundEventHandler = this._eventHandler.bind(this); this._boundEventHandler = this._eventHandler.bind(this);
this.initialDistance = 0;
this.initialScale = 1;
this.currentScale = 1;
} }
attach(target) { attach(target) {
@ -432,6 +437,61 @@ export default class GestureHandler {
this._pushEvent('gesturemove'); this._pushEvent('gesturemove');
} }
onGestureStart(detail) {
this.initialDistance = Math.sqrt(detail.magnitudeX**2 + detail.magnitudeY**2);
if (!this._initialCanvasWidth) {
this._initialCanvasWidth = this._target.width;
}
if (!this._initialCanvasHeight) {
this._initialCanvasHeight = this._target.height;
}
const viewer = document.getElementById('noVNC_container');
this.MIN_SCALE_WIDTH = viewer.clientWidth / this._initialCanvasWidth;
this.MIN_SCALE_HEIGHT = viewer.clientHeight / this._initialCanvasHeight;
this.MIN_SCALE = Math.max(this.MIN_SCALE_WIDTH, this.MIN_SCALE_HEIGHT);
}
onGestureMove(detail) {
if (this.initialDistance === 0) return;
let currentDistance = Math.sqrt(detail.magnitudeX**2 + detail.magnitudeY**2);
let scaleFactor = 1 / (currentDistance / this.initialDistance);
this.currentScale = this.initialScale * scaleFactor;
// Basic constraints
if (this.currentScale < 0.5) this.currentScale = 0.5;
if (this.currentScale > 4) this.currentScale = 4;
this.applyZoom(this.currentScale, detail.clientX, detail.clientY);
}
onGestureEnd(detail) {
this.initialScale = this.currentScale;
this.initialDistance = 0;
}
applyZoom(scale, centerX, centerY) {
let newWidth = this._initialCanvasWidth * scale;
let newHeight = this._initialCanvasHeight * scale;
this._display.viewportChangeSize(newWidth, newHeight);
const viewer = document.getElementById('noVNC_container');
const viewerWidth = viewer.clientWidth;
const viewerHeight = viewer.clientHeight;
const widthScale = viewerWidth / newWidth;
const heightScale = viewerHeight / newHeight;
const visualScale = Math.min(widthScale, heightScale);
this._display.customrescale(visualScale);
}
_pushEvent(type) { _pushEvent(type) {
let detail = { type: this._stateToGesture(this._state) }; let detail = { type: this._stateToGesture(this._state) };
@ -481,6 +541,16 @@ export default class GestureHandler {
} }
} }
if (this._state === GH_PINCH) {
if (type === 'gesturestart') {
this.onGestureStart(detail);
} else if (type === 'gesturemove') {
this.onGestureMove(detail);
} else if (type === 'gestureend') {
this.onGestureEnd(detail);
}
}
let gev = new CustomEvent(type, { detail: detail }); let gev = new CustomEvent(type, { detail: detail });
this._target.dispatchEvent(gev); this._target.dispatchEvent(gev);
} }

View File

@ -263,7 +263,7 @@ export default class RFB extends EventTargetMixin {
this._remoteCapsLock = null; // Null indicates unknown or irrelevant this._remoteCapsLock = null; // Null indicates unknown or irrelevant
this._remoteNumLock = null; this._remoteNumLock = null;
this._gestures = new GestureHandler(); this._gestures = new GestureHandler(this._display);
this._sock = new Websock(); this._sock = new Websock();
this._sock.on('open', this._socketOpen.bind(this)); this._sock.on('open', this._socketOpen.bind(this));
@ -282,6 +282,8 @@ export default class RFB extends EventTargetMixin {
// ===== PROPERTIES ===== // ===== PROPERTIES =====
this.gestures = this._gestures;
this.dragViewport = false; this.dragViewport = false;
this.focusOnClick = true; this.focusOnClick = true;

13368
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
{ {
"name": "@novnc/novnc", "name": "@agilicus/novnc",
"version": "1.4.0", "version": "1.4.0",
"description": "An HTML5 VNC client", "description": "An HTML5 VNC client",
"browser": "lib/rfb", "browser": "lib/rfb",
@ -23,7 +23,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/novnc/noVNC.git" "url": "git+https://github.com/agilicus/noVNC.git"
}, },
"author": "Joel Martin <github@martintribe.org> (https://github.com/kanaka)", "author": "Joel Martin <github@martintribe.org> (https://github.com/kanaka)",
"contributors": [ "contributors": [

View File

@ -71,9 +71,9 @@
<hr> <hr>
<!-- Drag/Pan the viewport --> <!-- Drag/Pan the viewport -->
<input type="image" alt="Drag" src="app/images/drag.svg" <!-- <input type="image" alt="Drag" src="app/images/drag.svg"
id="noVNC_view_drag_button" class="noVNC_button noVNC_hidden" id="noVNC_view_drag_button" class="noVNC_button noVNC_hidden"
title="Move/Drag Viewport"> title="Move/Drag Viewport"> -->
<!--noVNC Touch Device only buttons--> <!--noVNC Touch Device only buttons-->
<div id="noVNC_mobile_buttons"> <div id="noVNC_mobile_buttons">
@ -324,7 +324,8 @@
</div> </div>
<!-- This is where the RFB elements will attach --> <!-- This is where the RFB elements will attach -->
<div id="noVNC_container"> <!-- <div id="noVNC_container"> -->
<div id="noVNC_container" class="noVNC_container">
<!-- Note that Google Chrome on Android doesn't respect any of these, <!-- Note that Google Chrome on Android doesn't respect any of these,
html attributes which attempt to disable text suggestions on the html attributes which attempt to disable text suggestions on the
on-screen keyboard. Let's hope Chrome implements the ime-mode on-screen keyboard. Let's hope Chrome implements the ime-mode