2
0

display_server.cpp 31 KB

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