| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "servers/display/display_server.h" |
| 34 |
|
| 35 |
#include "servers/rendering/dummy/rasterizer_dummy.h" |
| 36 |
|
| 37 |
class DisplayServerHeadless : public DisplayServer { |
| 38 |
GDSOFTCLASS(DisplayServerHeadless, DisplayServer); |
| 39 |
|
| 40 |
private: |
| 41 |
friend class DisplayServer; |
| 42 |
|
| 43 |
static Vector<String> get_rendering_drivers_func() { |
| 44 |
Vector<String> drivers; |
| 45 |
drivers.push_back("dummy"); |
| 46 |
return drivers; |
| 47 |
} |
| 48 |
|
| 49 |
static DisplayServer *create_func(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, int64_t p_parent_window, Error &r_error) { |
| 50 |
r_error = OK; |
| 51 |
RasterizerDummy::make_current(); |
| 52 |
return memnew(DisplayServerHeadless()); |
| 53 |
} |
| 54 |
|
| 55 |
static void _dispatch_input_events(const Ref<InputEvent> &p_event) { |
| 56 |
static_cast<DisplayServerHeadless *>(get_singleton())->_dispatch_input_event(p_event); |
| 57 |
} |
| 58 |
|
| 59 |
void _dispatch_input_event(const Ref<InputEvent> &p_event) { |
| 60 |
if (input_event_callback.is_valid()) { |
| 61 |
input_event_callback.call(p_event); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
NativeMenu *native_menu = nullptr; |
| 66 |
Callable input_event_callback; |
| 67 |
|
| 68 |
public: |
| 69 |
bool has_feature(Feature p_feature) const override { return false; } |
| 70 |
String get_name() const override { return "headless"; } |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
int get_screen_count() const override { return 0; } |
| 76 |
int get_primary_screen() const override { return 0; } |
| 77 |
Point2i screen_get_position(int p_screen = SCREEN_OF_MAIN_WINDOW) const override { return Point2i(); } |
| 78 |
Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const override { return Size2i(); } |
| 79 |
Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const override { return Rect2i(); } |
| 80 |
int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const override { return 96; } |
| 81 |
float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const override { return 1; } |
| 82 |
float screen_get_max_scale() const override { return 1; } |
| 83 |
float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const override { return SCREEN_REFRESH_RATE_FALLBACK; } |
| 84 |
void screen_set_orientation(ScreenOrientation p_orientation, int p_screen = SCREEN_OF_MAIN_WINDOW) override {} |
| 85 |
void screen_set_keep_on(bool p_enable) override {} |
| 86 |
|
| 87 |
Vector<DisplayServer::WindowID> get_window_list() const override { return Vector<DisplayServer::WindowID>(); } |
| 88 |
|
| 89 |
WindowID create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i(), bool p_exclusive = false, WindowID p_transient_parent = INVALID_WINDOW_ID) override { return 0; } |
| 90 |
void show_window(WindowID p_id) override {} |
| 91 |
void delete_sub_window(WindowID p_id) override {} |
| 92 |
|
| 93 |
WindowID get_window_at_screen_position(const Point2i &p_position) const override { return 0; } |
| 94 |
|
| 95 |
void window_attach_instance_id(ObjectID p_instance, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 96 |
ObjectID window_get_attached_instance_id(WindowID p_window = MAIN_WINDOW_ID) const override { return ObjectID(); } |
| 97 |
|
| 98 |
void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 99 |
|
| 100 |
void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 101 |
|
| 102 |
void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override { |
| 103 |
input_event_callback = p_callable; |
| 104 |
} |
| 105 |
|
| 106 |
void window_set_input_text_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 107 |
void window_set_drop_files_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 108 |
|
| 109 |
void window_set_title(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 110 |
|
| 111 |
void window_set_mouse_passthrough(const Vector<Vector2> &p_region, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 112 |
|
| 113 |
int window_get_current_screen(WindowID p_window = MAIN_WINDOW_ID) const override { return INVALID_SCREEN; } |
| 114 |
void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 115 |
|
| 116 |
Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const override { return Point2i(); } |
| 117 |
Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override { return Point2i(); } |
| 118 |
void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 119 |
|
| 120 |
void window_set_transient(WindowID p_window, WindowID p_parent) override {} |
| 121 |
|
| 122 |
void window_set_max_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 123 |
Size2i window_get_max_size(WindowID p_window = MAIN_WINDOW_ID) const override { return Size2i(); } |
| 124 |
|
| 125 |
void window_set_min_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 126 |
Size2i window_get_min_size(WindowID p_window = MAIN_WINDOW_ID) const override { return Size2i(); } |
| 127 |
|
| 128 |
void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 129 |
Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const override { return Size2i(); } |
| 130 |
Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override { return Size2i(); } |
| 131 |
|
| 132 |
void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 133 |
WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const override { return WINDOW_MODE_MINIMIZED; } |
| 134 |
|
| 135 |
void window_set_vsync_mode(VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 136 |
VSyncMode window_get_vsync_mode(WindowID p_window) const override { return VSyncMode::VSYNC_ENABLED; } |
| 137 |
|
| 138 |
bool window_is_maximize_allowed(WindowID p_window = MAIN_WINDOW_ID) const override { return false; } |
| 139 |
|
| 140 |
void window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 141 |
bool window_get_flag(WindowFlags p_flag, WindowID p_window = MAIN_WINDOW_ID) const override { return false; } |
| 142 |
|
| 143 |
void window_request_attention(WindowID p_window = MAIN_WINDOW_ID) override {} |
| 144 |
void window_move_to_foreground(WindowID p_window = MAIN_WINDOW_ID) override {} |
| 145 |
bool window_is_focused(WindowID p_window = MAIN_WINDOW_ID) const override { return true; } |
| 146 |
|
| 147 |
bool window_can_draw(WindowID p_window = MAIN_WINDOW_ID) const override { return false; } |
| 148 |
|
| 149 |
bool can_any_window_draw() const override { return false; } |
| 150 |
|
| 151 |
void window_set_ime_active(const bool p_active, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 152 |
void window_set_ime_position(const Point2i &p_pos, WindowID p_window = MAIN_WINDOW_ID) override {} |
| 153 |
|
| 154 |
int64_t window_get_native_handle(HandleType p_handle_type, WindowID p_window = MAIN_WINDOW_ID) const override { return 0; } |
| 155 |
|
| 156 |
void process_events() override { |
| 157 |
Input::get_singleton()->flush_buffered_events(); |
| 158 |
} |
| 159 |
|
| 160 |
void set_native_icon(const String &p_filename) override {} |
| 161 |
void set_icon(const Ref<Image> &p_icon) override {} |
| 162 |
|
| 163 |
void help_set_search_callbacks(const Callable &p_search_callback = Callable(), const Callable &p_action_callback = Callable()) override {} |
| 164 |
|
| 165 |
bool tts_is_speaking() const override { return false; } |
| 166 |
bool tts_is_paused() const override { return false; } |
| 167 |
TypedArray<Dictionary> tts_get_voices() const override { return TypedArray<Dictionary>(); } |
| 168 |
void tts_speak(const String &p_text, const String &p_voice, int p_volume = 50, float p_pitch = 1.0f, float p_rate = 1.0f, int64_t p_utterance_id = 0, bool p_interrupt = false) override {} |
| 169 |
void tts_pause() override {} |
| 170 |
void tts_resume() override {} |
| 171 |
void tts_stop() override {} |
| 172 |
|
| 173 |
void mouse_set_mode(MouseMode p_mode) override {} |
| 174 |
void mouse_set_mode_override(MouseMode p_mode) override {} |
| 175 |
void mouse_set_mode_override_enabled(bool p_override_enabled) override {} |
| 176 |
Point2i mouse_get_position() const override { return Point2i(); } |
| 177 |
void clipboard_set(const String &p_text) override {} |
| 178 |
void clipboard_set_primary(const String &p_text) override {} |
| 179 |
|
| 180 |
void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT, int p_max_length = -1, int p_cursor_start = -1, int p_cursor_end = -1) override {} |
| 181 |
void virtual_keyboard_hide() override {} |
| 182 |
|
| 183 |
void cursor_set_shape(CursorShape p_shape) override {} |
| 184 |
void cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()) override {} |
| 185 |
|
| 186 |
Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback) override { return ERR_UNAVAILABLE; } |
| 187 |
Error dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback) override { return ERR_UNAVAILABLE; } |
| 188 |
Error file_dialog_show(const String &p_title, const String &p_current_directory, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback, WindowID p_window_id) override { return ERR_UNAVAILABLE; } |
| 189 |
Error file_dialog_with_options_show(const String &p_title, const String &p_current_directory, const String &p_root, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const TypedArray<Dictionary> &p_options, const Callable &p_callback, WindowID p_window_id) override { return ERR_UNAVAILABLE; } |
| 190 |
|
| 191 |
void release_rendering_thread() override {} |
| 192 |
void swap_buffers() override {} |
| 193 |
|
| 194 |
IndicatorID create_status_indicator(const Ref<Texture2D> &p_icon, const String &p_tooltip, const Callable &p_callback) override { return INVALID_INDICATOR_ID; } |
| 195 |
void status_indicator_set_icon(IndicatorID p_id, const Ref<Texture2D> &p_icon) override {} |
| 196 |
void status_indicator_set_tooltip(IndicatorID p_id, const String &p_tooltip) override {} |
| 197 |
void status_indicator_set_callback(IndicatorID p_id, const Callable &p_callback) override {} |
| 198 |
void delete_status_indicator(IndicatorID p_id) override {} |
| 199 |
|
| 200 |
DisplayServerHeadless() { |
| 201 |
native_menu = memnew(NativeMenu); |
| 202 |
Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events); |
| 203 |
} |
| 204 |
|
| 205 |
~DisplayServerHeadless() { |
| 206 |
if (native_menu) { |
| 207 |
memdelete(native_menu); |
| 208 |
native_menu = nullptr; |
| 209 |
} |
| 210 |
} |
| 211 |
}; |