bbennett-ks commented on code in PR #1164:
URL: https://github.com/apache/guacamole-client/pull/1164#discussion_r2814580227


##########
guacamole-common-js/src/main/webapp/modules/Keyboard.js:
##########
@@ -1379,6 +1508,62 @@ Guacamole.Keyboard = function Keyboard(element) {
 
         }, true);
 
+        /**
+         * Handles non-keyboard events, resynchronizing lock states
+         * based on modifier flags.
+         *
+         * @private
+         * @param {!Event} e
+         *     The event to handle.
+         */
+        var handleModifierSync = function handleModifierSync(e) {
+
+            // Only intercept if handler set
+            if (!guac_keyboard.onkeydown && !guac_keyboard.onkeyup) return;
+
+            // Ignore events which have already been handled
+            if (!markEvent(e)) return;
+
+            // Only sync if modifier state is available
+            if (!e.getModifierState) return;
+
+            // Resync lock states based modifier flags
+            var modifierState = 
Guacamole.Keyboard.ModifierState.fromKeyboardEvent(e);
+
+            updateToggleModifierState('capsLock', [
+                capsLockKeysym
+            ], {
+                modifiers: modifierState,
+                keysym: null,
+                eventType: e.type
+            });
+
+            updateToggleModifierState('numLock', [
+                numLockKeysym
+            ], {
+                modifiers: modifierState,
+                keysym: null,
+                eventType: e.type
+            });
+
+            updateToggleModifierState('scrollLock', [
+                scrollLockKeysym
+            ], {
+                modifiers: modifierState,
+                keysym: null,
+                eventType: e.type
+            });
+
+        };
+
+        // Resync lock states on mouse/touch events which may reflect lock 
flags
+        element.addEventListener("mousedown", handleModifierSync, true);
+        element.addEventListener("mouseup", handleModifierSync, true);
+        element.addEventListener("pointerdown", handleModifierSync, true);
+        element.addEventListener("pointerup", handleModifierSync, true);
+        element.addEventListener("touchstart", handleModifierSync, true);
+        element.addEventListener("touchend", handleModifierSync, true);

Review Comment:
   I can add a few short circuits to **handleModifierSync** to tighten it up. 
If I understand you correctly, I don't think an approach like 
**handleMouseEvent** would be useful in this case. This is a "catch all" to 
sync the modifier flags regardless if any modifier events are pending.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to