diff options
author | Mikael Hermansson <mikael@hermansson.io> | 2024-06-05 17:51:40 +0200 |
---|---|---|
committer | Mikael Hermansson <mikael@hermansson.io> | 2024-06-05 20:34:35 +0200 |
commit | f92b19609975517b4756069ba99084fec223ca75 (patch) | |
tree | b173d0a04432770e8e5758cc1311de1a8dcf8b44 /servers/display_server_headless.h | |
parent | 96a386f3c424af96d950ee5098b4b0e4907c9508 (diff) | |
download | redot-engine-f92b19609975517b4756069ba99084fec223ca75.tar.gz |
Add input event callback to `DisplayServerHeadless`
Diffstat (limited to 'servers/display_server_headless.h')
-rw-r--r-- | servers/display_server_headless.h | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/servers/display_server_headless.h b/servers/display_server_headless.h index 51755ddfbd..cf8299ad64 100644 --- a/servers/display_server_headless.h +++ b/servers/display_server_headless.h @@ -51,7 +51,18 @@ private: return memnew(DisplayServerHeadless()); } + static void _dispatch_input_events(const Ref<InputEvent> &p_event) { + static_cast<DisplayServerHeadless *>(get_singleton())->_dispatch_input_event(p_event); + } + + void _dispatch_input_event(const Ref<InputEvent> &p_event) { + if (input_event_callback.is_valid()) { + input_event_callback.call(p_event); + } + } + NativeMenu *native_menu = nullptr; + Callable input_event_callback; public: bool has_feature(Feature p_feature) const override { return false; } @@ -86,7 +97,11 @@ public: void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {} void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {} - void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {} + + void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override { + input_event_callback = p_callable; + } + void window_set_input_text_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {} void window_set_drop_files_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {} @@ -137,7 +152,9 @@ public: int64_t window_get_native_handle(HandleType p_handle_type, WindowID p_window = MAIN_WINDOW_ID) const override { return 0; } - void process_events() override {} + void process_events() override { + Input::get_singleton()->flush_buffered_events(); + } void set_native_icon(const String &p_filename) override {} void set_icon(const Ref<Image> &p_icon) override {} @@ -178,7 +195,9 @@ public: DisplayServerHeadless() { native_menu = memnew(NativeMenu); + Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events); } + ~DisplayServerHeadless() { if (native_menu) { memdelete(native_menu); |