mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-232: Automatically press modifiers if remote state does not match local state.
This commit is contained in:
@@ -852,6 +852,37 @@ Guacamole.Keyboard = function(element) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given the remote and local state of a particular key, resynchronizes the
|
||||||
|
* remote state of that key with the local state through pressing or
|
||||||
|
* releasing keysyms.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Boolean} remoteState
|
||||||
|
* Whether the key is currently pressed remotely.
|
||||||
|
*
|
||||||
|
* @param {Boolean} localState
|
||||||
|
* Whether the key is currently pressed remotely locally. If the state
|
||||||
|
* of the key is not known, this may be undefined.
|
||||||
|
*
|
||||||
|
* @param {Number[]} keysyms
|
||||||
|
* The keysyms which represent the key being updated.
|
||||||
|
*/
|
||||||
|
var updateModifierState = function updateModifierState(remoteState, localState, keysyms) {
|
||||||
|
|
||||||
|
// Release all related keys if modifier is implicitly released
|
||||||
|
if (remoteState && localState === false) {
|
||||||
|
for (var i = 0; i < keysyms.length; i++) {
|
||||||
|
guac_keyboard.release(keysyms[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Press if modifier is implicitly pressed
|
||||||
|
else if (!remoteState && localState)
|
||||||
|
guac_keyboard.press(keysyms[0]);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a keyboard event, updates the local modifier state and remote
|
* Given a keyboard event, updates the local modifier state and remote
|
||||||
* key state based on the modifier flags within the event. This function
|
* key state based on the modifier flags within the event. This function
|
||||||
@@ -861,41 +892,41 @@ Guacamole.Keyboard = function(element) {
|
|||||||
* @param {KeyboardEvent} e
|
* @param {KeyboardEvent} e
|
||||||
* The keyboard event containing the flags to update.
|
* The keyboard event containing the flags to update.
|
||||||
*/
|
*/
|
||||||
var update_modifier_state = function update_modifier_state(e) {
|
var syncModifierStates = function syncModifierStates(e) {
|
||||||
|
|
||||||
// Get state
|
// Get state
|
||||||
var state = Guacamole.Keyboard.ModifierState.fromKeyboardEvent(e);
|
var state = Guacamole.Keyboard.ModifierState.fromKeyboardEvent(e);
|
||||||
|
|
||||||
// Release alt if implicitly released
|
// Resync state of alt
|
||||||
if (guac_keyboard.modifiers.alt && state.alt === false) {
|
updateModifierState(guac_keyboard.modifiers.alt, state.alt, [
|
||||||
guac_keyboard.release(0xFFE9); // Left alt
|
0xFFE9, // Left alt
|
||||||
guac_keyboard.release(0xFFEA); // Right alt
|
0xFFEA, // Right alt
|
||||||
guac_keyboard.release(0xFE03); // AltGr
|
0xFE03 // AltGr
|
||||||
}
|
]);
|
||||||
|
|
||||||
// Release shift if implicitly released
|
// Resync state of shift
|
||||||
if (guac_keyboard.modifiers.shift && state.shift === false) {
|
updateModifierState(guac_keyboard.modifiers.shift, state.shift, [
|
||||||
guac_keyboard.release(0xFFE1); // Left shift
|
0xFFE1, // Left shift
|
||||||
guac_keyboard.release(0xFFE2); // Right shift
|
0xFFE2 // Right shift
|
||||||
}
|
]);
|
||||||
|
|
||||||
// Release ctrl if implicitly released
|
// Resync state of ctrl
|
||||||
if (guac_keyboard.modifiers.ctrl && state.ctrl === false) {
|
updateModifierState(guac_keyboard.modifiers.ctrl, state.ctrl, [
|
||||||
guac_keyboard.release(0xFFE3); // Left ctrl
|
0xFFE3, // Left ctrl
|
||||||
guac_keyboard.release(0xFFE4); // Right ctrl
|
0xFFE4 // Right ctrl
|
||||||
}
|
]);
|
||||||
|
|
||||||
// Release meta if implicitly released
|
// Resync state of meta
|
||||||
if (guac_keyboard.modifiers.meta && state.meta === false) {
|
updateModifierState(guac_keyboard.modifiers.meta, state.meta, [
|
||||||
guac_keyboard.release(0xFFE7); // Left meta
|
0xFFE7, // Left meta
|
||||||
guac_keyboard.release(0xFFE8); // Right meta
|
0xFFE8 // Right meta
|
||||||
}
|
]);
|
||||||
|
|
||||||
// Release hyper if implicitly released
|
// Resync state of hyper
|
||||||
if (guac_keyboard.modifiers.hyper && state.hyper === false) {
|
updateModifierState(guac_keyboard.modifiers.hyper, state.hyper, [
|
||||||
guac_keyboard.release(0xFFEB); // Left hyper
|
0xFFEB, // Left hyper
|
||||||
guac_keyboard.release(0xFFEC); // Right hyper
|
0xFFEC // Right hyper
|
||||||
}
|
]);
|
||||||
|
|
||||||
// Update state
|
// Update state
|
||||||
guac_keyboard.modifiers = state;
|
guac_keyboard.modifiers = state;
|
||||||
@@ -1101,7 +1132,7 @@ Guacamole.Keyboard = function(element) {
|
|||||||
else if (e.which) keyCode = e.which;
|
else if (e.which) keyCode = e.which;
|
||||||
|
|
||||||
// Fix modifier states
|
// Fix modifier states
|
||||||
update_modifier_state(e);
|
syncModifierStates(e);
|
||||||
|
|
||||||
// Ignore (but do not prevent) the "composition" keycode sent by some
|
// Ignore (but do not prevent) the "composition" keycode sent by some
|
||||||
// browsers when an IME is in use (see: http://lists.w3.org/Archives/Public/www-dom/2010JulSep/att-0182/keyCode-spec.html)
|
// browsers when an IME is in use (see: http://lists.w3.org/Archives/Public/www-dom/2010JulSep/att-0182/keyCode-spec.html)
|
||||||
@@ -1129,7 +1160,7 @@ Guacamole.Keyboard = function(element) {
|
|||||||
else if (e.which) charCode = e.which;
|
else if (e.which) charCode = e.which;
|
||||||
|
|
||||||
// Fix modifier states
|
// Fix modifier states
|
||||||
update_modifier_state(e);
|
syncModifierStates(e);
|
||||||
|
|
||||||
// Log event
|
// Log event
|
||||||
var keypressEvent = new KeypressEvent(charCode);
|
var keypressEvent = new KeypressEvent(charCode);
|
||||||
@@ -1154,7 +1185,7 @@ Guacamole.Keyboard = function(element) {
|
|||||||
else if (e.which) keyCode = e.which;
|
else if (e.which) keyCode = e.which;
|
||||||
|
|
||||||
// Fix modifier states
|
// Fix modifier states
|
||||||
update_modifier_state(e);
|
syncModifierStates(e);
|
||||||
|
|
||||||
// Log event, call for interpretation
|
// Log event, call for interpretation
|
||||||
var keyupEvent = new KeyupEvent(keyCode, e.keyIdentifier, e.key, getEventLocation(e));
|
var keyupEvent = new KeyupEvent(keyCode, e.keyIdentifier, e.key, getEventLocation(e));
|
||||||
|
Reference in New Issue
Block a user