mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
GUACAMOLE-1204: Automatically pass through Guacamole touch events if remote multi-touch is supported.
This commit is contained in:
@@ -119,6 +119,14 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
*/
|
*/
|
||||||
var touchPad = new Guacamole.Mouse.Touchpad(displayContainer);
|
var touchPad = new Guacamole.Mouse.Touchpad(displayContainer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guacamole touch event handling object, wrapped around the main
|
||||||
|
* client dislay.
|
||||||
|
*
|
||||||
|
* @type Guacamole.Touch
|
||||||
|
*/
|
||||||
|
var touch = new Guacamole.Touch(displayContainer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the scale of the attached Guacamole.Client based on current window
|
* Updates the scale of the attached Guacamole.Client based on current window
|
||||||
* size and "auto-fit" setting.
|
* size and "auto-fit" setting.
|
||||||
@@ -232,6 +240,27 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles a touch event originating from the user's device.
|
||||||
|
*
|
||||||
|
* @param {Guacamole.Touch.Event} touchEvent
|
||||||
|
* The touch event.
|
||||||
|
*/
|
||||||
|
var handleTouchEvent = function handleTouchEvent(event) {
|
||||||
|
|
||||||
|
// Do not attempt to handle touch state changes if the client
|
||||||
|
// or display are not yet available
|
||||||
|
if (!client || !display)
|
||||||
|
return;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
// Send touch state, hiding local cursor
|
||||||
|
display.showCursor(false);
|
||||||
|
client.sendTouchState(event.state, true);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
// Attach any given managed client
|
// Attach any given managed client
|
||||||
$scope.$watch('client', function attachManagedClient(managedClient) {
|
$scope.$watch('client', function attachManagedClient(managedClient) {
|
||||||
|
|
||||||
@@ -287,39 +316,42 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
localCursor = mouse.setCursor(cursor.canvas, cursor.x, cursor.y);
|
localCursor = mouse.setCursor(cursor.canvas, cursor.x, cursor.y);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Swap mouse emulation modes depending on absolute mode flag
|
// Update touch event handling depending on remote multi-touch
|
||||||
$scope.$watch('client.clientProperties.emulateAbsoluteMouse',
|
// support and mouse emulation mode
|
||||||
function mouseEmulationModeChanged(emulateAbsoluteMouse) {
|
$scope.$watchGroup([
|
||||||
|
'client.multiTouchSupport',
|
||||||
|
'client.clientProperties.emulateAbsoluteMouse'
|
||||||
|
], function touchBehaviorChanged(emulateAbsoluteMouse) {
|
||||||
|
|
||||||
var newMode, oldMode;
|
// Clear existing event handling
|
||||||
|
touch.offEach(['touchstart', 'touchmove', 'touchend'], handleTouchEvent);
|
||||||
|
|
||||||
// Switch to touchscreen if absolute
|
touchScreen.onmousedown =
|
||||||
if (emulateAbsoluteMouse) {
|
touchScreen.onmouseup =
|
||||||
newMode = touchScreen;
|
touchScreen.onmousemove = null;
|
||||||
oldMode = touchPad;
|
|
||||||
|
touchPad.onmousedown =
|
||||||
|
touchPad.onmouseup =
|
||||||
|
touchPad.onmousemove = null;
|
||||||
|
|
||||||
|
// Directly forward local touch events
|
||||||
|
if ($scope.client.multiTouchSupport)
|
||||||
|
touch.onEach(['touchstart', 'touchmove', 'touchend'], handleTouchEvent);
|
||||||
|
|
||||||
|
// Switch to touchscreen if mouse emulation is required and
|
||||||
|
// absolute mouse emulation is preferred
|
||||||
|
else if ($scope.client.clientProperties.emulateAbsoluteMouse) {
|
||||||
|
touchScreen.onmousedown =
|
||||||
|
touchScreen.onmouseup =
|
||||||
|
touchScreen.onmousemove = handleEmulatedMouseState;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch to touchpad if not absolute (relative)
|
// Use touchpad for mouse emulation if absolute mouse emulation
|
||||||
|
// is not preferred
|
||||||
else {
|
else {
|
||||||
newMode = touchPad;
|
touchPad.onmousedown =
|
||||||
oldMode = touchScreen;
|
touchPad.onmouseup =
|
||||||
}
|
touchPad.onmousemove = handleEmulatedMouseState;
|
||||||
|
|
||||||
// Set applicable mouse emulation object, unset the old one
|
|
||||||
if (newMode) {
|
|
||||||
|
|
||||||
// Clear old handlers and copy state to new emulation mode
|
|
||||||
if (oldMode) {
|
|
||||||
oldMode.onmousedown = oldMode.onmouseup = oldMode.onmousemove = null;
|
|
||||||
newMode.currentState.x = oldMode.currentState.x;
|
|
||||||
newMode.currentState.y = oldMode.currentState.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle emulated events only from the new emulation mode
|
|
||||||
newMode.onmousedown =
|
|
||||||
newMode.onmouseup =
|
|
||||||
newMode.onmousemove = handleEmulatedMouseState;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -155,7 +155,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Mouse mode -->
|
<!-- Mouse mode -->
|
||||||
<div class="menu-section" id="mouse-settings">
|
<div class="menu-section" id="mouse-settings" ng-hide="client.multiTouchSupport">
|
||||||
<h3>{{'CLIENT.SECTION_HEADER_MOUSE_MODE' | translate}}</h3>
|
<h3>{{'CLIENT.SECTION_HEADER_MOUSE_MODE' | translate}}</h3>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<p class="description">{{'CLIENT.HELP_MOUSE_MODE' | translate}}</p>
|
<p class="description">{{'CLIENT.HELP_MOUSE_MODE' | translate}}</p>
|
||||||
|
@@ -203,6 +203,15 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
|
|||||||
*/
|
*/
|
||||||
this.shareLinks = template.shareLinks || {};
|
this.shareLinks = template.shareLinks || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of simultaneous touch contacts supported by the remote
|
||||||
|
* desktop. Unless explicitly declared otherwise by the remote desktop
|
||||||
|
* after connecting, this will be 0 (multi-touch unsupported).
|
||||||
|
*
|
||||||
|
* @type Number
|
||||||
|
*/
|
||||||
|
this.multiTouchSupport = template.multiTouchSupport || 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current state of the Guacamole client (idle, connecting,
|
* The current state of the Guacamole client (idle, connecting,
|
||||||
* connected, terminated with error, etc.).
|
* connected, terminated with error, etc.).
|
||||||
@@ -578,6 +587,11 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Update level of multi-touch support when known
|
||||||
|
client.onmultitouch = function multiTouchSupportDeclared(layer, touches) {
|
||||||
|
managedClient.multiTouchSupport = touches;
|
||||||
|
};
|
||||||
|
|
||||||
// Update title when a "name" instruction is received
|
// Update title when a "name" instruction is received
|
||||||
client.onname = function clientNameReceived(name) {
|
client.onname = function clientNameReceived(name) {
|
||||||
$rootScope.$apply(function updateClientTitle() {
|
$rootScope.$apply(function updateClientTitle() {
|
||||||
|
Reference in New Issue
Block a user