From ebb36a03c6e79127de48b904a833048bb4859fc1 Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Thu, 11 Jan 2024 20:01:31 +0000 Subject: [PATCH] GUACAMOLE-1904: Allow a custom field to request keyboard access when menu is closed. --- .../client/controllers/clientController.js | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/guacamole/src/main/frontend/src/app/client/controllers/clientController.js b/guacamole/src/main/frontend/src/app/client/controllers/clientController.js index e20373e37b..7507d62b79 100644 --- a/guacamole/src/main/frontend/src/app/client/controllers/clientController.js +++ b/guacamole/src/main/frontend/src/app/client/controllers/clientController.js @@ -139,6 +139,21 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams }; + /** + * True if and only if a "guacFieldFocused" event was received, and a + * corresponding "guacFieldBlurred" event has not yet been received. + * This is intended to allow fields to receive keyboard input even when + * the menu is not being shown. + * + * @type {boolean} + */ + $scope.fieldIsFocused = false; + + // Enable and disable the custom field focused state as the relevant + // events are received + $scope.$on('guacFieldFocused', () => $scope.fieldIsFocused = true); + $scope.$on('guacFieldBlurred', () => $scope.fieldIsFocused = false); + // Convenience method for closing the menu $scope.closeMenu = function closeMenu() { $scope.menu.shown = false; @@ -468,7 +483,7 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams else if (menuShownPreviousState) $scope.applyParameterChanges($scope.focusedClient); - /* Broadcast changes to the menu display state */ + // Broadcast changes to the menu display state $scope.$broadcast('guacMenuShown', menuShown); }); @@ -610,15 +625,17 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams } - // Prevent all keydown events while menu is open - else if ($scope.menu.shown) + // Prevent all keydown events while menu is open, or if a field has + // explicity requested the focused state + else if ($scope.menu.shown || $scope.fieldIsFocused) event.preventDefault(); }); - // Prevent all keyup events while menu is open + // Prevent all keyup events while menu is open, + // or while a custom field is focused. $scope.$on('guacBeforeKeyup', function incomingKeyup(event, keysym, keyboard) { - if ($scope.menu.shown) + if ($scope.menu.shown || $scope.fieldIsFocused) event.preventDefault(); });