display_server.cpp 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. /**************************************************************************/
  2. /* display_server.cpp */
  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. #include "display_server.h"
  31. #include "core/input/input.h"
  32. #include "scene/resources/texture.h"
  33. #include "servers/display_server_headless.h"
  34. #if defined(VULKAN_ENABLED)
  35. #include "drivers/vulkan/rendering_context_driver_vulkan.h"
  36. #undef CursorShape
  37. #endif
  38. #if defined(D3D12_ENABLED)
  39. #include "drivers/d3d12/rendering_context_driver_d3d12.h"
  40. #endif
  41. #if defined(METAL_ENABLED)
  42. #include "drivers/metal/rendering_context_driver_metal.h"
  43. #endif
  44. DisplayServer *DisplayServer::singleton = nullptr;
  45. bool DisplayServer::hidpi_allowed = false;
  46. bool DisplayServer::window_early_clear_override_enabled = false;
  47. Color DisplayServer::window_early_clear_override_color = Color(0, 0, 0, 0);
  48. DisplayServer::DisplayServerCreate DisplayServer::server_create_functions[DisplayServer::MAX_SERVERS] = {
  49. { "headless", &DisplayServerHeadless::create_func, &DisplayServerHeadless::get_rendering_drivers_func }
  50. };
  51. int DisplayServer::server_create_count = 1;
  52. void DisplayServer::help_set_search_callbacks(const Callable &p_search_callback, const Callable &p_action_callback) {
  53. WARN_PRINT("Native help is not supported by this display server.");
  54. }
  55. #ifndef DISABLE_DEPRECATED
  56. RID DisplayServer::_get_rid_from_name(NativeMenu *p_nmenu, const String &p_menu_root) const {
  57. if (p_menu_root == "_main") {
  58. return p_nmenu->get_system_menu(NativeMenu::MAIN_MENU_ID);
  59. } else if (p_menu_root == "_apple") {
  60. return p_nmenu->get_system_menu(NativeMenu::APPLICATION_MENU_ID);
  61. } else if (p_menu_root == "_dock") {
  62. return p_nmenu->get_system_menu(NativeMenu::DOCK_MENU_ID);
  63. } else if (p_menu_root == "_help") {
  64. return p_nmenu->get_system_menu(NativeMenu::HELP_MENU_ID);
  65. } else if (p_menu_root == "_window") {
  66. return p_nmenu->get_system_menu(NativeMenu::WINDOW_MENU_ID);
  67. } else if (menu_names.has(p_menu_root)) {
  68. return menu_names[p_menu_root];
  69. }
  70. RID rid = p_nmenu->create_menu();
  71. menu_names[p_menu_root] = rid;
  72. return rid;
  73. }
  74. int DisplayServer::global_menu_add_item(const String &p_menu_root, const String &p_label, const Callable &p_callback, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  75. NativeMenu *nmenu = NativeMenu::get_singleton();
  76. ERR_FAIL_NULL_V(nmenu, -1);
  77. return nmenu->add_item(_get_rid_from_name(nmenu, p_menu_root), p_label, p_callback, p_key_callback, p_tag, p_accel, p_index);
  78. }
  79. int DisplayServer::global_menu_add_check_item(const String &p_menu_root, const String &p_label, const Callable &p_callback, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  80. NativeMenu *nmenu = NativeMenu::get_singleton();
  81. ERR_FAIL_NULL_V(nmenu, -1);
  82. return nmenu->add_check_item(_get_rid_from_name(nmenu, p_menu_root), p_label, p_callback, p_key_callback, p_tag, p_accel, p_index);
  83. }
  84. int DisplayServer::global_menu_add_icon_item(const String &p_menu_root, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  85. NativeMenu *nmenu = NativeMenu::get_singleton();
  86. ERR_FAIL_NULL_V(nmenu, -1);
  87. return nmenu->add_icon_item(_get_rid_from_name(nmenu, p_menu_root), p_icon, p_label, p_callback, p_key_callback, p_tag, p_accel, p_index);
  88. }
  89. int DisplayServer::global_menu_add_icon_check_item(const String &p_menu_root, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  90. NativeMenu *nmenu = NativeMenu::get_singleton();
  91. ERR_FAIL_NULL_V(nmenu, -1);
  92. return nmenu->add_icon_check_item(_get_rid_from_name(nmenu, p_menu_root), p_icon, p_label, p_callback, p_key_callback, p_tag, p_accel, p_index);
  93. }
  94. int DisplayServer::global_menu_add_radio_check_item(const String &p_menu_root, const String &p_label, const Callable &p_callback, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  95. NativeMenu *nmenu = NativeMenu::get_singleton();
  96. ERR_FAIL_NULL_V(nmenu, -1);
  97. return nmenu->add_radio_check_item(_get_rid_from_name(nmenu, p_menu_root), p_label, p_callback, p_key_callback, p_tag, p_accel, p_index);
  98. }
  99. int DisplayServer::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, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  100. NativeMenu *nmenu = NativeMenu::get_singleton();
  101. ERR_FAIL_NULL_V(nmenu, -1);
  102. return nmenu->add_icon_radio_check_item(_get_rid_from_name(nmenu, p_menu_root), p_icon, p_label, p_callback, p_key_callback, p_tag, p_accel, p_index);
  103. }
  104. int DisplayServer::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, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  105. NativeMenu *nmenu = NativeMenu::get_singleton();
  106. ERR_FAIL_NULL_V(nmenu, -1);
  107. return nmenu->add_multistate_item(_get_rid_from_name(nmenu, p_menu_root), p_label, p_max_states, p_default_state, p_callback, p_key_callback, p_tag, p_accel, p_index);
  108. }
  109. void DisplayServer::global_menu_set_popup_callbacks(const String &p_menu_root, const Callable &p_open_callback, const Callable &p_close_callback) {
  110. NativeMenu *nmenu = NativeMenu::get_singleton();
  111. ERR_FAIL_NULL(nmenu);
  112. nmenu->set_popup_open_callback(_get_rid_from_name(nmenu, p_menu_root), p_open_callback);
  113. nmenu->set_popup_open_callback(_get_rid_from_name(nmenu, p_menu_root), p_close_callback);
  114. }
  115. int DisplayServer::global_menu_add_submenu_item(const String &p_menu_root, const String &p_label, const String &p_submenu, int p_index) {
  116. NativeMenu *nmenu = NativeMenu::get_singleton();
  117. ERR_FAIL_NULL_V(nmenu, -1);
  118. return nmenu->add_submenu_item(_get_rid_from_name(nmenu, p_menu_root), p_label, _get_rid_from_name(nmenu, p_submenu), Variant(), p_index);
  119. }
  120. int DisplayServer::global_menu_add_separator(const String &p_menu_root, int p_index) {
  121. NativeMenu *nmenu = NativeMenu::get_singleton();
  122. ERR_FAIL_NULL_V(nmenu, -1);
  123. return nmenu->add_separator(_get_rid_from_name(nmenu, p_menu_root), p_index);
  124. }
  125. int DisplayServer::global_menu_get_item_index_from_text(const String &p_menu_root, const String &p_text) const {
  126. NativeMenu *nmenu = NativeMenu::get_singleton();
  127. ERR_FAIL_NULL_V(nmenu, -1);
  128. return nmenu->find_item_index_with_text(_get_rid_from_name(nmenu, p_menu_root), p_text);
  129. }
  130. int DisplayServer::global_menu_get_item_index_from_tag(const String &p_menu_root, const Variant &p_tag) const {
  131. NativeMenu *nmenu = NativeMenu::get_singleton();
  132. ERR_FAIL_NULL_V(nmenu, -1);
  133. return nmenu->find_item_index_with_tag(_get_rid_from_name(nmenu, p_menu_root), p_tag);
  134. }
  135. void DisplayServer::global_menu_set_item_callback(const String &p_menu_root, int p_idx, const Callable &p_callback) {
  136. NativeMenu *nmenu = NativeMenu::get_singleton();
  137. ERR_FAIL_NULL(nmenu);
  138. nmenu->set_item_callback(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_callback);
  139. }
  140. void DisplayServer::global_menu_set_item_hover_callbacks(const String &p_menu_root, int p_idx, const Callable &p_callback) {
  141. NativeMenu *nmenu = NativeMenu::get_singleton();
  142. ERR_FAIL_NULL(nmenu);
  143. nmenu->set_item_hover_callbacks(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_callback);
  144. }
  145. void DisplayServer::global_menu_set_item_key_callback(const String &p_menu_root, int p_idx, const Callable &p_key_callback) {
  146. NativeMenu *nmenu = NativeMenu::get_singleton();
  147. ERR_FAIL_NULL(nmenu);
  148. nmenu->set_item_key_callback(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_key_callback);
  149. }
  150. bool DisplayServer::global_menu_is_item_checked(const String &p_menu_root, int p_idx) const {
  151. NativeMenu *nmenu = NativeMenu::get_singleton();
  152. ERR_FAIL_NULL_V(nmenu, false);
  153. return nmenu->is_item_checked(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  154. }
  155. bool DisplayServer::global_menu_is_item_checkable(const String &p_menu_root, int p_idx) const {
  156. NativeMenu *nmenu = NativeMenu::get_singleton();
  157. ERR_FAIL_NULL_V(nmenu, false);
  158. return nmenu->is_item_checkable(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  159. }
  160. bool DisplayServer::global_menu_is_item_radio_checkable(const String &p_menu_root, int p_idx) const {
  161. NativeMenu *nmenu = NativeMenu::get_singleton();
  162. ERR_FAIL_NULL_V(nmenu, false);
  163. return nmenu->is_item_radio_checkable(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  164. }
  165. Callable DisplayServer::global_menu_get_item_callback(const String &p_menu_root, int p_idx) const {
  166. NativeMenu *nmenu = NativeMenu::get_singleton();
  167. ERR_FAIL_NULL_V(nmenu, Callable());
  168. return nmenu->get_item_callback(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  169. }
  170. Callable DisplayServer::global_menu_get_item_key_callback(const String &p_menu_root, int p_idx) const {
  171. NativeMenu *nmenu = NativeMenu::get_singleton();
  172. ERR_FAIL_NULL_V(nmenu, Callable());
  173. return nmenu->get_item_key_callback(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  174. }
  175. Variant DisplayServer::global_menu_get_item_tag(const String &p_menu_root, int p_idx) const {
  176. NativeMenu *nmenu = NativeMenu::get_singleton();
  177. ERR_FAIL_NULL_V(nmenu, Variant());
  178. return nmenu->get_item_tag(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  179. }
  180. String DisplayServer::global_menu_get_item_text(const String &p_menu_root, int p_idx) const {
  181. NativeMenu *nmenu = NativeMenu::get_singleton();
  182. ERR_FAIL_NULL_V(nmenu, String());
  183. return nmenu->get_item_text(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  184. }
  185. String DisplayServer::global_menu_get_item_submenu(const String &p_menu_root, int p_idx) const {
  186. NativeMenu *nmenu = NativeMenu::get_singleton();
  187. ERR_FAIL_NULL_V(nmenu, String());
  188. RID rid = nmenu->get_item_submenu(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  189. if (!nmenu->is_system_menu(rid)) {
  190. for (HashMap<String, RID>::Iterator E = menu_names.begin(); E; ++E) {
  191. if (E->value == rid) {
  192. return E->key;
  193. }
  194. }
  195. }
  196. return String();
  197. }
  198. Key DisplayServer::global_menu_get_item_accelerator(const String &p_menu_root, int p_idx) const {
  199. NativeMenu *nmenu = NativeMenu::get_singleton();
  200. ERR_FAIL_NULL_V(nmenu, Key::NONE);
  201. return nmenu->get_item_accelerator(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  202. }
  203. bool DisplayServer::global_menu_is_item_disabled(const String &p_menu_root, int p_idx) const {
  204. NativeMenu *nmenu = NativeMenu::get_singleton();
  205. ERR_FAIL_NULL_V(nmenu, false);
  206. return nmenu->is_item_disabled(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  207. }
  208. bool DisplayServer::global_menu_is_item_hidden(const String &p_menu_root, int p_idx) const {
  209. NativeMenu *nmenu = NativeMenu::get_singleton();
  210. ERR_FAIL_NULL_V(nmenu, false);
  211. return nmenu->is_item_hidden(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  212. }
  213. String DisplayServer::global_menu_get_item_tooltip(const String &p_menu_root, int p_idx) const {
  214. NativeMenu *nmenu = NativeMenu::get_singleton();
  215. ERR_FAIL_NULL_V(nmenu, String());
  216. return nmenu->get_item_tooltip(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  217. }
  218. int DisplayServer::global_menu_get_item_state(const String &p_menu_root, int p_idx) const {
  219. NativeMenu *nmenu = NativeMenu::get_singleton();
  220. ERR_FAIL_NULL_V(nmenu, -1);
  221. return nmenu->get_item_state(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  222. }
  223. int DisplayServer::global_menu_get_item_max_states(const String &p_menu_root, int p_idx) const {
  224. NativeMenu *nmenu = NativeMenu::get_singleton();
  225. ERR_FAIL_NULL_V(nmenu, -1);
  226. return nmenu->get_item_max_states(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  227. }
  228. Ref<Texture2D> DisplayServer::global_menu_get_item_icon(const String &p_menu_root, int p_idx) const {
  229. NativeMenu *nmenu = NativeMenu::get_singleton();
  230. ERR_FAIL_NULL_V(nmenu, Ref<Texture2D>());
  231. return nmenu->get_item_icon(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  232. }
  233. int DisplayServer::global_menu_get_item_indentation_level(const String &p_menu_root, int p_idx) const {
  234. NativeMenu *nmenu = NativeMenu::get_singleton();
  235. ERR_FAIL_NULL_V(nmenu, 0);
  236. return nmenu->get_item_indentation_level(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  237. }
  238. void DisplayServer::global_menu_set_item_checked(const String &p_menu_root, int p_idx, bool p_checked) {
  239. NativeMenu *nmenu = NativeMenu::get_singleton();
  240. ERR_FAIL_NULL(nmenu);
  241. nmenu->set_item_checked(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_checked);
  242. }
  243. void DisplayServer::global_menu_set_item_checkable(const String &p_menu_root, int p_idx, bool p_checkable) {
  244. NativeMenu *nmenu = NativeMenu::get_singleton();
  245. ERR_FAIL_NULL(nmenu);
  246. nmenu->set_item_checkable(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_checkable);
  247. }
  248. void DisplayServer::global_menu_set_item_radio_checkable(const String &p_menu_root, int p_idx, bool p_checkable) {
  249. NativeMenu *nmenu = NativeMenu::get_singleton();
  250. ERR_FAIL_NULL(nmenu);
  251. nmenu->set_item_radio_checkable(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_checkable);
  252. }
  253. void DisplayServer::global_menu_set_item_tag(const String &p_menu_root, int p_idx, const Variant &p_tag) {
  254. NativeMenu *nmenu = NativeMenu::get_singleton();
  255. ERR_FAIL_NULL(nmenu);
  256. nmenu->set_item_tag(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_tag);
  257. }
  258. void DisplayServer::global_menu_set_item_text(const String &p_menu_root, int p_idx, const String &p_text) {
  259. NativeMenu *nmenu = NativeMenu::get_singleton();
  260. ERR_FAIL_NULL(nmenu);
  261. nmenu->set_item_text(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_text);
  262. }
  263. void DisplayServer::global_menu_set_item_submenu(const String &p_menu_root, int p_idx, const String &p_submenu) {
  264. NativeMenu *nmenu = NativeMenu::get_singleton();
  265. ERR_FAIL_NULL(nmenu);
  266. nmenu->set_item_submenu(_get_rid_from_name(nmenu, p_menu_root), p_idx, _get_rid_from_name(nmenu, p_submenu));
  267. }
  268. void DisplayServer::global_menu_set_item_accelerator(const String &p_menu_root, int p_idx, Key p_keycode) {
  269. NativeMenu *nmenu = NativeMenu::get_singleton();
  270. ERR_FAIL_NULL(nmenu);
  271. nmenu->set_item_accelerator(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_keycode);
  272. }
  273. void DisplayServer::global_menu_set_item_disabled(const String &p_menu_root, int p_idx, bool p_disabled) {
  274. NativeMenu *nmenu = NativeMenu::get_singleton();
  275. ERR_FAIL_NULL(nmenu);
  276. nmenu->set_item_disabled(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_disabled);
  277. }
  278. void DisplayServer::global_menu_set_item_hidden(const String &p_menu_root, int p_idx, bool p_hidden) {
  279. NativeMenu *nmenu = NativeMenu::get_singleton();
  280. ERR_FAIL_NULL(nmenu);
  281. nmenu->set_item_hidden(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_hidden);
  282. }
  283. void DisplayServer::global_menu_set_item_tooltip(const String &p_menu_root, int p_idx, const String &p_tooltip) {
  284. NativeMenu *nmenu = NativeMenu::get_singleton();
  285. ERR_FAIL_NULL(nmenu);
  286. nmenu->set_item_tooltip(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_tooltip);
  287. }
  288. void DisplayServer::global_menu_set_item_state(const String &p_menu_root, int p_idx, int p_state) {
  289. NativeMenu *nmenu = NativeMenu::get_singleton();
  290. ERR_FAIL_NULL(nmenu);
  291. nmenu->set_item_state(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_state);
  292. }
  293. void DisplayServer::global_menu_set_item_max_states(const String &p_menu_root, int p_idx, int p_max_states) {
  294. NativeMenu *nmenu = NativeMenu::get_singleton();
  295. ERR_FAIL_NULL(nmenu);
  296. nmenu->set_item_max_states(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_max_states);
  297. }
  298. void DisplayServer::global_menu_set_item_icon(const String &p_menu_root, int p_idx, const Ref<Texture2D> &p_icon) {
  299. NativeMenu *nmenu = NativeMenu::get_singleton();
  300. ERR_FAIL_NULL(nmenu);
  301. nmenu->set_item_icon(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_icon);
  302. }
  303. void DisplayServer::global_menu_set_item_indentation_level(const String &p_menu_root, int p_idx, int p_level) {
  304. NativeMenu *nmenu = NativeMenu::get_singleton();
  305. ERR_FAIL_NULL(nmenu);
  306. nmenu->set_item_indentation_level(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_level);
  307. }
  308. int DisplayServer::global_menu_get_item_count(const String &p_menu_root) const {
  309. NativeMenu *nmenu = NativeMenu::get_singleton();
  310. ERR_FAIL_NULL_V(nmenu, 0);
  311. return nmenu->get_item_count(_get_rid_from_name(nmenu, p_menu_root));
  312. }
  313. void DisplayServer::global_menu_remove_item(const String &p_menu_root, int p_idx) {
  314. NativeMenu *nmenu = NativeMenu::get_singleton();
  315. ERR_FAIL_NULL(nmenu);
  316. nmenu->remove_item(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  317. }
  318. void DisplayServer::global_menu_clear(const String &p_menu_root) {
  319. NativeMenu *nmenu = NativeMenu::get_singleton();
  320. ERR_FAIL_NULL(nmenu);
  321. RID rid = _get_rid_from_name(nmenu, p_menu_root);
  322. nmenu->clear(rid);
  323. if (!nmenu->is_system_menu(rid)) {
  324. nmenu->free_menu(rid);
  325. menu_names.erase(p_menu_root);
  326. }
  327. }
  328. Dictionary DisplayServer::global_menu_get_system_menu_roots() const {
  329. NativeMenu *nmenu = NativeMenu::get_singleton();
  330. ERR_FAIL_NULL_V(nmenu, Dictionary());
  331. Dictionary out;
  332. if (nmenu->has_system_menu(NativeMenu::DOCK_MENU_ID)) {
  333. out["_dock"] = "@Dock";
  334. }
  335. if (nmenu->has_system_menu(NativeMenu::APPLICATION_MENU_ID)) {
  336. out["_apple"] = "@Apple";
  337. }
  338. if (nmenu->has_system_menu(NativeMenu::WINDOW_MENU_ID)) {
  339. out["_window"] = "Window";
  340. }
  341. if (nmenu->has_system_menu(NativeMenu::HELP_MENU_ID)) {
  342. out["_help"] = "Help";
  343. }
  344. return out;
  345. }
  346. #endif
  347. bool DisplayServer::tts_is_speaking() const {
  348. WARN_PRINT("TTS is not supported by this display server.");
  349. return false;
  350. }
  351. bool DisplayServer::tts_is_paused() const {
  352. WARN_PRINT("TTS is not supported by this display server.");
  353. return false;
  354. }
  355. void DisplayServer::tts_pause() {
  356. WARN_PRINT("TTS is not supported by this display server.");
  357. }
  358. void DisplayServer::tts_resume() {
  359. WARN_PRINT("TTS is not supported by this display server.");
  360. }
  361. TypedArray<Dictionary> DisplayServer::tts_get_voices() const {
  362. WARN_PRINT("TTS is not supported by this display server.");
  363. return TypedArray<Dictionary>();
  364. }
  365. PackedStringArray DisplayServer::tts_get_voices_for_language(const String &p_language) const {
  366. PackedStringArray ret;
  367. TypedArray<Dictionary> voices = tts_get_voices();
  368. for (int i = 0; i < voices.size(); i++) {
  369. const Dictionary &voice = voices[i];
  370. if (voice.has("id") && voice.has("language") && voice["language"].operator String().begins_with(p_language)) {
  371. ret.push_back(voice["id"]);
  372. }
  373. }
  374. return ret;
  375. }
  376. void DisplayServer::tts_speak(const String &p_text, const String &p_voice, int p_volume, float p_pitch, float p_rate, int p_utterance_id, bool p_interrupt) {
  377. WARN_PRINT("TTS is not supported by this display server.");
  378. }
  379. void DisplayServer::tts_stop() {
  380. WARN_PRINT("TTS is not supported by this display server.");
  381. }
  382. void DisplayServer::tts_set_utterance_callback(TTSUtteranceEvent p_event, const Callable &p_callable) {
  383. ERR_FAIL_INDEX(p_event, DisplayServer::TTS_UTTERANCE_MAX);
  384. utterance_callback[p_event] = p_callable;
  385. }
  386. void DisplayServer::tts_post_utterance_event(TTSUtteranceEvent p_event, int p_id, int p_pos) {
  387. ERR_FAIL_INDEX(p_event, DisplayServer::TTS_UTTERANCE_MAX);
  388. switch (p_event) {
  389. case DisplayServer::TTS_UTTERANCE_STARTED:
  390. case DisplayServer::TTS_UTTERANCE_ENDED:
  391. case DisplayServer::TTS_UTTERANCE_CANCELED: {
  392. if (utterance_callback[p_event].is_valid()) {
  393. utterance_callback[p_event].call_deferred(p_id); // Should be deferred, on some platforms utterance events can be called from different threads in a rapid succession.
  394. }
  395. } break;
  396. case DisplayServer::TTS_UTTERANCE_BOUNDARY: {
  397. if (utterance_callback[p_event].is_valid()) {
  398. utterance_callback[p_event].call_deferred(p_pos, p_id); // Should be deferred, on some platforms utterance events can be called from different threads in a rapid succession.
  399. }
  400. } break;
  401. default:
  402. break;
  403. }
  404. }
  405. bool DisplayServer::_get_window_early_clear_override(Color &r_color) {
  406. if (window_early_clear_override_enabled) {
  407. r_color = window_early_clear_override_color;
  408. return true;
  409. } else if (RenderingServer::get_singleton()) {
  410. r_color = RenderingServer::get_singleton()->get_default_clear_color();
  411. return true;
  412. } else {
  413. return false;
  414. }
  415. }
  416. void DisplayServer::set_early_window_clear_color_override(bool p_enabled, Color p_color) {
  417. window_early_clear_override_enabled = p_enabled;
  418. window_early_clear_override_color = p_color;
  419. }
  420. void DisplayServer::mouse_set_mode(MouseMode p_mode) {
  421. WARN_PRINT("Mouse is not supported by this display server.");
  422. }
  423. DisplayServer::MouseMode DisplayServer::mouse_get_mode() const {
  424. return MOUSE_MODE_VISIBLE;
  425. }
  426. void DisplayServer::warp_mouse(const Point2i &p_position) {
  427. }
  428. Point2i DisplayServer::mouse_get_position() const {
  429. ERR_FAIL_V_MSG(Point2i(), "Mouse is not supported by this display server.");
  430. }
  431. BitField<MouseButtonMask> DisplayServer::mouse_get_button_state() const {
  432. ERR_FAIL_V_MSG(0, "Mouse is not supported by this display server.");
  433. }
  434. void DisplayServer::clipboard_set(const String &p_text) {
  435. WARN_PRINT("Clipboard is not supported by this display server.");
  436. }
  437. String DisplayServer::clipboard_get() const {
  438. ERR_FAIL_V_MSG(String(), "Clipboard is not supported by this display server.");
  439. }
  440. Ref<Image> DisplayServer::clipboard_get_image() const {
  441. ERR_FAIL_V_MSG(Ref<Image>(), "Clipboard is not supported by this display server.");
  442. }
  443. bool DisplayServer::clipboard_has() const {
  444. return !clipboard_get().is_empty();
  445. }
  446. bool DisplayServer::clipboard_has_image() const {
  447. return clipboard_get_image().is_valid();
  448. }
  449. void DisplayServer::clipboard_set_primary(const String &p_text) {
  450. WARN_PRINT("Primary clipboard is not supported by this display server.");
  451. }
  452. String DisplayServer::clipboard_get_primary() const {
  453. ERR_FAIL_V_MSG(String(), "Primary clipboard is not supported by this display server.");
  454. }
  455. void DisplayServer::screen_set_orientation(ScreenOrientation p_orientation, int p_screen) {
  456. WARN_PRINT("Orientation not supported by this display server.");
  457. }
  458. DisplayServer::ScreenOrientation DisplayServer::screen_get_orientation(int p_screen) const {
  459. return SCREEN_LANDSCAPE;
  460. }
  461. float DisplayServer::screen_get_scale(int p_screen) const {
  462. return 1.0f;
  463. }
  464. bool DisplayServer::is_touchscreen_available() const {
  465. return Input::get_singleton() && Input::get_singleton()->is_emulating_touch_from_mouse();
  466. }
  467. void DisplayServer::screen_set_keep_on(bool p_enable) {
  468. WARN_PRINT("Keeping screen on not supported by this display server.");
  469. }
  470. bool DisplayServer::screen_is_kept_on() const {
  471. return false;
  472. }
  473. int DisplayServer::get_screen_from_rect(const Rect2 &p_rect) const {
  474. int nearest_area = 0;
  475. int pos_screen = -1;
  476. for (int i = 0; i < get_screen_count(); i++) {
  477. Rect2i r;
  478. r.position = screen_get_position(i);
  479. r.size = screen_get_size(i);
  480. Rect2 inters = r.intersection(p_rect);
  481. int area = inters.size.width * inters.size.height;
  482. if (area > nearest_area) {
  483. pos_screen = i;
  484. nearest_area = area;
  485. }
  486. }
  487. return pos_screen;
  488. }
  489. DisplayServer::WindowID DisplayServer::create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect, bool p_exclusive, WindowID p_transient_parent) {
  490. ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Sub-windows not supported by this display server.");
  491. }
  492. void DisplayServer::show_window(WindowID p_id) {
  493. ERR_FAIL_MSG("Sub-windows not supported by this display server.");
  494. }
  495. void DisplayServer::delete_sub_window(WindowID p_id) {
  496. ERR_FAIL_MSG("Sub-windows not supported by this display server.");
  497. }
  498. void DisplayServer::window_set_exclusive(WindowID p_window, bool p_exclusive) {
  499. // Do nothing, if not supported.
  500. }
  501. void DisplayServer::window_set_mouse_passthrough(const Vector<Vector2> &p_region, WindowID p_window) {
  502. ERR_FAIL_MSG("Mouse passthrough not supported by this display server.");
  503. }
  504. void DisplayServer::gl_window_make_current(DisplayServer::WindowID p_window_id) {
  505. // noop except in gles
  506. }
  507. void DisplayServer::window_set_ime_active(const bool p_active, WindowID p_window) {
  508. WARN_PRINT("IME not supported by this display server.");
  509. }
  510. void DisplayServer::window_set_ime_position(const Point2i &p_pos, WindowID p_window) {
  511. WARN_PRINT("IME not supported by this display server.");
  512. }
  513. Point2i DisplayServer::ime_get_selection() const {
  514. ERR_FAIL_V_MSG(Point2i(), "IME or NOTIFICATION_WM_IME_UPDATE not supported by this display server.");
  515. }
  516. String DisplayServer::ime_get_text() const {
  517. ERR_FAIL_V_MSG(String(), "IME or NOTIFICATION_WM_IME_UPDATEnot supported by this display server.");
  518. }
  519. void DisplayServer::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_length, int p_cursor_start, int p_cursor_end) {
  520. WARN_PRINT("Virtual keyboard not supported by this display server.");
  521. }
  522. void DisplayServer::virtual_keyboard_hide() {
  523. WARN_PRINT("Virtual keyboard not supported by this display server.");
  524. }
  525. // returns height of the currently shown keyboard (0 if keyboard is hidden)
  526. int DisplayServer::virtual_keyboard_get_height() const {
  527. ERR_FAIL_V_MSG(0, "Virtual keyboard not supported by this display server.");
  528. }
  529. bool DisplayServer::has_hardware_keyboard() const {
  530. return true;
  531. }
  532. void DisplayServer::cursor_set_shape(CursorShape p_shape) {
  533. WARN_PRINT("Cursor shape not supported by this display server.");
  534. }
  535. DisplayServer::CursorShape DisplayServer::cursor_get_shape() const {
  536. return CURSOR_ARROW;
  537. }
  538. void DisplayServer::cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
  539. WARN_PRINT("Custom cursor shape not supported by this display server.");
  540. }
  541. bool DisplayServer::get_swap_cancel_ok() {
  542. return false;
  543. }
  544. void DisplayServer::enable_for_stealing_focus(OS::ProcessID pid) {
  545. }
  546. Error DisplayServer::dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback) {
  547. WARN_PRINT("Native dialogs not supported by this display server.");
  548. return ERR_UNAVAILABLE;
  549. }
  550. Error DisplayServer::dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback) {
  551. WARN_PRINT("Native dialogs not supported by this display server.");
  552. return ERR_UNAVAILABLE;
  553. }
  554. Error DisplayServer::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) {
  555. WARN_PRINT("Native dialogs not supported by this display server.");
  556. return ERR_UNAVAILABLE;
  557. }
  558. Error DisplayServer::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) {
  559. WARN_PRINT("Native dialogs not supported by this display server.");
  560. return ERR_UNAVAILABLE;
  561. }
  562. int DisplayServer::keyboard_get_layout_count() const {
  563. return 0;
  564. }
  565. int DisplayServer::keyboard_get_current_layout() const {
  566. return -1;
  567. }
  568. void DisplayServer::keyboard_set_current_layout(int p_index) {
  569. }
  570. String DisplayServer::keyboard_get_layout_language(int p_index) const {
  571. return "";
  572. }
  573. String DisplayServer::keyboard_get_layout_name(int p_index) const {
  574. return "Not supported";
  575. }
  576. Key DisplayServer::keyboard_get_keycode_from_physical(Key p_keycode) const {
  577. ERR_FAIL_V_MSG(p_keycode, "Not supported by this display server.");
  578. }
  579. Key DisplayServer::keyboard_get_label_from_physical(Key p_keycode) const {
  580. ERR_FAIL_V_MSG(p_keycode, "Not supported by this display server.");
  581. }
  582. void DisplayServer::force_process_and_drop_events() {
  583. }
  584. void DisplayServer::release_rendering_thread() {
  585. WARN_PRINT("Rendering thread not supported by this display server.");
  586. }
  587. void DisplayServer::swap_buffers() {
  588. WARN_PRINT("Swap buffers not supported by this display server.");
  589. }
  590. void DisplayServer::set_native_icon(const String &p_filename) {
  591. WARN_PRINT("Native icon not supported by this display server.");
  592. }
  593. void DisplayServer::set_icon(const Ref<Image> &p_icon) {
  594. WARN_PRINT("Icon not supported by this display server.");
  595. }
  596. DisplayServer::IndicatorID DisplayServer::create_status_indicator(const Ref<Texture2D> &p_icon, const String &p_tooltip, const Callable &p_callback) {
  597. WARN_PRINT("Status indicator not supported by this display server.");
  598. return INVALID_INDICATOR_ID;
  599. }
  600. void DisplayServer::status_indicator_set_icon(IndicatorID p_id, const Ref<Texture2D> &p_icon) {
  601. WARN_PRINT("Status indicator not supported by this display server.");
  602. }
  603. void DisplayServer::status_indicator_set_tooltip(IndicatorID p_id, const String &p_tooltip) {
  604. WARN_PRINT("Status indicator not supported by this display server.");
  605. }
  606. void DisplayServer::status_indicator_set_menu(IndicatorID p_id, const RID &p_menu_rid) {
  607. WARN_PRINT("Status indicator not supported by this display server.");
  608. }
  609. void DisplayServer::status_indicator_set_callback(IndicatorID p_id, const Callable &p_callback) {
  610. WARN_PRINT("Status indicator not supported by this display server.");
  611. }
  612. Rect2 DisplayServer::status_indicator_get_rect(IndicatorID p_id) const {
  613. WARN_PRINT("Status indicator not supported by this display server.");
  614. return Rect2();
  615. }
  616. void DisplayServer::delete_status_indicator(IndicatorID p_id) {
  617. WARN_PRINT("Status indicator not supported by this display server.");
  618. }
  619. int64_t DisplayServer::window_get_native_handle(HandleType p_handle_type, WindowID p_window) const {
  620. WARN_PRINT("Native handle not supported by this display server.");
  621. return 0;
  622. }
  623. void DisplayServer::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) {
  624. WARN_PRINT("Changing the V-Sync mode is not supported by this display server.");
  625. }
  626. DisplayServer::VSyncMode DisplayServer::window_get_vsync_mode(WindowID p_window) const {
  627. WARN_PRINT("Changing the V-Sync mode is not supported by this display server.");
  628. return VSyncMode::VSYNC_ENABLED;
  629. }
  630. DisplayServer::WindowID DisplayServer::get_focused_window() const {
  631. return MAIN_WINDOW_ID; // Proper value for single windows.
  632. }
  633. void DisplayServer::set_context(Context p_context) {
  634. }
  635. void DisplayServer::register_additional_output(Object *p_object) {
  636. ObjectID id = p_object->get_instance_id();
  637. if (!additional_outputs.has(id)) {
  638. additional_outputs.push_back(id);
  639. }
  640. }
  641. void DisplayServer::unregister_additional_output(Object *p_object) {
  642. additional_outputs.erase(p_object->get_instance_id());
  643. }
  644. void DisplayServer::_bind_methods() {
  645. ClassDB::bind_method(D_METHOD("has_feature", "feature"), &DisplayServer::has_feature);
  646. ClassDB::bind_method(D_METHOD("get_name"), &DisplayServer::get_name);
  647. ClassDB::bind_method(D_METHOD("help_set_search_callbacks", "search_callback", "action_callback"), &DisplayServer::help_set_search_callbacks);
  648. #ifndef DISABLE_DEPRECATED
  649. ClassDB::bind_method(D_METHOD("global_menu_set_popup_callbacks", "menu_root", "open_callback", "close_callback"), &DisplayServer::global_menu_set_popup_callbacks);
  650. ClassDB::bind_method(D_METHOD("global_menu_add_submenu_item", "menu_root", "label", "submenu", "index"), &DisplayServer::global_menu_add_submenu_item, DEFVAL(-1));
  651. ClassDB::bind_method(D_METHOD("global_menu_add_item", "menu_root", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  652. ClassDB::bind_method(D_METHOD("global_menu_add_check_item", "menu_root", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  653. ClassDB::bind_method(D_METHOD("global_menu_add_icon_item", "menu_root", "icon", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_icon_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  654. ClassDB::bind_method(D_METHOD("global_menu_add_icon_check_item", "menu_root", "icon", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_icon_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  655. ClassDB::bind_method(D_METHOD("global_menu_add_radio_check_item", "menu_root", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_radio_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  656. ClassDB::bind_method(D_METHOD("global_menu_add_icon_radio_check_item", "menu_root", "icon", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_icon_radio_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  657. ClassDB::bind_method(D_METHOD("global_menu_add_multistate_item", "menu_root", "label", "max_states", "default_state", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_multistate_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  658. ClassDB::bind_method(D_METHOD("global_menu_add_separator", "menu_root", "index"), &DisplayServer::global_menu_add_separator, DEFVAL(-1));
  659. ClassDB::bind_method(D_METHOD("global_menu_get_item_index_from_text", "menu_root", "text"), &DisplayServer::global_menu_get_item_index_from_text);
  660. ClassDB::bind_method(D_METHOD("global_menu_get_item_index_from_tag", "menu_root", "tag"), &DisplayServer::global_menu_get_item_index_from_tag);
  661. ClassDB::bind_method(D_METHOD("global_menu_is_item_checked", "menu_root", "idx"), &DisplayServer::global_menu_is_item_checked);
  662. ClassDB::bind_method(D_METHOD("global_menu_is_item_checkable", "menu_root", "idx"), &DisplayServer::global_menu_is_item_checkable);
  663. ClassDB::bind_method(D_METHOD("global_menu_is_item_radio_checkable", "menu_root", "idx"), &DisplayServer::global_menu_is_item_radio_checkable);
  664. ClassDB::bind_method(D_METHOD("global_menu_get_item_callback", "menu_root", "idx"), &DisplayServer::global_menu_get_item_callback);
  665. ClassDB::bind_method(D_METHOD("global_menu_get_item_key_callback", "menu_root", "idx"), &DisplayServer::global_menu_get_item_key_callback);
  666. ClassDB::bind_method(D_METHOD("global_menu_get_item_tag", "menu_root", "idx"), &DisplayServer::global_menu_get_item_tag);
  667. ClassDB::bind_method(D_METHOD("global_menu_get_item_text", "menu_root", "idx"), &DisplayServer::global_menu_get_item_text);
  668. ClassDB::bind_method(D_METHOD("global_menu_get_item_submenu", "menu_root", "idx"), &DisplayServer::global_menu_get_item_submenu);
  669. ClassDB::bind_method(D_METHOD("global_menu_get_item_accelerator", "menu_root", "idx"), &DisplayServer::global_menu_get_item_accelerator);
  670. ClassDB::bind_method(D_METHOD("global_menu_is_item_disabled", "menu_root", "idx"), &DisplayServer::global_menu_is_item_disabled);
  671. ClassDB::bind_method(D_METHOD("global_menu_is_item_hidden", "menu_root", "idx"), &DisplayServer::global_menu_is_item_hidden);
  672. ClassDB::bind_method(D_METHOD("global_menu_get_item_tooltip", "menu_root", "idx"), &DisplayServer::global_menu_get_item_tooltip);
  673. ClassDB::bind_method(D_METHOD("global_menu_get_item_state", "menu_root", "idx"), &DisplayServer::global_menu_get_item_state);
  674. ClassDB::bind_method(D_METHOD("global_menu_get_item_max_states", "menu_root", "idx"), &DisplayServer::global_menu_get_item_max_states);
  675. ClassDB::bind_method(D_METHOD("global_menu_get_item_icon", "menu_root", "idx"), &DisplayServer::global_menu_get_item_icon);
  676. ClassDB::bind_method(D_METHOD("global_menu_get_item_indentation_level", "menu_root", "idx"), &DisplayServer::global_menu_get_item_indentation_level);
  677. ClassDB::bind_method(D_METHOD("global_menu_set_item_checked", "menu_root", "idx", "checked"), &DisplayServer::global_menu_set_item_checked);
  678. ClassDB::bind_method(D_METHOD("global_menu_set_item_checkable", "menu_root", "idx", "checkable"), &DisplayServer::global_menu_set_item_checkable);
  679. ClassDB::bind_method(D_METHOD("global_menu_set_item_radio_checkable", "menu_root", "idx", "checkable"), &DisplayServer::global_menu_set_item_radio_checkable);
  680. ClassDB::bind_method(D_METHOD("global_menu_set_item_callback", "menu_root", "idx", "callback"), &DisplayServer::global_menu_set_item_callback);
  681. ClassDB::bind_method(D_METHOD("global_menu_set_item_hover_callbacks", "menu_root", "idx", "callback"), &DisplayServer::global_menu_set_item_hover_callbacks);
  682. ClassDB::bind_method(D_METHOD("global_menu_set_item_key_callback", "menu_root", "idx", "key_callback"), &DisplayServer::global_menu_set_item_key_callback);
  683. ClassDB::bind_method(D_METHOD("global_menu_set_item_tag", "menu_root", "idx", "tag"), &DisplayServer::global_menu_set_item_tag);
  684. ClassDB::bind_method(D_METHOD("global_menu_set_item_text", "menu_root", "idx", "text"), &DisplayServer::global_menu_set_item_text);
  685. ClassDB::bind_method(D_METHOD("global_menu_set_item_submenu", "menu_root", "idx", "submenu"), &DisplayServer::global_menu_set_item_submenu);
  686. ClassDB::bind_method(D_METHOD("global_menu_set_item_accelerator", "menu_root", "idx", "keycode"), &DisplayServer::global_menu_set_item_accelerator);
  687. ClassDB::bind_method(D_METHOD("global_menu_set_item_disabled", "menu_root", "idx", "disabled"), &DisplayServer::global_menu_set_item_disabled);
  688. ClassDB::bind_method(D_METHOD("global_menu_set_item_hidden", "menu_root", "idx", "hidden"), &DisplayServer::global_menu_set_item_hidden);
  689. ClassDB::bind_method(D_METHOD("global_menu_set_item_tooltip", "menu_root", "idx", "tooltip"), &DisplayServer::global_menu_set_item_tooltip);
  690. ClassDB::bind_method(D_METHOD("global_menu_set_item_state", "menu_root", "idx", "state"), &DisplayServer::global_menu_set_item_state);
  691. ClassDB::bind_method(D_METHOD("global_menu_set_item_max_states", "menu_root", "idx", "max_states"), &DisplayServer::global_menu_set_item_max_states);
  692. ClassDB::bind_method(D_METHOD("global_menu_set_item_icon", "menu_root", "idx", "icon"), &DisplayServer::global_menu_set_item_icon);
  693. ClassDB::bind_method(D_METHOD("global_menu_set_item_indentation_level", "menu_root", "idx", "level"), &DisplayServer::global_menu_set_item_indentation_level);
  694. ClassDB::bind_method(D_METHOD("global_menu_get_item_count", "menu_root"), &DisplayServer::global_menu_get_item_count);
  695. ClassDB::bind_method(D_METHOD("global_menu_remove_item", "menu_root", "idx"), &DisplayServer::global_menu_remove_item);
  696. ClassDB::bind_method(D_METHOD("global_menu_clear", "menu_root"), &DisplayServer::global_menu_clear);
  697. ClassDB::bind_method(D_METHOD("global_menu_get_system_menu_roots"), &DisplayServer::global_menu_get_system_menu_roots);
  698. #endif
  699. ClassDB::bind_method(D_METHOD("tts_is_speaking"), &DisplayServer::tts_is_speaking);
  700. ClassDB::bind_method(D_METHOD("tts_is_paused"), &DisplayServer::tts_is_paused);
  701. ClassDB::bind_method(D_METHOD("tts_get_voices"), &DisplayServer::tts_get_voices);
  702. ClassDB::bind_method(D_METHOD("tts_get_voices_for_language", "language"), &DisplayServer::tts_get_voices_for_language);
  703. ClassDB::bind_method(D_METHOD("tts_speak", "text", "voice", "volume", "pitch", "rate", "utterance_id", "interrupt"), &DisplayServer::tts_speak, DEFVAL(50), DEFVAL(1.f), DEFVAL(1.f), DEFVAL(0), DEFVAL(false));
  704. ClassDB::bind_method(D_METHOD("tts_pause"), &DisplayServer::tts_pause);
  705. ClassDB::bind_method(D_METHOD("tts_resume"), &DisplayServer::tts_resume);
  706. ClassDB::bind_method(D_METHOD("tts_stop"), &DisplayServer::tts_stop);
  707. ClassDB::bind_method(D_METHOD("tts_set_utterance_callback", "event", "callable"), &DisplayServer::tts_set_utterance_callback);
  708. ClassDB::bind_method(D_METHOD("_tts_post_utterance_event", "event", "id", "char_pos"), &DisplayServer::tts_post_utterance_event);
  709. ClassDB::bind_method(D_METHOD("is_dark_mode_supported"), &DisplayServer::is_dark_mode_supported);
  710. ClassDB::bind_method(D_METHOD("is_dark_mode"), &DisplayServer::is_dark_mode);
  711. ClassDB::bind_method(D_METHOD("get_accent_color"), &DisplayServer::get_accent_color);
  712. ClassDB::bind_method(D_METHOD("get_base_color"), &DisplayServer::get_base_color);
  713. ClassDB::bind_method(D_METHOD("set_system_theme_change_callback", "callable"), &DisplayServer::set_system_theme_change_callback);
  714. ClassDB::bind_method(D_METHOD("mouse_set_mode", "mouse_mode"), &DisplayServer::mouse_set_mode);
  715. ClassDB::bind_method(D_METHOD("mouse_get_mode"), &DisplayServer::mouse_get_mode);
  716. ClassDB::bind_method(D_METHOD("warp_mouse", "position"), &DisplayServer::warp_mouse);
  717. ClassDB::bind_method(D_METHOD("mouse_get_position"), &DisplayServer::mouse_get_position);
  718. ClassDB::bind_method(D_METHOD("mouse_get_button_state"), &DisplayServer::mouse_get_button_state);
  719. ClassDB::bind_method(D_METHOD("clipboard_set", "clipboard"), &DisplayServer::clipboard_set);
  720. ClassDB::bind_method(D_METHOD("clipboard_get"), &DisplayServer::clipboard_get);
  721. ClassDB::bind_method(D_METHOD("clipboard_get_image"), &DisplayServer::clipboard_get_image);
  722. ClassDB::bind_method(D_METHOD("clipboard_has"), &DisplayServer::clipboard_has);
  723. ClassDB::bind_method(D_METHOD("clipboard_has_image"), &DisplayServer::clipboard_has_image);
  724. ClassDB::bind_method(D_METHOD("clipboard_set_primary", "clipboard_primary"), &DisplayServer::clipboard_set_primary);
  725. ClassDB::bind_method(D_METHOD("clipboard_get_primary"), &DisplayServer::clipboard_get_primary);
  726. ClassDB::bind_method(D_METHOD("get_display_cutouts"), &DisplayServer::get_display_cutouts);
  727. ClassDB::bind_method(D_METHOD("get_display_safe_area"), &DisplayServer::get_display_safe_area);
  728. ClassDB::bind_method(D_METHOD("get_screen_count"), &DisplayServer::get_screen_count);
  729. ClassDB::bind_method(D_METHOD("get_primary_screen"), &DisplayServer::get_primary_screen);
  730. ClassDB::bind_method(D_METHOD("get_keyboard_focus_screen"), &DisplayServer::get_keyboard_focus_screen);
  731. ClassDB::bind_method(D_METHOD("get_screen_from_rect", "rect"), &DisplayServer::get_screen_from_rect);
  732. ClassDB::bind_method(D_METHOD("screen_get_position", "screen"), &DisplayServer::screen_get_position, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  733. ClassDB::bind_method(D_METHOD("screen_get_size", "screen"), &DisplayServer::screen_get_size, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  734. ClassDB::bind_method(D_METHOD("screen_get_usable_rect", "screen"), &DisplayServer::screen_get_usable_rect, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  735. ClassDB::bind_method(D_METHOD("screen_get_dpi", "screen"), &DisplayServer::screen_get_dpi, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  736. ClassDB::bind_method(D_METHOD("screen_get_scale", "screen"), &DisplayServer::screen_get_scale, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  737. ClassDB::bind_method(D_METHOD("is_touchscreen_available"), &DisplayServer::is_touchscreen_available, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  738. ClassDB::bind_method(D_METHOD("screen_get_max_scale"), &DisplayServer::screen_get_max_scale);
  739. ClassDB::bind_method(D_METHOD("screen_get_refresh_rate", "screen"), &DisplayServer::screen_get_refresh_rate, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  740. ClassDB::bind_method(D_METHOD("screen_get_pixel", "position"), &DisplayServer::screen_get_pixel);
  741. ClassDB::bind_method(D_METHOD("screen_get_image", "screen"), &DisplayServer::screen_get_image, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  742. ClassDB::bind_method(D_METHOD("screen_set_orientation", "orientation", "screen"), &DisplayServer::screen_set_orientation, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  743. ClassDB::bind_method(D_METHOD("screen_get_orientation", "screen"), &DisplayServer::screen_get_orientation, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  744. ClassDB::bind_method(D_METHOD("screen_set_keep_on", "enable"), &DisplayServer::screen_set_keep_on);
  745. ClassDB::bind_method(D_METHOD("screen_is_kept_on"), &DisplayServer::screen_is_kept_on);
  746. ClassDB::bind_method(D_METHOD("get_window_list"), &DisplayServer::get_window_list);
  747. ClassDB::bind_method(D_METHOD("get_window_at_screen_position", "position"), &DisplayServer::get_window_at_screen_position);
  748. ClassDB::bind_method(D_METHOD("window_get_native_handle", "handle_type", "window_id"), &DisplayServer::window_get_native_handle, DEFVAL(MAIN_WINDOW_ID));
  749. ClassDB::bind_method(D_METHOD("window_get_active_popup"), &DisplayServer::window_get_active_popup);
  750. ClassDB::bind_method(D_METHOD("window_set_popup_safe_rect", "window", "rect"), &DisplayServer::window_set_popup_safe_rect);
  751. ClassDB::bind_method(D_METHOD("window_get_popup_safe_rect", "window"), &DisplayServer::window_get_popup_safe_rect);
  752. ClassDB::bind_method(D_METHOD("window_set_title", "title", "window_id"), &DisplayServer::window_set_title, DEFVAL(MAIN_WINDOW_ID));
  753. ClassDB::bind_method(D_METHOD("window_get_title_size", "title", "window_id"), &DisplayServer::window_get_title_size, DEFVAL(MAIN_WINDOW_ID));
  754. ClassDB::bind_method(D_METHOD("window_set_mouse_passthrough", "region", "window_id"), &DisplayServer::window_set_mouse_passthrough, DEFVAL(MAIN_WINDOW_ID));
  755. ClassDB::bind_method(D_METHOD("window_get_current_screen", "window_id"), &DisplayServer::window_get_current_screen, DEFVAL(MAIN_WINDOW_ID));
  756. ClassDB::bind_method(D_METHOD("window_set_current_screen", "screen", "window_id"), &DisplayServer::window_set_current_screen, DEFVAL(MAIN_WINDOW_ID));
  757. ClassDB::bind_method(D_METHOD("window_get_position", "window_id"), &DisplayServer::window_get_position, DEFVAL(MAIN_WINDOW_ID));
  758. ClassDB::bind_method(D_METHOD("window_get_position_with_decorations", "window_id"), &DisplayServer::window_get_position_with_decorations, DEFVAL(MAIN_WINDOW_ID));
  759. ClassDB::bind_method(D_METHOD("window_set_position", "position", "window_id"), &DisplayServer::window_set_position, DEFVAL(MAIN_WINDOW_ID));
  760. ClassDB::bind_method(D_METHOD("window_get_size", "window_id"), &DisplayServer::window_get_size, DEFVAL(MAIN_WINDOW_ID));
  761. ClassDB::bind_method(D_METHOD("window_set_size", "size", "window_id"), &DisplayServer::window_set_size, DEFVAL(MAIN_WINDOW_ID));
  762. ClassDB::bind_method(D_METHOD("window_set_rect_changed_callback", "callback", "window_id"), &DisplayServer::window_set_rect_changed_callback, DEFVAL(MAIN_WINDOW_ID));
  763. ClassDB::bind_method(D_METHOD("window_set_window_event_callback", "callback", "window_id"), &DisplayServer::window_set_window_event_callback, DEFVAL(MAIN_WINDOW_ID));
  764. ClassDB::bind_method(D_METHOD("window_set_input_event_callback", "callback", "window_id"), &DisplayServer::window_set_input_event_callback, DEFVAL(MAIN_WINDOW_ID));
  765. ClassDB::bind_method(D_METHOD("window_set_input_text_callback", "callback", "window_id"), &DisplayServer::window_set_input_text_callback, DEFVAL(MAIN_WINDOW_ID));
  766. ClassDB::bind_method(D_METHOD("window_set_drop_files_callback", "callback", "window_id"), &DisplayServer::window_set_drop_files_callback, DEFVAL(MAIN_WINDOW_ID));
  767. ClassDB::bind_method(D_METHOD("window_get_attached_instance_id", "window_id"), &DisplayServer::window_get_attached_instance_id, DEFVAL(MAIN_WINDOW_ID));
  768. ClassDB::bind_method(D_METHOD("window_get_max_size", "window_id"), &DisplayServer::window_get_max_size, DEFVAL(MAIN_WINDOW_ID));
  769. ClassDB::bind_method(D_METHOD("window_set_max_size", "max_size", "window_id"), &DisplayServer::window_set_max_size, DEFVAL(MAIN_WINDOW_ID));
  770. ClassDB::bind_method(D_METHOD("window_get_min_size", "window_id"), &DisplayServer::window_get_min_size, DEFVAL(MAIN_WINDOW_ID));
  771. ClassDB::bind_method(D_METHOD("window_set_min_size", "min_size", "window_id"), &DisplayServer::window_set_min_size, DEFVAL(MAIN_WINDOW_ID));
  772. ClassDB::bind_method(D_METHOD("window_get_size_with_decorations", "window_id"), &DisplayServer::window_get_size_with_decorations, DEFVAL(MAIN_WINDOW_ID));
  773. ClassDB::bind_method(D_METHOD("window_get_mode", "window_id"), &DisplayServer::window_get_mode, DEFVAL(MAIN_WINDOW_ID));
  774. ClassDB::bind_method(D_METHOD("window_set_mode", "mode", "window_id"), &DisplayServer::window_set_mode, DEFVAL(MAIN_WINDOW_ID));
  775. ClassDB::bind_method(D_METHOD("window_set_flag", "flag", "enabled", "window_id"), &DisplayServer::window_set_flag, DEFVAL(MAIN_WINDOW_ID));
  776. ClassDB::bind_method(D_METHOD("window_get_flag", "flag", "window_id"), &DisplayServer::window_get_flag, DEFVAL(MAIN_WINDOW_ID));
  777. ClassDB::bind_method(D_METHOD("window_set_window_buttons_offset", "offset", "window_id"), &DisplayServer::window_set_window_buttons_offset, DEFVAL(MAIN_WINDOW_ID));
  778. ClassDB::bind_method(D_METHOD("window_get_safe_title_margins", "window_id"), &DisplayServer::window_get_safe_title_margins, DEFVAL(MAIN_WINDOW_ID));
  779. ClassDB::bind_method(D_METHOD("window_request_attention", "window_id"), &DisplayServer::window_request_attention, DEFVAL(MAIN_WINDOW_ID));
  780. ClassDB::bind_method(D_METHOD("window_move_to_foreground", "window_id"), &DisplayServer::window_move_to_foreground, DEFVAL(MAIN_WINDOW_ID));
  781. ClassDB::bind_method(D_METHOD("window_is_focused", "window_id"), &DisplayServer::window_is_focused, DEFVAL(MAIN_WINDOW_ID));
  782. ClassDB::bind_method(D_METHOD("window_can_draw", "window_id"), &DisplayServer::window_can_draw, DEFVAL(MAIN_WINDOW_ID));
  783. ClassDB::bind_method(D_METHOD("window_set_transient", "window_id", "parent_window_id"), &DisplayServer::window_set_transient);
  784. ClassDB::bind_method(D_METHOD("window_set_exclusive", "window_id", "exclusive"), &DisplayServer::window_set_exclusive);
  785. ClassDB::bind_method(D_METHOD("window_set_ime_active", "active", "window_id"), &DisplayServer::window_set_ime_active, DEFVAL(MAIN_WINDOW_ID));
  786. ClassDB::bind_method(D_METHOD("window_set_ime_position", "position", "window_id"), &DisplayServer::window_set_ime_position, DEFVAL(MAIN_WINDOW_ID));
  787. ClassDB::bind_method(D_METHOD("window_set_vsync_mode", "vsync_mode", "window_id"), &DisplayServer::window_set_vsync_mode, DEFVAL(MAIN_WINDOW_ID));
  788. ClassDB::bind_method(D_METHOD("window_get_vsync_mode", "window_id"), &DisplayServer::window_get_vsync_mode, DEFVAL(MAIN_WINDOW_ID));
  789. ClassDB::bind_method(D_METHOD("window_is_maximize_allowed", "window_id"), &DisplayServer::window_is_maximize_allowed, DEFVAL(MAIN_WINDOW_ID));
  790. ClassDB::bind_method(D_METHOD("window_maximize_on_title_dbl_click"), &DisplayServer::window_maximize_on_title_dbl_click);
  791. ClassDB::bind_method(D_METHOD("window_minimize_on_title_dbl_click"), &DisplayServer::window_minimize_on_title_dbl_click);
  792. ClassDB::bind_method(D_METHOD("ime_get_selection"), &DisplayServer::ime_get_selection);
  793. ClassDB::bind_method(D_METHOD("ime_get_text"), &DisplayServer::ime_get_text);
  794. ClassDB::bind_method(D_METHOD("virtual_keyboard_show", "existing_text", "position", "type", "max_length", "cursor_start", "cursor_end"), &DisplayServer::virtual_keyboard_show, DEFVAL(Rect2()), DEFVAL(KEYBOARD_TYPE_DEFAULT), DEFVAL(-1), DEFVAL(-1), DEFVAL(-1));
  795. ClassDB::bind_method(D_METHOD("virtual_keyboard_hide"), &DisplayServer::virtual_keyboard_hide);
  796. ClassDB::bind_method(D_METHOD("virtual_keyboard_get_height"), &DisplayServer::virtual_keyboard_get_height);
  797. ClassDB::bind_method(D_METHOD("has_hardware_keyboard"), &DisplayServer::has_hardware_keyboard);
  798. ClassDB::bind_method(D_METHOD("cursor_set_shape", "shape"), &DisplayServer::cursor_set_shape);
  799. ClassDB::bind_method(D_METHOD("cursor_get_shape"), &DisplayServer::cursor_get_shape);
  800. ClassDB::bind_method(D_METHOD("cursor_set_custom_image", "cursor", "shape", "hotspot"), &DisplayServer::cursor_set_custom_image, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2()));
  801. ClassDB::bind_method(D_METHOD("get_swap_cancel_ok"), &DisplayServer::get_swap_cancel_ok);
  802. ClassDB::bind_method(D_METHOD("enable_for_stealing_focus", "process_id"), &DisplayServer::enable_for_stealing_focus);
  803. ClassDB::bind_method(D_METHOD("dialog_show", "title", "description", "buttons", "callback"), &DisplayServer::dialog_show);
  804. ClassDB::bind_method(D_METHOD("dialog_input_text", "title", "description", "existing_text", "callback"), &DisplayServer::dialog_input_text);
  805. ClassDB::bind_method(D_METHOD("file_dialog_show", "title", "current_directory", "filename", "show_hidden", "mode", "filters", "callback"), &DisplayServer::file_dialog_show);
  806. ClassDB::bind_method(D_METHOD("file_dialog_with_options_show", "title", "current_directory", "root", "filename", "show_hidden", "mode", "filters", "options", "callback"), &DisplayServer::file_dialog_with_options_show);
  807. ClassDB::bind_method(D_METHOD("keyboard_get_layout_count"), &DisplayServer::keyboard_get_layout_count);
  808. ClassDB::bind_method(D_METHOD("keyboard_get_current_layout"), &DisplayServer::keyboard_get_current_layout);
  809. ClassDB::bind_method(D_METHOD("keyboard_set_current_layout", "index"), &DisplayServer::keyboard_set_current_layout);
  810. ClassDB::bind_method(D_METHOD("keyboard_get_layout_language", "index"), &DisplayServer::keyboard_get_layout_language);
  811. ClassDB::bind_method(D_METHOD("keyboard_get_layout_name", "index"), &DisplayServer::keyboard_get_layout_name);
  812. ClassDB::bind_method(D_METHOD("keyboard_get_keycode_from_physical", "keycode"), &DisplayServer::keyboard_get_keycode_from_physical);
  813. ClassDB::bind_method(D_METHOD("keyboard_get_label_from_physical", "keycode"), &DisplayServer::keyboard_get_label_from_physical);
  814. ClassDB::bind_method(D_METHOD("process_events"), &DisplayServer::process_events);
  815. ClassDB::bind_method(D_METHOD("force_process_and_drop_events"), &DisplayServer::force_process_and_drop_events);
  816. ClassDB::bind_method(D_METHOD("set_native_icon", "filename"), &DisplayServer::set_native_icon);
  817. ClassDB::bind_method(D_METHOD("set_icon", "image"), &DisplayServer::set_icon);
  818. ClassDB::bind_method(D_METHOD("create_status_indicator", "icon", "tooltip", "callback"), &DisplayServer::create_status_indicator);
  819. ClassDB::bind_method(D_METHOD("status_indicator_set_icon", "id", "icon"), &DisplayServer::status_indicator_set_icon);
  820. ClassDB::bind_method(D_METHOD("status_indicator_set_tooltip", "id", "tooltip"), &DisplayServer::status_indicator_set_tooltip);
  821. ClassDB::bind_method(D_METHOD("status_indicator_set_menu", "id", "menu_rid"), &DisplayServer::status_indicator_set_menu);
  822. ClassDB::bind_method(D_METHOD("status_indicator_set_callback", "id", "callback"), &DisplayServer::status_indicator_set_callback);
  823. ClassDB::bind_method(D_METHOD("status_indicator_get_rect", "id"), &DisplayServer::status_indicator_get_rect);
  824. ClassDB::bind_method(D_METHOD("delete_status_indicator", "id"), &DisplayServer::delete_status_indicator);
  825. ClassDB::bind_method(D_METHOD("tablet_get_driver_count"), &DisplayServer::tablet_get_driver_count);
  826. ClassDB::bind_method(D_METHOD("tablet_get_driver_name", "idx"), &DisplayServer::tablet_get_driver_name);
  827. ClassDB::bind_method(D_METHOD("tablet_get_current_driver"), &DisplayServer::tablet_get_current_driver);
  828. ClassDB::bind_method(D_METHOD("tablet_set_current_driver", "name"), &DisplayServer::tablet_set_current_driver);
  829. ClassDB::bind_method(D_METHOD("is_window_transparency_available"), &DisplayServer::is_window_transparency_available);
  830. ClassDB::bind_method(D_METHOD("register_additional_output", "object"), &DisplayServer::register_additional_output);
  831. ClassDB::bind_method(D_METHOD("unregister_additional_output", "object"), &DisplayServer::unregister_additional_output);
  832. ClassDB::bind_method(D_METHOD("has_additional_outputs"), &DisplayServer::has_additional_outputs);
  833. #ifndef DISABLE_DEPRECATED
  834. BIND_ENUM_CONSTANT(FEATURE_GLOBAL_MENU);
  835. #endif
  836. BIND_ENUM_CONSTANT(FEATURE_SUBWINDOWS);
  837. BIND_ENUM_CONSTANT(FEATURE_TOUCHSCREEN);
  838. BIND_ENUM_CONSTANT(FEATURE_MOUSE);
  839. BIND_ENUM_CONSTANT(FEATURE_MOUSE_WARP);
  840. BIND_ENUM_CONSTANT(FEATURE_CLIPBOARD);
  841. BIND_ENUM_CONSTANT(FEATURE_VIRTUAL_KEYBOARD);
  842. BIND_ENUM_CONSTANT(FEATURE_CURSOR_SHAPE);
  843. BIND_ENUM_CONSTANT(FEATURE_CUSTOM_CURSOR_SHAPE);
  844. BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG);
  845. BIND_ENUM_CONSTANT(FEATURE_IME);
  846. BIND_ENUM_CONSTANT(FEATURE_WINDOW_TRANSPARENCY);
  847. BIND_ENUM_CONSTANT(FEATURE_HIDPI);
  848. BIND_ENUM_CONSTANT(FEATURE_ICON);
  849. BIND_ENUM_CONSTANT(FEATURE_NATIVE_ICON);
  850. BIND_ENUM_CONSTANT(FEATURE_ORIENTATION);
  851. BIND_ENUM_CONSTANT(FEATURE_SWAP_BUFFERS);
  852. BIND_ENUM_CONSTANT(FEATURE_CLIPBOARD_PRIMARY);
  853. BIND_ENUM_CONSTANT(FEATURE_TEXT_TO_SPEECH);
  854. BIND_ENUM_CONSTANT(FEATURE_EXTEND_TO_TITLE);
  855. BIND_ENUM_CONSTANT(FEATURE_SCREEN_CAPTURE);
  856. BIND_ENUM_CONSTANT(FEATURE_STATUS_INDICATOR);
  857. BIND_ENUM_CONSTANT(FEATURE_NATIVE_HELP);
  858. BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG_INPUT);
  859. BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG_FILE);
  860. BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG_FILE_EXTRA);
  861. BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE);
  862. BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN);
  863. BIND_ENUM_CONSTANT(MOUSE_MODE_CAPTURED);
  864. BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED);
  865. BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED_HIDDEN);
  866. BIND_CONSTANT(SCREEN_WITH_MOUSE_FOCUS);
  867. BIND_CONSTANT(SCREEN_WITH_KEYBOARD_FOCUS);
  868. BIND_CONSTANT(SCREEN_PRIMARY);
  869. BIND_CONSTANT(SCREEN_OF_MAIN_WINDOW);
  870. BIND_CONSTANT(MAIN_WINDOW_ID);
  871. BIND_CONSTANT(INVALID_WINDOW_ID);
  872. BIND_CONSTANT(INVALID_INDICATOR_ID);
  873. BIND_ENUM_CONSTANT(SCREEN_LANDSCAPE);
  874. BIND_ENUM_CONSTANT(SCREEN_PORTRAIT);
  875. BIND_ENUM_CONSTANT(SCREEN_REVERSE_LANDSCAPE);
  876. BIND_ENUM_CONSTANT(SCREEN_REVERSE_PORTRAIT);
  877. BIND_ENUM_CONSTANT(SCREEN_SENSOR_LANDSCAPE);
  878. BIND_ENUM_CONSTANT(SCREEN_SENSOR_PORTRAIT);
  879. BIND_ENUM_CONSTANT(SCREEN_SENSOR);
  880. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_DEFAULT);
  881. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_MULTILINE);
  882. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_NUMBER);
  883. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_NUMBER_DECIMAL);
  884. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_PHONE);
  885. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_EMAIL_ADDRESS);
  886. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_PASSWORD);
  887. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_URL);
  888. BIND_ENUM_CONSTANT(CURSOR_ARROW);
  889. BIND_ENUM_CONSTANT(CURSOR_IBEAM);
  890. BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND);
  891. BIND_ENUM_CONSTANT(CURSOR_CROSS);
  892. BIND_ENUM_CONSTANT(CURSOR_WAIT);
  893. BIND_ENUM_CONSTANT(CURSOR_BUSY);
  894. BIND_ENUM_CONSTANT(CURSOR_DRAG);
  895. BIND_ENUM_CONSTANT(CURSOR_CAN_DROP);
  896. BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN);
  897. BIND_ENUM_CONSTANT(CURSOR_VSIZE);
  898. BIND_ENUM_CONSTANT(CURSOR_HSIZE);
  899. BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE);
  900. BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE);
  901. BIND_ENUM_CONSTANT(CURSOR_MOVE);
  902. BIND_ENUM_CONSTANT(CURSOR_VSPLIT);
  903. BIND_ENUM_CONSTANT(CURSOR_HSPLIT);
  904. BIND_ENUM_CONSTANT(CURSOR_HELP);
  905. BIND_ENUM_CONSTANT(CURSOR_MAX);
  906. BIND_ENUM_CONSTANT(FILE_DIALOG_MODE_OPEN_FILE);
  907. BIND_ENUM_CONSTANT(FILE_DIALOG_MODE_OPEN_FILES);
  908. BIND_ENUM_CONSTANT(FILE_DIALOG_MODE_OPEN_DIR);
  909. BIND_ENUM_CONSTANT(FILE_DIALOG_MODE_OPEN_ANY);
  910. BIND_ENUM_CONSTANT(FILE_DIALOG_MODE_SAVE_FILE);
  911. BIND_ENUM_CONSTANT(WINDOW_MODE_WINDOWED);
  912. BIND_ENUM_CONSTANT(WINDOW_MODE_MINIMIZED);
  913. BIND_ENUM_CONSTANT(WINDOW_MODE_MAXIMIZED);
  914. BIND_ENUM_CONSTANT(WINDOW_MODE_FULLSCREEN);
  915. BIND_ENUM_CONSTANT(WINDOW_MODE_EXCLUSIVE_FULLSCREEN);
  916. BIND_ENUM_CONSTANT(WINDOW_FLAG_RESIZE_DISABLED);
  917. BIND_ENUM_CONSTANT(WINDOW_FLAG_BORDERLESS);
  918. BIND_ENUM_CONSTANT(WINDOW_FLAG_ALWAYS_ON_TOP);
  919. BIND_ENUM_CONSTANT(WINDOW_FLAG_TRANSPARENT);
  920. BIND_ENUM_CONSTANT(WINDOW_FLAG_NO_FOCUS);
  921. BIND_ENUM_CONSTANT(WINDOW_FLAG_POPUP);
  922. BIND_ENUM_CONSTANT(WINDOW_FLAG_EXTEND_TO_TITLE);
  923. BIND_ENUM_CONSTANT(WINDOW_FLAG_MOUSE_PASSTHROUGH);
  924. BIND_ENUM_CONSTANT(WINDOW_FLAG_SHARP_CORNERS);
  925. BIND_ENUM_CONSTANT(WINDOW_FLAG_MAX);
  926. BIND_ENUM_CONSTANT(WINDOW_EVENT_MOUSE_ENTER);
  927. BIND_ENUM_CONSTANT(WINDOW_EVENT_MOUSE_EXIT);
  928. BIND_ENUM_CONSTANT(WINDOW_EVENT_FOCUS_IN);
  929. BIND_ENUM_CONSTANT(WINDOW_EVENT_FOCUS_OUT);
  930. BIND_ENUM_CONSTANT(WINDOW_EVENT_CLOSE_REQUEST);
  931. BIND_ENUM_CONSTANT(WINDOW_EVENT_GO_BACK_REQUEST);
  932. BIND_ENUM_CONSTANT(WINDOW_EVENT_DPI_CHANGE);
  933. BIND_ENUM_CONSTANT(WINDOW_EVENT_TITLEBAR_CHANGE);
  934. BIND_ENUM_CONSTANT(VSYNC_DISABLED);
  935. BIND_ENUM_CONSTANT(VSYNC_ENABLED);
  936. BIND_ENUM_CONSTANT(VSYNC_ADAPTIVE);
  937. BIND_ENUM_CONSTANT(VSYNC_MAILBOX);
  938. BIND_ENUM_CONSTANT(DISPLAY_HANDLE);
  939. BIND_ENUM_CONSTANT(WINDOW_HANDLE);
  940. BIND_ENUM_CONSTANT(WINDOW_VIEW);
  941. BIND_ENUM_CONSTANT(OPENGL_CONTEXT);
  942. BIND_ENUM_CONSTANT(EGL_DISPLAY);
  943. BIND_ENUM_CONSTANT(EGL_CONFIG);
  944. BIND_ENUM_CONSTANT(TTS_UTTERANCE_STARTED);
  945. BIND_ENUM_CONSTANT(TTS_UTTERANCE_ENDED);
  946. BIND_ENUM_CONSTANT(TTS_UTTERANCE_CANCELED);
  947. BIND_ENUM_CONSTANT(TTS_UTTERANCE_BOUNDARY);
  948. }
  949. Ref<Image> DisplayServer::_get_cursor_image_from_resource(const Ref<Resource> &p_cursor, const Vector2 &p_hotspot) {
  950. Ref<Image> image;
  951. ERR_FAIL_COND_V_MSG(p_hotspot.x < 0 || p_hotspot.y < 0, image, "Hotspot outside cursor image.");
  952. Ref<Texture2D> texture = p_cursor;
  953. if (texture.is_valid()) {
  954. image = texture->get_image();
  955. } else {
  956. image = p_cursor;
  957. }
  958. ERR_FAIL_COND_V(image.is_null(), image);
  959. Size2 image_size = image->get_size();
  960. ERR_FAIL_COND_V_MSG(p_hotspot.x > image_size.width || p_hotspot.y > image_size.height, image, "Hotspot outside cursor image.");
  961. ERR_FAIL_COND_V_MSG(image_size.width > 256 || image_size.height > 256, image, "Cursor image too big. Max supported size is 256x256.");
  962. if (image->is_compressed()) {
  963. image = image->duplicate(true);
  964. Error err = image->decompress();
  965. ERR_FAIL_COND_V_MSG(err != OK, Ref<Image>(), "Couldn't decompress VRAM-compressed custom mouse cursor image. Switch to a lossless compression mode in the Import dock.");
  966. }
  967. return image;
  968. }
  969. void DisplayServer::register_create_function(const char *p_name, CreateFunction p_function, GetRenderingDriversFunction p_get_drivers) {
  970. ERR_FAIL_COND(server_create_count == MAX_SERVERS);
  971. // Headless display server is always last
  972. server_create_functions[server_create_count] = server_create_functions[server_create_count - 1];
  973. server_create_functions[server_create_count - 1].name = p_name;
  974. server_create_functions[server_create_count - 1].create_function = p_function;
  975. server_create_functions[server_create_count - 1].get_rendering_drivers_function = p_get_drivers;
  976. server_create_count++;
  977. }
  978. int DisplayServer::get_create_function_count() {
  979. return server_create_count;
  980. }
  981. const char *DisplayServer::get_create_function_name(int p_index) {
  982. ERR_FAIL_INDEX_V(p_index, server_create_count, nullptr);
  983. return server_create_functions[p_index].name;
  984. }
  985. Vector<String> DisplayServer::get_create_function_rendering_drivers(int p_index) {
  986. ERR_FAIL_INDEX_V(p_index, server_create_count, Vector<String>());
  987. return server_create_functions[p_index].get_rendering_drivers_function();
  988. }
  989. DisplayServer *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) {
  990. ERR_FAIL_INDEX_V(p_index, server_create_count, nullptr);
  991. return server_create_functions[p_index].create_function(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_position, p_resolution, p_screen, p_context, r_error);
  992. }
  993. void DisplayServer::_input_set_mouse_mode(Input::MouseMode p_mode) {
  994. singleton->mouse_set_mode(MouseMode(p_mode));
  995. }
  996. Input::MouseMode DisplayServer::_input_get_mouse_mode() {
  997. return Input::MouseMode(singleton->mouse_get_mode());
  998. }
  999. void DisplayServer::_input_warp(const Vector2 &p_to_pos) {
  1000. singleton->warp_mouse(p_to_pos);
  1001. }
  1002. Input::CursorShape DisplayServer::_input_get_current_cursor_shape() {
  1003. return (Input::CursorShape)singleton->cursor_get_shape();
  1004. }
  1005. void DisplayServer::_input_set_custom_mouse_cursor_func(const Ref<Resource> &p_image, Input::CursorShape p_shape, const Vector2 &p_hostspot) {
  1006. singleton->cursor_set_custom_image(p_image, (CursorShape)p_shape, p_hostspot);
  1007. }
  1008. bool DisplayServer::can_create_rendering_device() {
  1009. if (get_singleton()->get_name() == "headless") {
  1010. return false;
  1011. }
  1012. #if defined(RD_ENABLED)
  1013. RenderingDevice *device = RenderingDevice::get_singleton();
  1014. if (device) {
  1015. return true;
  1016. }
  1017. if (created_rendering_device == RenderingDeviceCreationStatus::SUCCESS) {
  1018. return true;
  1019. } else if (created_rendering_device == RenderingDeviceCreationStatus::FAILURE) {
  1020. return false;
  1021. }
  1022. Error err;
  1023. RenderingContextDriver *rcd = nullptr;
  1024. #if defined(VULKAN_ENABLED)
  1025. rcd = memnew(RenderingContextDriverVulkan);
  1026. #endif
  1027. #ifdef D3D12_ENABLED
  1028. if (rcd == nullptr) {
  1029. rcd = memnew(RenderingContextDriverD3D12);
  1030. }
  1031. #endif
  1032. #ifdef METAL_ENABLED
  1033. if (rcd == nullptr) {
  1034. #pragma clang diagnostic push
  1035. #pragma clang diagnostic ignored "-Wunguarded-availability"
  1036. // Eliminate "RenderingContextDriverMetal is only available on iOS 14.0 or newer".
  1037. rcd = memnew(RenderingContextDriverMetal);
  1038. #pragma clang diagnostic pop
  1039. }
  1040. #endif
  1041. if (rcd != nullptr) {
  1042. err = rcd->initialize();
  1043. if (err == OK) {
  1044. RenderingDevice *rd = memnew(RenderingDevice);
  1045. err = rd->initialize(rcd);
  1046. memdelete(rd);
  1047. rd = nullptr;
  1048. if (err == OK) {
  1049. // Creating a RenderingDevice is quite slow.
  1050. // Cache the result for future usage, so that it's much faster on subsequent calls.
  1051. created_rendering_device = RenderingDeviceCreationStatus::SUCCESS;
  1052. memdelete(rcd);
  1053. rcd = nullptr;
  1054. return true;
  1055. } else {
  1056. created_rendering_device = RenderingDeviceCreationStatus::FAILURE;
  1057. }
  1058. }
  1059. memdelete(rcd);
  1060. rcd = nullptr;
  1061. }
  1062. #endif // RD_ENABLED
  1063. return false;
  1064. }
  1065. DisplayServer::DisplayServer() {
  1066. singleton = this;
  1067. Input::set_mouse_mode_func = _input_set_mouse_mode;
  1068. Input::get_mouse_mode_func = _input_get_mouse_mode;
  1069. Input::warp_mouse_func = _input_warp;
  1070. Input::get_current_cursor_shape_func = _input_get_current_cursor_shape;
  1071. Input::set_custom_mouse_cursor_func = _input_set_custom_mouse_cursor_func;
  1072. }
  1073. DisplayServer::~DisplayServer() {
  1074. singleton = nullptr;
  1075. }