From 08efe327b67912e652fdfddda857e612a6a1e976 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Fri, 29 Jan 2021 16:32:46 +0100 Subject: [PATCH] [HTML5] Fix mouse_mode and fullscreen detection. The canvas_id is `#`-prefixed to work with emscripten as a CSS selector. When comparing to an event target ID (e.g. when checking if the canvas is fullscreen, or is locking the mouse) we need to skip the first char (the hash). --- platform/javascript/os_javascript.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 15b244d9e76..9b6942d930c 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -129,7 +129,7 @@ EM_BOOL OS_JavaScript::fullscreen_change_callback(int p_event_type, const Emscri OS_JavaScript *os = get_singleton(); // Empty ID is canvas. String target_id = String::utf8(p_event->id); - if (target_id.empty() || target_id == String::utf8(os->canvas_id)) { + if (target_id.empty() || target_id == String::utf8(&(os->canvas_id[1]))) { // This event property is the only reliable data on // browser fullscreen state. os->video_mode.fullscreen = p_event->isFullscreen; @@ -589,7 +589,7 @@ OS::MouseMode OS_JavaScript::get_mouse_mode() const { EmscriptenPointerlockChangeEvent ev; emscripten_get_pointerlock_status(&ev); - return (ev.isActive && String::utf8(ev.id) == String::utf8(canvas_id)) ? MOUSE_MODE_CAPTURED : MOUSE_MODE_VISIBLE; + return (ev.isActive && String::utf8(ev.id) == String::utf8(&canvas_id[1])) ? MOUSE_MODE_CAPTURED : MOUSE_MODE_VISIBLE; } // Wheel