summaryrefslogtreecommitdiff
path: root/platform/javascript/js/libs/library_godot_display.js
diff options
context:
space:
mode:
Diffstat (limited to 'platform/javascript/js/libs/library_godot_display.js')
-rw-r--r--platform/javascript/js/libs/library_godot_display.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/platform/javascript/js/libs/library_godot_display.js b/platform/javascript/js/libs/library_godot_display.js
index a254c92d4d..fa129f0e56 100644
--- a/platform/javascript/js/libs/library_godot_display.js
+++ b/platform/javascript/js/libs/library_godot_display.js
@@ -376,6 +376,20 @@ const GodotDisplayCursor = {
delete GodotDisplayCursor.cursors[key];
});
},
+ lockPointer: function () {
+ const canvas = GodotConfig.canvas;
+ if (canvas.requestPointerLock) {
+ canvas.requestPointerLock();
+ }
+ },
+ releasePointer: function () {
+ if (document.exitPointerLock) {
+ document.exitPointerLock();
+ }
+ },
+ isPointerLocked: function () {
+ return document.pointerLockElement === GodotConfig.canvas;
+ },
},
};
mergeInto(LibraryManager.library, GodotDisplayCursor);
@@ -850,6 +864,20 @@ const GodotDisplay = {
}
},
+ godot_js_display_cursor_lock_set__sig: 'vi',
+ godot_js_display_cursor_lock_set: function (p_lock) {
+ if (p_lock) {
+ GodotDisplayCursor.lockPointer();
+ } else {
+ GodotDisplayCursor.releasePointer();
+ }
+ },
+
+ godot_js_display_cursor_is_locked__sig: 'i',
+ godot_js_display_cursor_is_locked: function () {
+ return GodotDisplayCursor.isPointerLocked() ? 1 : 0;
+ },
+
/*
* Listeners
*/