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