display_server.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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/resource.h"
  34. #include "core/os/os.h"
  35. #include "core/variant/callable.h"
  36. class Texture2D;
  37. class DisplayServer : public Object {
  38. GDCLASS(DisplayServer, Object)
  39. static DisplayServer *singleton;
  40. static bool hidpi_allowed;
  41. public:
  42. _FORCE_INLINE_ static DisplayServer *get_singleton() {
  43. return singleton;
  44. }
  45. enum WindowMode {
  46. WINDOW_MODE_WINDOWED,
  47. WINDOW_MODE_MINIMIZED,
  48. WINDOW_MODE_MAXIMIZED,
  49. WINDOW_MODE_FULLSCREEN,
  50. WINDOW_MODE_EXCLUSIVE_FULLSCREEN,
  51. };
  52. // Keep the VSyncMode enum values in sync with the `display/window/vsync/vsync_mode`
  53. // project setting hint.
  54. enum VSyncMode {
  55. VSYNC_DISABLED,
  56. VSYNC_ENABLED,
  57. VSYNC_ADAPTIVE,
  58. VSYNC_MAILBOX
  59. };
  60. enum HandleType {
  61. DISPLAY_HANDLE,
  62. WINDOW_HANDLE,
  63. WINDOW_VIEW,
  64. OPENGL_CONTEXT,
  65. };
  66. typedef DisplayServer *(*CreateFunction)(const String &, WindowMode, VSyncMode, uint32_t, const Point2i *, const Size2i &, int p_screen, Error &r_error);
  67. typedef Vector<String> (*GetRenderingDriversFunction)();
  68. private:
  69. static void _input_set_mouse_mode(Input::MouseMode p_mode);
  70. static Input::MouseMode _input_get_mouse_mode();
  71. static void _input_warp(const Vector2 &p_to_pos);
  72. static Input::CursorShape _input_get_current_cursor_shape();
  73. static void _input_set_custom_mouse_cursor_func(const Ref<Resource> &, Input::CursorShape, const Vector2 &p_hostspot);
  74. protected:
  75. static void _bind_methods();
  76. enum {
  77. MAX_SERVERS = 64
  78. };
  79. struct DisplayServerCreate {
  80. const char *name;
  81. CreateFunction create_function;
  82. GetRenderingDriversFunction get_rendering_drivers_function;
  83. };
  84. static DisplayServerCreate server_create_functions[MAX_SERVERS];
  85. static int server_create_count;
  86. friend class RendererViewport;
  87. public:
  88. enum Feature {
  89. FEATURE_GLOBAL_MENU,
  90. FEATURE_SUBWINDOWS,
  91. FEATURE_TOUCHSCREEN,
  92. FEATURE_MOUSE,
  93. FEATURE_MOUSE_WARP,
  94. FEATURE_CLIPBOARD,
  95. FEATURE_VIRTUAL_KEYBOARD,
  96. FEATURE_CURSOR_SHAPE,
  97. FEATURE_CUSTOM_CURSOR_SHAPE,
  98. FEATURE_NATIVE_DIALOG,
  99. FEATURE_IME,
  100. FEATURE_WINDOW_TRANSPARENCY,
  101. FEATURE_HIDPI,
  102. FEATURE_ICON,
  103. FEATURE_NATIVE_ICON,
  104. FEATURE_ORIENTATION,
  105. FEATURE_SWAP_BUFFERS,
  106. FEATURE_KEEP_SCREEN_ON,
  107. FEATURE_CLIPBOARD_PRIMARY,
  108. FEATURE_TEXT_TO_SPEECH,
  109. FEATURE_EXTEND_TO_TITLE,
  110. FEATURE_SCREEN_CAPTURE,
  111. };
  112. virtual bool has_feature(Feature p_feature) const = 0;
  113. virtual String get_name() const = 0;
  114. virtual int global_menu_add_submenu_item(const String &p_menu_root, const String &p_label, const String &p_submenu, int p_index = -1);
  115. 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);
  116. 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);
  117. 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);
  118. 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);
  119. 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);
  120. 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);
  121. 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);
  122. virtual int global_menu_add_separator(const String &p_menu_root, int p_index = -1);
  123. virtual int global_menu_get_item_index_from_text(const String &p_menu_root, const String &p_text) const;
  124. virtual int global_menu_get_item_index_from_tag(const String &p_menu_root, const Variant &p_tag) const;
  125. virtual bool global_menu_is_item_checked(const String &p_menu_root, int p_idx) const;
  126. virtual bool global_menu_is_item_checkable(const String &p_menu_root, int p_idx) const;
  127. virtual bool global_menu_is_item_radio_checkable(const String &p_menu_root, int p_idx) const;
  128. virtual Callable global_menu_get_item_callback(const String &p_menu_root, int p_idx) const;
  129. virtual Callable global_menu_get_item_key_callback(const String &p_menu_root, int p_idx) const;
  130. virtual Variant global_menu_get_item_tag(const String &p_menu_root, int p_idx) const;
  131. virtual String global_menu_get_item_text(const String &p_menu_root, int p_idx) const;
  132. virtual String global_menu_get_item_submenu(const String &p_menu_root, int p_idx) const;
  133. virtual Key global_menu_get_item_accelerator(const String &p_menu_root, int p_idx) const;
  134. virtual bool global_menu_is_item_disabled(const String &p_menu_root, int p_idx) const;
  135. virtual String global_menu_get_item_tooltip(const String &p_menu_root, int p_idx) const;
  136. virtual int global_menu_get_item_state(const String &p_menu_root, int p_idx) const;
  137. virtual int global_menu_get_item_max_states(const String &p_menu_root, int p_idx) const;
  138. virtual Ref<Texture2D> global_menu_get_item_icon(const String &p_menu_root, int p_idx) const;
  139. virtual int global_menu_get_item_indentation_level(const String &p_menu_root, int p_idx) const;
  140. virtual void global_menu_set_item_checked(const String &p_menu_root, int p_idx, bool p_checked);
  141. virtual void global_menu_set_item_checkable(const String &p_menu_root, int p_idx, bool p_checkable);
  142. virtual void global_menu_set_item_radio_checkable(const String &p_menu_root, int p_idx, bool p_checkable);
  143. virtual void global_menu_set_item_callback(const String &p_menu_root, int p_idx, const Callable &p_callback);
  144. virtual void global_menu_set_item_key_callback(const String &p_menu_root, int p_idx, const Callable &p_key_callback);
  145. virtual void global_menu_set_item_tag(const String &p_menu_root, int p_idx, const Variant &p_tag);
  146. virtual void global_menu_set_item_text(const String &p_menu_root, int p_idx, const String &p_text);
  147. virtual void global_menu_set_item_submenu(const String &p_menu_root, int p_idx, const String &p_submenu);
  148. virtual void global_menu_set_item_accelerator(const String &p_menu_root, int p_idx, Key p_keycode);
  149. virtual void global_menu_set_item_disabled(const String &p_menu_root, int p_idx, bool p_disabled);
  150. virtual void global_menu_set_item_tooltip(const String &p_menu_root, int p_idx, const String &p_tooltip);
  151. virtual void global_menu_set_item_state(const String &p_menu_root, int p_idx, int p_state);
  152. virtual void global_menu_set_item_max_states(const String &p_menu_root, int p_idx, int p_max_states);
  153. virtual void global_menu_set_item_icon(const String &p_menu_root, int p_idx, const Ref<Texture2D> &p_icon);
  154. virtual void global_menu_set_item_indentation_level(const String &p_menu_root, int p_idx, int p_level);
  155. virtual int global_menu_get_item_count(const String &p_menu_root) const;
  156. virtual void global_menu_remove_item(const String &p_menu_root, int p_idx);
  157. virtual void global_menu_clear(const String &p_menu_root);
  158. struct TTSUtterance {
  159. String text;
  160. String voice;
  161. int volume = 50;
  162. float pitch = 1.f;
  163. float rate = 1.f;
  164. int id = 0;
  165. };
  166. enum TTSUtteranceEvent {
  167. TTS_UTTERANCE_STARTED,
  168. TTS_UTTERANCE_ENDED,
  169. TTS_UTTERANCE_CANCELED,
  170. TTS_UTTERANCE_BOUNDARY,
  171. TTS_UTTERANCE_MAX,
  172. };
  173. private:
  174. Callable utterance_callback[TTS_UTTERANCE_MAX];
  175. public:
  176. virtual bool tts_is_speaking() const;
  177. virtual bool tts_is_paused() const;
  178. virtual TypedArray<Dictionary> tts_get_voices() const;
  179. virtual PackedStringArray tts_get_voices_for_language(const String &p_language) const;
  180. 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);
  181. virtual void tts_pause();
  182. virtual void tts_resume();
  183. virtual void tts_stop();
  184. virtual void tts_set_utterance_callback(TTSUtteranceEvent p_event, const Callable &p_callable);
  185. virtual void tts_post_utterance_event(TTSUtteranceEvent p_event, int p_id, int p_pos = 0);
  186. virtual bool is_dark_mode_supported() const { return false; };
  187. virtual bool is_dark_mode() const { return false; };
  188. virtual Color get_accent_color() const { return Color(0, 0, 0, 0); };
  189. private:
  190. static bool window_early_clear_override_enabled;
  191. static Color window_early_clear_override_color;
  192. protected:
  193. static bool _get_window_early_clear_override(Color &r_color);
  194. public:
  195. static void set_early_window_clear_color_override(bool p_enabled, Color p_color = Color(0, 0, 0, 0));
  196. enum MouseMode {
  197. MOUSE_MODE_VISIBLE,
  198. MOUSE_MODE_HIDDEN,
  199. MOUSE_MODE_CAPTURED,
  200. MOUSE_MODE_CONFINED,
  201. MOUSE_MODE_CONFINED_HIDDEN,
  202. };
  203. virtual void mouse_set_mode(MouseMode p_mode);
  204. virtual MouseMode mouse_get_mode() const;
  205. virtual void warp_mouse(const Point2i &p_position);
  206. virtual Point2i mouse_get_position() const;
  207. virtual BitField<MouseButtonMask> mouse_get_button_state() const;
  208. virtual void clipboard_set(const String &p_text);
  209. virtual String clipboard_get() const;
  210. virtual bool clipboard_has() const;
  211. virtual void clipboard_set_primary(const String &p_text);
  212. virtual String clipboard_get_primary() const;
  213. virtual TypedArray<Rect2> get_display_cutouts() const { return TypedArray<Rect2>(); }
  214. virtual Rect2i get_display_safe_area() const { return screen_get_usable_rect(); }
  215. enum {
  216. SCREEN_WITH_MOUSE_FOCUS = -4,
  217. SCREEN_WITH_KEYBOARD_FOCUS = -3,
  218. SCREEN_PRIMARY = -2,
  219. SCREEN_OF_MAIN_WINDOW = -1, // Note: for the main window, determine screen from position.
  220. };
  221. const float SCREEN_REFRESH_RATE_FALLBACK = -1.0; // Returned by screen_get_refresh_rate if the method fails.
  222. int _get_screen_index(int p_screen) const {
  223. switch (p_screen) {
  224. case SCREEN_WITH_MOUSE_FOCUS: {
  225. const Rect2i rect = Rect2i(mouse_get_position(), Vector2i(1, 1));
  226. return get_screen_from_rect(rect);
  227. } break;
  228. case SCREEN_WITH_KEYBOARD_FOCUS: {
  229. return get_keyboard_focus_screen();
  230. } break;
  231. case SCREEN_PRIMARY: {
  232. return get_primary_screen();
  233. } break;
  234. case SCREEN_OF_MAIN_WINDOW: {
  235. return window_get_current_screen(MAIN_WINDOW_ID);
  236. } break;
  237. default: {
  238. return p_screen;
  239. } break;
  240. }
  241. }
  242. virtual int get_screen_count() const = 0;
  243. virtual int get_primary_screen() const = 0;
  244. virtual int get_keyboard_focus_screen() const { return get_primary_screen(); }
  245. virtual int get_screen_from_rect(const Rect2 &p_rect) const;
  246. virtual Point2i screen_get_position(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
  247. virtual Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
  248. virtual Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
  249. virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
  250. virtual float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
  251. virtual float screen_get_max_scale() const {
  252. float scale = 1.f;
  253. int screen_count = get_screen_count();
  254. for (int i = 0; i < screen_count; i++) {
  255. scale = fmax(scale, screen_get_scale(i));
  256. }
  257. return scale;
  258. }
  259. virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
  260. virtual Color screen_get_pixel(const Point2i &p_position) const { return Color(); };
  261. virtual Ref<Image> screen_get_image(int p_screen = SCREEN_OF_MAIN_WINDOW) const { return Ref<Image>(); };
  262. virtual bool is_touchscreen_available() const;
  263. // Keep the ScreenOrientation enum values in sync with the `display/window/handheld/orientation`
  264. // project setting hint.
  265. enum ScreenOrientation {
  266. SCREEN_LANDSCAPE,
  267. SCREEN_PORTRAIT,
  268. SCREEN_REVERSE_LANDSCAPE,
  269. SCREEN_REVERSE_PORTRAIT,
  270. SCREEN_SENSOR_LANDSCAPE,
  271. SCREEN_SENSOR_PORTRAIT,
  272. SCREEN_SENSOR,
  273. };
  274. virtual void screen_set_orientation(ScreenOrientation p_orientation, int p_screen = SCREEN_OF_MAIN_WINDOW);
  275. virtual ScreenOrientation screen_get_orientation(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
  276. virtual void screen_set_keep_on(bool p_enable); //disable screensaver
  277. virtual bool screen_is_kept_on() const;
  278. enum {
  279. MAIN_WINDOW_ID = 0,
  280. INVALID_WINDOW_ID = -1
  281. };
  282. typedef int WindowID;
  283. virtual Vector<DisplayServer::WindowID> get_window_list() const = 0;
  284. enum WindowFlags {
  285. WINDOW_FLAG_RESIZE_DISABLED,
  286. WINDOW_FLAG_BORDERLESS,
  287. WINDOW_FLAG_ALWAYS_ON_TOP,
  288. WINDOW_FLAG_TRANSPARENT,
  289. WINDOW_FLAG_NO_FOCUS,
  290. WINDOW_FLAG_POPUP,
  291. WINDOW_FLAG_EXTEND_TO_TITLE,
  292. WINDOW_FLAG_MOUSE_PASSTHROUGH,
  293. WINDOW_FLAG_MAX,
  294. };
  295. // Separate enum otherwise we get warnings in switches not handling all values.
  296. enum WindowFlagsBit {
  297. WINDOW_FLAG_RESIZE_DISABLED_BIT = (1 << WINDOW_FLAG_RESIZE_DISABLED),
  298. WINDOW_FLAG_BORDERLESS_BIT = (1 << WINDOW_FLAG_BORDERLESS),
  299. WINDOW_FLAG_ALWAYS_ON_TOP_BIT = (1 << WINDOW_FLAG_ALWAYS_ON_TOP),
  300. WINDOW_FLAG_TRANSPARENT_BIT = (1 << WINDOW_FLAG_TRANSPARENT),
  301. WINDOW_FLAG_NO_FOCUS_BIT = (1 << WINDOW_FLAG_NO_FOCUS),
  302. WINDOW_FLAG_POPUP_BIT = (1 << WINDOW_FLAG_POPUP),
  303. WINDOW_FLAG_EXTEND_TO_TITLE_BIT = (1 << WINDOW_FLAG_EXTEND_TO_TITLE),
  304. WINDOW_FLAG_MOUSE_PASSTHROUGH_BIT = (1 << WINDOW_FLAG_MOUSE_PASSTHROUGH),
  305. };
  306. virtual WindowID create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i());
  307. virtual void show_window(WindowID p_id);
  308. virtual void delete_sub_window(WindowID p_id);
  309. virtual WindowID window_get_active_popup() const { return INVALID_WINDOW_ID; };
  310. virtual void window_set_popup_safe_rect(WindowID p_window, const Rect2i &p_rect){};
  311. virtual Rect2i window_get_popup_safe_rect(WindowID p_window) const { return Rect2i(); };
  312. virtual int64_t window_get_native_handle(HandleType p_handle_type, WindowID p_window = MAIN_WINDOW_ID) const;
  313. virtual WindowID get_window_at_screen_position(const Point2i &p_position) const = 0;
  314. virtual void window_attach_instance_id(ObjectID p_instance, WindowID p_window = MAIN_WINDOW_ID) = 0;
  315. virtual ObjectID window_get_attached_instance_id(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  316. virtual void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0;
  317. enum WindowEvent {
  318. WINDOW_EVENT_MOUSE_ENTER,
  319. WINDOW_EVENT_MOUSE_EXIT,
  320. WINDOW_EVENT_FOCUS_IN,
  321. WINDOW_EVENT_FOCUS_OUT,
  322. WINDOW_EVENT_CLOSE_REQUEST,
  323. WINDOW_EVENT_GO_BACK_REQUEST,
  324. WINDOW_EVENT_DPI_CHANGE,
  325. WINDOW_EVENT_TITLEBAR_CHANGE,
  326. };
  327. virtual void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0;
  328. virtual void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0;
  329. virtual void window_set_input_text_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0;
  330. virtual void window_set_drop_files_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0;
  331. virtual void window_set_title(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) = 0;
  332. virtual void window_set_mouse_passthrough(const Vector<Vector2> &p_region, WindowID p_window = MAIN_WINDOW_ID);
  333. virtual int window_get_current_screen(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  334. virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) = 0;
  335. virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  336. virtual Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  337. virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) = 0;
  338. virtual void window_set_transient(WindowID p_window, WindowID p_parent) = 0;
  339. virtual void window_set_exclusive(WindowID p_window, bool p_exclusive);
  340. virtual void window_set_max_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) = 0;
  341. virtual Size2i window_get_max_size(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  342. virtual void window_set_min_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) = 0;
  343. virtual Size2i window_get_min_size(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  344. virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) = 0;
  345. virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  346. virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  347. virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) = 0;
  348. virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  349. virtual void window_set_vsync_mode(VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID);
  350. virtual VSyncMode window_get_vsync_mode(WindowID p_window) const;
  351. virtual bool window_is_maximize_allowed(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  352. virtual void window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window = MAIN_WINDOW_ID) = 0;
  353. virtual bool window_get_flag(WindowFlags p_flag, WindowID p_window = MAIN_WINDOW_ID) const = 0;
  354. virtual void window_request_attention(WindowID p_window = MAIN_WINDOW_ID) = 0;
  355. virtual void window_move_to_foreground(WindowID p_window = MAIN_WINDOW_ID) = 0;
  356. virtual bool window_is_focused(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  357. virtual void window_set_window_buttons_offset(const Vector2i &p_offset, WindowID p_window = MAIN_WINDOW_ID) {}
  358. virtual Vector3i window_get_safe_title_margins(WindowID p_window = MAIN_WINDOW_ID) const { return Vector3i(); }
  359. virtual bool window_can_draw(WindowID p_window = MAIN_WINDOW_ID) const = 0;
  360. virtual bool can_any_window_draw() const = 0;
  361. virtual void window_set_ime_active(const bool p_active, WindowID p_window = MAIN_WINDOW_ID);
  362. virtual void window_set_ime_position(const Point2i &p_pos, WindowID p_window = MAIN_WINDOW_ID);
  363. virtual bool window_maximize_on_title_dbl_click() const { return false; }
  364. virtual bool window_minimize_on_title_dbl_click() const { return false; }
  365. // necessary for GL focus, may be able to use one of the existing functions for this, not sure yet
  366. virtual void gl_window_make_current(DisplayServer::WindowID p_window_id);
  367. virtual Point2i ime_get_selection() const;
  368. virtual String ime_get_text() const;
  369. enum VirtualKeyboardType {
  370. KEYBOARD_TYPE_DEFAULT,
  371. KEYBOARD_TYPE_MULTILINE,
  372. KEYBOARD_TYPE_NUMBER,
  373. KEYBOARD_TYPE_NUMBER_DECIMAL,
  374. KEYBOARD_TYPE_PHONE,
  375. KEYBOARD_TYPE_EMAIL_ADDRESS,
  376. KEYBOARD_TYPE_PASSWORD,
  377. KEYBOARD_TYPE_URL
  378. };
  379. 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);
  380. virtual void virtual_keyboard_hide();
  381. // returns height of the currently shown virtual keyboard (0 if keyboard is hidden)
  382. virtual int virtual_keyboard_get_height() const;
  383. enum CursorShape {
  384. CURSOR_ARROW,
  385. CURSOR_IBEAM,
  386. CURSOR_POINTING_HAND,
  387. CURSOR_CROSS,
  388. CURSOR_WAIT,
  389. CURSOR_BUSY,
  390. CURSOR_DRAG,
  391. CURSOR_CAN_DROP,
  392. CURSOR_FORBIDDEN,
  393. CURSOR_VSIZE,
  394. CURSOR_HSIZE,
  395. CURSOR_BDIAGSIZE,
  396. CURSOR_FDIAGSIZE,
  397. CURSOR_MOVE,
  398. CURSOR_VSPLIT,
  399. CURSOR_HSPLIT,
  400. CURSOR_HELP,
  401. CURSOR_MAX
  402. };
  403. virtual void cursor_set_shape(CursorShape p_shape);
  404. virtual CursorShape cursor_get_shape() const;
  405. virtual void cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2());
  406. virtual bool get_swap_cancel_ok();
  407. virtual void enable_for_stealing_focus(OS::ProcessID pid);
  408. virtual Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback);
  409. virtual Error dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback);
  410. virtual int keyboard_get_layout_count() const;
  411. virtual int keyboard_get_current_layout() const;
  412. virtual void keyboard_set_current_layout(int p_index);
  413. virtual String keyboard_get_layout_language(int p_index) const;
  414. virtual String keyboard_get_layout_name(int p_index) const;
  415. virtual Key keyboard_get_keycode_from_physical(Key p_keycode) const;
  416. virtual int tablet_get_driver_count() const { return 1; };
  417. virtual String tablet_get_driver_name(int p_driver) const { return "default"; };
  418. virtual String tablet_get_current_driver() const { return "default"; };
  419. virtual void tablet_set_current_driver(const String &p_driver){};
  420. virtual void process_events() = 0;
  421. virtual void force_process_and_drop_events();
  422. virtual void release_rendering_thread();
  423. virtual void make_rendering_thread();
  424. virtual void swap_buffers();
  425. virtual void set_native_icon(const String &p_filename);
  426. virtual void set_icon(const Ref<Image> &p_icon);
  427. enum Context {
  428. CONTEXT_EDITOR,
  429. CONTEXT_PROJECTMAN,
  430. CONTEXT_ENGINE,
  431. };
  432. virtual void set_context(Context p_context);
  433. static void register_create_function(const char *p_name, CreateFunction p_function, GetRenderingDriversFunction p_get_drivers);
  434. static int get_create_function_count();
  435. static const char *get_create_function_name(int p_index);
  436. static Vector<String> get_create_function_rendering_drivers(int p_index);
  437. 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, Error &r_error);
  438. DisplayServer();
  439. ~DisplayServer();
  440. };
  441. VARIANT_ENUM_CAST(DisplayServer::WindowEvent)
  442. VARIANT_ENUM_CAST(DisplayServer::Feature)
  443. VARIANT_ENUM_CAST(DisplayServer::MouseMode)
  444. VARIANT_ENUM_CAST(DisplayServer::ScreenOrientation)
  445. VARIANT_ENUM_CAST(DisplayServer::WindowMode)
  446. VARIANT_ENUM_CAST(DisplayServer::WindowFlags)
  447. VARIANT_ENUM_CAST(DisplayServer::HandleType)
  448. VARIANT_ENUM_CAST(DisplayServer::VirtualKeyboardType);
  449. VARIANT_ENUM_CAST(DisplayServer::CursorShape)
  450. VARIANT_ENUM_CAST(DisplayServer::VSyncMode)
  451. VARIANT_ENUM_CAST(DisplayServer::TTSUtteranceEvent)
  452. #endif // DISPLAY_SERVER_H