Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pinch zoom #1809

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions app/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ const UI = {
document.getElementById("noVNC_control_bar")
.addEventListener('keydown', UI.keepControlbar);

document.getElementById("noVNC_view_drag_button")
.addEventListener('click', UI.toggleViewDrag);
// // Agilicus Modified
// document.getElementById("noVNC_view_drag_button")
// .addEventListener('click', UI.toggleViewDrag);
Comment on lines +232 to +234

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove the code instead of uncommenting.


document.getElementById("noVNC_control_bar_handle")
.addEventListener('mousedown', UI.controlbarHandleMouseDown);
Expand Down Expand Up @@ -1050,7 +1051,7 @@ const UI = {
UI.rfb.addEventListener("serververification", UI.serverVerify);
UI.rfb.addEventListener("credentialsrequired", UI.credentials);
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("clipboard", UI.clipboardReceive);
UI.rfb.addEventListener("bell", UI.bell);
Expand Down Expand Up @@ -1104,6 +1105,9 @@ const UI = {
connectFinished(e) {
UI.connected = true;
UI.inhibitReconnect = false;
// Agilicus modified from original file
// UI.toggleViewDrag();
UI.rfb.dragViewport = true;

let msg;
if (UI.getSetting('encrypt')) {
Expand Down Expand Up @@ -1355,7 +1359,7 @@ const UI = {

// Changing the viewport may change the state of
// the dragging button
UI.updateViewDrag();
// UI.updateViewDrag();
},

/* ------^-------
Expand All @@ -1364,12 +1368,12 @@ const UI = {
* VIEWDRAG
* ------v------*/

toggleViewDrag() {
if (!UI.rfb) return;
// toggleViewDrag() {
// if (!UI.rfb) return;

UI.rfb.dragViewport = !UI.rfb.dragViewport;
UI.updateViewDrag();
},
// UI.rfb.dragViewport = !UI.rfb.dragViewport;
// // UI.updateViewDrag();
// },

updateViewDrag() {
if (!UI.connected) return;
Expand Down
4 changes: 4 additions & 0 deletions core/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ export default class Display {
this._rescale(scaleRatio);
}

customrescale(factor) {
this._rescale(factor);
}

// ===== PRIVATE METHODS =====

_rescale(factor) {
Expand Down
72 changes: 71 additions & 1 deletion core/input/gesturehandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
const GH_TWOTOUCH_TIMEOUT = 50;

export default class GestureHandler {
constructor() {
constructor(display) {
this._display = display;
this._target = null;

this._state = GH_INITSTATE;
Expand All @@ -49,6 +50,10 @@
this._twoTouchTimeoutId = null;

this._boundEventHandler = this._eventHandler.bind(this);

this.initialDistance = 0;
this.initialScale = 1;
this.currentScale = 1;
}

attach(target) {
Expand Down Expand Up @@ -432,6 +437,61 @@
this._pushEvent('gesturemove');
}

onGestureStart(detail) {
this.initialDistance = Math.sqrt(detail.magnitudeX**2 + detail.magnitudeY**2);

Check failure on line 442 in core/input/gesturehandler.js

View workflow job for this annotation

GitHub Actions / eslint

Trailing spaces not allowed
if (!this._initialCanvasWidth) {
this._initialCanvasWidth = this._target.width;
}
if (!this._initialCanvasHeight) {
this._initialCanvasHeight = this._target.height;
}

Check failure on line 449 in core/input/gesturehandler.js

View workflow job for this annotation

GitHub Actions / eslint

Trailing spaces not allowed
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);
}

Check failure on line 454 in core/input/gesturehandler.js

View workflow job for this annotation

GitHub Actions / eslint

Trailing spaces not allowed

Check failure on line 455 in core/input/gesturehandler.js

View workflow job for this annotation

GitHub Actions / eslint

Trailing spaces not allowed
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;
}

Check failure on line 475 in core/input/gesturehandler.js

View workflow job for this annotation

GitHub Actions / eslint

Trailing spaces not allowed

Check failure on line 476 in core/input/gesturehandler.js

View workflow job for this annotation

GitHub Actions / eslint

Trailing spaces not allowed
applyZoom(scale, centerX, centerY) {
let newWidth = this._initialCanvasWidth * scale;
let newHeight = this._initialCanvasHeight * scale;

Check failure on line 480 in core/input/gesturehandler.js

View workflow job for this annotation

GitHub Actions / eslint

Trailing spaces not allowed
this._display.viewportChangeSize(newWidth, newHeight);

Check failure on line 482 in core/input/gesturehandler.js

View workflow job for this annotation

GitHub Actions / eslint

Trailing spaces not allowed
const viewer = document.getElementById('noVNC_container');
const viewerWidth = viewer.clientWidth;
const viewerHeight = viewer.clientHeight;

Check failure on line 486 in core/input/gesturehandler.js

View workflow job for this annotation

GitHub Actions / eslint

Trailing spaces not allowed
const widthScale = viewerWidth / newWidth;
const heightScale = viewerHeight / newHeight;

Check failure on line 489 in core/input/gesturehandler.js

View workflow job for this annotation

GitHub Actions / eslint

Trailing spaces not allowed
const visualScale = Math.min(widthScale, heightScale);
this._display.customrescale(visualScale);
}


_pushEvent(type) {
let detail = { type: this._stateToGesture(this._state) };

Expand Down Expand Up @@ -480,6 +540,16 @@
detail['magnitudeY'] = movement.y;
}
}

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 });
this._target.dispatchEvent(gev);
Expand Down
6 changes: 4 additions & 2 deletions core/rfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export default class RFB extends EventTargetMixin {
this._remoteCapsLock = null; // Null indicates unknown or irrelevant
this._remoteNumLock = null;

this._gestures = new GestureHandler();
this._gestures = new GestureHandler(this._display);

this._sock = new Websock();
this._sock.on('open', this._socketOpen.bind(this));
Expand All @@ -282,6 +282,8 @@ export default class RFB extends EventTargetMixin {

// ===== PROPERTIES =====

this.gestures = this._gestures;

this.dragViewport = false;
this.focusOnClick = true;

Expand Down Expand Up @@ -1443,7 +1445,7 @@ export default class RFB extends EventTargetMixin {
];

return clientTypes.includes(type);
}
}

_negotiateSecurity() {
if (this._rfbVersion >= 3.7) {
Expand Down