mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-08 06:01:22 +00:00
Set scroll and click thresholds relative to screen pixel density (if readable) and size of gesture.
This commit is contained in:
@@ -59,10 +59,10 @@ Guacamole.Mouse = function(element) {
|
|||||||
var guac_mouse = this;
|
var guac_mouse = this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of pixels a touch must move for it to be considered a scroll
|
* The distance a two-finger touch must move per scrollwheel event, relative
|
||||||
* wheel event.
|
* to the distance between the two touches.
|
||||||
*/
|
*/
|
||||||
this.scrollThreshold = 20;
|
this.scrollThreshold = 0.5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum number of milliseconds to wait for a touch to end for the
|
* The maximum number of milliseconds to wait for a touch to end for the
|
||||||
@@ -74,7 +74,7 @@ Guacamole.Mouse = function(element) {
|
|||||||
* The maximum number of pixels to allow a touch to move for the gesture to
|
* The maximum number of pixels to allow a touch to move for the gesture to
|
||||||
* be considered a click.
|
* be considered a click.
|
||||||
*/
|
*/
|
||||||
this.clickMoveThreshold = 10;
|
this.clickMoveThreshold = 10 * (window.displayPixelRatio || 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current mouse state. The properties of this state are updated when
|
* The current mouse state. The properties of this state are updated when
|
||||||
@@ -166,6 +166,7 @@ Guacamole.Mouse = function(element) {
|
|||||||
var last_touch_y = 0;
|
var last_touch_y = 0;
|
||||||
var last_touch_time = 0;
|
var last_touch_time = 0;
|
||||||
var pixels_moved = 0;
|
var pixels_moved = 0;
|
||||||
|
var touch_distance = 0;
|
||||||
|
|
||||||
var touch_buttons = {
|
var touch_buttons = {
|
||||||
1: "left",
|
1: "left",
|
||||||
@@ -262,6 +263,12 @@ Guacamole.Mouse = function(element) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (e.touches.length == 2) {
|
||||||
|
var diff_x = e.touches[0].screenX - e.touches[1].screenX;
|
||||||
|
var diff_y = e.touches[0].screenY - e.touches[1].screenY;
|
||||||
|
touch_distance = Math.sqrt(diff_x*diff_x + diff_y*diff_y);
|
||||||
|
}
|
||||||
|
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
element.addEventListener("touchmove", function(e) {
|
element.addEventListener("touchmove", function(e) {
|
||||||
@@ -305,11 +312,11 @@ Guacamole.Mouse = function(element) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, interpret as scrollwheel
|
// Interpret two-finger touch as scrollwheel
|
||||||
else {
|
else if (touch_count == 2) {
|
||||||
|
|
||||||
// If change in location passes threshold for scroll
|
// If change in location passes threshold for scroll
|
||||||
if (Math.abs(delta_y) >= guac_mouse.scrollThreshold) {
|
if (Math.abs(delta_y) >= touch_distance * guac_mouse.scrollThreshold) {
|
||||||
|
|
||||||
// Decide button based on Y movement direction
|
// Decide button based on Y movement direction
|
||||||
var button;
|
var button;
|
||||||
|
Reference in New Issue
Block a user