mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 09:03:21 +00:00 
			
		
		
		
	Implement right and middle-click.
This commit is contained in:
		| @@ -143,28 +143,38 @@ Guacamole.Mouse = function(element) { | |||||||
|  |  | ||||||
|     }, false); |     }, false); | ||||||
|  |  | ||||||
|  |     var touch_count = 0; | ||||||
|     var last_touch_x = 0; |     var last_touch_x = 0; | ||||||
|     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_buttons = { | ||||||
|  |         1: "left", | ||||||
|  |         2: "right", | ||||||
|  |         3: "middle" | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     var gesture_in_progress = false; |     var gesture_in_progress = false; | ||||||
|     var click_release_timeout = null; |     var click_release_timeout = null; | ||||||
|  |  | ||||||
|     element.addEventListener("touchend", function(e) { |     element.addEventListener("touchend", function(e) { | ||||||
|          |          | ||||||
|         // If we're handling a gesture |         // If we're handling a gesture AND this is the last touch | ||||||
|         if (gesture_in_progress) { |         if (gesture_in_progress && e.touches.length == 1) { | ||||||
|              |              | ||||||
|             cancelEvent(e); |             cancelEvent(e); | ||||||
|              |              | ||||||
|             var time = new Date().getTime(); |             var time = new Date().getTime(); | ||||||
|  |  | ||||||
|             // If mouse already down, release anad clear timeout |             // Get corresponding mouse button | ||||||
|             if (guac_mouse.currentState.left) { |             var button = touch_buttons[touch_count]; | ||||||
|  |  | ||||||
|                 // Fire left button up event |             // If mouse already down, release anad clear timeout | ||||||
|                 guac_mouse.currentState.left = false; |             if (guac_mouse.currentState[button]) { | ||||||
|  |  | ||||||
|  |                 // Fire button up event | ||||||
|  |                 guac_mouse.currentState[button] = false; | ||||||
|                 if (guac_mouse.onmouseup) |                 if (guac_mouse.onmouseup) | ||||||
|                     guac_mouse.onmouseup(guac_mouse.currentState); |                     guac_mouse.onmouseup(guac_mouse.currentState); | ||||||
|  |  | ||||||
| @@ -179,8 +189,8 @@ Guacamole.Mouse = function(element) { | |||||||
|             // If single tap detected (based on time and distance) |             // If single tap detected (based on time and distance) | ||||||
|             if (time - last_touch_time <= 250 && pixels_moved < 10) { |             if (time - last_touch_time <= 250 && pixels_moved < 10) { | ||||||
|  |  | ||||||
|                 // Fire left button down event |                 // Fire button down event | ||||||
|                 guac_mouse.currentState.left = true; |                 guac_mouse.currentState[button] = true; | ||||||
|                 if (guac_mouse.onmousedown) |                 if (guac_mouse.onmousedown) | ||||||
|                     guac_mouse.onmousedown(guac_mouse.currentState); |                     guac_mouse.onmousedown(guac_mouse.currentState); | ||||||
|  |  | ||||||
| @@ -188,8 +198,8 @@ Guacamole.Mouse = function(element) { | |||||||
|                 // touchstart within timeout. |                 // touchstart within timeout. | ||||||
|                 click_release_timeout = window.setTimeout(function() { |                 click_release_timeout = window.setTimeout(function() { | ||||||
|                      |                      | ||||||
|                     // Fire left button up event |                     // Fire button up event | ||||||
|                     guac_mouse.currentState.left = false; |                     guac_mouse.currentState[button] = false; | ||||||
|                     if (guac_mouse.onmouseup) |                     if (guac_mouse.onmouseup) | ||||||
|                         guac_mouse.onmouseup(guac_mouse.currentState); |                         guac_mouse.onmouseup(guac_mouse.currentState); | ||||||
|                      |                      | ||||||
| @@ -206,7 +216,10 @@ Guacamole.Mouse = function(element) { | |||||||
|  |  | ||||||
|     element.addEventListener("touchstart", function(e) { |     element.addEventListener("touchstart", function(e) { | ||||||
|  |  | ||||||
|         // Record initial touch location and time for single-touch movement |         // Track number of touches, but no more than three | ||||||
|  |         touch_count = Math.max(e.touches.length, 3); | ||||||
|  |  | ||||||
|  |         // Record initial touch location and time for touch movement | ||||||
|         // and tap gestures |         // and tap gestures | ||||||
|         if (e.touches.length == 1) { |         if (e.touches.length == 1) { | ||||||
|  |  | ||||||
| @@ -228,17 +241,12 @@ Guacamole.Mouse = function(element) { | |||||||
|             last_touch_time = new Date().getTime(); |             last_touch_time = new Date().getTime(); | ||||||
|             pixels_moved = 0; |             pixels_moved = 0; | ||||||
|  |  | ||||||
|             // TODO: Handle different buttons |  | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|     }, false); |     }, false); | ||||||
|  |  | ||||||
|     element.addEventListener("touchmove", function(e) { |     element.addEventListener("touchmove", function(e) { | ||||||
|  |  | ||||||
|         // Handle single-touch movement gesture (touchpad mouse move) |  | ||||||
|         if (e.touches.length == 1) { |  | ||||||
|  |  | ||||||
|         cancelEvent(e); |         cancelEvent(e); | ||||||
|  |  | ||||||
|         // Get change in touch location |         // Get change in touch location | ||||||
| @@ -273,8 +281,6 @@ Guacamole.Mouse = function(element) { | |||||||
|         last_touch_x = touch.screenX; |         last_touch_x = touch.screenX; | ||||||
|         last_touch_y = touch.screenY; |         last_touch_y = touch.screenY; | ||||||
|  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|     }, false); |     }, false); | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user