display_server.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*************************************************************************/
  2. /* display_server.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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. DisplayServer *DisplayServer::singleton = nullptr;
  34. DisplayServer::SwitchVSyncCallbackInThread DisplayServer::switch_vsync_function = nullptr;
  35. bool DisplayServer::hidpi_allowed = false;
  36. DisplayServer::DisplayServerCreate DisplayServer::server_create_functions[DisplayServer::MAX_SERVERS];
  37. int DisplayServer::server_create_count = 0;
  38. void DisplayServer::global_menu_add_item(const String &p_menu_root, const String &p_label, const Callable &p_callback, const Variant &p_tag) {
  39. WARN_PRINT("Global menus not supported by this display server.");
  40. }
  41. void DisplayServer::global_menu_add_check_item(const String &p_menu_root, const String &p_label, const Callable &p_callback, const Variant &p_tag) {
  42. WARN_PRINT("Global menus not supported by this display server.");
  43. }
  44. void DisplayServer::global_menu_add_submenu_item(const String &p_menu_root, const String &p_label, const String &p_submenu) {
  45. WARN_PRINT("Global menus not supported by this display server.");
  46. }
  47. void DisplayServer::global_menu_add_separator(const String &p_menu_root) {
  48. WARN_PRINT("Global menus not supported by this display server.");
  49. }
  50. void DisplayServer::global_menu_set_item_callback(const String &p_menu_root, int p_idx, const Callable &p_callback) {
  51. WARN_PRINT("Global menus not supported by this display server.");
  52. }
  53. bool DisplayServer::global_menu_is_item_checked(const String &p_menu_root, int p_idx) const {
  54. WARN_PRINT("Global menus not supported by this display server.");
  55. return false;
  56. }
  57. bool DisplayServer::global_menu_is_item_checkable(const String &p_menu_root, int p_idx) const {
  58. WARN_PRINT("Global menus not supported by this display server.");
  59. return false;
  60. }
  61. Callable DisplayServer::global_menu_get_item_callback(const String &p_menu_root, int p_idx) {
  62. WARN_PRINT("Global menus not supported by this display server.");
  63. return Callable();
  64. }
  65. Variant DisplayServer::global_menu_get_item_tag(const String &p_menu_root, int p_idx) {
  66. WARN_PRINT("Global menus not supported by this display server.");
  67. return Variant();
  68. }
  69. String DisplayServer::global_menu_get_item_text(const String &p_menu_root, int p_idx) {
  70. WARN_PRINT("Global menus not supported by this display server.");
  71. return String();
  72. }
  73. String DisplayServer::global_menu_get_item_submenu(const String &p_menu_root, int p_idx) {
  74. WARN_PRINT("Global menus not supported by this display server.");
  75. return String();
  76. }
  77. void DisplayServer::global_menu_set_item_checked(const String &p_menu_root, int p_idx, bool p_checked) {
  78. WARN_PRINT("Global menus not supported by this display server.");
  79. }
  80. void DisplayServer::global_menu_set_item_checkable(const String &p_menu_root, int p_idx, bool p_checkable) {
  81. WARN_PRINT("Global menus not supported by this display server.");
  82. }
  83. void DisplayServer::global_menu_set_item_tag(const String &p_menu_root, int p_idx, const Variant &p_tag) {
  84. WARN_PRINT("Global menus not supported by this display server.");
  85. }
  86. void DisplayServer::global_menu_set_item_text(const String &p_menu_root, int p_idx, const String &p_text) {
  87. WARN_PRINT("Global menus not supported by this display server.");
  88. }
  89. void DisplayServer::global_menu_set_item_submenu(const String &p_menu_root, int p_idx, const String &p_submenu) {
  90. WARN_PRINT("Global menus not supported by this display server.");
  91. }
  92. int DisplayServer::global_menu_get_item_count(const String &p_menu_root) const {
  93. WARN_PRINT("Global menus not supported by this display server.");
  94. return 0;
  95. }
  96. void DisplayServer::global_menu_remove_item(const String &p_menu_root, int p_idx) {
  97. WARN_PRINT("Global menus not supported by this display server.");
  98. }
  99. void DisplayServer::global_menu_clear(const String &p_menu_root) {
  100. WARN_PRINT("Global menus not supported by this display server.");
  101. }
  102. void DisplayServer::mouse_set_mode(MouseMode p_mode) {
  103. WARN_PRINT("Mouse is not supported by this display server.");
  104. }
  105. DisplayServer::MouseMode DisplayServer::mouse_get_mode() const {
  106. return MOUSE_MODE_VISIBLE;
  107. }
  108. void DisplayServer::mouse_warp_to_position(const Point2i &p_to) {
  109. WARN_PRINT("Mouse warping is not supported by this display server.");
  110. }
  111. Point2i DisplayServer::mouse_get_absolute_position() const {
  112. ERR_FAIL_V_MSG(Point2i(), "Mouse is not supported by this display server.");
  113. }
  114. Point2i DisplayServer::mouse_get_position() const {
  115. ERR_FAIL_V_MSG(Point2i(), "Mouse is not supported by this display server.");
  116. }
  117. int DisplayServer::mouse_get_button_state() const {
  118. ERR_FAIL_V_MSG(0, "Mouse is not supported by this display server.");
  119. }
  120. void DisplayServer::clipboard_set(const String &p_text) {
  121. WARN_PRINT("Clipboard is not supported by this display server.");
  122. }
  123. String DisplayServer::clipboard_get() const {
  124. ERR_FAIL_V_MSG(String(), "Clipboard is not supported by this display server.");
  125. }
  126. void DisplayServer::screen_set_orientation(ScreenOrientation p_orientation, int p_screen) {
  127. WARN_PRINT("Orientation not supported by this display server.");
  128. }
  129. DisplayServer::ScreenOrientation DisplayServer::screen_get_orientation(int p_screen) const {
  130. return SCREEN_LANDSCAPE;
  131. }
  132. float DisplayServer::screen_get_scale(int p_screen) const {
  133. return 1.0f;
  134. };
  135. bool DisplayServer::screen_is_touchscreen(int p_screen) const {
  136. //return false;
  137. return Input::get_singleton() && Input::get_singleton()->is_emulating_touch_from_mouse();
  138. }
  139. void DisplayServer::screen_set_keep_on(bool p_enable) {
  140. WARN_PRINT("Keeping screen on not supported by this display server.");
  141. }
  142. bool DisplayServer::screen_is_kept_on() const {
  143. return false;
  144. }
  145. DisplayServer::WindowID DisplayServer::create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect) {
  146. ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Sub-windows not supported by this display server.");
  147. }
  148. void DisplayServer::show_window(WindowID p_id) {
  149. ERR_FAIL_MSG("Sub-windows not supported by this display server.");
  150. }
  151. void DisplayServer::delete_sub_window(WindowID p_id) {
  152. ERR_FAIL_MSG("Sub-windows not supported by this display server.");
  153. }
  154. void DisplayServer::window_set_mouse_passthrough(const Vector<Vector2> &p_region, WindowID p_window) {
  155. ERR_FAIL_MSG("Mouse passthrough not supported by this display server.");
  156. }
  157. void DisplayServer::window_set_ime_active(const bool p_active, WindowID p_window) {
  158. WARN_PRINT("IME not supported by this display server.");
  159. }
  160. void DisplayServer::window_set_ime_position(const Point2i &p_pos, WindowID p_window) {
  161. WARN_PRINT("IME not supported by this display server.");
  162. }
  163. Point2i DisplayServer::ime_get_selection() const {
  164. ERR_FAIL_V_MSG(Point2i(), "IME or NOTIFICATION_WM_IME_UPDATE not supported by this display server.");
  165. }
  166. String DisplayServer::ime_get_text() const {
  167. ERR_FAIL_V_MSG(String(), "IME or NOTIFICATION_WM_IME_UPDATEnot supported by this display server.");
  168. }
  169. void DisplayServer::console_set_visible(bool p_enabled) {
  170. WARN_PRINT("Console window not supported by this display server.");
  171. }
  172. bool DisplayServer::is_console_visible() const {
  173. return false;
  174. }
  175. void DisplayServer::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, bool p_multiline, int p_max_length, int p_cursor_start, int p_cursor_end) {
  176. WARN_PRINT("Virtual keyboard not supported by this display server.");
  177. }
  178. void DisplayServer::virtual_keyboard_hide() {
  179. WARN_PRINT("Virtual keyboard not supported by this display server.");
  180. }
  181. // returns height of the currently shown keyboard (0 if keyboard is hidden)
  182. int DisplayServer::virtual_keyboard_get_height() const {
  183. ERR_FAIL_V_MSG(0, "Virtual keyboard not supported by this display server.");
  184. }
  185. void DisplayServer::cursor_set_shape(CursorShape p_shape) {
  186. WARN_PRINT("Cursor shape not supported by this display server.");
  187. }
  188. DisplayServer::CursorShape DisplayServer::cursor_get_shape() const {
  189. return CURSOR_ARROW;
  190. }
  191. void DisplayServer::cursor_set_custom_image(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
  192. WARN_PRINT("Custom cursor shape not supported by this display server.");
  193. }
  194. bool DisplayServer::get_swap_cancel_ok() {
  195. return false;
  196. }
  197. void DisplayServer::enable_for_stealing_focus(OS::ProcessID pid) {
  198. }
  199. //plays video natively, in fullscreen, only implemented in mobile for now, likely not possible to implement on linux also.
  200. Error DisplayServer::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track, int p_screen) {
  201. ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Native video not supported by this display server.");
  202. }
  203. bool DisplayServer::native_video_is_playing() const {
  204. return false;
  205. }
  206. void DisplayServer::native_video_pause() {
  207. WARN_PRINT("Native video not supported by this display server.");
  208. }
  209. void DisplayServer::native_video_unpause() {
  210. WARN_PRINT("Native video not supported by this display server.");
  211. }
  212. void DisplayServer::native_video_stop() {
  213. WARN_PRINT("Native video not supported by this display server.");
  214. }
  215. Error DisplayServer::dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback) {
  216. WARN_PRINT("Native dialogs not supported by this display server.");
  217. return OK;
  218. }
  219. Error DisplayServer::dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback) {
  220. WARN_PRINT("Native dialogs not supported by this display server.");
  221. return OK;
  222. }
  223. int DisplayServer::keyboard_get_layout_count() const {
  224. return 0;
  225. }
  226. int DisplayServer::keyboard_get_current_layout() const {
  227. return -1;
  228. }
  229. void DisplayServer::keyboard_set_current_layout(int p_index) {
  230. }
  231. String DisplayServer::keyboard_get_layout_language(int p_index) const {
  232. return "";
  233. }
  234. String DisplayServer::keyboard_get_layout_name(int p_index) const {
  235. return "Not supported";
  236. }
  237. void DisplayServer::force_process_and_drop_events() {
  238. }
  239. void DisplayServer::release_rendering_thread() {
  240. WARN_PRINT("Rendering thread not supported by this display server.");
  241. }
  242. void DisplayServer::make_rendering_thread() {
  243. WARN_PRINT("Rendering thread not supported by this display server.");
  244. }
  245. void DisplayServer::swap_buffers() {
  246. WARN_PRINT("Swap buffers not supported by this display server.");
  247. }
  248. void DisplayServer::set_native_icon(const String &p_filename) {
  249. WARN_PRINT("Native icon not supported by this display server.");
  250. }
  251. void DisplayServer::set_icon(const Ref<Image> &p_icon) {
  252. WARN_PRINT("Icon not supported by this display server.");
  253. }
  254. void DisplayServer::_set_use_vsync(bool p_enable) {
  255. WARN_PRINT("VSync not supported by this display server.");
  256. }
  257. void DisplayServer::vsync_set_enabled(bool p_enable) {
  258. vsync_enabled = p_enable;
  259. if (switch_vsync_function) { //if a function was set, use function
  260. switch_vsync_function(p_enable);
  261. } else { //otherwise just call here
  262. _set_use_vsync(p_enable);
  263. }
  264. }
  265. bool DisplayServer::vsync_is_enabled() const {
  266. return vsync_enabled;
  267. }
  268. void DisplayServer::vsync_set_use_via_compositor(bool p_enable) {
  269. WARN_PRINT("VSync via compositor not supported by this display server.");
  270. }
  271. bool DisplayServer::vsync_is_using_via_compositor() const {
  272. return false;
  273. }
  274. void DisplayServer::set_context(Context p_context) {
  275. }
  276. void DisplayServer::_bind_methods() {
  277. ClassDB::bind_method(D_METHOD("has_feature", "feature"), &DisplayServer::has_feature);
  278. ClassDB::bind_method(D_METHOD("get_name"), &DisplayServer::get_name);
  279. ClassDB::bind_method(D_METHOD("global_menu_add_item", "menu_root", "label", "callback", "tag"), &DisplayServer::global_menu_add_item, DEFVAL(Variant()));
  280. ClassDB::bind_method(D_METHOD("global_menu_add_check_item", "menu_root", "label", "callback", "tag"), &DisplayServer::global_menu_add_check_item, DEFVAL(Variant()));
  281. ClassDB::bind_method(D_METHOD("global_menu_add_submenu_item", "menu_root", "label", "submenu"), &DisplayServer::global_menu_add_submenu_item);
  282. ClassDB::bind_method(D_METHOD("global_menu_add_separator", "menu_root"), &DisplayServer::global_menu_add_separator);
  283. ClassDB::bind_method(D_METHOD("global_menu_is_item_checked", "menu_root", "idx"), &DisplayServer::global_menu_is_item_checked);
  284. ClassDB::bind_method(D_METHOD("global_menu_is_item_checkable", "menu_root", "idx"), &DisplayServer::global_menu_is_item_checkable);
  285. ClassDB::bind_method(D_METHOD("global_menu_get_item_callback", "menu_root", "idx"), &DisplayServer::global_menu_get_item_callback);
  286. ClassDB::bind_method(D_METHOD("global_menu_get_item_tag", "menu_root", "idx"), &DisplayServer::global_menu_get_item_tag);
  287. ClassDB::bind_method(D_METHOD("global_menu_get_item_text", "menu_root", "idx"), &DisplayServer::global_menu_get_item_text);
  288. ClassDB::bind_method(D_METHOD("global_menu_get_item_submenu", "menu_root", "idx"), &DisplayServer::global_menu_get_item_submenu);
  289. ClassDB::bind_method(D_METHOD("global_menu_set_item_checked", "menu_root", "idx", "checked"), &DisplayServer::global_menu_set_item_checked);
  290. ClassDB::bind_method(D_METHOD("global_menu_set_item_checkable", "menu_root", "idx", "checkable"), &DisplayServer::global_menu_set_item_checkable);
  291. ClassDB::bind_method(D_METHOD("global_menu_set_item_callback", "menu_root", "idx", "callback"), &DisplayServer::global_menu_set_item_callback);
  292. ClassDB::bind_method(D_METHOD("global_menu_set_item_tag", "menu_root", "idx", "tag"), &DisplayServer::global_menu_set_item_tag);
  293. ClassDB::bind_method(D_METHOD("global_menu_set_item_text", "menu_root", "idx", "text"), &DisplayServer::global_menu_set_item_text);
  294. ClassDB::bind_method(D_METHOD("global_menu_set_item_submenu", "menu_root", "idx", "submenu"), &DisplayServer::global_menu_set_item_submenu);
  295. ClassDB::bind_method(D_METHOD("global_menu_remove_item", "menu_root", "idx"), &DisplayServer::global_menu_remove_item);
  296. ClassDB::bind_method(D_METHOD("global_menu_clear", "menu_root"), &DisplayServer::global_menu_clear);
  297. ClassDB::bind_method(D_METHOD("alert", "text", "title"), &DisplayServer::alert, DEFVAL("Alert!"));
  298. ClassDB::bind_method(D_METHOD("mouse_set_mode", "mouse_mode"), &DisplayServer::mouse_set_mode);
  299. ClassDB::bind_method(D_METHOD("mouse_get_mode"), &DisplayServer::mouse_get_mode);
  300. ClassDB::bind_method(D_METHOD("mouse_warp_to_position", "position"), &DisplayServer::mouse_warp_to_position);
  301. ClassDB::bind_method(D_METHOD("mouse_get_position"), &DisplayServer::mouse_get_position);
  302. ClassDB::bind_method(D_METHOD("mouse_get_absolute_position"), &DisplayServer::mouse_get_absolute_position);
  303. ClassDB::bind_method(D_METHOD("mouse_get_button_state"), &DisplayServer::mouse_get_button_state);
  304. ClassDB::bind_method(D_METHOD("clipboard_set", "clipboard"), &DisplayServer::clipboard_set);
  305. ClassDB::bind_method(D_METHOD("clipboard_get"), &DisplayServer::clipboard_get);
  306. ClassDB::bind_method(D_METHOD("get_screen_count"), &DisplayServer::get_screen_count);
  307. ClassDB::bind_method(D_METHOD("screen_get_position", "screen"), &DisplayServer::screen_get_position, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  308. ClassDB::bind_method(D_METHOD("screen_get_size", "screen"), &DisplayServer::screen_get_size, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  309. ClassDB::bind_method(D_METHOD("screen_get_usable_rect", "screen"), &DisplayServer::screen_get_usable_rect, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  310. ClassDB::bind_method(D_METHOD("screen_get_dpi", "screen"), &DisplayServer::screen_get_dpi, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  311. ClassDB::bind_method(D_METHOD("screen_get_scale", "screen"), &DisplayServer::screen_get_scale, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  312. ClassDB::bind_method(D_METHOD("screen_is_touchscreen", "screen"), &DisplayServer::screen_is_touchscreen, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  313. ClassDB::bind_method(D_METHOD("screen_get_max_scale"), &DisplayServer::screen_get_max_scale);
  314. ClassDB::bind_method(D_METHOD("screen_set_orientation", "orientation", "screen"), &DisplayServer::screen_set_orientation, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  315. ClassDB::bind_method(D_METHOD("screen_get_orientation", "screen"), &DisplayServer::screen_get_orientation, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  316. ClassDB::bind_method(D_METHOD("screen_set_keep_on", "enable"), &DisplayServer::screen_set_keep_on);
  317. ClassDB::bind_method(D_METHOD("screen_is_kept_on"), &DisplayServer::screen_is_kept_on);
  318. ClassDB::bind_method(D_METHOD("get_window_list"), &DisplayServer::get_window_list);
  319. ClassDB::bind_method(D_METHOD("get_window_at_screen_position", "position"), &DisplayServer::get_window_at_screen_position);
  320. ClassDB::bind_method(D_METHOD("create_sub_window", "mode", "flags", "rect"), &DisplayServer::create_sub_window, DEFVAL(Rect2i()));
  321. ClassDB::bind_method(D_METHOD("delete_sub_window", "window_id"), &DisplayServer::delete_sub_window);
  322. ClassDB::bind_method(D_METHOD("window_set_title", "title", "window_id"), &DisplayServer::window_set_title, DEFVAL(MAIN_WINDOW_ID));
  323. ClassDB::bind_method(D_METHOD("window_set_mouse_passthrough", "region", "window_id"), &DisplayServer::window_set_mouse_passthrough, DEFVAL(MAIN_WINDOW_ID));
  324. ClassDB::bind_method(D_METHOD("window_get_current_screen", "window_id"), &DisplayServer::window_get_current_screen, DEFVAL(MAIN_WINDOW_ID));
  325. ClassDB::bind_method(D_METHOD("window_set_current_screen", "screen", "window_id"), &DisplayServer::window_set_current_screen, DEFVAL(MAIN_WINDOW_ID));
  326. ClassDB::bind_method(D_METHOD("window_get_position", "window_id"), &DisplayServer::window_get_position, DEFVAL(MAIN_WINDOW_ID));
  327. ClassDB::bind_method(D_METHOD("window_set_position", "position", "window_id"), &DisplayServer::window_set_position, DEFVAL(MAIN_WINDOW_ID));
  328. ClassDB::bind_method(D_METHOD("window_get_size", "window_id"), &DisplayServer::window_get_size, DEFVAL(MAIN_WINDOW_ID));
  329. ClassDB::bind_method(D_METHOD("window_set_size", "size", "window_id"), &DisplayServer::window_set_size, DEFVAL(MAIN_WINDOW_ID));
  330. ClassDB::bind_method(D_METHOD("window_set_rect_changed_callback", "callback", "window_id"), &DisplayServer::window_set_rect_changed_callback, DEFVAL(MAIN_WINDOW_ID));
  331. ClassDB::bind_method(D_METHOD("window_set_window_event_callback", "callback", "window_id"), &DisplayServer::window_set_window_event_callback, DEFVAL(MAIN_WINDOW_ID));
  332. ClassDB::bind_method(D_METHOD("window_set_input_event_callback", "callback", "window_id"), &DisplayServer::window_set_input_event_callback, DEFVAL(MAIN_WINDOW_ID));
  333. ClassDB::bind_method(D_METHOD("window_set_input_text_callback", "callback", "window_id"), &DisplayServer::window_set_input_text_callback, DEFVAL(MAIN_WINDOW_ID));
  334. ClassDB::bind_method(D_METHOD("window_set_drop_files_callback", "callback", "window_id"), &DisplayServer::window_set_drop_files_callback, DEFVAL(MAIN_WINDOW_ID));
  335. ClassDB::bind_method(D_METHOD("window_attach_instance_id", "instance_id", "window_id"), &DisplayServer::window_attach_instance_id, DEFVAL(MAIN_WINDOW_ID));
  336. ClassDB::bind_method(D_METHOD("window_get_attached_instance_id", "window_id"), &DisplayServer::window_get_attached_instance_id, DEFVAL(MAIN_WINDOW_ID));
  337. ClassDB::bind_method(D_METHOD("window_get_max_size", "window_id"), &DisplayServer::window_get_max_size, DEFVAL(MAIN_WINDOW_ID));
  338. ClassDB::bind_method(D_METHOD("window_set_max_size", "max_size", "window_id"), &DisplayServer::window_set_max_size, DEFVAL(MAIN_WINDOW_ID));
  339. ClassDB::bind_method(D_METHOD("window_get_min_size", "window_id"), &DisplayServer::window_get_min_size, DEFVAL(MAIN_WINDOW_ID));
  340. ClassDB::bind_method(D_METHOD("window_set_min_size", "min_size", "window_id"), &DisplayServer::window_set_min_size, DEFVAL(MAIN_WINDOW_ID));
  341. ClassDB::bind_method(D_METHOD("window_get_real_size", "window_id"), &DisplayServer::window_get_real_size, DEFVAL(MAIN_WINDOW_ID));
  342. ClassDB::bind_method(D_METHOD("window_get_mode", "window_id"), &DisplayServer::window_get_mode, DEFVAL(MAIN_WINDOW_ID));
  343. ClassDB::bind_method(D_METHOD("window_set_mode", "mode", "window_id"), &DisplayServer::window_set_mode, DEFVAL(MAIN_WINDOW_ID));
  344. ClassDB::bind_method(D_METHOD("window_set_flag", "flag", "enabled", "window_id"), &DisplayServer::window_set_flag, DEFVAL(MAIN_WINDOW_ID));
  345. ClassDB::bind_method(D_METHOD("window_get_flag", "flag", "window_id"), &DisplayServer::window_get_flag, DEFVAL(MAIN_WINDOW_ID));
  346. ClassDB::bind_method(D_METHOD("window_request_attention", "window_id"), &DisplayServer::window_request_attention, DEFVAL(MAIN_WINDOW_ID));
  347. ClassDB::bind_method(D_METHOD("window_move_to_foreground", "window_id"), &DisplayServer::window_move_to_foreground, DEFVAL(MAIN_WINDOW_ID));
  348. ClassDB::bind_method(D_METHOD("window_can_draw", "window_id"), &DisplayServer::window_can_draw, DEFVAL(MAIN_WINDOW_ID));
  349. ClassDB::bind_method(D_METHOD("window_set_transient", "window_id", "parent_window_id"), &DisplayServer::window_set_transient);
  350. ClassDB::bind_method(D_METHOD("window_set_ime_active", "active", "window_id"), &DisplayServer::window_set_ime_active, DEFVAL(MAIN_WINDOW_ID));
  351. ClassDB::bind_method(D_METHOD("window_set_ime_position", "position", "window_id"), &DisplayServer::window_set_ime_position, DEFVAL(MAIN_WINDOW_ID));
  352. ClassDB::bind_method(D_METHOD("ime_get_selection"), &DisplayServer::ime_get_selection);
  353. ClassDB::bind_method(D_METHOD("ime_get_text"), &DisplayServer::ime_get_text);
  354. ClassDB::bind_method(D_METHOD("console_set_visible", "console_visible"), &DisplayServer::console_set_visible);
  355. ClassDB::bind_method(D_METHOD("is_console_visible"), &DisplayServer::is_console_visible);
  356. ClassDB::bind_method(D_METHOD("virtual_keyboard_show", "existing_text", "position", "multiline", "max_length", "cursor_start", "cursor_end"), &DisplayServer::virtual_keyboard_show, DEFVAL(Rect2i()), DEFVAL(false), DEFVAL(-1), DEFVAL(-1), DEFVAL(-1));
  357. ClassDB::bind_method(D_METHOD("virtual_keyboard_hide"), &DisplayServer::virtual_keyboard_hide);
  358. ClassDB::bind_method(D_METHOD("virtual_keyboard_get_height"), &DisplayServer::virtual_keyboard_get_height);
  359. ClassDB::bind_method(D_METHOD("cursor_set_shape", "shape"), &DisplayServer::cursor_set_shape);
  360. ClassDB::bind_method(D_METHOD("cursor_get_shape"), &DisplayServer::cursor_get_shape);
  361. ClassDB::bind_method(D_METHOD("cursor_set_custom_image", "cursor", "shape", "hotspot"), &DisplayServer::cursor_set_custom_image, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2()));
  362. ClassDB::bind_method(D_METHOD("get_swap_cancel_ok"), &DisplayServer::get_swap_cancel_ok);
  363. ClassDB::bind_method(D_METHOD("enable_for_stealing_focus", "process_id"), &DisplayServer::enable_for_stealing_focus);
  364. ClassDB::bind_method(D_METHOD("native_video_play", "path", "volume", "audio_track", "subtitle_track", "screen"), &DisplayServer::native_video_play);
  365. ClassDB::bind_method(D_METHOD("native_video_is_playing"), &DisplayServer::native_video_is_playing);
  366. ClassDB::bind_method(D_METHOD("native_video_stop"), &DisplayServer::native_video_stop);
  367. ClassDB::bind_method(D_METHOD("native_video_pause"), &DisplayServer::native_video_pause);
  368. ClassDB::bind_method(D_METHOD("native_video_unpause"), &DisplayServer::native_video_unpause);
  369. ClassDB::bind_method(D_METHOD("dialog_show", "title", "description", "buttons", "callback"), &DisplayServer::dialog_show);
  370. ClassDB::bind_method(D_METHOD("dialog_input_text", "title", "description", "existing_text", "callback"), &DisplayServer::dialog_input_text);
  371. ClassDB::bind_method(D_METHOD("keyboard_get_layout_count"), &DisplayServer::keyboard_get_layout_count);
  372. ClassDB::bind_method(D_METHOD("keyboard_get_current_layout"), &DisplayServer::keyboard_get_current_layout);
  373. ClassDB::bind_method(D_METHOD("keyboard_set_current_layout", "index"), &DisplayServer::keyboard_set_current_layout);
  374. ClassDB::bind_method(D_METHOD("keyboard_get_layout_language", "index"), &DisplayServer::keyboard_get_layout_language);
  375. ClassDB::bind_method(D_METHOD("keyboard_get_layout_name", "index"), &DisplayServer::keyboard_get_layout_name);
  376. ClassDB::bind_method(D_METHOD("process_events"), &DisplayServer::process_events);
  377. ClassDB::bind_method(D_METHOD("force_process_and_drop_events"), &DisplayServer::force_process_and_drop_events);
  378. ClassDB::bind_method(D_METHOD("vsync_set_enabled", "enabled"), &DisplayServer::vsync_set_enabled);
  379. ClassDB::bind_method(D_METHOD("vsync_is_enabled"), &DisplayServer::vsync_is_enabled);
  380. ClassDB::bind_method(D_METHOD("vsync_set_use_via_compositor", "enabled"), &DisplayServer::vsync_set_use_via_compositor);
  381. ClassDB::bind_method(D_METHOD("vsync_is_using_via_compositor"), &DisplayServer::vsync_is_using_via_compositor);
  382. ClassDB::bind_method(D_METHOD("set_native_icon", "filename"), &DisplayServer::set_native_icon);
  383. ClassDB::bind_method(D_METHOD("set_icon", "image"), &DisplayServer::set_icon);
  384. ClassDB::bind_method(D_METHOD("tablet_get_driver_count"), &DisplayServer::tablet_get_driver_count);
  385. ClassDB::bind_method(D_METHOD("tablet_get_driver_name", "idx"), &DisplayServer::tablet_get_driver_name);
  386. ClassDB::bind_method(D_METHOD("tablet_get_current_driver"), &DisplayServer::tablet_get_current_driver);
  387. ClassDB::bind_method(D_METHOD("tablet_set_current_driver", "name"), &DisplayServer::tablet_set_current_driver);
  388. BIND_ENUM_CONSTANT(FEATURE_GLOBAL_MENU);
  389. BIND_ENUM_CONSTANT(FEATURE_SUBWINDOWS);
  390. BIND_ENUM_CONSTANT(FEATURE_TOUCHSCREEN);
  391. BIND_ENUM_CONSTANT(FEATURE_MOUSE);
  392. BIND_ENUM_CONSTANT(FEATURE_MOUSE_WARP);
  393. BIND_ENUM_CONSTANT(FEATURE_CLIPBOARD);
  394. BIND_ENUM_CONSTANT(FEATURE_VIRTUAL_KEYBOARD);
  395. BIND_ENUM_CONSTANT(FEATURE_CURSOR_SHAPE);
  396. BIND_ENUM_CONSTANT(FEATURE_CUSTOM_CURSOR_SHAPE);
  397. BIND_ENUM_CONSTANT(FEATURE_NATIVE_VIDEO);
  398. BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG);
  399. BIND_ENUM_CONSTANT(FEATURE_CONSOLE_WINDOW);
  400. BIND_ENUM_CONSTANT(FEATURE_IME);
  401. BIND_ENUM_CONSTANT(FEATURE_WINDOW_TRANSPARENCY);
  402. BIND_ENUM_CONSTANT(FEATURE_HIDPI);
  403. BIND_ENUM_CONSTANT(FEATURE_ICON);
  404. BIND_ENUM_CONSTANT(FEATURE_NATIVE_ICON);
  405. BIND_ENUM_CONSTANT(FEATURE_ORIENTATION);
  406. BIND_ENUM_CONSTANT(FEATURE_SWAP_BUFFERS);
  407. BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE);
  408. BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN);
  409. BIND_ENUM_CONSTANT(MOUSE_MODE_CAPTURED);
  410. BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED);
  411. BIND_CONSTANT(SCREEN_OF_MAIN_WINDOW);
  412. BIND_CONSTANT(MAIN_WINDOW_ID);
  413. BIND_CONSTANT(INVALID_WINDOW_ID);
  414. BIND_ENUM_CONSTANT(SCREEN_LANDSCAPE);
  415. BIND_ENUM_CONSTANT(SCREEN_PORTRAIT);
  416. BIND_ENUM_CONSTANT(SCREEN_REVERSE_LANDSCAPE);
  417. BIND_ENUM_CONSTANT(SCREEN_REVERSE_PORTRAIT);
  418. BIND_ENUM_CONSTANT(SCREEN_SENSOR_LANDSCAPE);
  419. BIND_ENUM_CONSTANT(SCREEN_SENSOR_PORTRAIT);
  420. BIND_ENUM_CONSTANT(SCREEN_SENSOR);
  421. BIND_ENUM_CONSTANT(CURSOR_ARROW);
  422. BIND_ENUM_CONSTANT(CURSOR_IBEAM);
  423. BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND);
  424. BIND_ENUM_CONSTANT(CURSOR_CROSS);
  425. BIND_ENUM_CONSTANT(CURSOR_WAIT);
  426. BIND_ENUM_CONSTANT(CURSOR_BUSY);
  427. BIND_ENUM_CONSTANT(CURSOR_DRAG);
  428. BIND_ENUM_CONSTANT(CURSOR_CAN_DROP);
  429. BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN);
  430. BIND_ENUM_CONSTANT(CURSOR_VSIZE);
  431. BIND_ENUM_CONSTANT(CURSOR_HSIZE);
  432. BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE);
  433. BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE);
  434. BIND_ENUM_CONSTANT(CURSOR_MOVE);
  435. BIND_ENUM_CONSTANT(CURSOR_VSPLIT);
  436. BIND_ENUM_CONSTANT(CURSOR_HSPLIT);
  437. BIND_ENUM_CONSTANT(CURSOR_HELP);
  438. BIND_ENUM_CONSTANT(CURSOR_MAX);
  439. BIND_ENUM_CONSTANT(WINDOW_MODE_WINDOWED);
  440. BIND_ENUM_CONSTANT(WINDOW_MODE_MINIMIZED);
  441. BIND_ENUM_CONSTANT(WINDOW_MODE_MAXIMIZED);
  442. BIND_ENUM_CONSTANT(WINDOW_MODE_FULLSCREEN);
  443. BIND_ENUM_CONSTANT(WINDOW_FLAG_RESIZE_DISABLED);
  444. BIND_ENUM_CONSTANT(WINDOW_FLAG_BORDERLESS);
  445. BIND_ENUM_CONSTANT(WINDOW_FLAG_ALWAYS_ON_TOP);
  446. BIND_ENUM_CONSTANT(WINDOW_FLAG_TRANSPARENT);
  447. BIND_ENUM_CONSTANT(WINDOW_FLAG_NO_FOCUS);
  448. BIND_ENUM_CONSTANT(WINDOW_FLAG_MAX);
  449. BIND_ENUM_CONSTANT(WINDOW_EVENT_MOUSE_ENTER);
  450. BIND_ENUM_CONSTANT(WINDOW_EVENT_MOUSE_EXIT);
  451. BIND_ENUM_CONSTANT(WINDOW_EVENT_FOCUS_IN);
  452. BIND_ENUM_CONSTANT(WINDOW_EVENT_FOCUS_OUT);
  453. BIND_ENUM_CONSTANT(WINDOW_EVENT_CLOSE_REQUEST);
  454. BIND_ENUM_CONSTANT(WINDOW_EVENT_GO_BACK_REQUEST);
  455. BIND_ENUM_CONSTANT(WINDOW_EVENT_DPI_CHANGE);
  456. }
  457. void DisplayServer::register_create_function(const char *p_name, CreateFunction p_function, GetRenderingDriversFunction p_get_drivers) {
  458. ERR_FAIL_COND(server_create_count == MAX_SERVERS);
  459. server_create_functions[server_create_count].name = p_name;
  460. server_create_functions[server_create_count].create_function = p_function;
  461. server_create_functions[server_create_count].get_rendering_drivers_function = p_get_drivers;
  462. server_create_count++;
  463. }
  464. int DisplayServer::get_create_function_count() {
  465. return server_create_count;
  466. }
  467. const char *DisplayServer::get_create_function_name(int p_index) {
  468. ERR_FAIL_INDEX_V(p_index, server_create_count, nullptr);
  469. return server_create_functions[p_index].name;
  470. }
  471. Vector<String> DisplayServer::get_create_function_rendering_drivers(int p_index) {
  472. ERR_FAIL_INDEX_V(p_index, server_create_count, Vector<String>());
  473. return server_create_functions[p_index].get_rendering_drivers_function();
  474. }
  475. DisplayServer *DisplayServer::create(int p_index, const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) {
  476. ERR_FAIL_INDEX_V(p_index, server_create_count, nullptr);
  477. return server_create_functions[p_index].create_function(p_rendering_driver, p_mode, p_flags, p_resolution, r_error);
  478. }
  479. void DisplayServer::_input_set_mouse_mode(Input::MouseMode p_mode) {
  480. singleton->mouse_set_mode(MouseMode(p_mode));
  481. }
  482. Input::MouseMode DisplayServer::_input_get_mouse_mode() {
  483. return Input::MouseMode(singleton->mouse_get_mode());
  484. }
  485. void DisplayServer::_input_warp(const Vector2 &p_to_pos) {
  486. singleton->mouse_warp_to_position(p_to_pos);
  487. }
  488. Input::CursorShape DisplayServer::_input_get_current_cursor_shape() {
  489. return (Input::CursorShape)singleton->cursor_get_shape();
  490. }
  491. void DisplayServer::_input_set_custom_mouse_cursor_func(const RES &p_image, Input::CursorShape p_shape, const Vector2 &p_hostspot) {
  492. singleton->cursor_set_custom_image(p_image, (CursorShape)p_shape, p_hostspot);
  493. }
  494. DisplayServer::DisplayServer() {
  495. singleton = this;
  496. Input::set_mouse_mode_func = _input_set_mouse_mode;
  497. Input::get_mouse_mode_func = _input_get_mouse_mode;
  498. Input::warp_mouse_func = _input_warp;
  499. Input::get_current_cursor_shape_func = _input_get_current_cursor_shape;
  500. Input::set_custom_mouse_cursor_func = _input_set_custom_mouse_cursor_func;
  501. }
  502. DisplayServer::~DisplayServer() {
  503. }