diff options
-rw-r--r-- | platform/javascript/display_server_javascript.cpp | 22 | ||||
-rw-r--r-- | platform/javascript/display_server_javascript.h | 3 | ||||
-rw-r--r-- | platform/javascript/godot_js.h | 1 | ||||
-rw-r--r-- | platform/javascript/js/libs/library_godot_display.js | 14 |
4 files changed, 22 insertions, 18 deletions
diff --git a/platform/javascript/display_server_javascript.cpp b/platform/javascript/display_server_javascript.cpp index c00a1cd57b..04f3a3cbca 100644 --- a/platform/javascript/display_server_javascript.cpp +++ b/platform/javascript/display_server_javascript.cpp @@ -62,20 +62,13 @@ bool DisplayServerJavaScript::check_size_force_redraw() { return godot_js_display_size_update() != 0; } -EM_BOOL DisplayServerJavaScript::fullscreen_change_callback(int p_event_type, const EmscriptenFullscreenChangeEvent *p_event, void *p_user_data) { +void DisplayServerJavaScript::fullscreen_change_callback(int p_fullscreen) { DisplayServerJavaScript *display = get_singleton(); - // Empty ID is canvas. - String target_id = String::utf8(p_event->id); - if (target_id.is_empty() || target_id == String::utf8(&(display->canvas_id[1]))) { - // This event property is the only reliable data on - // browser fullscreen state. - if (p_event->isFullscreen) { - display->window_mode = WINDOW_MODE_FULLSCREEN; - } else { - display->window_mode = WINDOW_MODE_WINDOWED; - } + if (p_fullscreen) { + display->window_mode = WINDOW_MODE_FULLSCREEN; + } else { + display->window_mode = WINDOW_MODE_WINDOWED; } - return false; } // Drag and drop callback. @@ -736,7 +729,6 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive // These callbacks from Emscripten's html5.h suffice to access most // JavaScript APIs. SET_EM_WINDOW_CALLBACK(blur, blur_callback) - SET_EM_CALLBACK(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, fullscreenchange, fullscreen_change_callback) #undef SET_EM_CALLBACK #undef EM_CHECK @@ -745,9 +737,7 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive godot_js_display_mouse_wheel_cb(&DisplayServerJavaScript::mouse_wheel_callback); godot_js_display_touch_cb(&DisplayServerJavaScript::touch_callback, touch_event.identifier, touch_event.coords); godot_js_display_key_cb(&DisplayServerJavaScript::key_callback, key_event.code, key_event.key); - - // For APIs that are not (sufficiently) exposed, a - // library is used below (implemented in library_godot_display.js). + godot_js_display_fullscreen_cb(&DisplayServerJavaScript::fullscreen_change_callback); godot_js_display_notification_cb(&send_window_event_callback, WINDOW_EVENT_MOUSE_ENTER, WINDOW_EVENT_MOUSE_EXIT, diff --git a/platform/javascript/display_server_javascript.h b/platform/javascript/display_server_javascript.h index 4e2da4e96d..8294f019e5 100644 --- a/platform/javascript/display_server_javascript.h +++ b/platform/javascript/display_server_javascript.h @@ -78,8 +78,7 @@ private: static const char *godot2dom_cursor(DisplayServer::CursorShape p_shape); // events - static EM_BOOL fullscreen_change_callback(int p_event_type, const EmscriptenFullscreenChangeEvent *p_event, void *p_user_data); - + static void fullscreen_change_callback(int p_fullscreen); static int mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers); static void mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers); static int mouse_wheel_callback(double p_delta_x, double p_delta_y); diff --git a/platform/javascript/godot_js.h b/platform/javascript/godot_js.h index 512349180f..32e168da96 100644 --- a/platform/javascript/godot_js.h +++ b/platform/javascript/godot_js.h @@ -94,6 +94,7 @@ extern void godot_js_display_mouse_move_cb(void (*p_callback)(double p_x, double extern void godot_js_display_mouse_wheel_cb(int (*p_callback)(double p_delta_x, double p_delta_y)); extern void godot_js_display_touch_cb(void (*p_callback)(int p_type, int p_count), uint32_t *r_identifiers, double *r_coords); extern void godot_js_display_key_cb(void (*p_callback)(int p_type, int p_repeat, int p_modifiers), char r_code[32], char r_key[32]); +extern void godot_js_display_fullscreen_cb(void (*p_callback)(int p_fullscreen)); extern void godot_js_display_notification_cb(void (*p_callback)(int p_notification), int p_enter, int p_exit, int p_in, int p_out); extern void godot_js_display_paste_cb(void (*p_callback)(const char *p_text)); extern void godot_js_display_drop_files_cb(void (*p_callback)(char **p_filev, int p_filec)); diff --git a/platform/javascript/js/libs/library_godot_display.js b/platform/javascript/js/libs/library_godot_display.js index 0ad52a690f..435e5d89c8 100644 --- a/platform/javascript/js/libs/library_godot_display.js +++ b/platform/javascript/js/libs/library_godot_display.js @@ -853,6 +853,20 @@ const GodotDisplay = { /* * Listeners */ + godot_js_display_fullscreen_cb__sig: 'vi', + godot_js_display_fullscreen_cb: function (callback) { + const canvas = GodotConfig.canvas; + const func = GodotRuntime.get_func(callback); + function change_cb(evt) { + if (evt.target === canvas) { + func(GodotDisplayScreen.isFullscreen()); + } + } + GodotDisplayListeners.add(document, 'fullscreenchange', change_cb, false); + GodotDisplayListeners.add(document, 'mozfullscreenchange', change_cb, false); + GodotDisplayListeners.add(document, 'webkitfullscreenchange', change_cb, false); + }, + godot_js_display_notification_cb__sig: 'viiiii', godot_js_display_notification_cb: function (callback, p_enter, p_exit, p_in, p_out) { const canvas = GodotConfig.canvas; |