1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-08 12:40:44 +00:00

[HTML5] Implement window blur in JS library.

Removes more emscripten HTML5 library dependencies.
This commit is contained in:
Fabio Alessandrelli
2021-10-05 13:10:47 +02:00
parent ac78e7f940
commit 89c6aaa96d
4 changed files with 12 additions and 20 deletions

View File

@@ -95,6 +95,7 @@ extern void godot_js_display_mouse_wheel_cb(int (*p_callback)(double p_delta_x,
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_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_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_fullscreen_cb(void (*p_callback)(int p_fullscreen));
extern void godot_js_display_window_blur_cb(void (*p_callback)());
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_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_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)); extern void godot_js_display_drop_files_cb(void (*p_callback)(char **p_filev, int p_filec));

View File

@@ -867,6 +867,14 @@ const GodotDisplay = {
GodotDisplayListeners.add(document, 'webkitfullscreenchange', change_cb, false); GodotDisplayListeners.add(document, 'webkitfullscreenchange', change_cb, false);
}, },
godot_js_display_window_blur_cb__sig: 'vi',
godot_js_display_window_blur_cb: function (callback) {
const func = GodotRuntime.get_func(callback);
GodotDisplayListeners.add(window, 'blur', function () {
func();
}, false);
},
godot_js_display_notification_cb__sig: 'viiiii', godot_js_display_notification_cb__sig: 'viiiii',
godot_js_display_notification_cb: function (callback, p_enter, p_exit, p_in, p_out) { godot_js_display_notification_cb: function (callback, p_enter, p_exit, p_in, p_out) {
const canvas = GodotConfig.canvas; const canvas = GodotConfig.canvas;

View File

@@ -108,9 +108,8 @@ void OS_JavaScript::fullscreen_change_callback(int p_fullscreen) {
} }
} }
EM_BOOL OS_JavaScript::blur_callback(int p_event_type, const EmscriptenFocusEvent *p_event, void *p_user_data) { void OS_JavaScript::window_blur_callback() {
get_singleton()->input->release_pressed_events(); get_singleton()->input->release_pressed_events();
return false;
} }
void OS_JavaScript::set_video_mode(const VideoMode &p_video_mode, int p_screen) { void OS_JavaScript::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
@@ -803,28 +802,13 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
#endif #endif
input = memnew(InputDefault); input = memnew(InputDefault);
EMSCRIPTEN_RESULT result;
#define EM_CHECK(ev) \
if (result != EMSCRIPTEN_RESULT_SUCCESS) \
ERR_PRINT("Error while setting " #ev " callback: Code " + itos(result));
#define SET_EM_CALLBACK(target, ev, cb) \
result = emscripten_set_##ev##_callback(target, NULL, true, &cb); \
EM_CHECK(ev)
#define SET_EM_WINDOW_CALLBACK(ev, cb) \
result = emscripten_set_##ev##_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, false, &cb); \
EM_CHECK(ev)
// These callbacks from Emscripten's html5.h suffice to access most
// JavaScript APIs.
SET_EM_WINDOW_CALLBACK(blur, blur_callback)
#undef SET_EM_CALLBACK
#undef EM_CHECK
godot_js_display_mouse_button_cb(&OS_JavaScript::mouse_button_callback); godot_js_display_mouse_button_cb(&OS_JavaScript::mouse_button_callback);
godot_js_display_mouse_move_cb(&OS_JavaScript::mouse_move_callback); godot_js_display_mouse_move_cb(&OS_JavaScript::mouse_move_callback);
godot_js_display_mouse_wheel_cb(&OS_JavaScript::mouse_wheel_callback); godot_js_display_mouse_wheel_cb(&OS_JavaScript::mouse_wheel_callback);
godot_js_display_touch_cb(&OS_JavaScript::touch_callback, touch_event.identifier, touch_event.coords); godot_js_display_touch_cb(&OS_JavaScript::touch_callback, touch_event.identifier, touch_event.coords);
godot_js_display_key_cb(&OS_JavaScript::key_callback, key_event.code, key_event.key); godot_js_display_key_cb(&OS_JavaScript::key_callback, key_event.code, key_event.key);
godot_js_display_fullscreen_cb(&OS_JavaScript::fullscreen_change_callback); godot_js_display_fullscreen_cb(&OS_JavaScript::fullscreen_change_callback);
godot_js_display_window_blur_cb(&window_blur_callback);
godot_js_display_notification_cb(&OS_JavaScript::send_notification_callback, godot_js_display_notification_cb(&OS_JavaScript::send_notification_callback,
MainLoop::NOTIFICATION_WM_MOUSE_ENTER, MainLoop::NOTIFICATION_WM_MOUSE_ENTER,
MainLoop::NOTIFICATION_WM_MOUSE_EXIT, MainLoop::NOTIFICATION_WM_MOUSE_EXIT,

View File

@@ -82,8 +82,6 @@ private:
bool idb_needs_sync; bool idb_needs_sync;
bool idb_is_syncing; bool idb_is_syncing;
static EM_BOOL blur_callback(int p_event_type, const EmscriptenFocusEvent *p_event, void *p_user_data);
static void fullscreen_change_callback(int p_fullscreen); 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 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 void mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers);
@@ -98,6 +96,7 @@ private:
static void file_access_close_callback(const String &p_file, int p_flags); static void file_access_close_callback(const String &p_file, int p_flags);
static void request_quit_callback(); static void request_quit_callback();
static void window_blur_callback();
static void drop_files_callback(char **p_filev, int p_filec); static void drop_files_callback(char **p_filev, int p_filec);
static void send_notification_callback(int p_notification); static void send_notification_callback(int p_notification);
static void fs_sync_callback(); static void fs_sync_callback();