From 8c6e1a1df588c4edffc4cf346746c1f940566637 Mon Sep 17 00:00:00 2001 From: Corentin SORIANO Date: Mon, 2 Jun 2025 18:15:06 +0200 Subject: [PATCH] GUACAMOLE-2079: Fix keyboard lock/unlock in fullscreen mode. --- .../src/app/client/services/guacFullscreen.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/guacamole/src/main/frontend/src/app/client/services/guacFullscreen.js b/guacamole/src/main/frontend/src/app/client/services/guacFullscreen.js index 12720e936..cf04b397a 100644 --- a/guacamole/src/main/frontend/src/app/client/services/guacFullscreen.js +++ b/guacamole/src/main/frontend/src/app/client/services/guacFullscreen.js @@ -36,9 +36,9 @@ angular.module('client').factory('guacFullscreen', ['$injector', service.setFullscreenMode = function setFullscreenMode(state) { if (document.fullscreenEnabled) { if (state && !service.isInFullscreenMode()) - document.documentElement.requestFullscreen().then(navigator.keyboard.lock()); + document.documentElement.requestFullscreen(); else if (!state && service.isInFullscreenMode()) - document.exitFullscreen().then(navigator.keyboard.unlock()); + document.exitFullscreen(); } } @@ -50,6 +50,19 @@ angular.module('client').factory('guacFullscreen', ['$injector', service.setFullscreenMode(false); } + // If the browser supports keyboard lock, lock the keyboard when entering + // fullscreen mode and unlock it when exiting fullscreen mode. + if (navigator.keyboard?.lock) { + document.addEventListener('fullscreenchange', () => { + if (document.fullscreenElement) { + navigator.keyboard.lock(); + return; + } + + navigator.keyboard.unlock(); + }); + } + return service; -}]); \ No newline at end of file +}]);