summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-07-01 18:28:41 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-07-01 18:28:41 +0200
commitd4fdf16353074e4117383f6fe7af67fd096034d5 (patch)
treec89752c56befab69c98b53b4b086284b00009179
parent446e7a7c228d19341392ec3b02417244fe7dfe03 (diff)
parentf92b19609975517b4756069ba99084fec223ca75 (diff)
downloadredot-engine-d4fdf16353074e4117383f6fe7af67fd096034d5.tar.gz
Merge pull request #92806 from mihe/headless-input
Add input event callback to `DisplayServerHeadless`
-rw-r--r--servers/display_server_headless.h23
-rw-r--r--tests/display_server_mock.h22
2 files changed, 22 insertions, 23 deletions
diff --git a/servers/display_server_headless.h b/servers/display_server_headless.h
index 7e4a517c1d..60422c16cc 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 {}
@@ -179,7 +196,9 @@ public:
DisplayServerHeadless() {
native_menu = memnew(NativeMenu);
+ Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events);
}
+
~DisplayServerHeadless() {
if (native_menu) {
memdelete(native_menu);
diff --git a/tests/display_server_mock.h b/tests/display_server_mock.h
index e4946995a7..b44ff06b35 100644
--- a/tests/display_server_mock.h
+++ b/tests/display_server_mock.h
@@ -36,7 +36,7 @@
#include "servers/rendering/dummy/rasterizer_dummy.h"
// Specialized DisplayServer for unittests based on DisplayServerHeadless, that
-// additionally supports rudimentary InputEvent handling and mouse position.
+// additionally supports things like mouse enter/exit events and clipboard.
class DisplayServerMock : public DisplayServerHeadless {
private:
friend class DisplayServer;
@@ -45,7 +45,6 @@ private:
CursorShape cursor_shape = CursorShape::CURSOR_ARROW;
bool window_over = false;
Callable event_callback;
- Callable input_event_callback;
String clipboard_text;
String primary_clipboard_text;
@@ -62,16 +61,6 @@ private:
return memnew(DisplayServerMock());
}
- static void _dispatch_input_events(const Ref<InputEvent> &p_event) {
- static_cast<DisplayServerMock *>(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);
- }
- }
-
void _set_mouse_position(const Point2i &p_position) {
if (mouse_position == p_position) {
return;
@@ -153,18 +142,9 @@ public:
event_callback = p_callable;
}
- virtual void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {
- input_event_callback = p_callable;
- }
-
static void register_mock_driver() {
register_create_function("mock", create_func, get_rendering_drivers_func);
}
-
- DisplayServerMock() {
- Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events);
- }
- ~DisplayServerMock() {}
};
#endif // DISPLAY_SERVER_MOCK_H