GUACAMOLE-2079: Fix keyboard lock/unlock in fullscreen mode.

This commit is contained in:
Corentin SORIANO committed 2025-06-02 18:15:06 +02:00
1 parent 42473ad2c3
commit 8c6e1a1df5
1 file changed
+16 -3
@@ -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;
}]);
}]);