From da62cb1afd3ecb3d306ee5478a76a622b2736140 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 4 Jul 2021 13:19:42 -0700 Subject: [PATCH] GUACAMOLE-724: Allow keyboard interaction with client notifications. --- .../client/directives/guacClientNotification.js | 17 +++++++++++++++++ .../app/index/controllers/indexController.js | 7 +++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/guacamole/src/main/frontend/src/app/client/directives/guacClientNotification.js b/guacamole/src/main/frontend/src/app/client/directives/guacClientNotification.js index 60c7595db..cae932ba3 100644 --- a/guacamole/src/main/frontend/src/app/client/directives/guacClientNotification.js +++ b/guacamole/src/main/frontend/src/app/client/directives/guacClientNotification.js @@ -407,6 +407,23 @@ angular.module('client').directive('guacClientNotification', [function guacClien }); + /** + * Prevents the default behavior of the given AngularJS event if a + * notification is currently shown and the client is focused. + * + * @param {event} e + * The AngularJS event to selectively prevent. + */ + var preventDefaultDuringNotification = function preventDefaultDuringNotification(e) { + if ($scope.status && $scope.client.clientProperties.focused) + e.preventDefault(); + }; + + // Block internal handling of key events (by the client) if a + // notification is visible + $scope.$on('guacBeforeKeydown', preventDefaultDuringNotification); + $scope.$on('guacBeforeKeyup', preventDefaultDuringNotification); + }]; return directive; diff --git a/guacamole/src/main/frontend/src/app/index/controllers/indexController.js b/guacamole/src/main/frontend/src/app/index/controllers/indexController.js index 1ed49b7a8..5f7e70211 100644 --- a/guacamole/src/main/frontend/src/app/index/controllers/indexController.js +++ b/guacamole/src/main/frontend/src/app/index/controllers/indexController.js @@ -163,9 +163,8 @@ angular.module('index').controller('indexController', ['$scope', '$injector', // Broadcast keydown events keyboard.onkeydown = function onkeydown(keysym) { - // Do not handle key events if not logged in or if a notification is - // shown - if ($scope.applicationState !== ApplicationState.READY || guacNotification.getStatus()) + // Do not handle key events if not logged in + if ($scope.applicationState !== ApplicationState.READY) return true; // Warn of pending keydown @@ -184,7 +183,7 @@ angular.module('index').controller('indexController', ['$scope', '$injector', // Do not handle key events if not logged in or if a notification is // shown - if ($scope.applicationState !== ApplicationState.READY || guacNotification.getStatus()) + if ($scope.applicationState !== ApplicationState.READY) return; // Warn of pending keyup