display_server.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /**************************************************************************/
  2. /* display_server.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef DISPLAY_SERVER_H
  31. #define DISPLAY_SERVER_H
  32. #include "core/input/input.h"
  33. #include "core/io/image.h"
  34. #include "core/io/resource.h"
  35. #include "core/os/os.h"
  36. #include "core/variant/callable.h"
  37. #include "display/native_menu.h"
  38. class Texture2D;
  39. class DisplayServer : public Object {
  40. GDCLASS(DisplayServer, Object)
  41. static DisplayServer *singleton;
  42. static bool hidpi_allowed;
  43. #ifndef DISABLE_DEPRECATED
  44. mutable HashMap<String, RID> menu_names;
  45. RID _get_rid_from_name(NativeMenu *p_nmenu, const String &p_menu_root) const;
  46. #endif
  47. LocalVector<ObjectID> additional_outputs;
  48. public:
  49. _FORCE_INLINE_ static DisplayServer *get_singleton() {
  50. return singleton;
  51. }
  52. enum WindowMode {
  53. WINDOW_MODE_WINDOWED,
  54. WINDOW_MODE_MINIMIZED,
  55. WINDOW_MODE_MAXIMIZED,
  56. WINDOW_MODE_FULLSCREEN,
  57. WINDOW_MODE_EXCLUSIVE_FULLSCREEN,
  58. };
  59. // Keep the VSyncMode enum values in sync with the `display/window/vsync/vsync_mode`
  60. // project setting hint.
  61. enum VSyncMode {
  62. VSYNC_DISABLED,
  63. VSYNC_ENABLED,
  64. VSYNC_ADAPTIVE,
  65. VSYNC_MAILBOX
  66. };
  67. enum HandleType {
  68. DISPLAY_HANDLE,
  69. WINDOW_HANDLE,
  70. WINDOW_VIEW,
  71. OPENGL_CONTEXT,
  72. EGL_DISPLAY,
  73. EGL_CONFIG,
  74. };
  75. enum Context {
  76. CONTEXT_EDITOR,
  77. CONTEXT_PROJECTMAN,
  78. CONTEXT_ENGINE,
  79. };
  80. typedef DisplayServer *(*CreateFunction)(const String &, WindowMode, VSyncMode, uint32_t, const Point2i *, const Size2i &, int p_screen, Context, Error &r_error);
  81. typedef Vector<String> (*GetRenderingDriversFunction)();
  82. private:
  83. static void _input_set_mouse_mode(Input::MouseMode p_mode);
  84. static Input::MouseMode _input_get_mouse_mode();
  85. static void _input_warp(const Vector2 &p_to_pos);
  86. static Input::CursorShape _input_get_current_cursor_shape();
  87. static void _input_set_custom_mouse_cursor_func(const Ref<Resource> &, Input::CursorShape, const Vector2 &p_hostspot);
  88. protected:
  89. static void _bind_methods();
  90. static Ref<Image> _get_cursor_image_from_resource(const Ref<Resource> &p_cursor, const Vector2 &p_hotspot);
  91. enum {
  92. MAX_SERVERS = 64
  93. };
  94. struct DisplayServerCreate {
  95. const char *name;
  96. CreateFunction create_function;
  97. GetRenderingDriversFunction get_rendering_drivers_function;
  98. };
  99. static DisplayServerCreate server_create_functions[MAX_SERVERS];
  100. static int server_create_count;
  101. friend class RendererViewport;
  102. public:
  103. enum Feature {
  104. #ifndef DISABLE_DEPRECATED
  105. FEATURE_GLOBAL_MENU,
  106. #endif
  107. FEATURE_SUBWINDOWS,
  108. FEATURE_TOUCHSCREEN,
  109. FEATURE_MOUSE,
  110. FEATURE_MOUSE_WARP,
  111. FEATURE_CLIPBOARD,
  112. FEATURE_VIRTUAL_KEYBOARD,
  113. FEATURE_CURSOR_SHAPE,
  114. FEATURE_CUSTOM_CURSOR_SHAPE,
  115. FEATURE_NATIVE_DIALOG,
  116. FEATURE_IME,
  117. FEATURE_WINDOW_TRANSPARENCY,
  118. FEATURE_HIDPI,
  119. FEATURE_ICON,
  120. FEATURE_NATIVE_ICON,
  121. FEATURE_ORIENTATION,
  122. FEATURE_SWAP_BUFFERS,
  123. FEATURE_KEEP_SCREEN_ON,
  124. FEATURE_CLIPBOARD_PRIMARY,
  125. FEATURE_TEXT_TO_SPEECH,
  126. FEATURE_EXTEND_TO_TITLE,
  127. FEATURE_SCREEN_CAPTURE,
  128. FEATURE_STATUS_INDICATOR,
  129. FEATURE_NATIVE_HELP,
  130. FEATURE_NATIVE_DIALOG_INPUT,
  131. FEATURE_NATIVE_DIALOG_FILE,
  132. FEATURE_NATIVE_DIALOG_FILE_EXTRA,
  133. FEATURE_WINDOW_DRAG,
  134. FEATURE_SCREEN_EXCLUDE_FROM_CAPTURE,
  135. };
  136. virtual bool has_feature(Feature p_feature) const = 0;
  137. virtual String get_name() const = 0;
  138. virtual void help_set_search_callbacks(const Callable &p_search_callback = Callable(), const Callable &p_action_callback = Callable());
  139. #ifndef DISABLE_DEPRECATED
  140. virtual void global_menu_set_popup_callbacks(const String &p_menu_root, const Callable &p_open_callback = Callable(), const Callable &p_close_callback = Callable());
  141. virtual int global_menu_add_submenu_item(const String &p_menu_root, const String &p_label, const String &p_submenu, int p_index = -1);
  142. virtual int global_menu_add_item(const String &p_menu_root, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1);
  143. virtual int global_menu_add_check_item(const String &p_menu_root, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1);
  144. virtual int global_menu_add_icon_item(const String &p_menu_root, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1);
  145. virtual int global_menu_add_icon_check_item(const String &p_menu_root, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1);
  146. virtual int global_menu_add_radio_check_item(const String &p_menu_root, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1);
  147. virtual int global_menu_add_icon_radio_check_item(const String &p_menu_root, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1);
  148. virtual int global_menu_add_multistate_item(const String &p_menu_root, const String &p_label, int p_max_states, int p_default_state, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1);
  149. virtual int global_menu_add_separator(const String &p_menu_root, int p_index = -1);
  150. virtual int global_menu_get_item_index_from_text(const String &p_menu_root, const String &p_text) const;
  151. virtual int global_menu_get_item_index_from_tag(const String &p_menu_root, const Variant &p_tag) const;
  152. virtual bool global_menu_is_item_checked(const String &p_menu_root, int p_idx) const;
  153. virtual bool global_menu_is_item_checkable(const String &p_menu_root, int p_idx) const;
  154. virtual bool global_menu_is_item_radio_checkable(const String &p_menu_root, int p_idx) const;
  155. virtual Callable global_menu_get_item_callback(const String &p_menu_root, int p_idx) const;
  156. virtual Callable global_menu_get_item_key_callback(const String &p_menu_root, int p_idx) const;
  157. virtual Variant global_menu_get_item_tag(const String &p_menu_root, int p_idx) const;
  158. virtual String global_menu_get_item_text(const String &p_menu_root, int p_idx) const;
  159. virtual String global_menu_get_item_submenu(const String &p_menu_root, int p_idx) const;
  160. virtual Key global_menu_get_item_accelerator(const String &p_menu_root, int p_idx) const;
  161. virtual bool global_menu_is_item_disabled(const String &p_menu_root, int p_idx) const;
  162. virtual bool global_menu_is_item_hidden(const String &p_menu_root, int p_idx) const;
  163. virtual String global_menu_get_item_tooltip(const String &p_menu_root, int p_idx) const;
  164. virtual int global_menu_get_item_state(const String &p_menu_root, int p_idx) const;
  165. virtual int global_menu_get_item_max_states(const String &p_menu_root, int p_idx) const;
  166. virtual Ref<Texture2D> global_menu_get_item_icon(const String &p_menu_root, int p_idx) const;
  167. virtual int global_menu_get_item_indentation_level(const String &p_menu_root, int p_idx) const;
  168. virtual void global_menu_set_item_checked(const String &p_menu_root, int p_idx, bool p_checked);
  169. virtual void global_menu_set_item_checkable(const String &p_menu_root, int p_idx, bool p_checkable);
  170. virtual void global_menu_set_item_radio_checkable(const String &p_menu_root, int p_idx, bool p_checkable);
  171. virtual void global_menu_set_item_callback(const String &p_menu_root, int p_idx, const Callable &p_callback);
  172. virtual void global_menu_set_item_key_callback(const String &p_menu_root, int p_idx, const Callable &p_key_callback);
  173. virtual void global_menu_set_item_hover_callbacks(const String &p_menu_root, int p_idx, const Callable &p_callback);
  174. virtual void global_menu_set_item_tag(const String &p_menu_root, int p_idx, const Variant &p_tag);
  175. virtual void global_menu_set_item_text(const String &p_menu_root, int p_idx, const String &p_text);
  176. virtual void global_menu_set_item_submenu(const String &p_menu_root, int p_idx, const String &p_submenu);
  177. virtual void global_menu_set_item_accelerator(const String &p_menu_root, int p_idx, Key p_keycode);
  178. virtual void global_menu_set_item_disabled(const String &p_menu_root, int p_idx, bool p_disabled);
  179. virtual void global_menu_set_item_hidden(const String &p_menu_root, int p_idx, bool p_hidden);
  180. virtual void global_menu_set_item_tooltip(const String &p_menu_root, int p_idx, const String &p_tooltip);
  181. virtual void global_menu_set_item_state(const String &p_menu_root, int p_idx, int p_state);
  182. virtual void global_menu_set_item_max_states(const String &p_menu_root, int p_idx, int p_max_states);
  183. virtual void global_menu_set_item_icon(const String &p_menu_root, int p_idx, const Ref<Texture2D> &p_icon);
  184. virtual void global_menu_set_item_indentation_level(const String &p_menu_root, int p_idx, int p_level);
  185. virtual int global_menu_get_item_count(const String &p_menu_root) const;
  186. virtual void global_menu_remove_item(const String &p_menu_root, int p_idx);
  187. virtual void global_menu_clear(const String &p_menu_root);
  188. virtual Dictionary global_menu_get_system_menu_roots() const;
  189. #endif
  190. struct TTSUtterance {
  191. String text;
  192. String voice;
  193. int volume = 50;
  194. float pitch = 1.f;
  195. float rate = 1.f;
  196. int id = 0;
  197. };
  198. enum TTSUtteranceEvent {
  199. TTS_UTTERANCE_STARTED,
  200. TTS_UTTERANCE_ENDED,
  201. TTS_UTTERANCE_CANCELED,
  202. TTS_UTTERANCE_BOUNDARY,
  203. TTS_UTTERANCE_MAX,
  204. };
  205. private:
  206. Callable utterance_callback[TTS_UTTERANCE_MAX];
  207. public:
  208. virtual bool tts_is_speaking() const;
  209. virtual bool tts_is_paused() const;
  210. virtual TypedArray<Dictionary> tts_get_voices() const;
  211. virtual PackedStringArray tts_get_voices_for_language(const String &p_language) const;
  212. virtual void tts_speak(const String &p_text, const String &p_voice, int p_volume = 50, float p_pitch = 1.f, float p_rate = 1.f, int p_utterance_id = 0, bool p_interrupt = false);
  213. virtual void tts_pause();
  214. virtual void tts_resume();
  215. virtual void tts_stop();
  216. virtual void tts_set_utterance_callback(TTSUtteranceEvent p_event, const Callable &p_callable);
  217. virtual void tts_post_utterance_event(TTSUtteranceEvent p_event, int p_id, int p_pos = 0);
  218. virtual bool is_dark_mode_supported() const { return false; }
  219. virtual bool is_dark_mode() const { return false; }
  220. virtual Color get_accent_color() const { return Color(0, 0, 0, 0); }
  221. virtual Color get_base_color() const { return Color(0, 0, 0, 0); }
  222. virtual void set_system_theme_change_callback(const Callable &p_callable) {}
  223. private:
  224. static bool window_early_clear_override_enabled;
  225. static Color window_early_clear_override_color;
  226. protected:
  227. static bool _get_window_early_clear_override(Color &r_color);
  228. public:
  229. static void set_early_window_clear_color_override(bool p_enabled, Color p_color = Color(0, 0, 0, 0));
  230. enum MouseMode {
  231. MOUSE_MODE_VISIBLE,
  232. MOUSE_MODE_HIDDEN,
  233. MOUSE_MODE_CAPTURED,
  234. MOUSE_MODE_CONFINED,
  235. MOUSE_MODE_CONFINED_HIDDEN,
  236. };
  237. virtual void mouse_set_mode(MouseMode p_mode);
  238. virtual MouseMode mouse_get_mode() const;
  239. virtual void warp_mouse(const Point2i &p_position);
  240. virtual Point2i mouse_get_position() const;
  241. virtual BitField<MouseButtonMask> mouse_get_button_state() const;
  242. virtual void clipboard_set(const String &p_text);
  243. virtual String clipboard_get() const;
  244. virtual Ref<Image> clipboard_get_image() const;
  245. virtual bool clipboard_has() const;
  246. virtual bool clipboard_has_image() const;
  247. virtual void clipboard_set_primary(const String &p_text);
  248. virtual String clipboard_get_primary() const;
  249. virtual TypedArray<Rect2> get_display_cutouts() const { return TypedArray<Rect2>(); }
  250. virtual Rect2i get_display_safe_area() const { return screen_get_usable_rect(); }
  251. enum {
  252. SCREEN_WITH_MOUSE_FOCUS = -4,
  253. SCREEN_WITH_KEYBOARD_FOCUS = -3,
  254. SCREEN_PRIMARY = -2,
  255. SCREEN_OF_MAIN_WINDOW = -1, // Note: for the main window, determine screen from position.
  256. };
  257. const float SCREEN_REFRESH_RATE_FALLBACK = -1.0; // Returned by screen_get_refresh_rate if the method fails.
  258. int _get_screen_index(int p_screen) const {
  259. switch (p_screen) {
  260. case SCREEN_WITH_MOUSE_FOCUS: {
  261. const Rect2i rect = Rect2i(mouse_get_position(), Vector2i(1, 1));
  262. return get_screen_from_rect(rect);
  263. } break;
  264. case SCREEN_WITH_KEYBOARD_FOCUS: {
  265. return get_keyboard_focus_screen();
  266. } break;
  267. case SCREEN_PRIMARY: {
  268. return get_primary_screen();
  269. } break;
  270. case SCREEN_OF_MAIN_WINDOW: {
  271. return window_get_current_screen(MAIN_WINDOW_ID);
  272. } break;
  273. default: {
  274. return p_screen;
  275. } break;
  276. }
  277. }
  278. virtual int get_screen_count() const = 0;
  279. virtual int get_primary_screen() const = 0;
  280. virtual int get_keyboard_focus_screen() const { return get_primary_screen(); }
  281. virtual int get_screen_from_rect(const Rect2 &p_rect) const;
  282. virtual Point2i screen_get_position(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
  283. virtual Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
  284. virtual Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
  285. virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
  286. virtual float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
  287. virtual float screen_get_max_scale() const {
  288. float scale = 1.f;
  289. int screen_count = get_screen_count();
  290. for (int i = 0; i < screen_count; i++) {
  291. scale = fmax(scale, screen_get_scale(i));
  292. }
  293. return scale;
  294. }
  295. virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
  296. virtual Color screen_get_pixel(const Point2i &p_position) const { return Color(); }
  297. virtual Ref<Image> screen_get_image(int p_screen = SCREEN_OF_MAIN_WINDOW) const { return Ref<Image>(); }
  298. virtual Ref<Image> screen_get_image_rect(const Rect2i &p_rect) const { return Ref<Image>(); }
  299. virtual bool is_touchscreen_available() const;
  300. // Keep the ScreenOrientation enum values in sync with the `display/window/handheld/orientation`
  301. // project setting hint.
  302. enum ScreenOrientation {
  303. SCREEN_LANDSCAPE,
  304. SCREEN_PORTRAIT,
  305. SCREEN_REVERSE_LANDSCAPE,
  306. SCREEN_REVERSE_PORTRAIT,
  307. SCREEN_SENSOR_LANDSCAPE,
  308. SCREEN_SENSOR_PORTRAIT,
  309. SCREEN_SENSOR,
  310. };
  311. virtual void screen_set_orientation(ScreenOrientation p_orientation, int p_screen = SCREEN_OF_MAIN_WINDOW);
  312. virtual ScreenOrientation screen_get_orientation(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
  313. virtual void screen_set_keep_on(bool p_enable); //disable screensaver
  314. virtual bool screen_is_kept_on() const;
  315. enum {
  316. MAIN_WINDOW_ID = 0,
  317. INVALID_WINDOW_ID = -1,
  318. INVALID_INDICATOR_ID = -1
  319. };
  320. public:
  321. typedef int WindowID;
  322. typedef int IndicatorID;
  323. virtual Vector<DisplayServer::WindowID> get_window_list() const = 0;
  324. enum WindowFlags {
  325. WINDOW_FLAG_RESIZE_DISABLED,
  326. WINDOW_FLAG_BORDERLESS,
  327. WINDOW_FLAG_ALWAYS_ON_TOP,
  328. WINDOW_FLAG_TRANSPARENT,
  329. WINDOW_FLAG_NO_FOCUS,
  330. WINDOW_FLAG_POPUP,
  331. WINDOW_FLAG_EXTEND_TO_TITLE,
  332. WINDOW_FLAG_MOUSE_PASSTHROUGH,
  333. WINDOW_FLAG_SHARP_CORNERS,
  334. WINDOW_FLAG_EXCLUDE_FROM_CAPTURE,
  335. WINDOW_FLAG_MAX,
  336. };
  337. // Separate enum otherwise we get warnings in switches not handling all values.
  338. enum WindowFlagsBit {
  339. WINDOW_FLAG_RESIZE_DISABLED_BIT = (1 << WINDOW_FLAG_RESIZE_DISABLED),
  340. WINDOW_FLAG_BORDERLESS_BIT = (1 << WINDOW_FLAG_BORDERLESS),
  341. WINDOW_FLAG_ALWAYS_ON_TOP_BIT = (1 << WINDOW_FLAG_ALWAYS_ON_TOP),
  342. WINDOW_FLAG_TRANSPARENT_BIT = (1 << WINDOW_FLAG_TRANSPARENT),
  343. WINDOW_FLAG_NO_FOCUS_BIT = (1 << WINDOW_FLAG_NO_FOCUS),
  344. WINDOW_FLAG_POPUP_BIT = (1 << WINDOW_FLAG_POPUP),
  345. WINDOW_FLAG_EXTEND_TO_TITLE_BIT = (1 << WINDOW_FLAG_EXTEND_TO_TITLE),
  346. WINDOW_FLAG_MOUSE_PASSTHROUGH_BIT = (1 << WINDOW_FLAG_MOUSE_PASSTHROUGH),
  347. WINDOW_FLAG_SHARP_CORNERS_BIT = (1 << WINDOW_FLAG_SHARP_CORNERS),
  348. WINDOW_FLAG_EXCLUDE_FROM_CAPTURE_BIT = (1 << WINDOW_FLAG_EXCLUDE_FROM_CAPTURE),
  349. };
  350. virtual 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);
  351. virtual void show_window(WindowID p_id);
  352. virtual void delete_sub_window(WindowID p_id);
  353. virtual WindowID window_get_active_popup() const { return INVALID_WINDOW_ID; }
  354. virtual void window_set_popup_safe_rect(WindowID p_window, const Rect2i &p_rect) {}
  355. virtual Rect2i window_get_popup_safe_rect(WindowID p_window) const { return Rect2i(); }
  356. virtual int64_t window_get_native_handle(HandleType p_handle_type, WindowID p_window = MAIN_WINDOW_ID) const;
  357. virtual WindowID get_window_at_screen_position(const Point2i &p_position) const = 0;
  358. virtual void window_attach_instance_id(ObjectID p_instance, WindowID p_window = MAIN_WINDOW_ID) = 0;
  359. virtual ObjectID window_get_attached_instance_id(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  360. virtual void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0;
  361. enum WindowEvent {
  362. WINDOW_EVENT_MOUSE_ENTER,
  363. WINDOW_EVENT_MOUSE_EXIT,
  364. WINDOW_EVENT_FOCUS_IN,
  365. WINDOW_EVENT_FOCUS_OUT,
  366. WINDOW_EVENT_CLOSE_REQUEST,
  367. WINDOW_EVENT_GO_BACK_REQUEST,
  368. WINDOW_EVENT_DPI_CHANGE,
  369. WINDOW_EVENT_TITLEBAR_CHANGE,
  370. };
  371. virtual void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0;
  372. virtual void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0;
  373. virtual void window_set_input_text_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0;
  374. virtual void window_set_drop_files_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0;
  375. virtual void window_set_title(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) = 0;
  376. virtual Size2i window_get_title_size(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) const { return Size2i(); }
  377. virtual void window_set_mouse_passthrough(const Vector<Vector2> &p_region, WindowID p_window = MAIN_WINDOW_ID);
  378. virtual int window_get_current_screen(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  379. virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) = 0;
  380. virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  381. virtual Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  382. virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) = 0;
  383. virtual void window_set_transient(WindowID p_window, WindowID p_parent) = 0;
  384. virtual void window_set_exclusive(WindowID p_window, bool p_exclusive);
  385. virtual void window_set_max_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) = 0;
  386. virtual Size2i window_get_max_size(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  387. virtual void window_set_min_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) = 0;
  388. virtual Size2i window_get_min_size(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  389. virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) = 0;
  390. virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  391. virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  392. virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) = 0;
  393. virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  394. virtual void window_set_vsync_mode(VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID);
  395. virtual VSyncMode window_get_vsync_mode(WindowID p_window) const;
  396. virtual bool window_is_maximize_allowed(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  397. virtual void window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window = MAIN_WINDOW_ID) = 0;
  398. virtual bool window_get_flag(WindowFlags p_flag, WindowID p_window = MAIN_WINDOW_ID) const = 0;
  399. virtual void window_request_attention(WindowID p_window = MAIN_WINDOW_ID) = 0;
  400. virtual void window_move_to_foreground(WindowID p_window = MAIN_WINDOW_ID) = 0;
  401. virtual bool window_is_focused(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  402. virtual WindowID get_focused_window() const;
  403. virtual void window_set_window_buttons_offset(const Vector2i &p_offset, WindowID p_window = MAIN_WINDOW_ID) {}
  404. virtual Vector3i window_get_safe_title_margins(WindowID p_window = MAIN_WINDOW_ID) const { return Vector3i(); }
  405. virtual bool window_can_draw(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  406. virtual bool can_any_window_draw() const = 0;
  407. virtual void window_set_ime_active(const bool p_active, WindowID p_window = MAIN_WINDOW_ID);
  408. virtual void window_set_ime_position(const Point2i &p_pos, WindowID p_window = MAIN_WINDOW_ID);
  409. virtual bool window_maximize_on_title_dbl_click() const { return false; }
  410. virtual bool window_minimize_on_title_dbl_click() const { return false; }
  411. virtual void window_start_drag(WindowID p_window = MAIN_WINDOW_ID) {}
  412. // necessary for GL focus, may be able to use one of the existing functions for this, not sure yet
  413. virtual void gl_window_make_current(DisplayServer::WindowID p_window_id);
  414. virtual Point2i ime_get_selection() const;
  415. virtual String ime_get_text() const;
  416. enum VirtualKeyboardType {
  417. KEYBOARD_TYPE_DEFAULT,
  418. KEYBOARD_TYPE_MULTILINE,
  419. KEYBOARD_TYPE_NUMBER,
  420. KEYBOARD_TYPE_NUMBER_DECIMAL,
  421. KEYBOARD_TYPE_PHONE,
  422. KEYBOARD_TYPE_EMAIL_ADDRESS,
  423. KEYBOARD_TYPE_PASSWORD,
  424. KEYBOARD_TYPE_URL
  425. };
  426. virtual 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);
  427. virtual void virtual_keyboard_hide();
  428. // returns height of the currently shown virtual keyboard (0 if keyboard is hidden)
  429. virtual int virtual_keyboard_get_height() const;
  430. virtual bool has_hardware_keyboard() const;
  431. enum CursorShape {
  432. CURSOR_ARROW,
  433. CURSOR_IBEAM,
  434. CURSOR_POINTING_HAND,
  435. CURSOR_CROSS,
  436. CURSOR_WAIT,
  437. CURSOR_BUSY,
  438. CURSOR_DRAG,
  439. CURSOR_CAN_DROP,
  440. CURSOR_FORBIDDEN,
  441. CURSOR_VSIZE,
  442. CURSOR_HSIZE,
  443. CURSOR_BDIAGSIZE,
  444. CURSOR_FDIAGSIZE,
  445. CURSOR_MOVE,
  446. CURSOR_VSPLIT,
  447. CURSOR_HSPLIT,
  448. CURSOR_HELP,
  449. CURSOR_MAX
  450. };
  451. virtual void cursor_set_shape(CursorShape p_shape);
  452. virtual CursorShape cursor_get_shape() const;
  453. virtual void cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2());
  454. virtual bool get_swap_cancel_ok();
  455. virtual void enable_for_stealing_focus(OS::ProcessID pid);
  456. virtual Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback);
  457. virtual Error dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback);
  458. enum FileDialogMode {
  459. FILE_DIALOG_MODE_OPEN_FILE,
  460. FILE_DIALOG_MODE_OPEN_FILES,
  461. FILE_DIALOG_MODE_OPEN_DIR,
  462. FILE_DIALOG_MODE_OPEN_ANY,
  463. FILE_DIALOG_MODE_SAVE_FILE,
  464. FILE_DIALOG_MODE_SAVE_MAX
  465. };
  466. virtual 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);
  467. virtual 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);
  468. virtual void beep() const;
  469. virtual int keyboard_get_layout_count() const;
  470. virtual int keyboard_get_current_layout() const;
  471. virtual void keyboard_set_current_layout(int p_index);
  472. virtual String keyboard_get_layout_language(int p_index) const;
  473. virtual String keyboard_get_layout_name(int p_index) const;
  474. virtual Key keyboard_get_keycode_from_physical(Key p_keycode) const;
  475. virtual Key keyboard_get_label_from_physical(Key p_keycode) const;
  476. virtual int tablet_get_driver_count() const { return 1; }
  477. virtual String tablet_get_driver_name(int p_driver) const { return "default"; }
  478. virtual String tablet_get_current_driver() const { return "default"; }
  479. virtual void tablet_set_current_driver(const String &p_driver) {}
  480. virtual void process_events() = 0;
  481. virtual void force_process_and_drop_events();
  482. virtual void release_rendering_thread();
  483. virtual void swap_buffers();
  484. virtual void set_native_icon(const String &p_filename);
  485. virtual void set_icon(const Ref<Image> &p_icon);
  486. virtual IndicatorID create_status_indicator(const Ref<Texture2D> &p_icon, const String &p_tooltip, const Callable &p_callback);
  487. virtual void status_indicator_set_icon(IndicatorID p_id, const Ref<Texture2D> &p_icon);
  488. virtual void status_indicator_set_tooltip(IndicatorID p_id, const String &p_tooltip);
  489. virtual void status_indicator_set_menu(IndicatorID p_id, const RID &p_menu_rid);
  490. virtual void status_indicator_set_callback(IndicatorID p_id, const Callable &p_callback);
  491. virtual Rect2 status_indicator_get_rect(IndicatorID p_id) const;
  492. virtual void delete_status_indicator(IndicatorID p_id);
  493. virtual void set_context(Context p_context);
  494. virtual bool is_window_transparency_available() const { return false; }
  495. void register_additional_output(Object *p_output);
  496. void unregister_additional_output(Object *p_output);
  497. bool has_additional_outputs() const { return additional_outputs.size() > 0; }
  498. static void register_create_function(const char *p_name, CreateFunction p_function, GetRenderingDriversFunction p_get_drivers);
  499. static int get_create_function_count();
  500. static const char *get_create_function_name(int p_index);
  501. static Vector<String> get_create_function_rendering_drivers(int p_index);
  502. static DisplayServer *create(int p_index, const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error);
  503. enum RenderingDeviceCreationStatus {
  504. UNKNOWN,
  505. SUCCESS,
  506. FAILURE,
  507. };
  508. // Used to cache the result of `can_create_rendering_device()` when RenderingDevice isn't currently being used.
  509. // This is done as creating a RenderingDevice is quite slow.
  510. static inline RenderingDeviceCreationStatus created_rendering_device = RenderingDeviceCreationStatus::UNKNOWN;
  511. static bool can_create_rendering_device();
  512. DisplayServer();
  513. ~DisplayServer();
  514. };
  515. VARIANT_ENUM_CAST(DisplayServer::WindowEvent)
  516. VARIANT_ENUM_CAST(DisplayServer::Feature)
  517. VARIANT_ENUM_CAST(DisplayServer::MouseMode)
  518. VARIANT_ENUM_CAST(DisplayServer::ScreenOrientation)
  519. VARIANT_ENUM_CAST(DisplayServer::WindowMode)
  520. VARIANT_ENUM_CAST(DisplayServer::WindowFlags)
  521. VARIANT_ENUM_CAST(DisplayServer::HandleType)
  522. VARIANT_ENUM_CAST(DisplayServer::VirtualKeyboardType);
  523. VARIANT_ENUM_CAST(DisplayServer::CursorShape)
  524. VARIANT_ENUM_CAST(DisplayServer::VSyncMode)
  525. VARIANT_ENUM_CAST(DisplayServer::TTSUtteranceEvent)
  526. VARIANT_ENUM_CAST(DisplayServer::FileDialogMode)
  527. #endif // DISPLAY_SERVER_H