You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by vn...@apache.org on 2018/10/03 17:34:46 UTC

[4/6] guacamole-client git commit: GUACAMOLE-232: Track whether keys were pressed implicitly. Automatically release all keys if only implicitly pressed keys remain.

GUACAMOLE-232: Track whether keys were pressed implicitly. Automatically release all keys if only implicitly pressed keys remain.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/3246458a
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/3246458a
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/3246458a

Branch: refs/heads/staging/1.0.0
Commit: 3246458a023f685693054303708bcaa13a5cdfbb
Parents: 6f0787f
Author: Michael Jumper <mj...@apache.org>
Authored: Tue Oct 2 22:42:58 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Tue Oct 2 22:42:58 2018 -0700

----------------------------------------------------------------------
 .../src/main/webapp/modules/Keyboard.js         | 48 +++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/3246458a/guacamole-common-js/src/main/webapp/modules/Keyboard.js
----------------------------------------------------------------------
diff --git a/guacamole-common-js/src/main/webapp/modules/Keyboard.js b/guacamole-common-js/src/main/webapp/modules/Keyboard.js
index a4ebe36..ea7edf4 100644
--- a/guacamole-common-js/src/main/webapp/modules/Keyboard.js
+++ b/guacamole-common-js/src/main/webapp/modules/Keyboard.js
@@ -616,6 +616,19 @@ Guacamole.Keyboard = function Keyboard(element) {
     this.pressed = {};
 
     /**
+     * The state of every key, indexed by keysym, for strictly those keys whose
+     * status has been indirectly determined thorugh observation of other key
+     * events. If a particular key is implicitly pressed, the value of
+     * implicitlyPressed for that keysym will be true. If a key
+     * is not currently implicitly pressed (the key is not pressed OR the state
+     * of the key is explicitly known), it will not be defined.
+     *
+     * @private
+     * @tyle {Object.<Number, Boolean>}
+     */
+    var implicitlyPressed = {};
+
+    /**
      * The last result of calling the onkeydown handler for each key, indexed
      * by keysym. This is used to prevent/allow default actions for key events,
      * even when the onkeydown handler cannot be called again because the key
@@ -851,6 +864,7 @@ Guacamole.Keyboard = function Keyboard(element) {
             
             // Mark key as released
             delete guac_keyboard.pressed[keysym];
+            delete implicitlyPressed[keysym];
 
             // Stop repeat
             window.clearTimeout(key_repeat_timeout);
@@ -953,7 +967,13 @@ Guacamole.Keyboard = function Keyboard(element) {
                     return;
             }
 
-            guac_keyboard.press(keysyms[0]);
+            // Press key and mark as implicitly pressed (if not already
+            // explicitly pressed)
+            var keysym = keysyms[0];
+            if (!guac_keyboard.pressed(keysym)) {
+                implicitlyPressed[keysym] = true;
+                guac_keyboard.press(keysym);
+            }
 
         }
 
@@ -1014,6 +1034,27 @@ Guacamole.Keyboard = function Keyboard(element) {
     };
 
     /**
+     * Returns whether all currently pressed keys were implicitly pressed. A
+     * key is implicitly pressed if its status was inferred indirectly from
+     * inspection of other key events.
+     *
+     * @private
+     * @returns {Boolean}
+     *     true of all currently pressed keys were implicitly pressed, false
+     *     otherwise.
+     */
+    var isStateImplicit = function isStateImplicit() {
+
+        for (var keysym in guac_keyboard.pressed) {
+            if (!implicitlyPressed[keysym])
+                return true;
+        }
+
+        return false;
+
+    };
+
+    /**
      * Reads through the event log, removing events from the head of the log
      * when the corresponding true key presses are known (or as known as they
      * can be).
@@ -1036,6 +1077,11 @@ Guacamole.Keyboard = function Keyboard(element) {
             handled_event = interpret_event();
         } while (handled_event !== null);
 
+        // Reset keyboard state if we cannot expect to receive any further
+        // keyup events
+        if (isStateImplicit())
+            guac_keyboard.reset();
+
         return last_event.defaultPrevented;
 
     }