display_server_wayland.cpp 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244
  1. /**************************************************************************/
  2. /* display_server_wayland.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_wayland.h"
  31. #ifdef WAYLAND_ENABLED
  32. #define WAYLAND_DISPLAY_SERVER_DEBUG_LOGS_ENABLED
  33. #ifdef WAYLAND_DISPLAY_SERVER_DEBUG_LOGS_ENABLED
  34. #define DEBUG_LOG_WAYLAND(...) print_verbose(__VA_ARGS__)
  35. #else
  36. #define DEBUG_LOG_WAYLAND(...)
  37. #endif
  38. #include "servers/rendering/dummy/rasterizer_dummy.h"
  39. #ifdef VULKAN_ENABLED
  40. #include "servers/rendering/renderer_rd/renderer_compositor_rd.h"
  41. #endif
  42. #ifdef GLES3_ENABLED
  43. #include "detect_prime_egl.h"
  44. #include "drivers/gles3/rasterizer_gles3.h"
  45. #include "wayland/egl_manager_wayland.h"
  46. #include "wayland/egl_manager_wayland_gles.h"
  47. #endif
  48. #ifdef ACCESSKIT_ENABLED
  49. #include "drivers/accesskit/accessibility_driver_accesskit.h"
  50. #endif
  51. #ifdef DBUS_ENABLED
  52. #ifdef SOWRAP_ENABLED
  53. #include "dbus-so_wrap.h"
  54. #else
  55. #include <dbus/dbus.h>
  56. #endif
  57. #endif
  58. #define WAYLAND_MAX_FRAME_TIME_US (1'000'000)
  59. String DisplayServerWayland::_get_app_id_from_context(Context p_context) {
  60. String app_id;
  61. switch (p_context) {
  62. case CONTEXT_EDITOR: {
  63. app_id = "org.godotengine.Editor";
  64. } break;
  65. case CONTEXT_PROJECTMAN: {
  66. app_id = "org.godotengine.ProjectManager";
  67. } break;
  68. case CONTEXT_ENGINE:
  69. default: {
  70. String config_name = GLOBAL_GET("application/config/name");
  71. if (config_name.length() != 0) {
  72. app_id = config_name;
  73. } else {
  74. app_id = "org.godotengine.Godot";
  75. }
  76. }
  77. }
  78. return app_id;
  79. }
  80. void DisplayServerWayland::_send_window_event(WindowEvent p_event, WindowID p_window_id) {
  81. ERR_FAIL_COND(!windows.has(p_window_id));
  82. WindowData &wd = windows[p_window_id];
  83. if (wd.window_event_callback.is_valid()) {
  84. Variant event = int(p_event);
  85. wd.window_event_callback.call(event);
  86. }
  87. }
  88. void DisplayServerWayland::dispatch_input_events(const Ref<InputEvent> &p_event) {
  89. static_cast<DisplayServerWayland *>(get_singleton())->_dispatch_input_event(p_event);
  90. }
  91. void DisplayServerWayland::_dispatch_input_event(const Ref<InputEvent> &p_event) {
  92. Ref<InputEventFromWindow> event_from_window = p_event;
  93. if (event_from_window.is_valid()) {
  94. WindowID window_id = event_from_window->get_window_id();
  95. Ref<InputEventKey> key_event = p_event;
  96. if (!popup_menu_list.is_empty() && key_event.is_valid()) {
  97. // Redirect to the highest popup menu.
  98. window_id = popup_menu_list.back()->get();
  99. }
  100. // Send to a single window.
  101. if (windows.has(window_id)) {
  102. Callable callable = windows[window_id].input_event_callback;
  103. if (callable.is_valid()) {
  104. callable.call(p_event);
  105. }
  106. }
  107. } else {
  108. // Send to all windows. Copy all pending callbacks, since callback can erase window.
  109. Vector<Callable> cbs;
  110. for (KeyValue<WindowID, WindowData> &E : windows) {
  111. Callable callable = E.value.input_event_callback;
  112. if (callable.is_valid()) {
  113. cbs.push_back(callable);
  114. }
  115. }
  116. for (const Callable &cb : cbs) {
  117. cb.call(p_event);
  118. }
  119. }
  120. }
  121. void DisplayServerWayland::_update_window_rect(const Rect2i &p_rect, WindowID p_window_id) {
  122. ERR_FAIL_COND(!windows.has(p_window_id));
  123. WindowData &wd = windows[p_window_id];
  124. if (wd.rect == p_rect) {
  125. return;
  126. }
  127. wd.rect = p_rect;
  128. #ifdef RD_ENABLED
  129. if (wd.visible && rendering_context) {
  130. rendering_context->window_set_size(p_window_id, wd.rect.size.width, wd.rect.size.height);
  131. }
  132. #endif
  133. #ifdef GLES3_ENABLED
  134. if (wd.visible && egl_manager) {
  135. wl_egl_window_resize(wd.wl_egl_window, wd.rect.size.width, wd.rect.size.height, 0, 0);
  136. }
  137. #endif
  138. if (wd.rect_changed_callback.is_valid()) {
  139. wd.rect_changed_callback.call(wd.rect);
  140. }
  141. }
  142. // Interface methods.
  143. bool DisplayServerWayland::has_feature(Feature p_feature) const {
  144. switch (p_feature) {
  145. #ifndef DISABLE_DEPRECATED
  146. case FEATURE_GLOBAL_MENU: {
  147. return (native_menu && native_menu->has_feature(NativeMenu::FEATURE_GLOBAL_MENU));
  148. } break;
  149. #endif
  150. case FEATURE_MOUSE:
  151. case FEATURE_MOUSE_WARP:
  152. case FEATURE_CLIPBOARD:
  153. case FEATURE_CURSOR_SHAPE:
  154. case FEATURE_CUSTOM_CURSOR_SHAPE:
  155. case FEATURE_WINDOW_TRANSPARENCY:
  156. case FEATURE_ICON:
  157. case FEATURE_HIDPI:
  158. case FEATURE_SWAP_BUFFERS:
  159. case FEATURE_KEEP_SCREEN_ON:
  160. case FEATURE_IME:
  161. case FEATURE_WINDOW_DRAG:
  162. case FEATURE_CLIPBOARD_PRIMARY:
  163. case FEATURE_SUBWINDOWS:
  164. case FEATURE_SELF_FITTING_WINDOWS: {
  165. return true;
  166. } break;
  167. //case FEATURE_NATIVE_DIALOG:
  168. //case FEATURE_NATIVE_DIALOG_INPUT:
  169. #ifdef DBUS_ENABLED
  170. case FEATURE_NATIVE_DIALOG_FILE:
  171. case FEATURE_NATIVE_DIALOG_FILE_EXTRA:
  172. case FEATURE_NATIVE_DIALOG_FILE_MIME: {
  173. return (portal_desktop && portal_desktop->is_supported() && portal_desktop->is_file_chooser_supported());
  174. } break;
  175. case FEATURE_NATIVE_COLOR_PICKER: {
  176. return (portal_desktop && portal_desktop->is_supported() && portal_desktop->is_screenshot_supported());
  177. } break;
  178. #endif
  179. #ifdef SPEECHD_ENABLED
  180. case FEATURE_TEXT_TO_SPEECH: {
  181. return true;
  182. } break;
  183. #endif
  184. #ifdef ACCESSKIT_ENABLED
  185. case FEATURE_ACCESSIBILITY_SCREEN_READER: {
  186. return (accessibility_driver != nullptr);
  187. } break;
  188. #endif
  189. default: {
  190. return false;
  191. }
  192. }
  193. }
  194. String DisplayServerWayland::get_name() const {
  195. return "Wayland";
  196. }
  197. #ifdef SPEECHD_ENABLED
  198. void DisplayServerWayland::initialize_tts() const {
  199. const_cast<DisplayServerWayland *>(this)->tts = memnew(TTS_Linux);
  200. }
  201. bool DisplayServerWayland::tts_is_speaking() const {
  202. if (unlikely(!tts)) {
  203. initialize_tts();
  204. }
  205. ERR_FAIL_NULL_V(tts, false);
  206. return tts->is_speaking();
  207. }
  208. bool DisplayServerWayland::tts_is_paused() const {
  209. if (unlikely(!tts)) {
  210. initialize_tts();
  211. }
  212. ERR_FAIL_NULL_V(tts, false);
  213. return tts->is_paused();
  214. }
  215. TypedArray<Dictionary> DisplayServerWayland::tts_get_voices() const {
  216. if (unlikely(!tts)) {
  217. initialize_tts();
  218. }
  219. ERR_FAIL_NULL_V(tts, TypedArray<Dictionary>());
  220. return tts->get_voices();
  221. }
  222. void DisplayServerWayland::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) {
  223. if (unlikely(!tts)) {
  224. initialize_tts();
  225. }
  226. ERR_FAIL_NULL(tts);
  227. tts->speak(p_text, p_voice, p_volume, p_pitch, p_rate, p_utterance_id, p_interrupt);
  228. }
  229. void DisplayServerWayland::tts_pause() {
  230. if (unlikely(!tts)) {
  231. initialize_tts();
  232. }
  233. ERR_FAIL_NULL(tts);
  234. tts->pause();
  235. }
  236. void DisplayServerWayland::tts_resume() {
  237. if (unlikely(!tts)) {
  238. initialize_tts();
  239. }
  240. ERR_FAIL_NULL(tts);
  241. tts->resume();
  242. }
  243. void DisplayServerWayland::tts_stop() {
  244. if (unlikely(!tts)) {
  245. initialize_tts();
  246. }
  247. ERR_FAIL_NULL(tts);
  248. tts->stop();
  249. }
  250. #endif
  251. #ifdef DBUS_ENABLED
  252. bool DisplayServerWayland::is_dark_mode_supported() const {
  253. return portal_desktop && portal_desktop->is_supported() && portal_desktop->is_settings_supported();
  254. }
  255. bool DisplayServerWayland::is_dark_mode() const {
  256. if (!is_dark_mode_supported()) {
  257. return false;
  258. }
  259. switch (portal_desktop->get_appearance_color_scheme()) {
  260. case 1:
  261. // Prefers dark theme.
  262. return true;
  263. case 2:
  264. // Prefers light theme.
  265. return false;
  266. default:
  267. // Preference unknown.
  268. return false;
  269. }
  270. }
  271. Color DisplayServerWayland::get_accent_color() const {
  272. if (!portal_desktop) {
  273. return Color();
  274. }
  275. return portal_desktop->get_appearance_accent_color();
  276. }
  277. void DisplayServerWayland::set_system_theme_change_callback(const Callable &p_callable) {
  278. ERR_FAIL_COND(!portal_desktop);
  279. portal_desktop->set_system_theme_change_callback(p_callable);
  280. }
  281. Error DisplayServerWayland::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, WindowID p_window_id) {
  282. ERR_FAIL_COND_V(!portal_desktop, ERR_UNAVAILABLE);
  283. MutexLock mutex_lock(wayland_thread.mutex);
  284. WindowID window_id = p_window_id;
  285. if (!windows.has(window_id) || window_get_flag(WINDOW_FLAG_POPUP_WM_HINT, window_id)) {
  286. window_id = MAIN_WINDOW_ID;
  287. }
  288. WaylandThread::WindowState *ws = wayland_thread.window_get_state(window_id);
  289. ERR_FAIL_NULL_V(ws, ERR_BUG);
  290. return portal_desktop->file_dialog_show(window_id, (ws ? ws->exported_handle : String()), p_title, p_current_directory, String(), p_filename, p_mode, p_filters, TypedArray<Dictionary>(), p_callback, false);
  291. }
  292. Error DisplayServerWayland::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, WindowID p_window_id) {
  293. ERR_FAIL_COND_V(!portal_desktop, ERR_UNAVAILABLE);
  294. MutexLock mutex_lock(wayland_thread.mutex);
  295. WindowID window_id = p_window_id;
  296. if (!windows.has(window_id) || window_get_flag(WINDOW_FLAG_POPUP_WM_HINT, window_id)) {
  297. window_id = MAIN_WINDOW_ID;
  298. }
  299. WaylandThread::WindowState *ws = wayland_thread.window_get_state(window_id);
  300. ERR_FAIL_NULL_V(ws, ERR_BUG);
  301. return portal_desktop->file_dialog_show(window_id, (ws ? ws->exported_handle : String()), p_title, p_current_directory, p_root, p_filename, p_mode, p_filters, p_options, p_callback, true);
  302. }
  303. #endif
  304. void DisplayServerWayland::beep() const {
  305. wayland_thread.beep();
  306. }
  307. void DisplayServerWayland::_mouse_update_mode() {
  308. MouseMode wanted_mouse_mode = mouse_mode_override_enabled
  309. ? mouse_mode_override
  310. : mouse_mode_base;
  311. if (wanted_mouse_mode == mouse_mode) {
  312. return;
  313. }
  314. MutexLock mutex_lock(wayland_thread.mutex);
  315. bool show_cursor = (wanted_mouse_mode == MOUSE_MODE_VISIBLE || wanted_mouse_mode == MOUSE_MODE_CONFINED);
  316. wayland_thread.cursor_set_visible(show_cursor);
  317. WaylandThread::PointerConstraint constraint = WaylandThread::PointerConstraint::NONE;
  318. switch (wanted_mouse_mode) {
  319. case DisplayServer::MOUSE_MODE_CAPTURED: {
  320. constraint = WaylandThread::PointerConstraint::LOCKED;
  321. } break;
  322. case DisplayServer::MOUSE_MODE_CONFINED:
  323. case DisplayServer::MOUSE_MODE_CONFINED_HIDDEN: {
  324. constraint = WaylandThread::PointerConstraint::CONFINED;
  325. } break;
  326. default: {
  327. }
  328. }
  329. wayland_thread.pointer_set_constraint(constraint);
  330. if (wanted_mouse_mode == DisplayServer::MOUSE_MODE_CAPTURED) {
  331. WindowData *pointed_win = windows.getptr(wayland_thread.pointer_get_pointed_window_id());
  332. ERR_FAIL_NULL(pointed_win);
  333. wayland_thread.pointer_set_hint(pointed_win->rect.size / 2);
  334. }
  335. mouse_mode = wanted_mouse_mode;
  336. }
  337. void DisplayServerWayland::mouse_set_mode(MouseMode p_mode) {
  338. ERR_FAIL_INDEX(p_mode, MouseMode::MOUSE_MODE_MAX);
  339. if (p_mode == mouse_mode_base) {
  340. return;
  341. }
  342. mouse_mode_base = p_mode;
  343. _mouse_update_mode();
  344. }
  345. DisplayServerWayland::MouseMode DisplayServerWayland::mouse_get_mode() const {
  346. return mouse_mode;
  347. }
  348. void DisplayServerWayland::mouse_set_mode_override(MouseMode p_mode) {
  349. ERR_FAIL_INDEX(p_mode, MouseMode::MOUSE_MODE_MAX);
  350. if (p_mode == mouse_mode_override) {
  351. return;
  352. }
  353. mouse_mode_override = p_mode;
  354. _mouse_update_mode();
  355. }
  356. DisplayServerWayland::MouseMode DisplayServerWayland::mouse_get_mode_override() const {
  357. return mouse_mode_override;
  358. }
  359. void DisplayServerWayland::mouse_set_mode_override_enabled(bool p_override_enabled) {
  360. if (p_override_enabled == mouse_mode_override_enabled) {
  361. return;
  362. }
  363. mouse_mode_override_enabled = p_override_enabled;
  364. _mouse_update_mode();
  365. }
  366. bool DisplayServerWayland::mouse_is_mode_override_enabled() const {
  367. return mouse_mode_override_enabled;
  368. }
  369. // NOTE: This is hacked together (and not guaranteed to work in the first place)
  370. // as for some reason the there's no proper way to ask the compositor to warp
  371. // the pointer, although, at the time of writing, there's a proposal for a
  372. // proper protocol for this. See:
  373. // https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/158
  374. void DisplayServerWayland::warp_mouse(const Point2i &p_to) {
  375. MutexLock mutex_lock(wayland_thread.mutex);
  376. WaylandThread::PointerConstraint old_constraint = wayland_thread.pointer_get_constraint();
  377. wayland_thread.pointer_set_constraint(WaylandThread::PointerConstraint::LOCKED);
  378. wayland_thread.pointer_set_hint(p_to);
  379. wayland_thread.pointer_set_constraint(old_constraint);
  380. }
  381. Point2i DisplayServerWayland::mouse_get_position() const {
  382. MutexLock mutex_lock(wayland_thread.mutex);
  383. WindowID pointed_id = wayland_thread.pointer_get_pointed_window_id();
  384. if (pointed_id != INVALID_WINDOW_ID && windows.has(pointed_id)) {
  385. return Input::get_singleton()->get_mouse_position() + windows[pointed_id].rect.position;
  386. }
  387. // We can't properly implement this method by design.
  388. // This is the best we can do unfortunately.
  389. return Input::get_singleton()->get_mouse_position();
  390. }
  391. BitField<MouseButtonMask> DisplayServerWayland::mouse_get_button_state() const {
  392. MutexLock mutex_lock(wayland_thread.mutex);
  393. // Are we sure this is the only way? This seems sus.
  394. // TODO: Handle tablets properly.
  395. //mouse_button_mask.set_flag(MouseButtonMask((int64_t)wls.current_seat->tablet_tool_data.pressed_button_mask));
  396. return wayland_thread.pointer_get_button_mask();
  397. }
  398. // NOTE: According to the Wayland specification, this method will only do
  399. // anything if the user has interacted with the application by sending a
  400. // "recent enough" input event.
  401. // TODO: Add this limitation to the documentation.
  402. void DisplayServerWayland::clipboard_set(const String &p_text) {
  403. MutexLock mutex_lock(wayland_thread.mutex);
  404. wayland_thread.selection_set_text(p_text);
  405. }
  406. String DisplayServerWayland::clipboard_get() const {
  407. MutexLock mutex_lock(wayland_thread.mutex);
  408. Vector<uint8_t> data;
  409. const String text_mimes[] = {
  410. "text/plain;charset=utf-8",
  411. "text/plain",
  412. };
  413. for (String mime : text_mimes) {
  414. if (wayland_thread.selection_has_mime(mime)) {
  415. print_verbose(vformat("Selecting media type \"%s\" from offered types.", mime));
  416. data = wayland_thread.selection_get_mime(mime);
  417. break;
  418. }
  419. }
  420. return String::utf8((const char *)data.ptr(), data.size());
  421. }
  422. Ref<Image> DisplayServerWayland::clipboard_get_image() const {
  423. MutexLock mutex_lock(wayland_thread.mutex);
  424. Ref<Image> image;
  425. image.instantiate();
  426. Error err = OK;
  427. // TODO: Fallback to next media type on missing module or parse error.
  428. if (wayland_thread.selection_has_mime("image/png")) {
  429. err = image->load_png_from_buffer(wayland_thread.selection_get_mime("image/png"));
  430. } else if (wayland_thread.selection_has_mime("image/jpeg")) {
  431. err = image->load_jpg_from_buffer(wayland_thread.selection_get_mime("image/jpeg"));
  432. } else if (wayland_thread.selection_has_mime("image/webp")) {
  433. err = image->load_webp_from_buffer(wayland_thread.selection_get_mime("image/webp"));
  434. } else if (wayland_thread.selection_has_mime("image/svg+xml")) {
  435. err = image->load_svg_from_buffer(wayland_thread.selection_get_mime("image/svg+xml"));
  436. } else if (wayland_thread.selection_has_mime("image/bmp")) {
  437. err = image->load_bmp_from_buffer(wayland_thread.selection_get_mime("image/bmp"));
  438. } else if (wayland_thread.selection_has_mime("image/x-tga")) {
  439. err = image->load_tga_from_buffer(wayland_thread.selection_get_mime("image/x-tga"));
  440. } else if (wayland_thread.selection_has_mime("image/x-targa")) {
  441. err = image->load_tga_from_buffer(wayland_thread.selection_get_mime("image/x-targa"));
  442. } else if (wayland_thread.selection_has_mime("image/ktx")) {
  443. err = image->load_ktx_from_buffer(wayland_thread.selection_get_mime("image/ktx"));
  444. }
  445. ERR_FAIL_COND_V(err != OK, Ref<Image>());
  446. return image;
  447. }
  448. void DisplayServerWayland::clipboard_set_primary(const String &p_text) {
  449. MutexLock mutex_lock(wayland_thread.mutex);
  450. wayland_thread.primary_set_text(p_text);
  451. }
  452. String DisplayServerWayland::clipboard_get_primary() const {
  453. MutexLock mutex_lock(wayland_thread.mutex);
  454. Vector<uint8_t> data;
  455. const String text_mimes[] = {
  456. "text/plain;charset=utf-8",
  457. "text/plain",
  458. };
  459. for (String mime : text_mimes) {
  460. if (wayland_thread.primary_has_mime(mime)) {
  461. print_verbose(vformat("Selecting media type \"%s\" from offered types.", mime));
  462. data = wayland_thread.primary_get_mime(mime);
  463. break;
  464. }
  465. }
  466. return String::utf8((const char *)data.ptr(), data.size());
  467. }
  468. int DisplayServerWayland::get_screen_count() const {
  469. MutexLock mutex_lock(wayland_thread.mutex);
  470. return wayland_thread.get_screen_count();
  471. }
  472. int DisplayServerWayland::get_primary_screen() const {
  473. // AFAIK Wayland doesn't allow knowing (nor we care) about which screen is
  474. // primary.
  475. return 0;
  476. }
  477. Point2i DisplayServerWayland::screen_get_position(int p_screen) const {
  478. MutexLock mutex_lock(wayland_thread.mutex);
  479. p_screen = _get_screen_index(p_screen);
  480. int screen_count = get_screen_count();
  481. ERR_FAIL_INDEX_V(p_screen, screen_count, Point2i());
  482. return wayland_thread.screen_get_data(p_screen).position;
  483. }
  484. Size2i DisplayServerWayland::screen_get_size(int p_screen) const {
  485. MutexLock mutex_lock(wayland_thread.mutex);
  486. p_screen = _get_screen_index(p_screen);
  487. int screen_count = get_screen_count();
  488. ERR_FAIL_INDEX_V(p_screen, screen_count, Size2i());
  489. return wayland_thread.screen_get_data(p_screen).size;
  490. }
  491. Rect2i DisplayServerWayland::screen_get_usable_rect(int p_screen) const {
  492. p_screen = _get_screen_index(p_screen);
  493. int screen_count = get_screen_count();
  494. ERR_FAIL_INDEX_V(p_screen, screen_count, Rect2i());
  495. return Rect2i(screen_get_position(p_screen), screen_get_size(p_screen));
  496. }
  497. int DisplayServerWayland::screen_get_dpi(int p_screen) const {
  498. MutexLock mutex_lock(wayland_thread.mutex);
  499. p_screen = _get_screen_index(p_screen);
  500. int screen_count = get_screen_count();
  501. ERR_FAIL_INDEX_V(p_screen, screen_count, 96);
  502. const WaylandThread::ScreenData &data = wayland_thread.screen_get_data(p_screen);
  503. int width_mm = data.physical_size.width;
  504. int height_mm = data.physical_size.height;
  505. double xdpi = (width_mm ? data.size.width / (double)width_mm * 25.4 : 0);
  506. double ydpi = (height_mm ? data.size.height / (double)height_mm * 25.4 : 0);
  507. if (xdpi || ydpi) {
  508. return (xdpi + ydpi) / (xdpi && ydpi ? 2 : 1);
  509. }
  510. // Could not get DPI.
  511. return 96;
  512. }
  513. float DisplayServerWayland::screen_get_scale(int p_screen) const {
  514. MutexLock mutex_lock(wayland_thread.mutex);
  515. if (p_screen == SCREEN_OF_MAIN_WINDOW) {
  516. // Wayland does not expose fractional scale factors at the screen-level, but
  517. // some code relies on it. Since this special screen is the default and a lot
  518. // of code relies on it, we'll return the window's scale, which is what we
  519. // really care about. After all, we have very little use of the actual screen
  520. // enumeration APIs and we're (for now) in single-window mode anyways.
  521. struct wl_surface *wl_surface = wayland_thread.window_get_wl_surface(MAIN_WINDOW_ID);
  522. WaylandThread::WindowState *ws = wayland_thread.wl_surface_get_window_state(wl_surface);
  523. return wayland_thread.window_state_get_scale_factor(ws);
  524. }
  525. p_screen = _get_screen_index(p_screen);
  526. int screen_count = get_screen_count();
  527. ERR_FAIL_INDEX_V(p_screen, screen_count, 1.0f);
  528. return wayland_thread.screen_get_data(p_screen).scale;
  529. }
  530. float DisplayServerWayland::screen_get_refresh_rate(int p_screen) const {
  531. MutexLock mutex_lock(wayland_thread.mutex);
  532. p_screen = _get_screen_index(p_screen);
  533. int screen_count = get_screen_count();
  534. ERR_FAIL_INDEX_V(p_screen, screen_count, SCREEN_REFRESH_RATE_FALLBACK);
  535. return wayland_thread.screen_get_data(p_screen).refresh_rate;
  536. }
  537. void DisplayServerWayland::screen_set_keep_on(bool p_enable) {
  538. MutexLock mutex_lock(wayland_thread.mutex);
  539. // FIXME: For some reason this does not also windows from the wayland thread.
  540. if (screen_is_kept_on() == p_enable) {
  541. return;
  542. }
  543. #ifdef DBUS_ENABLED
  544. if (screensaver) {
  545. if (p_enable) {
  546. screensaver->inhibit();
  547. } else {
  548. screensaver->uninhibit();
  549. }
  550. screensaver_inhibited = p_enable;
  551. }
  552. #endif
  553. }
  554. bool DisplayServerWayland::screen_is_kept_on() const {
  555. // FIXME: Multiwindow support.
  556. #ifdef DBUS_ENABLED
  557. return wayland_thread.window_get_idle_inhibition(MAIN_WINDOW_ID) || screensaver_inhibited;
  558. #else
  559. return wayland_thread.window_get_idle_inhibition(MAIN_WINDOW_ID);
  560. #endif
  561. }
  562. Vector<DisplayServer::WindowID> DisplayServerWayland::get_window_list() const {
  563. MutexLock mutex_lock(wayland_thread.mutex);
  564. Vector<int> ret;
  565. for (const KeyValue<WindowID, WindowData> &E : windows) {
  566. ret.push_back(E.key);
  567. }
  568. return ret;
  569. }
  570. DisplayServer::WindowID DisplayServerWayland::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) {
  571. WindowID id = ++window_id_counter;
  572. WindowData &wd = windows[id];
  573. wd.id = id;
  574. wd.mode = p_mode;
  575. wd.flags = p_flags;
  576. wd.vsync_mode = p_vsync_mode;
  577. #ifdef ACCESSKIT_ENABLED
  578. if (accessibility_driver && !accessibility_driver->window_create(wd.id, nullptr)) {
  579. if (OS::get_singleton()->is_stdout_verbose()) {
  580. ERR_PRINT("Can't create an accessibility adapter for window, accessibility support disabled!");
  581. }
  582. memdelete(accessibility_driver);
  583. accessibility_driver = nullptr;
  584. }
  585. #endif
  586. // NOTE: Remember to clear its position if this window will be a toplevel. We
  587. // can only know once we show it.
  588. wd.rect = p_rect;
  589. wd.title = "Godot";
  590. wd.parent_id = p_transient_parent;
  591. return id;
  592. }
  593. void DisplayServerWayland::show_window(WindowID p_window_id) {
  594. MutexLock mutex_lock(wayland_thread.mutex);
  595. ERR_FAIL_COND(!windows.has(p_window_id));
  596. WindowData &wd = windows[p_window_id];
  597. if (!wd.visible) {
  598. DEBUG_LOG_WAYLAND(vformat("Showing window %d", p_window_id));
  599. // Showing this window will reset its mode with whatever the compositor
  600. // reports. We'll save the mode beforehand so that we can reapply it later.
  601. // TODO: Fix/Port/Move/Whatever to `WaylandThread` APIs.
  602. WindowMode setup_mode = wd.mode;
  603. // Let's determine the closest toplevel. For toplevels it will be themselves,
  604. // for popups the first toplevel ancestor it finds.
  605. WindowID root_id = wd.id;
  606. while (root_id != INVALID_WINDOW_ID && window_get_flag(WINDOW_FLAG_POPUP_WM_HINT, root_id)) {
  607. root_id = windows[root_id].parent_id;
  608. }
  609. ERR_FAIL_COND(root_id == INVALID_WINDOW_ID);
  610. wd.root_id = root_id;
  611. if (!window_get_flag(WINDOW_FLAG_POPUP_WM_HINT, p_window_id)) {
  612. // NOTE: DO **NOT** KEEP THE POSITION SET FOR TOPLEVELS. Wayland does not
  613. // track them and we're gonna get our events transformed in unexpected ways.
  614. wd.rect.position = Point2i();
  615. DEBUG_LOG_WAYLAND(vformat("Creating regular window of size %s", wd.rect.size));
  616. wayland_thread.window_create(p_window_id, wd.rect.size.width, wd.rect.size.height);
  617. wayland_thread.window_set_min_size(p_window_id, wd.min_size);
  618. wayland_thread.window_set_max_size(p_window_id, wd.max_size);
  619. wayland_thread.window_set_app_id(p_window_id, _get_app_id_from_context(context));
  620. wayland_thread.window_set_borderless(p_window_id, window_get_flag(WINDOW_FLAG_BORDERLESS, p_window_id));
  621. if (wd.parent_id != INVALID_WINDOW_ID) {
  622. wayland_thread.window_set_parent(wd.id, wd.parent_id);
  623. }
  624. // Since it can't have a position. Let's tell the window node the news by
  625. // the actual rect to it.
  626. if (wd.rect_changed_callback.is_valid()) {
  627. wd.rect_changed_callback.call(wd.rect);
  628. }
  629. } else {
  630. DEBUG_LOG_WAYLAND("!!!!! Making popup !!!!!");
  631. windows[root_id].popup_stack.push_back(p_window_id);
  632. if (window_get_flag(WINDOW_FLAG_POPUP, p_window_id)) {
  633. // Reroutes all input to it.
  634. popup_menu_list.push_back(p_window_id);
  635. }
  636. wayland_thread.window_create_popup(p_window_id, wd.parent_id, wd.rect);
  637. }
  638. // NOTE: The XDG shell protocol is built in a way that causes the window to
  639. // be immediately shown as soon as a valid buffer is assigned to it. Hence,
  640. // the only acceptable way of implementing window showing is to move the
  641. // graphics context window creation logic here.
  642. #ifdef RD_ENABLED
  643. if (rendering_context) {
  644. union {
  645. #ifdef VULKAN_ENABLED
  646. RenderingContextDriverVulkanWayland::WindowPlatformData vulkan;
  647. #endif
  648. } wpd;
  649. #ifdef VULKAN_ENABLED
  650. if (rendering_driver == "vulkan") {
  651. wpd.vulkan.surface = wayland_thread.window_get_wl_surface(wd.id);
  652. wpd.vulkan.display = wayland_thread.get_wl_display();
  653. }
  654. #endif
  655. Error err = rendering_context->window_create(wd.id, &wpd);
  656. ERR_FAIL_COND_MSG(err != OK, vformat("Can't create a %s window", rendering_driver));
  657. rendering_context->window_set_size(wd.id, wd.rect.size.width, wd.rect.size.height);
  658. // NOTE: Looks like we have to set the vsync mode before creating the screen
  659. // or it won't work. Resist any temptation.
  660. window_set_vsync_mode(wd.vsync_mode, p_window_id);
  661. }
  662. if (rendering_device) {
  663. rendering_device->screen_create(wd.id);
  664. }
  665. #endif
  666. #ifdef GLES3_ENABLED
  667. if (egl_manager) {
  668. struct wl_surface *wl_surface = wayland_thread.window_get_wl_surface(wd.id);
  669. wd.wl_egl_window = wl_egl_window_create(wl_surface, wd.rect.size.width, wd.rect.size.height);
  670. Error err = egl_manager->window_create(p_window_id, wayland_thread.get_wl_display(), wd.wl_egl_window, wd.rect.size.width, wd.rect.size.height);
  671. ERR_FAIL_COND_MSG(err == ERR_CANT_CREATE, "Can't show a GLES3 window.");
  672. window_set_vsync_mode(wd.vsync_mode, p_window_id);
  673. }
  674. #endif
  675. // NOTE: Some public window-handling methods might depend on this flag being
  676. // set. Make sure the method you're calling does not depend on it before this
  677. // assignment.
  678. wd.visible = true;
  679. // Actually try to apply the window's mode now that it's visible.
  680. window_set_mode(setup_mode, wd.id);
  681. wayland_thread.window_set_title(p_window_id, wd.title);
  682. }
  683. }
  684. void DisplayServerWayland::delete_sub_window(WindowID p_window_id) {
  685. MutexLock mutex_lock(wayland_thread.mutex);
  686. ERR_FAIL_COND(!windows.has(p_window_id));
  687. WindowData &wd = windows[p_window_id];
  688. ERR_FAIL_COND(!windows.has(wd.root_id));
  689. WindowData &root_wd = windows[wd.root_id];
  690. // NOTE: By the time the Wayland thread will send a `WINDOW_EVENT_MOUSE_EXIT`
  691. // the window will be gone and the message will be discarded, confusing the
  692. // engine. We thus have to send it ourselves.
  693. if (wayland_thread.pointer_get_pointed_window_id() == p_window_id) {
  694. _send_window_event(WINDOW_EVENT_MOUSE_EXIT, p_window_id);
  695. }
  696. // The XDG shell specification requires us to clear all popups in reverse order.
  697. while (!root_wd.popup_stack.is_empty() && root_wd.popup_stack.back()->get() != p_window_id) {
  698. _send_window_event(WINDOW_EVENT_FORCE_CLOSE, root_wd.popup_stack.back()->get());
  699. }
  700. if (root_wd.popup_stack.back() && root_wd.popup_stack.back()->get() == p_window_id) {
  701. root_wd.popup_stack.pop_back();
  702. }
  703. if (popup_menu_list.back() && popup_menu_list.back()->get() == p_window_id) {
  704. popup_menu_list.pop_back();
  705. }
  706. #ifdef ACCESSKIT_ENABLED
  707. if (accessibility_driver) {
  708. accessibility_driver->window_destroy(p_window_id);
  709. }
  710. #endif
  711. if (wd.visible) {
  712. #ifdef VULKAN_ENABLED
  713. if (rendering_device) {
  714. rendering_device->screen_free(p_window_id);
  715. }
  716. if (rendering_context) {
  717. rendering_context->window_destroy(p_window_id);
  718. }
  719. #endif
  720. #ifdef GLES3_ENABLED
  721. if (egl_manager) {
  722. egl_manager->window_destroy(p_window_id);
  723. }
  724. #endif
  725. wayland_thread.window_destroy(p_window_id);
  726. }
  727. windows.erase(p_window_id);
  728. DEBUG_LOG_WAYLAND(vformat("Destroyed window %d", p_window_id));
  729. }
  730. DisplayServer::WindowID DisplayServerWayland::window_get_active_popup() const {
  731. MutexLock mutex_lock(wayland_thread.mutex);
  732. if (!popup_menu_list.is_empty()) {
  733. return popup_menu_list.back()->get();
  734. }
  735. return INVALID_WINDOW_ID;
  736. }
  737. void DisplayServerWayland::window_set_popup_safe_rect(WindowID p_window, const Rect2i &p_rect) {
  738. MutexLock mutex_lock(wayland_thread.mutex);
  739. ERR_FAIL_COND(!windows.has(p_window));
  740. windows[p_window].safe_rect = p_rect;
  741. }
  742. Rect2i DisplayServerWayland::window_get_popup_safe_rect(WindowID p_window) const {
  743. MutexLock mutex_lock(wayland_thread.mutex);
  744. ERR_FAIL_COND_V(!windows.has(p_window), Rect2i());
  745. return windows[p_window].safe_rect;
  746. }
  747. int64_t DisplayServerWayland::window_get_native_handle(HandleType p_handle_type, WindowID p_window) const {
  748. MutexLock mutex_lock(wayland_thread.mutex);
  749. switch (p_handle_type) {
  750. case DISPLAY_HANDLE: {
  751. return (int64_t)wayland_thread.get_wl_display();
  752. } break;
  753. case WINDOW_HANDLE: {
  754. return (int64_t)wayland_thread.window_get_wl_surface(p_window);
  755. } break;
  756. case WINDOW_VIEW: {
  757. return 0; // Not supported.
  758. } break;
  759. #ifdef GLES3_ENABLED
  760. case OPENGL_CONTEXT: {
  761. if (egl_manager) {
  762. return (int64_t)egl_manager->get_context(p_window);
  763. }
  764. return 0;
  765. } break;
  766. case EGL_DISPLAY: {
  767. if (egl_manager) {
  768. return (int64_t)egl_manager->get_display(p_window);
  769. }
  770. return 0;
  771. }
  772. case EGL_CONFIG: {
  773. if (egl_manager) {
  774. return (int64_t)egl_manager->get_config(p_window);
  775. }
  776. return 0;
  777. }
  778. #endif // GLES3_ENABLED
  779. default: {
  780. return 0;
  781. } break;
  782. }
  783. }
  784. DisplayServer::WindowID DisplayServerWayland::get_window_at_screen_position(const Point2i &p_position) const {
  785. // Standard Wayland APIs don't support this.
  786. return MAIN_WINDOW_ID;
  787. }
  788. void DisplayServerWayland::window_attach_instance_id(ObjectID p_instance, WindowID p_window_id) {
  789. MutexLock mutex_lock(wayland_thread.mutex);
  790. ERR_FAIL_COND(!windows.has(p_window_id));
  791. windows[p_window_id].instance_id = p_instance;
  792. }
  793. ObjectID DisplayServerWayland::window_get_attached_instance_id(WindowID p_window_id) const {
  794. MutexLock mutex_lock(wayland_thread.mutex);
  795. ERR_FAIL_COND_V(!windows.has(p_window_id), ObjectID());
  796. return windows[p_window_id].instance_id;
  797. }
  798. void DisplayServerWayland::window_set_title(const String &p_title, DisplayServer::WindowID p_window_id) {
  799. MutexLock mutex_lock(wayland_thread.mutex);
  800. ERR_FAIL_COND(!windows.has(p_window_id));
  801. WindowData &wd = windows[p_window_id];
  802. wd.title = p_title;
  803. if (wd.visible) {
  804. wayland_thread.window_set_title(p_window_id, wd.title);
  805. }
  806. }
  807. void DisplayServerWayland::window_set_mouse_passthrough(const Vector<Vector2> &p_region, DisplayServer::WindowID p_window_id) {
  808. // TODO
  809. DEBUG_LOG_WAYLAND(vformat("wayland stub window_set_mouse_passthrough region %s", p_region));
  810. }
  811. void DisplayServerWayland::window_set_rect_changed_callback(const Callable &p_callable, DisplayServer::WindowID p_window_id) {
  812. MutexLock mutex_lock(wayland_thread.mutex);
  813. ERR_FAIL_COND(!windows.has(p_window_id));
  814. windows[p_window_id].rect_changed_callback = p_callable;
  815. }
  816. void DisplayServerWayland::window_set_window_event_callback(const Callable &p_callable, DisplayServer::WindowID p_window_id) {
  817. MutexLock mutex_lock(wayland_thread.mutex);
  818. ERR_FAIL_COND(!windows.has(p_window_id));
  819. windows[p_window_id].window_event_callback = p_callable;
  820. }
  821. void DisplayServerWayland::window_set_input_event_callback(const Callable &p_callable, DisplayServer::WindowID p_window_id) {
  822. MutexLock mutex_lock(wayland_thread.mutex);
  823. ERR_FAIL_COND(!windows.has(p_window_id));
  824. windows[p_window_id].input_event_callback = p_callable;
  825. }
  826. void DisplayServerWayland::window_set_input_text_callback(const Callable &p_callable, WindowID p_window_id) {
  827. MutexLock mutex_lock(wayland_thread.mutex);
  828. ERR_FAIL_COND(!windows.has(p_window_id));
  829. windows[p_window_id].input_text_callback = p_callable;
  830. }
  831. void DisplayServerWayland::window_set_drop_files_callback(const Callable &p_callable, DisplayServer::WindowID p_window_id) {
  832. MutexLock mutex_lock(wayland_thread.mutex);
  833. ERR_FAIL_COND(!windows.has(p_window_id));
  834. windows[p_window_id].drop_files_callback = p_callable;
  835. }
  836. int DisplayServerWayland::window_get_current_screen(DisplayServer::WindowID p_window_id) const {
  837. ERR_FAIL_COND_V(!windows.has(p_window_id), INVALID_SCREEN);
  838. // Standard Wayland APIs don't support getting the screen of a window.
  839. return 0;
  840. }
  841. void DisplayServerWayland::window_set_current_screen(int p_screen, DisplayServer::WindowID p_window_id) {
  842. // Standard Wayland APIs don't support setting the screen of a window.
  843. }
  844. Point2i DisplayServerWayland::window_get_position(DisplayServer::WindowID p_window_id) const {
  845. MutexLock mutex_lock(wayland_thread.mutex);
  846. return windows[p_window_id].rect.position;
  847. }
  848. Point2i DisplayServerWayland::window_get_position_with_decorations(DisplayServer::WindowID p_window_id) const {
  849. MutexLock mutex_lock(wayland_thread.mutex);
  850. return windows[p_window_id].rect.position;
  851. }
  852. void DisplayServerWayland::window_set_position(const Point2i &p_position, DisplayServer::WindowID p_window_id) {
  853. // Unsupported with toplevels.
  854. }
  855. void DisplayServerWayland::window_set_max_size(const Size2i p_size, DisplayServer::WindowID p_window_id) {
  856. MutexLock mutex_lock(wayland_thread.mutex);
  857. DEBUG_LOG_WAYLAND(vformat("window max size set to %s", p_size));
  858. if (p_size.x < 0 || p_size.y < 0) {
  859. ERR_FAIL_MSG("Maximum window size can't be negative!");
  860. }
  861. ERR_FAIL_COND(!windows.has(p_window_id));
  862. WindowData &wd = windows[p_window_id];
  863. // FIXME: Is `p_size.x < wd.min_size.x || p_size.y < wd.min_size.y` == `p_size < wd.min_size`?
  864. if ((p_size != Size2i()) && ((p_size.x < wd.min_size.x) || (p_size.y < wd.min_size.y))) {
  865. ERR_PRINT("Maximum window size can't be smaller than minimum window size!");
  866. return;
  867. }
  868. wd.max_size = p_size;
  869. if (wd.visible) {
  870. wayland_thread.window_set_max_size(p_window_id, p_size);
  871. }
  872. }
  873. Size2i DisplayServerWayland::window_get_max_size(DisplayServer::WindowID p_window_id) const {
  874. MutexLock mutex_lock(wayland_thread.mutex);
  875. ERR_FAIL_COND_V(!windows.has(p_window_id), Size2i());
  876. return windows[p_window_id].max_size;
  877. }
  878. void DisplayServerWayland::gl_window_make_current(DisplayServer::WindowID p_window_id) {
  879. #ifdef GLES3_ENABLED
  880. if (egl_manager) {
  881. egl_manager->window_make_current(p_window_id);
  882. }
  883. #endif
  884. }
  885. void DisplayServerWayland::window_set_transient(WindowID p_window_id, WindowID p_parent) {
  886. MutexLock mutex_lock(wayland_thread.mutex);
  887. ERR_FAIL_COND(!windows.has(p_window_id));
  888. WindowData &wd = windows[p_window_id];
  889. ERR_FAIL_COND(wd.parent_id == p_parent);
  890. if (p_parent != INVALID_WINDOW_ID) {
  891. ERR_FAIL_COND(!windows.has(p_parent));
  892. ERR_FAIL_COND_MSG(wd.parent_id != INVALID_WINDOW_ID, "Window already has a transient parent");
  893. wd.parent_id = p_parent;
  894. // NOTE: Looks like live unparenting is not really practical unfortunately.
  895. // See WaylandThread::window_set_parent for more info.
  896. if (wd.visible) {
  897. wayland_thread.window_set_parent(p_window_id, p_parent);
  898. }
  899. }
  900. }
  901. void DisplayServerWayland::window_set_min_size(const Size2i p_size, DisplayServer::WindowID p_window_id) {
  902. MutexLock mutex_lock(wayland_thread.mutex);
  903. DEBUG_LOG_WAYLAND(vformat("window minsize set to %s", p_size));
  904. ERR_FAIL_COND(!windows.has(p_window_id));
  905. WindowData &wd = windows[p_window_id];
  906. if (p_size.x < 0 || p_size.y < 0) {
  907. ERR_FAIL_MSG("Minimum window size can't be negative!");
  908. }
  909. // FIXME: Is `p_size.x > wd.max_size.x || p_size.y > wd.max_size.y` == `p_size > wd.max_size`?
  910. if ((p_size != Size2i()) && (wd.max_size != Size2i()) && ((p_size.x > wd.max_size.x) || (p_size.y > wd.max_size.y))) {
  911. ERR_PRINT("Minimum window size can't be larger than maximum window size!");
  912. return;
  913. }
  914. wd.min_size = p_size;
  915. if (wd.visible) {
  916. wayland_thread.window_set_min_size(p_window_id, p_size);
  917. }
  918. }
  919. Size2i DisplayServerWayland::window_get_min_size(DisplayServer::WindowID p_window_id) const {
  920. MutexLock mutex_lock(wayland_thread.mutex);
  921. ERR_FAIL_COND_V(!windows.has(p_window_id), Size2i());
  922. return windows[p_window_id].min_size;
  923. }
  924. void DisplayServerWayland::window_set_size(const Size2i p_size, DisplayServer::WindowID p_window_id) {
  925. MutexLock mutex_lock(wayland_thread.mutex);
  926. ERR_FAIL_COND(!windows.has(p_window_id));
  927. WindowData &wd = windows[p_window_id];
  928. // The XDG spec doesn't allow non-interactive resizes. Let's update the
  929. // window's internal representation to account for that.
  930. if (wd.rect_changed_callback.is_valid()) {
  931. wd.rect_changed_callback.call(wd.rect);
  932. }
  933. }
  934. Size2i DisplayServerWayland::window_get_size(DisplayServer::WindowID p_window_id) const {
  935. MutexLock mutex_lock(wayland_thread.mutex);
  936. ERR_FAIL_COND_V(!windows.has(p_window_id), Size2i());
  937. return windows[p_window_id].rect.size;
  938. }
  939. Size2i DisplayServerWayland::window_get_size_with_decorations(DisplayServer::WindowID p_window_id) const {
  940. MutexLock mutex_lock(wayland_thread.mutex);
  941. // I don't think there's a way of actually knowing the size of the window
  942. // decoration in Wayland, at least in the case of SSDs, nor that it would be
  943. // that useful in this case. We'll just return the main window's size.
  944. ERR_FAIL_COND_V(!windows.has(p_window_id), Size2i());
  945. return windows[p_window_id].rect.size;
  946. }
  947. void DisplayServerWayland::window_set_mode(WindowMode p_mode, DisplayServer::WindowID p_window_id) {
  948. MutexLock mutex_lock(wayland_thread.mutex);
  949. ERR_FAIL_COND(!windows.has(p_window_id));
  950. WindowData &wd = windows[p_window_id];
  951. if (!wd.visible) {
  952. return;
  953. }
  954. wayland_thread.window_try_set_mode(p_window_id, p_mode);
  955. }
  956. DisplayServer::WindowMode DisplayServerWayland::window_get_mode(DisplayServer::WindowID p_window_id) const {
  957. MutexLock mutex_lock(wayland_thread.mutex);
  958. ERR_FAIL_COND_V(!windows.has(p_window_id), WINDOW_MODE_WINDOWED);
  959. const WindowData &wd = windows[p_window_id];
  960. if (!wd.visible) {
  961. return WINDOW_MODE_WINDOWED;
  962. }
  963. return wayland_thread.window_get_mode(p_window_id);
  964. }
  965. bool DisplayServerWayland::window_is_maximize_allowed(DisplayServer::WindowID p_window_id) const {
  966. MutexLock mutex_lock(wayland_thread.mutex);
  967. return wayland_thread.window_can_set_mode(p_window_id, WINDOW_MODE_MAXIMIZED);
  968. }
  969. void DisplayServerWayland::window_set_flag(WindowFlags p_flag, bool p_enabled, DisplayServer::WindowID p_window_id) {
  970. MutexLock mutex_lock(wayland_thread.mutex);
  971. ERR_FAIL_COND(!windows.has(p_window_id));
  972. WindowData &wd = windows[p_window_id];
  973. DEBUG_LOG_WAYLAND(vformat("Window set flag %d", p_flag));
  974. switch (p_flag) {
  975. case WINDOW_FLAG_BORDERLESS: {
  976. wayland_thread.window_set_borderless(p_window_id, p_enabled);
  977. } break;
  978. case WINDOW_FLAG_POPUP: {
  979. ERR_FAIL_COND_MSG(p_window_id == MAIN_WINDOW_ID, "Main window can't be popup.");
  980. ERR_FAIL_COND_MSG(wd.visible && (wd.flags & WINDOW_FLAG_POPUP_BIT) != p_enabled, "Popup flag can't changed while window is opened.");
  981. } break;
  982. case WINDOW_FLAG_POPUP_WM_HINT: {
  983. ERR_FAIL_COND_MSG(p_window_id == MAIN_WINDOW_ID, "Main window can't have popup hint.");
  984. ERR_FAIL_COND_MSG(wd.visible && (wd.flags & WINDOW_FLAG_POPUP_WM_HINT_BIT) != p_enabled, "Popup hint can't changed while window is opened.");
  985. } break;
  986. default: {
  987. }
  988. }
  989. if (p_enabled) {
  990. wd.flags |= 1 << p_flag;
  991. } else {
  992. wd.flags &= ~(1 << p_flag);
  993. }
  994. }
  995. bool DisplayServerWayland::window_get_flag(WindowFlags p_flag, DisplayServer::WindowID p_window_id) const {
  996. MutexLock mutex_lock(wayland_thread.mutex);
  997. ERR_FAIL_COND_V(!windows.has(p_window_id), false);
  998. return windows[p_window_id].flags & (1 << p_flag);
  999. }
  1000. void DisplayServerWayland::window_request_attention(DisplayServer::WindowID p_window_id) {
  1001. MutexLock mutex_lock(wayland_thread.mutex);
  1002. DEBUG_LOG_WAYLAND("Requested attention.");
  1003. wayland_thread.window_request_attention(p_window_id);
  1004. }
  1005. void DisplayServerWayland::window_move_to_foreground(DisplayServer::WindowID p_window_id) {
  1006. // Standard Wayland APIs don't support this.
  1007. }
  1008. bool DisplayServerWayland::window_is_focused(WindowID p_window_id) const {
  1009. return wayland_thread.pointer_get_pointed_window_id() == p_window_id;
  1010. }
  1011. bool DisplayServerWayland::window_can_draw(DisplayServer::WindowID p_window_id) const {
  1012. MutexLock mutex_lock(wayland_thread.mutex);
  1013. uint64_t last_frame_time = wayland_thread.window_get_last_frame_time(p_window_id);
  1014. uint64_t time_since_frame = OS::get_singleton()->get_ticks_usec() - last_frame_time;
  1015. if (time_since_frame > WAYLAND_MAX_FRAME_TIME_US) {
  1016. return false;
  1017. }
  1018. if (wayland_thread.window_is_suspended(p_window_id)) {
  1019. return false;
  1020. }
  1021. return suspend_state == SuspendState::NONE;
  1022. }
  1023. bool DisplayServerWayland::can_any_window_draw() const {
  1024. return suspend_state == SuspendState::NONE;
  1025. }
  1026. void DisplayServerWayland::window_set_ime_active(const bool p_active, DisplayServer::WindowID p_window_id) {
  1027. MutexLock mutex_lock(wayland_thread.mutex);
  1028. wayland_thread.window_set_ime_active(p_active, p_window_id);
  1029. }
  1030. void DisplayServerWayland::window_set_ime_position(const Point2i &p_pos, DisplayServer::WindowID p_window_id) {
  1031. MutexLock mutex_lock(wayland_thread.mutex);
  1032. wayland_thread.window_set_ime_position(p_pos, p_window_id);
  1033. }
  1034. int DisplayServerWayland::accessibility_should_increase_contrast() const {
  1035. #ifdef DBUS_ENABLED
  1036. if (!portal_desktop) {
  1037. return -1;
  1038. }
  1039. return portal_desktop->get_high_contrast();
  1040. #endif
  1041. return -1;
  1042. }
  1043. int DisplayServerWayland::accessibility_screen_reader_active() const {
  1044. #ifdef DBUS_ENABLED
  1045. if (atspi_monitor && atspi_monitor->is_supported()) {
  1046. return atspi_monitor->is_active();
  1047. }
  1048. #endif
  1049. return -1;
  1050. }
  1051. Point2i DisplayServerWayland::ime_get_selection() const {
  1052. return ime_selection;
  1053. }
  1054. String DisplayServerWayland::ime_get_text() const {
  1055. return ime_text;
  1056. }
  1057. // NOTE: While Wayland is supposed to be tear-free, wayland-protocols version
  1058. // 1.30 added a protocol for allowing async flips which is supposed to be
  1059. // handled by drivers such as Vulkan. We can then just ask to disable v-sync and
  1060. // hope for the best. See: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/commit/6394f0b4f3be151076f10a845a2fb131eeb56706
  1061. void DisplayServerWayland::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, DisplayServer::WindowID p_window_id) {
  1062. MutexLock mutex_lock(wayland_thread.mutex);
  1063. WindowData &wd = windows[p_window_id];
  1064. #ifdef RD_ENABLED
  1065. if (rendering_context) {
  1066. rendering_context->window_set_vsync_mode(p_window_id, p_vsync_mode);
  1067. wd.emulate_vsync = (!wayland_thread.is_fifo_available() && rendering_context->window_get_vsync_mode(p_window_id) == DisplayServer::VSYNC_ENABLED);
  1068. if (wd.emulate_vsync) {
  1069. print_verbose("VSYNC: manually throttling frames using MAILBOX.");
  1070. rendering_context->window_set_vsync_mode(p_window_id, DisplayServer::VSYNC_MAILBOX);
  1071. }
  1072. }
  1073. #endif // VULKAN_ENABLED
  1074. #ifdef GLES3_ENABLED
  1075. if (egl_manager) {
  1076. egl_manager->set_use_vsync(p_vsync_mode != DisplayServer::VSYNC_DISABLED);
  1077. // NOTE: Mesa's EGL implementation does not seem to make use of fifo_v1 so
  1078. // we'll have to always emulate V-Sync.
  1079. wd.emulate_vsync = egl_manager->is_using_vsync();
  1080. if (wd.emulate_vsync) {
  1081. print_verbose("VSYNC: manually throttling frames with swap delay 0.");
  1082. egl_manager->set_use_vsync(false);
  1083. }
  1084. }
  1085. #endif // GLES3_ENABLED
  1086. }
  1087. DisplayServer::VSyncMode DisplayServerWayland::window_get_vsync_mode(DisplayServer::WindowID p_window_id) const {
  1088. const WindowData &wd = windows[p_window_id];
  1089. if (wd.emulate_vsync) {
  1090. return DisplayServer::VSYNC_ENABLED;
  1091. }
  1092. #ifdef VULKAN_ENABLED
  1093. if (rendering_context) {
  1094. return rendering_context->window_get_vsync_mode(p_window_id);
  1095. }
  1096. #endif // VULKAN_ENABLED
  1097. #ifdef GLES3_ENABLED
  1098. if (egl_manager) {
  1099. return egl_manager->is_using_vsync() ? DisplayServer::VSYNC_ENABLED : DisplayServer::VSYNC_DISABLED;
  1100. }
  1101. #endif // GLES3_ENABLED
  1102. return DisplayServer::VSYNC_ENABLED;
  1103. }
  1104. void DisplayServerWayland::window_start_drag(WindowID p_window) {
  1105. MutexLock mutex_lock(wayland_thread.mutex);
  1106. wayland_thread.window_start_drag(p_window);
  1107. }
  1108. void DisplayServerWayland::window_start_resize(WindowResizeEdge p_edge, WindowID p_window) {
  1109. MutexLock mutex_lock(wayland_thread.mutex);
  1110. ERR_FAIL_INDEX(int(p_edge), WINDOW_EDGE_MAX);
  1111. wayland_thread.window_start_resize(p_edge, p_window);
  1112. }
  1113. void DisplayServerWayland::cursor_set_shape(CursorShape p_shape) {
  1114. ERR_FAIL_INDEX(p_shape, CURSOR_MAX);
  1115. MutexLock mutex_lock(wayland_thread.mutex);
  1116. if (p_shape == cursor_shape) {
  1117. return;
  1118. }
  1119. cursor_shape = p_shape;
  1120. if (mouse_mode != MOUSE_MODE_VISIBLE && mouse_mode != MOUSE_MODE_CONFINED) {
  1121. // Hidden.
  1122. return;
  1123. }
  1124. wayland_thread.cursor_set_shape(p_shape);
  1125. }
  1126. DisplayServerWayland::CursorShape DisplayServerWayland::cursor_get_shape() const {
  1127. MutexLock mutex_lock(wayland_thread.mutex);
  1128. return cursor_shape;
  1129. }
  1130. void DisplayServerWayland::cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
  1131. MutexLock mutex_lock(wayland_thread.mutex);
  1132. if (p_cursor.is_valid()) {
  1133. HashMap<CursorShape, CustomCursor>::Iterator cursor_c = custom_cursors.find(p_shape);
  1134. if (cursor_c) {
  1135. if (cursor_c->value.resource == p_cursor && cursor_c->value.hotspot == p_hotspot) {
  1136. // We have a cached cursor. Nice.
  1137. wayland_thread.cursor_set_shape(p_shape);
  1138. return;
  1139. }
  1140. // We're changing this cursor; we'll have to rebuild it.
  1141. custom_cursors.erase(p_shape);
  1142. wayland_thread.cursor_shape_clear_custom_image(p_shape);
  1143. }
  1144. Ref<Image> image = _get_cursor_image_from_resource(p_cursor, p_hotspot);
  1145. ERR_FAIL_COND(image.is_null());
  1146. CustomCursor &cursor = custom_cursors[p_shape];
  1147. cursor.resource = p_cursor;
  1148. cursor.hotspot = p_hotspot;
  1149. wayland_thread.cursor_shape_set_custom_image(p_shape, image, p_hotspot);
  1150. wayland_thread.cursor_set_shape(p_shape);
  1151. } else {
  1152. // Clear cache and reset to default system cursor.
  1153. wayland_thread.cursor_shape_clear_custom_image(p_shape);
  1154. if (cursor_shape == p_shape) {
  1155. wayland_thread.cursor_set_shape(p_shape);
  1156. }
  1157. if (custom_cursors.has(p_shape)) {
  1158. custom_cursors.erase(p_shape);
  1159. }
  1160. }
  1161. }
  1162. bool DisplayServerWayland::get_swap_cancel_ok() {
  1163. return swap_cancel_ok;
  1164. }
  1165. int DisplayServerWayland::keyboard_get_layout_count() const {
  1166. MutexLock mutex_lock(wayland_thread.mutex);
  1167. return wayland_thread.keyboard_get_layout_count();
  1168. }
  1169. int DisplayServerWayland::keyboard_get_current_layout() const {
  1170. MutexLock mutex_lock(wayland_thread.mutex);
  1171. return wayland_thread.keyboard_get_current_layout_index();
  1172. }
  1173. void DisplayServerWayland::keyboard_set_current_layout(int p_index) {
  1174. MutexLock mutex_lock(wayland_thread.mutex);
  1175. wayland_thread.keyboard_set_current_layout_index(p_index);
  1176. }
  1177. String DisplayServerWayland::keyboard_get_layout_language(int p_index) const {
  1178. MutexLock mutex_lock(wayland_thread.mutex);
  1179. // xkbcommon exposes only the layout's name, which looks like it overlaps with
  1180. // its language.
  1181. return wayland_thread.keyboard_get_layout_name(p_index);
  1182. }
  1183. String DisplayServerWayland::keyboard_get_layout_name(int p_index) const {
  1184. MutexLock mutex_lock(wayland_thread.mutex);
  1185. return wayland_thread.keyboard_get_layout_name(p_index);
  1186. }
  1187. Key DisplayServerWayland::keyboard_get_keycode_from_physical(Key p_keycode) const {
  1188. MutexLock mutex_lock(wayland_thread.mutex);
  1189. Key key = wayland_thread.keyboard_get_key_from_physical(p_keycode);
  1190. // If not found, fallback to QWERTY.
  1191. // This should match the behavior of the event pump.
  1192. if (key == Key::NONE) {
  1193. return p_keycode;
  1194. }
  1195. if (key >= Key::A + 32 && key <= Key::Z + 32) {
  1196. key -= 'a' - 'A';
  1197. }
  1198. // Make it consistent with the keys returned by `Input`.
  1199. if (key == Key::BACKTAB) {
  1200. key = Key::TAB;
  1201. }
  1202. return key;
  1203. }
  1204. bool DisplayServerWayland::color_picker(const Callable &p_callback) {
  1205. #ifdef DBUS_ENABLED
  1206. if (!portal_desktop) {
  1207. return false;
  1208. }
  1209. MutexLock mutex_lock(wayland_thread.mutex);
  1210. WindowID window_id = MAIN_WINDOW_ID;
  1211. // TODO: Use window IDs for multiwindow support.
  1212. WaylandThread::WindowState *ws = wayland_thread.wl_surface_get_window_state(wayland_thread.window_get_wl_surface(window_id));
  1213. return portal_desktop->color_picker((ws ? ws->exported_handle : String()), p_callback);
  1214. #else
  1215. return false;
  1216. #endif
  1217. }
  1218. void DisplayServerWayland::try_suspend() {
  1219. // Due to various reasons, we manually handle display synchronization by
  1220. // waiting for a frame event (request to draw) or, if available, the actual
  1221. // window's suspend status. When a window is suspended, we can avoid drawing
  1222. // altogether, either because the compositor told us that we don't need to or
  1223. // because the pace of the frame events became unreliable.
  1224. bool frame = wayland_thread.wait_frame_suspend_ms(WAYLAND_MAX_FRAME_TIME_US / 1000);
  1225. if (!frame) {
  1226. suspend_state = SuspendState::TIMEOUT;
  1227. }
  1228. }
  1229. void DisplayServerWayland::process_events() {
  1230. wayland_thread.mutex.lock();
  1231. while (wayland_thread.has_message()) {
  1232. Ref<WaylandThread::Message> msg = wayland_thread.pop_message();
  1233. // Generic check. Not actual message handling.
  1234. Ref<WaylandThread::WindowMessage> win_msg = msg;
  1235. if (win_msg.is_valid()) {
  1236. ERR_CONTINUE_MSG(win_msg->id == INVALID_WINDOW_ID, "Invalid window ID received from Wayland thread.");
  1237. if (!windows.has(win_msg->id)) {
  1238. // Window got probably deleted.
  1239. continue;
  1240. }
  1241. }
  1242. Ref<WaylandThread::WindowRectMessage> winrect_msg = msg;
  1243. if (winrect_msg.is_valid()) {
  1244. _update_window_rect(winrect_msg->rect, winrect_msg->id);
  1245. continue;
  1246. }
  1247. Ref<WaylandThread::WindowEventMessage> winev_msg = msg;
  1248. if (winev_msg.is_valid() && windows.has(winev_msg->id)) {
  1249. _send_window_event(winev_msg->event, winev_msg->id);
  1250. if (winev_msg->event == WINDOW_EVENT_FOCUS_IN) {
  1251. #ifdef ACCESSKIT_ENABLED
  1252. if (accessibility_driver) {
  1253. accessibility_driver->accessibility_set_window_focused(winev_msg->id, true);
  1254. }
  1255. #endif
  1256. if (OS::get_singleton()->get_main_loop()) {
  1257. OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_FOCUS_IN);
  1258. }
  1259. } else if (winev_msg->event == WINDOW_EVENT_FOCUS_OUT) {
  1260. #ifdef ACCESSKIT_ENABLED
  1261. if (accessibility_driver) {
  1262. accessibility_driver->accessibility_set_window_focused(winev_msg->id, false);
  1263. }
  1264. #endif
  1265. if (OS::get_singleton()->get_main_loop()) {
  1266. OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_FOCUS_OUT);
  1267. }
  1268. Input::get_singleton()->release_pressed_events();
  1269. }
  1270. continue;
  1271. }
  1272. Ref<WaylandThread::InputEventMessage> inputev_msg = msg;
  1273. if (inputev_msg.is_valid()) {
  1274. Ref<InputEventMouseButton> mb = inputev_msg->event;
  1275. bool handled = false;
  1276. if (!popup_menu_list.is_empty() && mb.is_valid()) {
  1277. // Popup menu handling.
  1278. BitField<MouseButtonMask> mouse_mask = mb->get_button_mask();
  1279. if (mouse_mask != last_mouse_monitor_mask && mb->is_pressed()) {
  1280. List<WindowID>::Element *E = popup_menu_list.back();
  1281. List<WindowID>::Element *C = nullptr;
  1282. // Looking for the oldest popup to close.
  1283. while (E) {
  1284. WindowData &wd = windows[E->get()];
  1285. Point2 global_pos = mb->get_position() + window_get_position(mb->get_window_id());
  1286. if (wd.rect.has_point(global_pos)) {
  1287. break;
  1288. } else if (wd.safe_rect.has_point(global_pos)) {
  1289. break;
  1290. }
  1291. C = E;
  1292. E = E->prev();
  1293. }
  1294. if (C) {
  1295. handled = true;
  1296. _send_window_event(WINDOW_EVENT_CLOSE_REQUEST, C->get());
  1297. }
  1298. }
  1299. last_mouse_monitor_mask = mouse_mask;
  1300. }
  1301. if (!handled) {
  1302. Input::get_singleton()->parse_input_event(inputev_msg->event);
  1303. }
  1304. continue;
  1305. }
  1306. Ref<WaylandThread::DropFilesEventMessage> dropfiles_msg = msg;
  1307. if (dropfiles_msg.is_valid()) {
  1308. WindowData wd = windows[dropfiles_msg->id];
  1309. if (wd.drop_files_callback.is_valid()) {
  1310. Variant v_files = dropfiles_msg->files;
  1311. const Variant *v_args[1] = { &v_files };
  1312. Variant ret;
  1313. Callable::CallError ce;
  1314. wd.drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce);
  1315. if (ce.error != Callable::CallError::CALL_OK) {
  1316. ERR_PRINT(vformat("Failed to execute drop files callback: %s.", Variant::get_callable_error_text(wd.drop_files_callback, v_args, 1, ce)));
  1317. }
  1318. }
  1319. continue;
  1320. }
  1321. Ref<WaylandThread::IMECommitEventMessage> ime_commit_msg = msg;
  1322. if (ime_commit_msg.is_valid()) {
  1323. for (int i = 0; i < ime_commit_msg->text.length(); i++) {
  1324. const char32_t codepoint = ime_commit_msg->text[i];
  1325. Ref<InputEventKey> ke;
  1326. ke.instantiate();
  1327. ke->set_window_id(ime_commit_msg->id);
  1328. ke->set_pressed(true);
  1329. ke->set_echo(false);
  1330. ke->set_keycode(Key::NONE);
  1331. ke->set_physical_keycode(Key::NONE);
  1332. ke->set_key_label(Key::NONE);
  1333. ke->set_unicode(codepoint);
  1334. Input::get_singleton()->parse_input_event(ke);
  1335. }
  1336. ime_text = String();
  1337. ime_selection = Vector2i();
  1338. OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_OS_IME_UPDATE);
  1339. continue;
  1340. }
  1341. Ref<WaylandThread::IMEUpdateEventMessage> ime_update_msg = msg;
  1342. if (ime_update_msg.is_valid()) {
  1343. if (ime_text != ime_update_msg->text || ime_selection != ime_update_msg->selection) {
  1344. ime_text = ime_update_msg->text;
  1345. ime_selection = ime_update_msg->selection;
  1346. OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_OS_IME_UPDATE);
  1347. }
  1348. continue;
  1349. }
  1350. }
  1351. wayland_thread.keyboard_echo_keys();
  1352. switch (suspend_state) {
  1353. case SuspendState::NONE: {
  1354. bool emulate_vsync = false;
  1355. for (KeyValue<DisplayServer::WindowID, WindowData> &pair : windows) {
  1356. if (pair.value.emulate_vsync) {
  1357. emulate_vsync = true;
  1358. break;
  1359. }
  1360. }
  1361. if (emulate_vsync) {
  1362. // Due to the way legacy suspension works, we have to treat low processor
  1363. // usage mode very differently than the regular one.
  1364. if (OS::get_singleton()->is_in_low_processor_usage_mode()) {
  1365. // NOTE: We must avoid committing a surface if we expect a new frame, as we
  1366. // might otherwise commit some inconsistent data (e.g. buffer scale). Note
  1367. // that if a new frame is expected it's going to be committed by the renderer
  1368. // soon anyways.
  1369. if (!RenderingServer::get_singleton()->has_changed()) {
  1370. // We _can't_ commit in a different thread (such as in the frame callback
  1371. // itself) because we would risk to step on the renderer's feet, which would
  1372. // cause subtle but severe issues, such as crashes on setups with explicit
  1373. // sync. This isn't normally a problem, as the renderer commits at every
  1374. // frame (which is what we need for atomic surface updates anyways), but in
  1375. // low processor usage mode that expectation is broken. When it's on, our
  1376. // frame rate stops being constant. This also reflects in the frame
  1377. // information we use for legacy suspension. In order to avoid issues, let's
  1378. // manually commit all surfaces, so that we can get fresh frame data.
  1379. wayland_thread.commit_surfaces();
  1380. try_suspend();
  1381. }
  1382. } else {
  1383. try_suspend();
  1384. }
  1385. }
  1386. if (wayland_thread.is_suspended()) {
  1387. suspend_state = SuspendState::CAPABILITY;
  1388. }
  1389. if (suspend_state == SuspendState::TIMEOUT) {
  1390. DEBUG_LOG_WAYLAND("Suspending. Reason: timeout.");
  1391. } else if (suspend_state == SuspendState::CAPABILITY) {
  1392. DEBUG_LOG_WAYLAND("Suspending. Reason: capability.");
  1393. }
  1394. } break;
  1395. case SuspendState::TIMEOUT: {
  1396. // Certain compositors might not report the "suspended" wm_capability flag.
  1397. // Because of this we'll wake up at the next frame event, indicating the
  1398. // desire for the compositor to let us repaint.
  1399. if (wayland_thread.get_reset_frame()) {
  1400. suspend_state = SuspendState::NONE;
  1401. DEBUG_LOG_WAYLAND("Unsuspending from timeout.");
  1402. }
  1403. // Since we're not rendering, nothing is committing the windows'
  1404. // surfaces. We have to do it ourselves.
  1405. wayland_thread.commit_surfaces();
  1406. } break;
  1407. case SuspendState::CAPABILITY: {
  1408. // If we suspended by capability we can assume that it will be reset when
  1409. // the compositor wants us to repaint.
  1410. if (!wayland_thread.is_suspended()) {
  1411. suspend_state = SuspendState::NONE;
  1412. DEBUG_LOG_WAYLAND("Unsuspending from capability.");
  1413. }
  1414. } break;
  1415. }
  1416. #ifdef DBUS_ENABLED
  1417. if (portal_desktop) {
  1418. portal_desktop->process_callbacks();
  1419. }
  1420. #endif
  1421. wayland_thread.mutex.unlock();
  1422. Input::get_singleton()->flush_buffered_events();
  1423. }
  1424. void DisplayServerWayland::release_rendering_thread() {
  1425. #ifdef GLES3_ENABLED
  1426. if (egl_manager) {
  1427. egl_manager->release_current();
  1428. }
  1429. #endif
  1430. }
  1431. void DisplayServerWayland::swap_buffers() {
  1432. #ifdef GLES3_ENABLED
  1433. if (egl_manager) {
  1434. egl_manager->swap_buffers();
  1435. }
  1436. #endif
  1437. }
  1438. void DisplayServerWayland::set_icon(const Ref<Image> &p_icon) {
  1439. MutexLock mutex_lock(wayland_thread.mutex);
  1440. wayland_thread.set_icon(p_icon);
  1441. }
  1442. void DisplayServerWayland::set_context(Context p_context) {
  1443. MutexLock mutex_lock(wayland_thread.mutex);
  1444. DEBUG_LOG_WAYLAND(vformat("Setting context %d.", p_context));
  1445. context = p_context;
  1446. String app_id = _get_app_id_from_context(p_context);
  1447. wayland_thread.window_set_app_id(MAIN_WINDOW_ID, app_id);
  1448. }
  1449. bool DisplayServerWayland::is_window_transparency_available() const {
  1450. #if defined(RD_ENABLED)
  1451. if (rendering_device && !rendering_device->is_composite_alpha_supported()) {
  1452. return false;
  1453. }
  1454. #endif
  1455. return OS::get_singleton()->is_layered_allowed();
  1456. }
  1457. Vector<String> DisplayServerWayland::get_rendering_drivers_func() {
  1458. Vector<String> drivers;
  1459. #ifdef VULKAN_ENABLED
  1460. drivers.push_back("vulkan");
  1461. #endif
  1462. #ifdef GLES3_ENABLED
  1463. drivers.push_back("opengl3");
  1464. drivers.push_back("opengl3_es");
  1465. #endif
  1466. drivers.push_back("dummy");
  1467. return drivers;
  1468. }
  1469. DisplayServer *DisplayServerWayland::create_func(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Point2i *p_position, const Size2i &p_resolution, int p_screen, Context p_context, int64_t p_parent_window, Error &r_error) {
  1470. DisplayServer *ds = memnew(DisplayServerWayland(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_resolution, p_context, p_parent_window, r_error));
  1471. if (r_error != OK) {
  1472. ERR_PRINT("Can't create the Wayland display server.");
  1473. memdelete(ds);
  1474. return nullptr;
  1475. }
  1476. return ds;
  1477. }
  1478. DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Context p_context, int64_t p_parent_window, Error &r_error) {
  1479. #if defined(GLES3_ENABLED) || defined(DBUS_ENABLED)
  1480. #ifdef SOWRAP_ENABLED
  1481. #ifdef DEBUG_ENABLED
  1482. int dylibloader_verbose = 1;
  1483. #else
  1484. int dylibloader_verbose = 0;
  1485. #endif // DEBUG_ENABLED
  1486. #endif // SOWRAP_ENABLED
  1487. #endif // defined(GLES3_ENABLED) || defined(DBUS_ENABLED)
  1488. r_error = ERR_UNAVAILABLE;
  1489. context = p_context;
  1490. String current_desk = OS::get_singleton()->get_environment("XDG_CURRENT_DESKTOP").to_lower();
  1491. String session_desk = OS::get_singleton()->get_environment("XDG_SESSION_DESKTOP").to_lower();
  1492. swap_cancel_ok = (current_desk.contains("kde") || session_desk.contains("kde") || current_desk.contains("lxqt") || session_desk.contains("lxqt"));
  1493. Error thread_err = wayland_thread.init();
  1494. if (thread_err != OK) {
  1495. r_error = thread_err;
  1496. ERR_FAIL_MSG("Could not initialize the Wayland thread.");
  1497. }
  1498. // Input.
  1499. Input::get_singleton()->set_event_dispatch_function(dispatch_input_events);
  1500. native_menu = memnew(NativeMenu);
  1501. #ifdef SPEECHD_ENABLED
  1502. // Init TTS
  1503. bool tts_enabled = GLOBAL_GET("audio/general/text_to_speech");
  1504. if (tts_enabled) {
  1505. initialize_tts();
  1506. }
  1507. #endif
  1508. #ifdef ACCESSKIT_ENABLED
  1509. if (accessibility_get_mode() != DisplayServer::AccessibilityMode::ACCESSIBILITY_DISABLED) {
  1510. accessibility_driver = memnew(AccessibilityDriverAccessKit);
  1511. if (accessibility_driver->init() != OK) {
  1512. memdelete(accessibility_driver);
  1513. accessibility_driver = nullptr;
  1514. }
  1515. }
  1516. #endif
  1517. rendering_driver = p_rendering_driver;
  1518. bool driver_found = false;
  1519. String executable_name = OS::get_singleton()->get_executable_path().get_file();
  1520. if (rendering_driver == "dummy") {
  1521. RasterizerDummy::make_current();
  1522. driver_found = true;
  1523. }
  1524. #ifdef RD_ENABLED
  1525. #ifdef VULKAN_ENABLED
  1526. if (rendering_driver == "vulkan") {
  1527. rendering_context = memnew(RenderingContextDriverVulkanWayland);
  1528. }
  1529. #endif // VULKAN_ENABLED
  1530. if (rendering_context) {
  1531. if (rendering_context->initialize() != OK) {
  1532. memdelete(rendering_context);
  1533. rendering_context = nullptr;
  1534. #if defined(GLES3_ENABLED)
  1535. bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3");
  1536. if (fallback_to_opengl3 && rendering_driver != "opengl3") {
  1537. WARN_PRINT("Your video card drivers seem not to support the required Vulkan version, switching to OpenGL 3.");
  1538. rendering_driver = "opengl3";
  1539. OS::get_singleton()->set_current_rendering_method("gl_compatibility");
  1540. OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
  1541. } else
  1542. #endif // GLES3_ENABLED
  1543. {
  1544. r_error = ERR_CANT_CREATE;
  1545. if (p_rendering_driver == "vulkan") {
  1546. OS::get_singleton()->alert(
  1547. vformat("Your video card drivers seem not to support the required Vulkan version.\n\n"
  1548. "If possible, consider updating your video card drivers or using the OpenGL 3 driver.\n\n"
  1549. "You can enable the OpenGL 3 driver by starting the engine from the\n"
  1550. "command line with the command:\n\n \"%s\" --rendering-driver opengl3\n\n"
  1551. "If you recently updated your video card drivers, try rebooting.",
  1552. executable_name),
  1553. "Unable to initialize Vulkan video driver");
  1554. }
  1555. ERR_FAIL_MSG(vformat("Could not initialize %s", rendering_driver));
  1556. }
  1557. }
  1558. driver_found = true;
  1559. }
  1560. #endif // RD_ENABLED
  1561. #ifdef GLES3_ENABLED
  1562. if (rendering_driver == "opengl3" || rendering_driver == "opengl3_es") {
  1563. #ifdef SOWRAP_ENABLED
  1564. if (initialize_wayland_egl(dylibloader_verbose) != 0) {
  1565. WARN_PRINT("Can't load the Wayland EGL library.");
  1566. return;
  1567. }
  1568. #endif // SOWRAP_ENABLED
  1569. if (getenv("DRI_PRIME") == nullptr) {
  1570. int prime_idx = -1;
  1571. if (getenv("PRIMUS_DISPLAY") ||
  1572. getenv("PRIMUS_libGLd") ||
  1573. getenv("PRIMUS_libGLa") ||
  1574. getenv("PRIMUS_libGL") ||
  1575. getenv("PRIMUS_LOAD_GLOBAL") ||
  1576. getenv("BUMBLEBEE_SOCKET") ||
  1577. getenv("__NV_PRIME_RENDER_OFFLOAD")) {
  1578. print_verbose("Optirun/primusrun detected. Skipping GPU detection");
  1579. prime_idx = 0;
  1580. }
  1581. // Some tools use fake libGL libraries and have them override the real one using
  1582. // LD_LIBRARY_PATH, so we skip them. *But* Steam also sets LD_LIBRARY_PATH for its
  1583. // runtime and includes system `/lib` and `/lib64`... so ignore Steam.
  1584. if (prime_idx == -1 && getenv("LD_LIBRARY_PATH") && !getenv("STEAM_RUNTIME_LIBRARY_PATH")) {
  1585. String ld_library_path(getenv("LD_LIBRARY_PATH"));
  1586. Vector<String> libraries = ld_library_path.split(":");
  1587. for (int i = 0; i < libraries.size(); ++i) {
  1588. if (FileAccess::exists(libraries[i] + "/libGL.so.1") ||
  1589. FileAccess::exists(libraries[i] + "/libGL.so")) {
  1590. print_verbose("Custom libGL override detected. Skipping GPU detection");
  1591. prime_idx = 0;
  1592. }
  1593. }
  1594. }
  1595. if (prime_idx == -1) {
  1596. print_verbose("Detecting GPUs, set DRI_PRIME in the environment to override GPU detection logic.");
  1597. prime_idx = DetectPrimeEGL::detect_prime(EGL_PLATFORM_WAYLAND_KHR);
  1598. }
  1599. if (prime_idx) {
  1600. print_line(vformat("Found discrete GPU, setting DRI_PRIME=%d to use it.", prime_idx));
  1601. print_line("Note: Set DRI_PRIME=0 in the environment to disable Godot from using the discrete GPU.");
  1602. setenv("DRI_PRIME", itos(prime_idx).utf8().ptr(), 1);
  1603. }
  1604. }
  1605. if (rendering_driver == "opengl3") {
  1606. egl_manager = memnew(EGLManagerWayland);
  1607. if (egl_manager->initialize(wayland_thread.get_wl_display()) != OK || egl_manager->open_display(wayland_thread.get_wl_display()) != OK) {
  1608. memdelete(egl_manager);
  1609. egl_manager = nullptr;
  1610. bool fallback = GLOBAL_GET("rendering/gl_compatibility/fallback_to_gles");
  1611. if (fallback) {
  1612. WARN_PRINT("Your video card drivers seem not to support the required OpenGL version, switching to OpenGLES.");
  1613. rendering_driver = "opengl3_es";
  1614. OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
  1615. } else {
  1616. r_error = ERR_UNAVAILABLE;
  1617. OS::get_singleton()->alert(
  1618. vformat("Your video card drivers seem not to support the required OpenGL 3.3 version.\n\n"
  1619. "If possible, consider updating your video card drivers or using the Vulkan driver.\n\n"
  1620. "You can enable the Vulkan driver by starting the engine from the\n"
  1621. "command line with the command:\n\n \"%s\" --rendering-driver vulkan\n\n"
  1622. "If you recently updated your video card drivers, try rebooting.",
  1623. executable_name),
  1624. "Unable to initialize OpenGL video driver");
  1625. ERR_FAIL_MSG("Could not initialize OpenGL.");
  1626. }
  1627. } else {
  1628. RasterizerGLES3::make_current(true);
  1629. driver_found = true;
  1630. }
  1631. }
  1632. if (rendering_driver == "opengl3_es") {
  1633. egl_manager = memnew(EGLManagerWaylandGLES);
  1634. if (egl_manager->initialize(wayland_thread.get_wl_display()) != OK || egl_manager->open_display(wayland_thread.get_wl_display()) != OK) {
  1635. memdelete(egl_manager);
  1636. egl_manager = nullptr;
  1637. r_error = ERR_CANT_CREATE;
  1638. OS::get_singleton()->alert(
  1639. vformat("Your video card drivers seem not to support the required OpenGL ES 3.0 version.\n\n"
  1640. "If possible, consider updating your video card drivers or using the Vulkan driver.\n\n"
  1641. "You can enable the Vulkan driver by starting the engine from the\n"
  1642. "command line with the command:\n\n \"%s\" --rendering-driver vulkan\n\n"
  1643. "If you recently updated your video card drivers, try rebooting.",
  1644. executable_name),
  1645. "Unable to initialize OpenGL ES video driver");
  1646. ERR_FAIL_MSG("Could not initialize OpenGL ES.");
  1647. }
  1648. RasterizerGLES3::make_current(false);
  1649. driver_found = true;
  1650. }
  1651. }
  1652. #endif // GLES3_ENABLED
  1653. if (!driver_found) {
  1654. r_error = ERR_UNAVAILABLE;
  1655. ERR_FAIL_MSG("Video driver not found.");
  1656. }
  1657. cursor_set_shape(CURSOR_BUSY);
  1658. WindowData &wd = windows[MAIN_WINDOW_ID];
  1659. wd.id = MAIN_WINDOW_ID;
  1660. wd.mode = p_mode;
  1661. wd.flags = p_flags;
  1662. wd.vsync_mode = p_vsync_mode;
  1663. wd.rect.size = p_resolution;
  1664. wd.title = "Godot";
  1665. #ifdef ACCESSKIT_ENABLED
  1666. if (accessibility_driver && !accessibility_driver->window_create(wd.id, nullptr)) {
  1667. if (OS::get_singleton()->is_stdout_verbose()) {
  1668. ERR_PRINT("Can't create an accessibility adapter for window, accessibility support disabled!");
  1669. }
  1670. memdelete(accessibility_driver);
  1671. accessibility_driver = nullptr;
  1672. }
  1673. #endif
  1674. show_window(MAIN_WINDOW_ID);
  1675. #ifdef RD_ENABLED
  1676. if (rendering_context) {
  1677. rendering_device = memnew(RenderingDevice);
  1678. if (rendering_device->initialize(rendering_context, MAIN_WINDOW_ID) != OK) {
  1679. memdelete(rendering_device);
  1680. rendering_device = nullptr;
  1681. memdelete(rendering_context);
  1682. rendering_context = nullptr;
  1683. r_error = ERR_UNAVAILABLE;
  1684. return;
  1685. }
  1686. rendering_device->screen_create(MAIN_WINDOW_ID);
  1687. RendererCompositorRD::make_current();
  1688. }
  1689. #endif // RD_ENABLED
  1690. #ifdef DBUS_ENABLED
  1691. bool dbus_ok = true;
  1692. #ifdef SOWRAP_ENABLED
  1693. if (initialize_dbus(dylibloader_verbose) != 0) {
  1694. print_verbose("Failed to load DBus library!");
  1695. dbus_ok = false;
  1696. }
  1697. #endif
  1698. if (dbus_ok) {
  1699. bool ver_ok = false;
  1700. int version_major = 0;
  1701. int version_minor = 0;
  1702. int version_rev = 0;
  1703. dbus_get_version(&version_major, &version_minor, &version_rev);
  1704. ver_ok = (version_major == 1 && version_minor >= 10) || (version_major > 1); // 1.10.0
  1705. print_verbose(vformat("DBus %d.%d.%d detected.", version_major, version_minor, version_rev));
  1706. if (!ver_ok) {
  1707. print_verbose("Unsupported DBus library version!");
  1708. dbus_ok = false;
  1709. }
  1710. }
  1711. if (dbus_ok) {
  1712. screensaver = memnew(FreeDesktopScreenSaver);
  1713. portal_desktop = memnew(FreeDesktopPortalDesktop);
  1714. atspi_monitor = memnew(FreeDesktopAtSPIMonitor);
  1715. }
  1716. #endif // DBUS_ENABLED
  1717. screen_set_keep_on(GLOBAL_GET("display/window/energy_saving/keep_screen_on"));
  1718. r_error = OK;
  1719. }
  1720. DisplayServerWayland::~DisplayServerWayland() {
  1721. if (native_menu) {
  1722. memdelete(native_menu);
  1723. native_menu = nullptr;
  1724. }
  1725. // Iterating on the window map while we delete stuff from it is a bit
  1726. // uncomfortable, plus we can't even delete /all/ windows in an arbitrary order
  1727. // (due to popups).
  1728. List<WindowID> toplevels;
  1729. for (const KeyValue<WindowID, WindowData> &pair : windows) {
  1730. WindowID id = pair.key;
  1731. if (!window_get_flag(WINDOW_FLAG_POPUP_WM_HINT, id)) {
  1732. toplevels.push_back(id);
  1733. #ifdef ACCESSKIT_ENABLED
  1734. } else if (accessibility_driver) {
  1735. accessibility_driver->window_destroy(id);
  1736. #endif
  1737. }
  1738. }
  1739. for (WindowID &id : toplevels) {
  1740. delete_sub_window(id);
  1741. }
  1742. windows.clear();
  1743. wayland_thread.destroy();
  1744. // Destroy all drivers.
  1745. #ifdef RD_ENABLED
  1746. if (rendering_device) {
  1747. memdelete(rendering_device);
  1748. }
  1749. if (rendering_context) {
  1750. memdelete(rendering_context);
  1751. }
  1752. #endif
  1753. #ifdef SPEECHD_ENABLED
  1754. if (tts) {
  1755. memdelete(tts);
  1756. }
  1757. #endif
  1758. #ifdef ACCESSKIT_ENABLED
  1759. if (accessibility_driver) {
  1760. memdelete(accessibility_driver);
  1761. }
  1762. #endif
  1763. #ifdef DBUS_ENABLED
  1764. if (portal_desktop) {
  1765. memdelete(portal_desktop);
  1766. }
  1767. if (screensaver) {
  1768. memdelete(screensaver);
  1769. }
  1770. if (atspi_monitor) {
  1771. memdelete(atspi_monitor);
  1772. }
  1773. #endif
  1774. }
  1775. void DisplayServerWayland::register_wayland_driver() {
  1776. register_create_function("wayland", create_func, get_rendering_drivers_func);
  1777. }
  1778. #endif //WAYLAND_ENABLED