Add preventDefault in UltraVNC touch and manage touch ids manually

This commit is contained in:
Rui Reis 2024-09-24 09:23:45 +02:00
parent 6b770c9da2
commit 43ddc6c982
2 changed files with 12 additions and 4 deletions

View File

@ -61,7 +61,8 @@ export default class TouchHandlerUltraVNC {
}
_handleTouch(ev) {
Log.Debug("Gesture: " + ev.type);
ev.preventDefault();
ev.stopImmediatePropagation();
if (!this._isUltraVNCTouchActivated) {
return;
@ -69,6 +70,7 @@ export default class TouchHandlerUltraVNC {
if (ev.type === "touchstart") {
for (let i = 0; i < ev.changedTouches.length; i++) {
ev.changedTouches[i].touchIdentifier = this._getTouchIdentifier();
this._currentTouches.push({ event: ev.changedTouches[i], status: "POINTER_DOWN" });
}
@ -82,6 +84,7 @@ export default class TouchHandlerUltraVNC {
for (let i = 0; i < ev.changedTouches.length; i++) {
const index = this._currentTouches.findIndex(t => t.event.identifier === ev.changedTouches[i].identifier);
if (index !== -1) {
ev.changedTouches[i].touchIdentifier = this._currentTouches[index].event.touchIdentifier;
this._currentTouches[index].event = ev.changedTouches[i];
this._currentTouches[index].status = "POINTER_UPDATE";
}
@ -102,6 +105,13 @@ export default class TouchHandlerUltraVNC {
return indexes;
}
_getTouchIdentifier() {
const ids = this._currentTouches.map((ev) => ev.event.touchIdentifier);
let i = 0;
while (ids.includes(i)) { i++; }
return i;
}
_dispatchTouchEvent(ev) {
let tev = new CustomEvent('ultravnctouch', { event: ev, detail: { currentTouches: this._currentTouches, giiDeviceOrigin: this._giiDeviceOrigin } });
this._target.dispatchEvent(tev);

View File

@ -1390,7 +1390,6 @@ export default class RFB extends EventTargetMixin {
}
_handleUltraVNCTouch(ev) {
Log.Debug("SENDING " + ev.detail.currentTouches.length + " TOUCH(ES)");
this._sock.sQpush8(253); // GII message type
this._sock.sQpush8(128); // GII event
this._sock.sQpush16(4 + 16 + (6 * 2 * ev.detail.currentTouches.length)); // Length
@ -1405,7 +1404,6 @@ export default class RFB extends EventTargetMixin {
// Send all current touches
for (let i = 0; i < ev.detail.currentTouches.length; i++) {
Log.Debug("Touch Id: " + ev.detail.currentTouches[i].event.identifier);
let valuatorFlag = 0x00000000;
valuatorFlag |= TouchHandlerUltraVNC.LENGTH_16_flag;
valuatorFlag |= TouchHandlerUltraVNC.IDFORMAT_32;
@ -1413,7 +1411,7 @@ export default class RFB extends EventTargetMixin {
if (ev.detail.currentTouches[i].event.identifier === 0) valuatorFlag |= TouchHandlerUltraVNC.IF_flag; // IF_flag
this._sock.sQpush32(valuatorFlag);
this._sock.sQpush32(ev.detail.currentTouches[i].event.identifier);
this._sock.sQpush32(ev.detail.currentTouches[i].event.touchIdentifier);
let scaledPosition = clientToElement(ev.detail.currentTouches[i].event.clientX, ev.detail.currentTouches[i].event.clientY,
this._canvas);