mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
Handle start/end of gestures more cleanly.
This commit is contained in:
@@ -868,6 +868,32 @@ Guacamole.Mouse.Touchscreen = function(element) {
|
|||||||
&& Math.abs(touch.clientY - gesture_start_y) >= guac_touchscreen.clickMoveThreshold;
|
&& Math.abs(touch.clientY - gesture_start_y) >= guac_touchscreen.clickMoveThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Begins a new gesture at the location of the first touch in the given
|
||||||
|
* touch event.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {TouchEvent} e The touch event beginning this new gesture.
|
||||||
|
*/
|
||||||
|
function begin_gesture(e) {
|
||||||
|
var touch = e.touches[0];
|
||||||
|
gesture_in_progress = true;
|
||||||
|
gesture_start_x = touch.clientX;
|
||||||
|
gesture_start_y = touch.clientY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End the current gesture entirely. Wait for all touches to be done before
|
||||||
|
* resuming gesture detection.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
function end_gesture() {
|
||||||
|
window.clearTimeout(click_release_timeout);
|
||||||
|
window.clearTimeout(long_press_timeout);
|
||||||
|
gesture_in_progress = false;
|
||||||
|
}
|
||||||
|
|
||||||
element.addEventListener("touchend", function(e) {
|
element.addEventListener("touchend", function(e) {
|
||||||
|
|
||||||
// Do not handle if no gesture
|
// Do not handle if no gesture
|
||||||
@@ -875,12 +901,13 @@ Guacamole.Mouse.Touchscreen = function(element) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Ignore if more than one touch
|
// Ignore if more than one touch
|
||||||
if (e.touches.length !== 0 || e.changedTouches.length !== 1)
|
if (e.touches.length !== 0 || e.changedTouches.length !== 1) {
|
||||||
|
end_gesture();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Long-press, if any, is over
|
// Long-press, if any, is over
|
||||||
window.clearTimeout(long_press_timeout);
|
window.clearTimeout(long_press_timeout);
|
||||||
long_press_timeout = null;
|
|
||||||
|
|
||||||
// Always release mouse button if pressed
|
// Always release mouse button if pressed
|
||||||
release_button("left");
|
release_button("left");
|
||||||
@@ -893,12 +920,14 @@ Guacamole.Mouse.Touchscreen = function(element) {
|
|||||||
// If not yet pressed, press and start delay release
|
// If not yet pressed, press and start delay release
|
||||||
if (!guac_touchscreen.currentState.left) {
|
if (!guac_touchscreen.currentState.left) {
|
||||||
|
|
||||||
|
var touch = e.changedTouches[0];
|
||||||
|
move_mouse(touch.clientX, touch.clientY);
|
||||||
press_button("left");
|
press_button("left");
|
||||||
|
|
||||||
// Release button after a delay, if not canceled
|
// Release button after a delay, if not canceled
|
||||||
click_release_timeout = window.setTimeout(function() {
|
click_release_timeout = window.setTimeout(function() {
|
||||||
release_button("left");
|
release_button("left");
|
||||||
gesture_in_progress = false;
|
end_gesture();
|
||||||
}, guac_touchscreen.clickTimingThreshold);
|
}, guac_touchscreen.clickTimingThreshold);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -910,31 +939,25 @@ Guacamole.Mouse.Touchscreen = function(element) {
|
|||||||
element.addEventListener("touchstart", function(e) {
|
element.addEventListener("touchstart", function(e) {
|
||||||
|
|
||||||
// Ignore if more than one touch
|
// Ignore if more than one touch
|
||||||
if (e.touches.length !== 1)
|
if (e.touches.length !== 1) {
|
||||||
|
end_gesture();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// Update state
|
|
||||||
var touch = e.touches[0];
|
|
||||||
move_mouse(touch.clientX, touch.clientY);
|
|
||||||
|
|
||||||
// New touch begins a new gesture
|
// New touch begins a new gesture
|
||||||
gesture_in_progress = true;
|
begin_gesture(e);
|
||||||
gesture_start_x = touch.clientX;
|
|
||||||
gesture_start_y = touch.clientY;
|
|
||||||
|
|
||||||
// Keep button pressed if tap after left click
|
// Keep button pressed if tap after left click
|
||||||
if (click_release_timeout) {
|
window.clearTimeout(click_release_timeout);
|
||||||
window.clearTimeout(click_release_timeout);
|
|
||||||
click_release_timeout = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Click right button if this turns into a long-press
|
// Click right button if this turns into a long-press
|
||||||
long_press_timeout = window.setTimeout(function() {
|
long_press_timeout = window.setTimeout(function() {
|
||||||
|
var touch = e.touches[0];
|
||||||
|
move_mouse(touch.clientX, touch.clientY);
|
||||||
click_button("right");
|
click_button("right");
|
||||||
long_press_timeout = null;
|
end_gesture();
|
||||||
gesture_in_progress = false;
|
|
||||||
}, guac_touchscreen.longPressThreshold);
|
}, guac_touchscreen.longPressThreshold);
|
||||||
|
|
||||||
}, false);
|
}, false);
|
||||||
@@ -946,14 +969,14 @@ Guacamole.Mouse.Touchscreen = function(element) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Cancel long press if finger moved
|
// Cancel long press if finger moved
|
||||||
if (long_press_timeout && finger_moved(e)) {
|
if (finger_moved(e))
|
||||||
window.clearTimeout(long_press_timeout);
|
window.clearTimeout(long_press_timeout);
|
||||||
long_press_timeout = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore if more than one touch
|
// Ignore if more than one touch
|
||||||
if (e.touches.length !== 1)
|
if (e.touches.length !== 1) {
|
||||||
|
end_gesture();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Update mouse position if dragging
|
// Update mouse position if dragging
|
||||||
if (guac_touchscreen.currentState.left) {
|
if (guac_touchscreen.currentState.left) {
|
||||||
|
Reference in New Issue
Block a user