[HTML5] Implement window blur in JS library.
Removes more emscripten HTML5 library dependencies.
This commit is contained in:
parent
ac78e7f940
commit
89c6aaa96d
4 changed files with 12 additions and 20 deletions
|
@ -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_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_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_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));
|
||||
|
|
|
@ -867,6 +867,14 @@ const GodotDisplay = {
|
|||
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: function (callback, p_enter, p_exit, p_in, p_out) {
|
||||
const canvas = GodotConfig.canvas;
|
||||
|
|
|
@ -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();
|
||||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
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_move_cb(&OS_JavaScript::mouse_move_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_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_window_blur_cb(&window_blur_callback);
|
||||
godot_js_display_notification_cb(&OS_JavaScript::send_notification_callback,
|
||||
MainLoop::NOTIFICATION_WM_MOUSE_ENTER,
|
||||
MainLoop::NOTIFICATION_WM_MOUSE_EXIT,
|
||||
|
|
|
@ -82,8 +82,6 @@ private:
|
|||
bool idb_needs_sync;
|
||||
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 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);
|
||||
|
@ -98,6 +96,7 @@ private:
|
|||
static void file_access_close_callback(const String &p_file, int p_flags);
|
||||
|
||||
static void request_quit_callback();
|
||||
static void window_blur_callback();
|
||||
static void drop_files_callback(char **p_filev, int p_filec);
|
||||
static void send_notification_callback(int p_notification);
|
||||
static void fs_sync_callback();
|
||||
|
|
Loading…
Reference in a new issue