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 b673af9925
commit d78d8752df
2 changed files with 12 additions and 4 deletions

View File

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

View File

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