| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#ifdef WAYLAND_ENABLED |
| 34 |
|
| 35 |
#include "key_mapping_xkb.h" |
| 36 |
|
| 37 |
#ifdef SOWRAP_ENABLED |
| 38 |
#include "wayland/dynwrappers/wayland-client-core-so_wrap.h" |
| 39 |
#include "wayland/dynwrappers/wayland-cursor-so_wrap.h" |
| 40 |
#include "wayland/dynwrappers/wayland-egl-core-so_wrap.h" |
| 41 |
#include "xkbcommon-so_wrap.h" |
| 42 |
#else |
| 43 |
#include <wayland-client-core.h> |
| 44 |
#include <wayland-cursor.h> |
| 45 |
#ifdef GLES3_ENABLED |
| 46 |
#include <wayland-egl-core.h> |
| 47 |
#endif |
| 48 |
#include <xkbcommon/xkbcommon-compose.h> |
| 49 |
#include <xkbcommon/xkbcommon.h> |
| 50 |
#endif |
| 51 |
|
| 52 |
|
| 53 |
#include "wayland/protocol/idle_inhibit.gen.h" |
| 54 |
#include "wayland/protocol/primary_selection.gen.h" |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
#define pointer wl_pointer |
| 59 |
#include "wayland/protocol/cursor_shape.gen.h" |
| 60 |
#include "wayland/protocol/pointer_constraints.gen.h" |
| 61 |
#include "wayland/protocol/pointer_gestures.gen.h" |
| 62 |
#include "wayland/protocol/relative_pointer.gen.h" |
| 63 |
#undef pointer |
| 64 |
#include "wayland/protocol/fractional_scale.gen.h" |
| 65 |
#include "wayland/protocol/tablet.gen.h" |
| 66 |
#include "wayland/protocol/text_input.gen.h" |
| 67 |
#include "wayland/protocol/viewporter.gen.h" |
| 68 |
#include "wayland/protocol/wayland.gen.h" |
| 69 |
#include "wayland/protocol/xdg_activation.gen.h" |
| 70 |
#include "wayland/protocol/xdg_decoration.gen.h" |
| 71 |
#include "wayland/protocol/xdg_foreign_v2.gen.h" |
| 72 |
#include "wayland/protocol/xdg_shell.gen.h" |
| 73 |
#include "wayland/protocol/xdg_system_bell.gen.h" |
| 74 |
#include "wayland/protocol/xdg_toplevel_icon.gen.h" |
| 75 |
|
| 76 |
#include "wayland/protocol/godot_embedding_compositor.gen.h" |
| 77 |
|
| 78 |
|
| 79 |
#include "wayland/protocol/xdg_foreign_v1.gen.h" |
| 80 |
|
| 81 |
#ifdef LIBDECOR_ENABLED |
| 82 |
#ifdef SOWRAP_ENABLED |
| 83 |
#include "dynwrappers/libdecor-so_wrap.h" |
| 84 |
#else |
| 85 |
#include <libdecor.h> |
| 86 |
#endif |
| 87 |
#endif |
| 88 |
|
| 89 |
#include "core/os/thread.h" |
| 90 |
#include "servers/display/display_server.h" |
| 91 |
|
| 92 |
#include "wayland_embedder.h" |
| 93 |
|
| 94 |
class WaylandThread { |
| 95 |
public: |
| 96 |
|
| 97 |
class Message : public RefCounted { |
| 98 |
GDSOFTCLASS(Message, RefCounted); |
| 99 |
|
| 100 |
public: |
| 101 |
Message() {} |
| 102 |
virtual ~Message() = default; |
| 103 |
}; |
| 104 |
|
| 105 |
class WindowMessage : public Message { |
| 106 |
GDSOFTCLASS(WindowMessage, Message); |
| 107 |
|
| 108 |
public: |
| 109 |
DisplayServer::WindowID id = DisplayServer::INVALID_WINDOW_ID; |
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
class WindowRectMessage : public WindowMessage { |
| 114 |
GDSOFTCLASS(WindowRectMessage, WindowMessage); |
| 115 |
|
| 116 |
public: |
| 117 |
|
| 118 |
|
| 119 |
Rect2i rect; |
| 120 |
}; |
| 121 |
|
| 122 |
class WindowEventMessage : public WindowMessage { |
| 123 |
GDSOFTCLASS(WindowEventMessage, WindowMessage); |
| 124 |
|
| 125 |
public: |
| 126 |
DisplayServer::WindowEvent event; |
| 127 |
}; |
| 128 |
|
| 129 |
class InputEventMessage : public Message { |
| 130 |
GDSOFTCLASS(InputEventMessage, Message); |
| 131 |
|
| 132 |
public: |
| 133 |
Ref<InputEvent> event; |
| 134 |
}; |
| 135 |
|
| 136 |
class DropFilesEventMessage : public WindowMessage { |
| 137 |
GDSOFTCLASS(DropFilesEventMessage, WindowMessage); |
| 138 |
|
| 139 |
public: |
| 140 |
Vector<String> files; |
| 141 |
}; |
| 142 |
|
| 143 |
class IMEUpdateEventMessage : public WindowMessage { |
| 144 |
GDSOFTCLASS(IMEUpdateEventMessage, WindowMessage); |
| 145 |
|
| 146 |
public: |
| 147 |
String text; |
| 148 |
Vector2i selection; |
| 149 |
}; |
| 150 |
|
| 151 |
class IMECommitEventMessage : public WindowMessage { |
| 152 |
GDSOFTCLASS(IMECommitEventMessage, WindowMessage); |
| 153 |
|
| 154 |
public: |
| 155 |
String text; |
| 156 |
}; |
| 157 |
|
| 158 |
struct RegistryState { |
| 159 |
WaylandThread *wayland_thread; |
| 160 |
|
| 161 |
|
| 162 |
struct wl_shm *wl_shm = nullptr; |
| 163 |
uint32_t wl_shm_name = 0; |
| 164 |
|
| 165 |
struct wl_compositor *wl_compositor = nullptr; |
| 166 |
uint32_t wl_compositor_name = 0; |
| 167 |
|
| 168 |
struct wl_subcompositor *wl_subcompositor = nullptr; |
| 169 |
uint32_t wl_subcompositor_name = 0; |
| 170 |
|
| 171 |
struct wl_data_device_manager *wl_data_device_manager = nullptr; |
| 172 |
uint32_t wl_data_device_manager_name = 0; |
| 173 |
|
| 174 |
List<struct wl_output *> wl_outputs; |
| 175 |
List<struct wl_seat *> wl_seats; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
struct xdg_wm_base *xdg_wm_base = nullptr; |
| 180 |
uint32_t xdg_wm_base_name = 0; |
| 181 |
|
| 182 |
|
| 183 |
struct zxdg_exporter_v1 *xdg_exporter_v1 = nullptr; |
| 184 |
uint32_t xdg_exporter_v1_name = 0; |
| 185 |
|
| 186 |
uint32_t xdg_exporter_v2_name = 0; |
| 187 |
struct zxdg_exporter_v2 *xdg_exporter_v2 = nullptr; |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
struct wp_viewporter *wp_viewporter = nullptr; |
| 192 |
uint32_t wp_viewporter_name = 0; |
| 193 |
|
| 194 |
struct wp_fractional_scale_manager_v1 *wp_fractional_scale_manager = nullptr; |
| 195 |
uint32_t wp_fractional_scale_manager_name = 0; |
| 196 |
|
| 197 |
struct wp_cursor_shape_manager_v1 *wp_cursor_shape_manager = nullptr; |
| 198 |
uint32_t wp_cursor_shape_manager_name = 0; |
| 199 |
|
| 200 |
struct zxdg_decoration_manager_v1 *xdg_decoration_manager = nullptr; |
| 201 |
uint32_t xdg_decoration_manager_name = 0; |
| 202 |
|
| 203 |
struct xdg_system_bell_v1 *xdg_system_bell = nullptr; |
| 204 |
uint32_t xdg_system_bell_name = 0; |
| 205 |
|
| 206 |
struct xdg_toplevel_icon_manager_v1 *xdg_toplevel_icon_manager = nullptr; |
| 207 |
uint32_t xdg_toplevel_icon_manager_name = 0; |
| 208 |
|
| 209 |
struct xdg_activation_v1 *xdg_activation = nullptr; |
| 210 |
uint32_t xdg_activation_name = 0; |
| 211 |
|
| 212 |
struct zwp_primary_selection_device_manager_v1 *wp_primary_selection_device_manager = nullptr; |
| 213 |
uint32_t wp_primary_selection_device_manager_name = 0; |
| 214 |
|
| 215 |
struct zwp_relative_pointer_manager_v1 *wp_relative_pointer_manager = nullptr; |
| 216 |
uint32_t wp_relative_pointer_manager_name = 0; |
| 217 |
|
| 218 |
struct zwp_pointer_constraints_v1 *wp_pointer_constraints = nullptr; |
| 219 |
uint32_t wp_pointer_constraints_name = 0; |
| 220 |
|
| 221 |
struct zwp_pointer_gestures_v1 *wp_pointer_gestures = nullptr; |
| 222 |
uint32_t wp_pointer_gestures_name = 0; |
| 223 |
|
| 224 |
struct zwp_idle_inhibit_manager_v1 *wp_idle_inhibit_manager = nullptr; |
| 225 |
uint32_t wp_idle_inhibit_manager_name = 0; |
| 226 |
|
| 227 |
struct zwp_tablet_manager_v2 *wp_tablet_manager = nullptr; |
| 228 |
uint32_t wp_tablet_manager_name = 0; |
| 229 |
|
| 230 |
struct zwp_text_input_manager_v3 *wp_text_input_manager = nullptr; |
| 231 |
uint32_t wp_text_input_manager_name = 0; |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
uint32_t wp_fifo_manager_name = 0; |
| 236 |
|
| 237 |
struct godot_embedding_compositor *godot_embedding_compositor = nullptr; |
| 238 |
uint32_t godot_embedding_compositor_name = 0; |
| 239 |
}; |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
struct WindowState { |
| 245 |
DisplayServer::WindowID id = DisplayServer::INVALID_WINDOW_ID; |
| 246 |
DisplayServer::WindowID parent_id = DisplayServer::INVALID_WINDOW_ID; |
| 247 |
|
| 248 |
Rect2i rect; |
| 249 |
DisplayServer::WindowMode mode = DisplayServer::WINDOW_MODE_WINDOWED; |
| 250 |
|
| 251 |
bool ready = false; |
| 252 |
|
| 253 |
|
| 254 |
bool maximized = false; |
| 255 |
bool fullscreen = false; |
| 256 |
bool resizing = false; |
| 257 |
|
| 258 |
bool tiled_left = false; |
| 259 |
bool tiled_right = false; |
| 260 |
bool tiled_top = false; |
| 261 |
bool tiled_bottom = false; |
| 262 |
bool suspended = false; |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
bool can_minimize = true; |
| 269 |
bool can_maximize = true; |
| 270 |
bool can_fullscreen = true; |
| 271 |
|
| 272 |
HashSet<struct wl_output *> wl_outputs; |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
struct wl_callback *frame_callback = nullptr; |
| 280 |
uint64_t last_frame_time = 0; |
| 281 |
|
| 282 |
struct wl_surface *wl_surface = nullptr; |
| 283 |
struct xdg_surface *xdg_surface = nullptr; |
| 284 |
struct xdg_toplevel *xdg_toplevel = nullptr; |
| 285 |
|
| 286 |
struct wp_viewport *wp_viewport = nullptr; |
| 287 |
struct wp_fractional_scale_v1 *wp_fractional_scale = nullptr; |
| 288 |
|
| 289 |
|
| 290 |
struct zxdg_exported_v1 *xdg_exported_v1 = nullptr; |
| 291 |
|
| 292 |
struct zxdg_exported_v2 *xdg_exported_v2 = nullptr; |
| 293 |
|
| 294 |
struct xdg_popup *xdg_popup = nullptr; |
| 295 |
|
| 296 |
String exported_handle; |
| 297 |
|
| 298 |
|
| 299 |
int buffer_scale = 1; |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
bool buffer_scale_changed = false; |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
double fractional_scale = 0; |
| 316 |
|
| 317 |
|
| 318 |
double preferred_fractional_scale = 0; |
| 319 |
|
| 320 |
struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration = nullptr; |
| 321 |
|
| 322 |
struct zwp_idle_inhibitor_v1 *wp_idle_inhibitor = nullptr; |
| 323 |
|
| 324 |
#ifdef LIBDECOR_ENABLED |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
struct libdecor_frame *libdecor_frame = nullptr; |
| 329 |
struct libdecor_configuration *pending_libdecor_configuration = nullptr; |
| 330 |
#endif |
| 331 |
|
| 332 |
RegistryState *registry; |
| 333 |
WaylandThread *wayland_thread; |
| 334 |
}; |
| 335 |
|
| 336 |
|
| 337 |
struct ScreenData { |
| 338 |
|
| 339 |
Point2i position; |
| 340 |
|
| 341 |
String make; |
| 342 |
String model; |
| 343 |
|
| 344 |
Size2i size; |
| 345 |
Size2i physical_size; |
| 346 |
|
| 347 |
float refresh_rate = -1; |
| 348 |
int scale = 1; |
| 349 |
}; |
| 350 |
|
| 351 |
struct ScreenState { |
| 352 |
uint32_t wl_output_name = 0; |
| 353 |
|
| 354 |
ScreenData pending_data; |
| 355 |
ScreenData data; |
| 356 |
|
| 357 |
WaylandThread *wayland_thread; |
| 358 |
}; |
| 359 |
|
| 360 |
enum class Gesture { |
| 361 |
NONE, |
| 362 |
MAGNIFY, |
| 363 |
}; |
| 364 |
|
| 365 |
enum class PointerConstraint { |
| 366 |
NONE, |
| 367 |
LOCKED, |
| 368 |
CONFINED, |
| 369 |
}; |
| 370 |
|
| 371 |
struct PointerData { |
| 372 |
Point2 position; |
| 373 |
uint32_t motion_time = 0; |
| 374 |
|
| 375 |
|
| 376 |
Vector2 relative_motion; |
| 377 |
uint32_t relative_motion_time = 0; |
| 378 |
|
| 379 |
BitField<MouseButtonMask> pressed_button_mask = MouseButtonMask::NONE; |
| 380 |
|
| 381 |
MouseButton last_button_pressed = MouseButton::NONE; |
| 382 |
Point2 last_pressed_position; |
| 383 |
|
| 384 |
DisplayServer::WindowID pointed_id = DisplayServer::INVALID_WINDOW_ID; |
| 385 |
DisplayServer::WindowID last_pointed_id = DisplayServer::INVALID_WINDOW_ID; |
| 386 |
|
| 387 |
|
| 388 |
bool double_click_begun = false; |
| 389 |
|
| 390 |
uint32_t button_time = 0; |
| 391 |
uint32_t button_serial = 0; |
| 392 |
|
| 393 |
uint32_t scroll_type = WL_POINTER_AXIS_SOURCE_WHEEL; |
| 394 |
|
| 395 |
|
| 396 |
Vector2 scroll_vector; |
| 397 |
|
| 398 |
|
| 399 |
Vector2i discrete_scroll_vector_120; |
| 400 |
|
| 401 |
uint32_t pinch_scale = 1; |
| 402 |
}; |
| 403 |
|
| 404 |
struct TabletToolData { |
| 405 |
Point2 position; |
| 406 |
Vector2 tilt; |
| 407 |
uint32_t pressure = 0; |
| 408 |
|
| 409 |
BitField<MouseButtonMask> pressed_button_mask = MouseButtonMask::NONE; |
| 410 |
|
| 411 |
MouseButton last_button_pressed = MouseButton::NONE; |
| 412 |
Point2 last_pressed_position; |
| 413 |
|
| 414 |
bool double_click_begun = false; |
| 415 |
|
| 416 |
uint64_t button_time = 0; |
| 417 |
uint64_t motion_time = 0; |
| 418 |
|
| 419 |
DisplayServer::WindowID proximal_id = DisplayServer::INVALID_WINDOW_ID; |
| 420 |
DisplayServer::WindowID last_proximal_id = DisplayServer::INVALID_WINDOW_ID; |
| 421 |
uint32_t proximity_serial = 0; |
| 422 |
}; |
| 423 |
|
| 424 |
struct TabletToolState { |
| 425 |
struct wl_seat *wl_seat = nullptr; |
| 426 |
|
| 427 |
bool is_eraser = false; |
| 428 |
|
| 429 |
TabletToolData data_pending; |
| 430 |
TabletToolData data; |
| 431 |
}; |
| 432 |
|
| 433 |
struct OfferState { |
| 434 |
HashSet<String> mime_types; |
| 435 |
}; |
| 436 |
|
| 437 |
struct SeatState { |
| 438 |
RegistryState *registry = nullptr; |
| 439 |
|
| 440 |
WaylandThread *wayland_thread = nullptr; |
| 441 |
|
| 442 |
struct wl_seat *wl_seat = nullptr; |
| 443 |
uint32_t wl_seat_name = 0; |
| 444 |
|
| 445 |
|
| 446 |
struct wl_pointer *wl_pointer = nullptr; |
| 447 |
|
| 448 |
uint32_t pointer_enter_serial = 0; |
| 449 |
|
| 450 |
struct wp_cursor_shape_device_v1 *wp_cursor_shape_device = nullptr; |
| 451 |
|
| 452 |
struct zwp_relative_pointer_v1 *wp_relative_pointer = nullptr; |
| 453 |
struct zwp_locked_pointer_v1 *wp_locked_pointer = nullptr; |
| 454 |
struct zwp_confined_pointer_v1 *wp_confined_pointer = nullptr; |
| 455 |
|
| 456 |
struct zwp_pointer_gesture_pinch_v1 *wp_pointer_gesture_pinch = nullptr; |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
Gesture active_gesture = Gesture::NONE; |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
wl_fixed_t old_pinch_scale = 0; |
| 466 |
|
| 467 |
struct wl_surface *cursor_surface = nullptr; |
| 468 |
struct wl_callback *cursor_frame_callback = nullptr; |
| 469 |
uint32_t cursor_time_ms = 0; |
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
PointerData pointer_data_buffer; |
| 477 |
PointerData pointer_data; |
| 478 |
|
| 479 |
|
| 480 |
struct wl_keyboard *wl_keyboard = nullptr; |
| 481 |
|
| 482 |
|
| 483 |
DisplayServer::WindowID focused_id = DisplayServer::INVALID_WINDOW_ID; |
| 484 |
|
| 485 |
struct xkb_context *xkb_context = nullptr; |
| 486 |
struct xkb_keymap *xkb_keymap = nullptr; |
| 487 |
struct xkb_state *xkb_state = nullptr; |
| 488 |
struct xkb_compose_state *xkb_compose_state = nullptr; |
| 489 |
struct xkb_compose_table *xkb_compose_table = nullptr; |
| 490 |
|
| 491 |
const char *keymap_buffer = nullptr; |
| 492 |
uint32_t keymap_buffer_size = 0; |
| 493 |
|
| 494 |
HashMap<xkb_keycode_t, Key> pressed_keycodes; |
| 495 |
|
| 496 |
xkb_layout_index_t current_layout_index = 0; |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
int32_t repeat_key_delay_msec = 1000 / 25; |
| 502 |
int32_t repeat_start_delay_msec = 600; |
| 503 |
|
| 504 |
xkb_keycode_t repeating_keycode = XKB_KEYCODE_INVALID; |
| 505 |
uint64_t last_repeat_start_msec = 0; |
| 506 |
uint64_t last_repeat_msec = 0; |
| 507 |
|
| 508 |
uint32_t mods_depressed = 0; |
| 509 |
uint32_t mods_latched = 0; |
| 510 |
uint32_t mods_locked = 0; |
| 511 |
|
| 512 |
bool shift_pressed = false; |
| 513 |
bool ctrl_pressed = false; |
| 514 |
bool alt_pressed = false; |
| 515 |
bool meta_pressed = false; |
| 516 |
|
| 517 |
uint32_t last_key_pressed_serial = 0; |
| 518 |
|
| 519 |
struct wl_data_device *wl_data_device = nullptr; |
| 520 |
|
| 521 |
|
| 522 |
DisplayServer::WindowID dnd_id = DisplayServer::INVALID_WINDOW_ID; |
| 523 |
struct wl_data_offer *wl_data_offer_dnd = nullptr; |
| 524 |
uint32_t dnd_enter_serial = 0; |
| 525 |
|
| 526 |
|
| 527 |
struct wl_data_source *wl_data_source_selection = nullptr; |
| 528 |
Vector<uint8_t> selection_data; |
| 529 |
|
| 530 |
struct wl_data_offer *wl_data_offer_selection = nullptr; |
| 531 |
|
| 532 |
|
| 533 |
struct zwp_primary_selection_device_v1 *wp_primary_selection_device = nullptr; |
| 534 |
|
| 535 |
struct zwp_primary_selection_source_v1 *wp_primary_selection_source = nullptr; |
| 536 |
Vector<uint8_t> primary_data; |
| 537 |
|
| 538 |
struct zwp_primary_selection_offer_v1 *wp_primary_selection_offer = nullptr; |
| 539 |
|
| 540 |
|
| 541 |
struct zwp_tablet_seat_v2 *wp_tablet_seat = nullptr; |
| 542 |
|
| 543 |
List<struct zwp_tablet_tool_v2 *> tablet_tools; |
| 544 |
|
| 545 |
|
| 546 |
struct zwp_text_input_v3 *wp_text_input = nullptr; |
| 547 |
DisplayServer::WindowID ime_window_id = DisplayServer::INVALID_WINDOW_ID; |
| 548 |
bool ime_enabled = false; |
| 549 |
bool ime_active = false; |
| 550 |
String ime_text; |
| 551 |
String ime_text_commit; |
| 552 |
Vector2i ime_cursor; |
| 553 |
Rect2i ime_rect; |
| 554 |
}; |
| 555 |
|
| 556 |
struct CustomCursor { |
| 557 |
struct wl_buffer *wl_buffer = nullptr; |
| 558 |
uint32_t *buffer_data = nullptr; |
| 559 |
uint32_t buffer_data_size = 0; |
| 560 |
|
| 561 |
Point2i hotspot; |
| 562 |
}; |
| 563 |
|
| 564 |
struct EmbeddingCompositorState { |
| 565 |
LocalVector<struct godot_embedded_client *> clients; |
| 566 |
|
| 567 |
|
| 568 |
HashMap<int, struct godot_embedded_client *> mapped_clients; |
| 569 |
|
| 570 |
OS::ProcessID focused_pid = -1; |
| 571 |
}; |
| 572 |
|
| 573 |
struct EmbeddedClientState { |
| 574 |
struct godot_embedding_compositor *embedding_compositor = nullptr; |
| 575 |
|
| 576 |
uint32_t pid = 0; |
| 577 |
bool window_mapped = false; |
| 578 |
}; |
| 579 |
|
| 580 |
private: |
| 581 |
struct ThreadData { |
| 582 |
SafeFlag thread_done; |
| 583 |
Mutex mutex; |
| 584 |
|
| 585 |
struct wl_display *wl_display = nullptr; |
| 586 |
}; |
| 587 |
|
| 588 |
|
| 589 |
inline static const char *proxy_tag = "godot"; |
| 590 |
|
| 591 |
Thread events_thread; |
| 592 |
ThreadData thread_data; |
| 593 |
|
| 594 |
HashMap<DisplayServer::WindowID, WindowState> windows; |
| 595 |
|
| 596 |
List<Ref<Message>> messages; |
| 597 |
|
| 598 |
xdg_toplevel_icon_v1 *xdg_icon = nullptr; |
| 599 |
wl_buffer *icon_buffer = nullptr; |
| 600 |
|
| 601 |
String cursor_theme_name; |
| 602 |
int unscaled_cursor_size = 24; |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
int cursor_scale = 1; |
| 610 |
|
| 611 |
|
| 612 |
wp_cursor_shape_device_v1_shape standard_cursors[DisplayServer::CURSOR_MAX] = { |
| 613 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT, |
| 614 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT, |
| 615 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_POINTER, |
| 616 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CROSSHAIR, |
| 617 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_WAIT, |
| 618 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_PROGRESS, |
| 619 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_GRAB, |
| 620 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_GRABBING, |
| 621 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NO_DROP, |
| 622 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NS_RESIZE, |
| 623 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_EW_RESIZE, |
| 624 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NESW_RESIZE, |
| 625 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NWSE_RESIZE, |
| 626 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_MOVE, |
| 627 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ROW_RESIZE, |
| 628 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_COL_RESIZE, |
| 629 |
wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_HELP, |
| 630 |
}; |
| 631 |
|
| 632 |
|
| 633 |
struct wl_cursor_theme *wl_cursor_theme = nullptr; |
| 634 |
struct wl_cursor *wl_cursors[DisplayServer::CURSOR_MAX] = {}; |
| 635 |
|
| 636 |
|
| 637 |
HashMap<DisplayServer::CursorShape, CustomCursor> custom_cursors; |
| 638 |
|
| 639 |
DisplayServer::CursorShape cursor_shape = DisplayServer::CURSOR_ARROW; |
| 640 |
bool cursor_visible = true; |
| 641 |
|
| 642 |
PointerConstraint pointer_constraint = PointerConstraint::NONE; |
| 643 |
|
| 644 |
struct wl_display *wl_display = nullptr; |
| 645 |
struct wl_registry *wl_registry = nullptr; |
| 646 |
|
| 647 |
struct wl_seat *wl_seat_current = nullptr; |
| 648 |
|
| 649 |
bool frame = true; |
| 650 |
|
| 651 |
RegistryState registry; |
| 652 |
|
| 653 |
bool initialized = false; |
| 654 |
|
| 655 |
#ifdef TOOLS_ENABLED |
| 656 |
WaylandEmbedder embedder; |
| 657 |
#endif |
| 658 |
|
| 659 |
#ifdef LIBDECOR_ENABLED |
| 660 |
struct libdecor *libdecor_context = nullptr; |
| 661 |
#endif |
| 662 |
|
| 663 |
static void _clipboard_send(Vector<uint8_t> &p_data, const char *p_media_type, int32_t p_fd); |
| 664 |
|
| 665 |
|
| 666 |
static void _poll_events_thread(void *p_data); |
| 667 |
|
| 668 |
|
| 669 |
static void _wl_registry_on_global(void *data, struct wl_registry *wl_registry, uint32_t name, const char *interface, uint32_t version); |
| 670 |
static void _wl_registry_on_global_remove(void *data, struct wl_registry *wl_registry, uint32_t name); |
| 671 |
|
| 672 |
static void _wl_surface_on_enter(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output); |
| 673 |
static void _wl_surface_on_leave(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output); |
| 674 |
static void _wl_surface_on_preferred_buffer_scale(void *data, struct wl_surface *wl_surface, int32_t factor); |
| 675 |
static void _wl_surface_on_preferred_buffer_transform(void *data, struct wl_surface *wl_surface, uint32_t transform); |
| 676 |
|
| 677 |
static void _frame_wl_callback_on_done(void *data, struct wl_callback *wl_callback, uint32_t callback_data); |
| 678 |
|
| 679 |
static void _wl_output_on_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char *make, const char *model, int32_t transform); |
| 680 |
static void _wl_output_on_mode(void *data, struct wl_output *wl_output, uint32_t flags, int32_t width, int32_t height, int32_t refresh); |
| 681 |
static void _wl_output_on_done(void *data, struct wl_output *wl_output); |
| 682 |
static void _wl_output_on_scale(void *data, struct wl_output *wl_output, int32_t factor); |
| 683 |
static void _wl_output_on_name(void *data, struct wl_output *wl_output, const char *name); |
| 684 |
static void _wl_output_on_description(void *data, struct wl_output *wl_output, const char *description); |
| 685 |
|
| 686 |
static void _wl_seat_on_capabilities(void *data, struct wl_seat *wl_seat, uint32_t capabilities); |
| 687 |
static void _wl_seat_on_name(void *data, struct wl_seat *wl_seat, const char *name); |
| 688 |
|
| 689 |
static void _cursor_frame_callback_on_done(void *data, struct wl_callback *wl_callback, uint32_t time_ms); |
| 690 |
|
| 691 |
static void _wl_pointer_on_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y); |
| 692 |
static void _wl_pointer_on_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface); |
| 693 |
static void _wl_pointer_on_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y); |
| 694 |
static void _wl_pointer_on_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state); |
| 695 |
static void _wl_pointer_on_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value); |
| 696 |
static void _wl_pointer_on_frame(void *data, struct wl_pointer *wl_pointer); |
| 697 |
static void _wl_pointer_on_axis_source(void *data, struct wl_pointer *wl_pointer, uint32_t axis_source); |
| 698 |
static void _wl_pointer_on_axis_stop(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis); |
| 699 |
static void _wl_pointer_on_axis_discrete(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete); |
| 700 |
static void _wl_pointer_on_axis_value120(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t value120); |
| 701 |
static void _wl_pointer_on_axis_relative_direction(void *data, struct wl_pointer *wl_pointer, uint32_t axis, uint32_t direction); |
| 702 |
|
| 703 |
static void _wl_keyboard_on_keymap(void *data, struct wl_keyboard *wl_keyboard, uint32_t format, int32_t fd, uint32_t size); |
| 704 |
static void _wl_keyboard_on_enter(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys); |
| 705 |
static void _wl_keyboard_on_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface); |
| 706 |
static void _wl_keyboard_on_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state); |
| 707 |
static void _wl_keyboard_on_modifiers(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group); |
| 708 |
static void _wl_keyboard_on_repeat_info(void *data, struct wl_keyboard *wl_keyboard, int32_t rate, int32_t delay); |
| 709 |
|
| 710 |
static void _wl_data_device_on_data_offer(void *data, struct wl_data_device *wl_data_device, struct wl_data_offer *id); |
| 711 |
static void _wl_data_device_on_enter(void *data, struct wl_data_device *wl_data_device, uint32_t serial, struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y, struct wl_data_offer *id); |
| 712 |
static void _wl_data_device_on_leave(void *data, struct wl_data_device *wl_data_device); |
| 713 |
static void _wl_data_device_on_motion(void *data, struct wl_data_device *wl_data_device, uint32_t time, wl_fixed_t x, wl_fixed_t y); |
| 714 |
static void _wl_data_device_on_drop(void *data, struct wl_data_device *wl_data_device); |
| 715 |
static void _wl_data_device_on_selection(void *data, struct wl_data_device *wl_data_device, struct wl_data_offer *id); |
| 716 |
|
| 717 |
static void _wl_data_offer_on_offer(void *data, struct wl_data_offer *wl_data_offer, const char *mime_type); |
| 718 |
static void _wl_data_offer_on_source_actions(void *data, struct wl_data_offer *wl_data_offer, uint32_t source_actions); |
| 719 |
static void _wl_data_offer_on_action(void *data, struct wl_data_offer *wl_data_offer, uint32_t dnd_action); |
| 720 |
|
| 721 |
static void _wl_data_source_on_target(void *data, struct wl_data_source *wl_data_source, const char *mime_type); |
| 722 |
static void _wl_data_source_on_send(void *data, struct wl_data_source *wl_data_source, const char *mime_type, int32_t fd); |
| 723 |
static void _wl_data_source_on_cancelled(void *data, struct wl_data_source *wl_data_source); |
| 724 |
static void _wl_data_source_on_dnd_drop_performed(void *data, struct wl_data_source *wl_data_source); |
| 725 |
static void _wl_data_source_on_dnd_finished(void *data, struct wl_data_source *wl_data_source); |
| 726 |
static void _wl_data_source_on_action(void *data, struct wl_data_source *wl_data_source, uint32_t dnd_action); |
| 727 |
|
| 728 |
|
| 729 |
static void _xdg_wm_base_on_ping(void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial); |
| 730 |
|
| 731 |
static void _xdg_surface_on_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial); |
| 732 |
|
| 733 |
static void _xdg_toplevel_on_configure(void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height, struct wl_array *states); |
| 734 |
static void _xdg_toplevel_on_close(void *data, struct xdg_toplevel *xdg_toplevel); |
| 735 |
static void _xdg_toplevel_on_configure_bounds(void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height); |
| 736 |
static void _xdg_toplevel_on_wm_capabilities(void *data, struct xdg_toplevel *xdg_toplevel, struct wl_array *capabilities); |
| 737 |
|
| 738 |
static void _xdg_popup_on_configure(void *data, struct xdg_popup *xdg_popup, int32_t x, int32_t y, int32_t width, int32_t height); |
| 739 |
static void _xdg_popup_on_popup_done(void *data, struct xdg_popup *xdg_popup); |
| 740 |
static void _xdg_popup_on_repositioned(void *data, struct xdg_popup *xdg_popup, uint32_t token); |
| 741 |
|
| 742 |
|
| 743 |
static void _wp_fractional_scale_on_preferred_scale(void *data, struct wp_fractional_scale_v1 *wp_fractional_scale_v1, uint32_t scale); |
| 744 |
|
| 745 |
static void _wp_relative_pointer_on_relative_motion(void *data, struct zwp_relative_pointer_v1 *wp_relative_pointer_v1, uint32_t uptime_hi, uint32_t uptime_lo, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t dx_unaccel, wl_fixed_t dy_unaccel); |
| 746 |
|
| 747 |
static void _wp_pointer_gesture_pinch_on_begin(void *data, struct zwp_pointer_gesture_pinch_v1 *wp_pointer_gesture_pinch_v1, uint32_t serial, uint32_t time, struct wl_surface *surface, uint32_t fingers); |
| 748 |
static void _wp_pointer_gesture_pinch_on_update(void *data, struct zwp_pointer_gesture_pinch_v1 *wp_pointer_gesture_pinch_v1, uint32_t time, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t scale, wl_fixed_t rotation); |
| 749 |
static void _wp_pointer_gesture_pinch_on_end(void *data, struct zwp_pointer_gesture_pinch_v1 *zp_pointer_gesture_pinch_v1, uint32_t serial, uint32_t time, int32_t cancelled); |
| 750 |
|
| 751 |
static void _wp_primary_selection_device_on_data_offer(void *data, struct zwp_primary_selection_device_v1 *wp_primary_selection_device_v1, struct zwp_primary_selection_offer_v1 *offer); |
| 752 |
static void _wp_primary_selection_device_on_selection(void *data, struct zwp_primary_selection_device_v1 *wp_primary_selection_device_v1, struct zwp_primary_selection_offer_v1 *id); |
| 753 |
|
| 754 |
static void _wp_primary_selection_offer_on_offer(void *data, struct zwp_primary_selection_offer_v1 *wp_primary_selection_offer_v1, const char *mime_type); |
| 755 |
|
| 756 |
static void _wp_primary_selection_source_on_send(void *data, struct zwp_primary_selection_source_v1 *wp_primary_selection_source_v1, const char *mime_type, int32_t fd); |
| 757 |
static void _wp_primary_selection_source_on_cancelled(void *data, struct zwp_primary_selection_source_v1 *wp_primary_selection_source_v1); |
| 758 |
|
| 759 |
static void _wp_tablet_seat_on_tablet_added(void *data, struct zwp_tablet_seat_v2 *wp_tablet_seat_v2, struct zwp_tablet_v2 *id); |
| 760 |
static void _wp_tablet_seat_on_tool_added(void *data, struct zwp_tablet_seat_v2 *wp_tablet_seat_v2, struct zwp_tablet_tool_v2 *id); |
| 761 |
static void _wp_tablet_seat_on_pad_added(void *data, struct zwp_tablet_seat_v2 *wp_tablet_seat_v2, struct zwp_tablet_pad_v2 *id); |
| 762 |
|
| 763 |
static void _wp_tablet_tool_on_type(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t tool_type); |
| 764 |
static void _wp_tablet_tool_on_hardware_serial(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t hardware_serial_hi, uint32_t hardware_serial_lo); |
| 765 |
static void _wp_tablet_tool_on_hardware_id_wacom(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t hardware_id_hi, uint32_t hardware_id_lo); |
| 766 |
static void _wp_tablet_tool_on_capability(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t capability); |
| 767 |
static void _wp_tablet_tool_on_done(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2); |
| 768 |
static void _wp_tablet_tool_on_removed(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2); |
| 769 |
static void _wp_tablet_tool_on_proximity_in(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t serial, struct zwp_tablet_v2 *tablet, struct wl_surface *surface); |
| 770 |
static void _wp_tablet_tool_on_proximity_out(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2); |
| 771 |
static void _wp_tablet_tool_on_down(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t serial); |
| 772 |
static void _wp_tablet_tool_on_up(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2); |
| 773 |
static void _wp_tablet_tool_on_motion(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, wl_fixed_t x, wl_fixed_t y); |
| 774 |
static void _wp_tablet_tool_on_pressure(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t pressure); |
| 775 |
static void _wp_tablet_tool_on_distance(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t distance); |
| 776 |
static void _wp_tablet_tool_on_tilt(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, wl_fixed_t tilt_x, wl_fixed_t tilt_y); |
| 777 |
static void _wp_tablet_tool_on_rotation(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, wl_fixed_t degrees); |
| 778 |
static void _wp_tablet_tool_on_slider(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, int32_t position); |
| 779 |
static void _wp_tablet_tool_on_wheel(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, wl_fixed_t degrees, int32_t clicks); |
| 780 |
static void _wp_tablet_tool_on_button(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t serial, uint32_t button, uint32_t state); |
| 781 |
static void _wp_tablet_tool_on_frame(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t time); |
| 782 |
|
| 783 |
static void _wp_text_input_on_enter(void *data, struct zwp_text_input_v3 *wp_text_input_v3, struct wl_surface *surface); |
| 784 |
static void _wp_text_input_on_leave(void *data, struct zwp_text_input_v3 *wp_text_input_v3, struct wl_surface *surface); |
| 785 |
static void _wp_text_input_on_preedit_string(void *data, struct zwp_text_input_v3 *wp_text_input_v3, const char *text, int32_t cursor_begin, int32_t cursor_end); |
| 786 |
static void _wp_text_input_on_commit_string(void *data, struct zwp_text_input_v3 *wp_text_input_v3, const char *text); |
| 787 |
static void _wp_text_input_on_delete_surrounding_text(void *data, struct zwp_text_input_v3 *wp_text_input_v3, uint32_t before_length, uint32_t after_length); |
| 788 |
static void _wp_text_input_on_done(void *data, struct zwp_text_input_v3 *wp_text_input_v3, uint32_t serial); |
| 789 |
|
| 790 |
static void _xdg_toplevel_decoration_on_configure(void *data, struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration, uint32_t mode); |
| 791 |
|
| 792 |
|
| 793 |
static void _xdg_exported_v1_on_handle(void *data, zxdg_exported_v1 *exported, const char *handle); |
| 794 |
|
| 795 |
static void _xdg_exported_v2_on_handle(void *data, zxdg_exported_v2 *exported, const char *handle); |
| 796 |
|
| 797 |
static void _xdg_activation_token_on_done(void *data, struct xdg_activation_token_v1 *xdg_activation_token, const char *token); |
| 798 |
|
| 799 |
static void _godot_embedding_compositor_on_client(void *data, struct godot_embedding_compositor *godot_embedding_compositor, struct godot_embedded_client *godot_embedded_client, int32_t pid); |
| 800 |
|
| 801 |
static void _godot_embedded_client_on_disconnected(void *data, struct godot_embedded_client *godot_embedded_client); |
| 802 |
static void _godot_embedded_client_on_window_embedded(void *data, struct godot_embedded_client *godot_embedded_client); |
| 803 |
static void _godot_embedded_client_on_window_focus_in(void *data, struct godot_embedded_client *godot_embedded_client); |
| 804 |
static void _godot_embedded_client_on_window_focus_out(void *data, struct godot_embedded_client *godot_embedded_client); |
| 805 |
|
| 806 |
|
| 807 |
static constexpr struct wl_registry_listener wl_registry_listener = { |
| 808 |
.global = _wl_registry_on_global, |
| 809 |
.global_remove = _wl_registry_on_global_remove, |
| 810 |
}; |
| 811 |
|
| 812 |
static constexpr struct wl_surface_listener wl_surface_listener = { |
| 813 |
.enter = _wl_surface_on_enter, |
| 814 |
.leave = _wl_surface_on_leave, |
| 815 |
.preferred_buffer_scale = _wl_surface_on_preferred_buffer_scale, |
| 816 |
.preferred_buffer_transform = _wl_surface_on_preferred_buffer_transform, |
| 817 |
}; |
| 818 |
|
| 819 |
static constexpr struct wl_callback_listener frame_wl_callback_listener = { |
| 820 |
.done = _frame_wl_callback_on_done, |
| 821 |
}; |
| 822 |
|
| 823 |
static constexpr struct wl_output_listener wl_output_listener = { |
| 824 |
.geometry = _wl_output_on_geometry, |
| 825 |
.mode = _wl_output_on_mode, |
| 826 |
.done = _wl_output_on_done, |
| 827 |
.scale = _wl_output_on_scale, |
| 828 |
.name = _wl_output_on_name, |
| 829 |
.description = _wl_output_on_description, |
| 830 |
}; |
| 831 |
|
| 832 |
static constexpr struct wl_seat_listener wl_seat_listener = { |
| 833 |
.capabilities = _wl_seat_on_capabilities, |
| 834 |
.name = _wl_seat_on_name, |
| 835 |
}; |
| 836 |
|
| 837 |
static constexpr struct wl_callback_listener cursor_frame_callback_listener = { |
| 838 |
.done = _cursor_frame_callback_on_done, |
| 839 |
}; |
| 840 |
|
| 841 |
static constexpr struct wl_pointer_listener wl_pointer_listener = { |
| 842 |
.enter = _wl_pointer_on_enter, |
| 843 |
.leave = _wl_pointer_on_leave, |
| 844 |
.motion = _wl_pointer_on_motion, |
| 845 |
.button = _wl_pointer_on_button, |
| 846 |
.axis = _wl_pointer_on_axis, |
| 847 |
.frame = _wl_pointer_on_frame, |
| 848 |
.axis_source = _wl_pointer_on_axis_source, |
| 849 |
.axis_stop = _wl_pointer_on_axis_stop, |
| 850 |
.axis_discrete = _wl_pointer_on_axis_discrete, |
| 851 |
.axis_value120 = _wl_pointer_on_axis_value120, |
| 852 |
.axis_relative_direction = _wl_pointer_on_axis_relative_direction, |
| 853 |
}; |
| 854 |
|
| 855 |
static constexpr struct wl_keyboard_listener wl_keyboard_listener = { |
| 856 |
.keymap = _wl_keyboard_on_keymap, |
| 857 |
.enter = _wl_keyboard_on_enter, |
| 858 |
.leave = _wl_keyboard_on_leave, |
| 859 |
.key = _wl_keyboard_on_key, |
| 860 |
.modifiers = _wl_keyboard_on_modifiers, |
| 861 |
.repeat_info = _wl_keyboard_on_repeat_info, |
| 862 |
}; |
| 863 |
|
| 864 |
static constexpr struct wl_data_device_listener wl_data_device_listener = { |
| 865 |
.data_offer = _wl_data_device_on_data_offer, |
| 866 |
.enter = _wl_data_device_on_enter, |
| 867 |
.leave = _wl_data_device_on_leave, |
| 868 |
.motion = _wl_data_device_on_motion, |
| 869 |
.drop = _wl_data_device_on_drop, |
| 870 |
.selection = _wl_data_device_on_selection, |
| 871 |
}; |
| 872 |
|
| 873 |
static constexpr struct wl_data_offer_listener wl_data_offer_listener = { |
| 874 |
.offer = _wl_data_offer_on_offer, |
| 875 |
.source_actions = _wl_data_offer_on_source_actions, |
| 876 |
.action = _wl_data_offer_on_action, |
| 877 |
}; |
| 878 |
|
| 879 |
static constexpr struct wl_data_source_listener wl_data_source_listener = { |
| 880 |
.target = _wl_data_source_on_target, |
| 881 |
.send = _wl_data_source_on_send, |
| 882 |
.cancelled = _wl_data_source_on_cancelled, |
| 883 |
.dnd_drop_performed = _wl_data_source_on_dnd_drop_performed, |
| 884 |
.dnd_finished = _wl_data_source_on_dnd_finished, |
| 885 |
.action = _wl_data_source_on_action, |
| 886 |
}; |
| 887 |
|
| 888 |
|
| 889 |
static constexpr struct xdg_wm_base_listener xdg_wm_base_listener = { |
| 890 |
.ping = _xdg_wm_base_on_ping, |
| 891 |
}; |
| 892 |
|
| 893 |
static constexpr struct xdg_surface_listener xdg_surface_listener = { |
| 894 |
.configure = _xdg_surface_on_configure, |
| 895 |
}; |
| 896 |
|
| 897 |
static constexpr struct xdg_toplevel_listener xdg_toplevel_listener = { |
| 898 |
.configure = _xdg_toplevel_on_configure, |
| 899 |
.close = _xdg_toplevel_on_close, |
| 900 |
.configure_bounds = _xdg_toplevel_on_configure_bounds, |
| 901 |
.wm_capabilities = _xdg_toplevel_on_wm_capabilities, |
| 902 |
}; |
| 903 |
|
| 904 |
static constexpr struct xdg_popup_listener xdg_popup_listener = { |
| 905 |
.configure = _xdg_popup_on_configure, |
| 906 |
.popup_done = _xdg_popup_on_popup_done, |
| 907 |
.repositioned = _xdg_popup_on_repositioned, |
| 908 |
}; |
| 909 |
|
| 910 |
|
| 911 |
static constexpr struct wp_fractional_scale_v1_listener wp_fractional_scale_listener = { |
| 912 |
.preferred_scale = _wp_fractional_scale_on_preferred_scale, |
| 913 |
}; |
| 914 |
|
| 915 |
static constexpr struct zwp_relative_pointer_v1_listener wp_relative_pointer_listener = { |
| 916 |
.relative_motion = _wp_relative_pointer_on_relative_motion, |
| 917 |
}; |
| 918 |
|
| 919 |
static constexpr struct zwp_pointer_gesture_pinch_v1_listener wp_pointer_gesture_pinch_listener = { |
| 920 |
.begin = _wp_pointer_gesture_pinch_on_begin, |
| 921 |
.update = _wp_pointer_gesture_pinch_on_update, |
| 922 |
.end = _wp_pointer_gesture_pinch_on_end, |
| 923 |
}; |
| 924 |
|
| 925 |
static constexpr struct zwp_primary_selection_device_v1_listener wp_primary_selection_device_listener = { |
| 926 |
.data_offer = _wp_primary_selection_device_on_data_offer, |
| 927 |
.selection = _wp_primary_selection_device_on_selection, |
| 928 |
}; |
| 929 |
|
| 930 |
static constexpr struct zwp_primary_selection_offer_v1_listener wp_primary_selection_offer_listener = { |
| 931 |
.offer = _wp_primary_selection_offer_on_offer, |
| 932 |
}; |
| 933 |
|
| 934 |
static constexpr struct zwp_primary_selection_source_v1_listener wp_primary_selection_source_listener = { |
| 935 |
.send = _wp_primary_selection_source_on_send, |
| 936 |
.cancelled = _wp_primary_selection_source_on_cancelled, |
| 937 |
}; |
| 938 |
|
| 939 |
static constexpr struct zwp_tablet_seat_v2_listener wp_tablet_seat_listener = { |
| 940 |
.tablet_added = _wp_tablet_seat_on_tablet_added, |
| 941 |
.tool_added = _wp_tablet_seat_on_tool_added, |
| 942 |
.pad_added = _wp_tablet_seat_on_pad_added, |
| 943 |
}; |
| 944 |
|
| 945 |
static constexpr struct zwp_tablet_tool_v2_listener wp_tablet_tool_listener = { |
| 946 |
.type = _wp_tablet_tool_on_type, |
| 947 |
.hardware_serial = _wp_tablet_tool_on_hardware_serial, |
| 948 |
.hardware_id_wacom = _wp_tablet_tool_on_hardware_id_wacom, |
| 949 |
.capability = _wp_tablet_tool_on_capability, |
| 950 |
.done = _wp_tablet_tool_on_done, |
| 951 |
.removed = _wp_tablet_tool_on_removed, |
| 952 |
.proximity_in = _wp_tablet_tool_on_proximity_in, |
| 953 |
.proximity_out = _wp_tablet_tool_on_proximity_out, |
| 954 |
.down = _wp_tablet_tool_on_down, |
| 955 |
.up = _wp_tablet_tool_on_up, |
| 956 |
.motion = _wp_tablet_tool_on_motion, |
| 957 |
.pressure = _wp_tablet_tool_on_pressure, |
| 958 |
.distance = _wp_tablet_tool_on_distance, |
| 959 |
.tilt = _wp_tablet_tool_on_tilt, |
| 960 |
.rotation = _wp_tablet_tool_on_rotation, |
| 961 |
.slider = _wp_tablet_tool_on_slider, |
| 962 |
.wheel = _wp_tablet_tool_on_wheel, |
| 963 |
.button = _wp_tablet_tool_on_button, |
| 964 |
.frame = _wp_tablet_tool_on_frame, |
| 965 |
}; |
| 966 |
|
| 967 |
static constexpr struct zwp_text_input_v3_listener wp_text_input_listener = { |
| 968 |
.enter = _wp_text_input_on_enter, |
| 969 |
.leave = _wp_text_input_on_leave, |
| 970 |
.preedit_string = _wp_text_input_on_preedit_string, |
| 971 |
.commit_string = _wp_text_input_on_commit_string, |
| 972 |
.delete_surrounding_text = _wp_text_input_on_delete_surrounding_text, |
| 973 |
.done = _wp_text_input_on_done, |
| 974 |
}; |
| 975 |
|
| 976 |
|
| 977 |
static constexpr struct zxdg_exported_v1_listener xdg_exported_v1_listener = { |
| 978 |
.handle = _xdg_exported_v1_on_handle, |
| 979 |
}; |
| 980 |
|
| 981 |
static constexpr struct zxdg_exported_v2_listener xdg_exported_v2_listener = { |
| 982 |
.handle = _xdg_exported_v2_on_handle, |
| 983 |
}; |
| 984 |
|
| 985 |
static constexpr struct zxdg_toplevel_decoration_v1_listener xdg_toplevel_decoration_listener = { |
| 986 |
.configure = _xdg_toplevel_decoration_on_configure, |
| 987 |
}; |
| 988 |
|
| 989 |
static constexpr struct xdg_activation_token_v1_listener xdg_activation_token_listener = { |
| 990 |
.done = _xdg_activation_token_on_done, |
| 991 |
}; |
| 992 |
|
| 993 |
|
| 994 |
static constexpr struct godot_embedding_compositor_listener godot_embedding_compositor_listener = { |
| 995 |
.client = _godot_embedding_compositor_on_client, |
| 996 |
}; |
| 997 |
|
| 998 |
static constexpr struct godot_embedded_client_listener godot_embedded_client_listener = { |
| 999 |
.disconnected = _godot_embedded_client_on_disconnected, |
| 1000 |
.window_embedded = _godot_embedded_client_on_window_embedded, |
| 1001 |
.window_focus_in = _godot_embedded_client_on_window_focus_in, |
| 1002 |
.window_focus_out = _godot_embedded_client_on_window_focus_out, |
| 1003 |
}; |
| 1004 |
|
| 1005 |
#ifdef LIBDECOR_ENABLED |
| 1006 |
|
| 1007 |
static void libdecor_on_error(struct libdecor *context, enum libdecor_error error, const char *message); |
| 1008 |
|
| 1009 |
static void libdecor_frame_on_configure(struct libdecor_frame *frame, struct libdecor_configuration *configuration, void *user_data); |
| 1010 |
|
| 1011 |
static void libdecor_frame_on_close(struct libdecor_frame *frame, void *user_data); |
| 1012 |
|
| 1013 |
static void libdecor_frame_on_commit(struct libdecor_frame *frame, void *user_data); |
| 1014 |
|
| 1015 |
static void libdecor_frame_on_dismiss_popup(struct libdecor_frame *frame, const char *seat_name, void *user_data); |
| 1016 |
|
| 1017 |
|
| 1018 |
static constexpr struct libdecor_interface libdecor_interface = { |
| 1019 |
.error = libdecor_on_error, |
| 1020 |
.reserved0 = nullptr, |
| 1021 |
.reserved1 = nullptr, |
| 1022 |
.reserved2 = nullptr, |
| 1023 |
.reserved3 = nullptr, |
| 1024 |
.reserved4 = nullptr, |
| 1025 |
.reserved5 = nullptr, |
| 1026 |
.reserved6 = nullptr, |
| 1027 |
.reserved7 = nullptr, |
| 1028 |
.reserved8 = nullptr, |
| 1029 |
.reserved9 = nullptr, |
| 1030 |
}; |
| 1031 |
|
| 1032 |
static constexpr struct libdecor_frame_interface libdecor_frame_interface = { |
| 1033 |
.configure = libdecor_frame_on_configure, |
| 1034 |
.close = libdecor_frame_on_close, |
| 1035 |
.commit = libdecor_frame_on_commit, |
| 1036 |
.dismiss_popup = libdecor_frame_on_dismiss_popup, |
| 1037 |
.reserved0 = nullptr, |
| 1038 |
.reserved1 = nullptr, |
| 1039 |
.reserved2 = nullptr, |
| 1040 |
.reserved3 = nullptr, |
| 1041 |
.reserved4 = nullptr, |
| 1042 |
.reserved5 = nullptr, |
| 1043 |
.reserved6 = nullptr, |
| 1044 |
.reserved7 = nullptr, |
| 1045 |
.reserved8 = nullptr, |
| 1046 |
.reserved9 = nullptr, |
| 1047 |
}; |
| 1048 |
#endif |
| 1049 |
|
| 1050 |
static Vector<uint8_t> _read_fd(int fd); |
| 1051 |
static int _allocate_shm_file(size_t size); |
| 1052 |
|
| 1053 |
static Vector<uint8_t> _wl_data_offer_read(struct wl_display *wl_display, const char *p_mime, struct wl_data_offer *wl_data_offer); |
| 1054 |
static Vector<uint8_t> _wp_primary_selection_offer_read(struct wl_display *wl_display, const char *p_mime, struct zwp_primary_selection_offer_v1 *wp_primary_selection_offer); |
| 1055 |
|
| 1056 |
|
| 1057 |
static void _wl_display_check_error(struct wl_display *wl_display); |
| 1058 |
|
| 1059 |
static void _seat_state_set_current(WaylandThread::SeatState &p_ss); |
| 1060 |
static Ref<InputEventKey> _seat_state_get_key_event(SeatState *p_ss, xkb_keycode_t p_keycode, bool p_pressed); |
| 1061 |
static Ref<InputEventKey> _seat_state_get_unstuck_key_event(SeatState *p_ss, xkb_keycode_t p_keycode, bool p_pressed, Key p_key); |
| 1062 |
|
| 1063 |
static void _seat_state_handle_xkb_keycode(SeatState *p_ss, xkb_keycode_t p_xkb_keycode, bool p_pressed, bool p_echo = false); |
| 1064 |
|
| 1065 |
static void _wayland_state_update_cursor(); |
| 1066 |
|
| 1067 |
void _set_current_seat(struct wl_seat *p_seat); |
| 1068 |
|
| 1069 |
bool _load_cursor_theme(int p_cursor_size); |
| 1070 |
|
| 1071 |
void _update_scale(int p_scale); |
| 1072 |
|
| 1073 |
public: |
| 1074 |
Mutex &mutex = thread_data.mutex; |
| 1075 |
|
| 1076 |
struct wl_display *get_wl_display() const; |
| 1077 |
|
| 1078 |
|
| 1079 |
static bool wl_proxy_is_godot(struct wl_proxy *p_proxy); |
| 1080 |
static void wl_proxy_tag_godot(struct wl_proxy *p_proxy); |
| 1081 |
|
| 1082 |
static WindowState *wl_surface_get_window_state(struct wl_surface *p_surface); |
| 1083 |
static ScreenState *wl_output_get_screen_state(struct wl_output *p_output); |
| 1084 |
static SeatState *wl_seat_get_seat_state(struct wl_seat *p_seat); |
| 1085 |
static TabletToolState *wp_tablet_tool_get_state(struct zwp_tablet_tool_v2 *p_tool); |
| 1086 |
static OfferState *wl_data_offer_get_offer_state(struct wl_data_offer *p_offer); |
| 1087 |
|
| 1088 |
static OfferState *wp_primary_selection_offer_get_offer_state(struct zwp_primary_selection_offer_v1 *p_offer); |
| 1089 |
|
| 1090 |
static EmbeddingCompositorState *godot_embedding_compositor_get_state(struct godot_embedding_compositor *p_compositor); |
| 1091 |
|
| 1092 |
void seat_state_unlock_pointer(SeatState *p_ss); |
| 1093 |
void seat_state_lock_pointer(SeatState *p_ss); |
| 1094 |
void seat_state_set_hint(SeatState *p_ss, int p_x, int p_y); |
| 1095 |
void seat_state_confine_pointer(SeatState *p_ss); |
| 1096 |
|
| 1097 |
static void seat_state_update_cursor(SeatState *p_ss); |
| 1098 |
|
| 1099 |
void seat_state_echo_keys(SeatState *p_ss); |
| 1100 |
|
| 1101 |
static int window_state_get_preferred_buffer_scale(WindowState *p_ws); |
| 1102 |
static double window_state_get_scale_factor(const WindowState *p_ws); |
| 1103 |
static void window_state_update_size(WindowState *p_ws, int p_width, int p_height); |
| 1104 |
|
| 1105 |
static Vector2i scale_vector2i(const Vector2i &p_vector, double p_amount); |
| 1106 |
|
| 1107 |
void push_message(Ref<Message> message); |
| 1108 |
bool has_message(); |
| 1109 |
Ref<Message> pop_message(); |
| 1110 |
|
| 1111 |
void beep() const; |
| 1112 |
|
| 1113 |
void set_icon(const Ref<Image> &p_icon); |
| 1114 |
|
| 1115 |
void window_create(DisplayServer::WindowID p_window_id, const Size2i &p_size, DisplayServer::WindowID p_parent_id = DisplayServer::INVALID_WINDOW_ID); |
| 1116 |
void window_create_popup(DisplayServer::WindowID p_window_id, DisplayServer::WindowID p_parent_id, Rect2i p_rect); |
| 1117 |
void window_destroy(DisplayServer::WindowID p_window_Id); |
| 1118 |
|
| 1119 |
void window_set_parent(DisplayServer::WindowID p_window_id, DisplayServer::WindowID p_parent_id); |
| 1120 |
|
| 1121 |
struct wl_surface *window_get_wl_surface(DisplayServer::WindowID p_window_id) const; |
| 1122 |
WindowState *window_get_state(DisplayServer::WindowID p_window_id); |
| 1123 |
const WindowState *window_get_state(DisplayServer::WindowID p_window_id) const; |
| 1124 |
Size2i window_set_size(DisplayServer::WindowID p_window_id, const Size2i &p_size); |
| 1125 |
|
| 1126 |
void window_start_resize(DisplayServer::WindowResizeEdge p_edge, DisplayServer::WindowID p_window); |
| 1127 |
|
| 1128 |
void window_set_max_size(DisplayServer::WindowID p_window_id, const Size2i &p_size); |
| 1129 |
void window_set_min_size(DisplayServer::WindowID p_window_id, const Size2i &p_size); |
| 1130 |
|
| 1131 |
bool window_can_set_mode(DisplayServer::WindowID p_window_id, DisplayServer::WindowMode p_window_mode) const; |
| 1132 |
void window_try_set_mode(DisplayServer::WindowID p_window_id, DisplayServer::WindowMode p_window_mode); |
| 1133 |
DisplayServer::WindowMode window_get_mode(DisplayServer::WindowID p_window_id) const; |
| 1134 |
|
| 1135 |
void window_set_borderless(DisplayServer::WindowID p_window_id, bool p_borderless); |
| 1136 |
void window_set_title(DisplayServer::WindowID p_window_id, const String &p_title); |
| 1137 |
void window_set_app_id(DisplayServer::WindowID p_window_id, const String &p_app_id); |
| 1138 |
|
| 1139 |
bool window_is_focused(DisplayServer::WindowID p_window_id); |
| 1140 |
|
| 1141 |
|
| 1142 |
void window_request_attention(DisplayServer::WindowID p_window_id); |
| 1143 |
|
| 1144 |
void window_start_drag(DisplayServer::WindowID p_window_id); |
| 1145 |
|
| 1146 |
|
| 1147 |
void window_set_idle_inhibition(DisplayServer::WindowID p_window_id, bool p_enable); |
| 1148 |
bool window_get_idle_inhibition(DisplayServer::WindowID p_window_id) const; |
| 1149 |
|
| 1150 |
ScreenData screen_get_data(int p_screen) const; |
| 1151 |
int get_screen_count() const; |
| 1152 |
|
| 1153 |
void pointer_set_constraint(PointerConstraint p_constraint); |
| 1154 |
void pointer_set_hint(const Point2i &p_hint); |
| 1155 |
PointerConstraint pointer_get_constraint() const; |
| 1156 |
DisplayServer::WindowID pointer_get_pointed_window_id() const; |
| 1157 |
DisplayServer::WindowID pointer_get_last_pointed_window_id() const; |
| 1158 |
BitField<MouseButtonMask> pointer_get_button_mask() const; |
| 1159 |
|
| 1160 |
void cursor_set_visible(bool p_visible); |
| 1161 |
void cursor_set_shape(DisplayServer::CursorShape p_cursor_shape); |
| 1162 |
|
| 1163 |
void cursor_set_custom_shape(DisplayServer::CursorShape p_cursor_shape); |
| 1164 |
void cursor_shape_set_custom_image(DisplayServer::CursorShape p_cursor_shape, Ref<Image> p_image, const Point2i &p_hotspot); |
| 1165 |
void cursor_shape_clear_custom_image(DisplayServer::CursorShape p_cursor_shape); |
| 1166 |
|
| 1167 |
void window_set_ime_active(const bool p_active, DisplayServer::WindowID p_window_id); |
| 1168 |
void window_set_ime_position(const Point2i &p_pos, DisplayServer::WindowID p_window_id); |
| 1169 |
|
| 1170 |
int keyboard_get_layout_count() const; |
| 1171 |
int keyboard_get_current_layout_index() const; |
| 1172 |
void keyboard_set_current_layout_index(int p_index); |
| 1173 |
String keyboard_get_layout_name(int p_index) const; |
| 1174 |
|
| 1175 |
Key keyboard_get_key_from_physical(Key p_key) const; |
| 1176 |
Key keyboard_get_label_from_physical(Key p_key) const; |
| 1177 |
|
| 1178 |
void keyboard_echo_keys(); |
| 1179 |
|
| 1180 |
bool selection_has_mime(const String &p_mime) const; |
| 1181 |
Vector<uint8_t> selection_get_mime(const String &p_mime) const; |
| 1182 |
|
| 1183 |
void selection_set_text(const String &p_text); |
| 1184 |
|
| 1185 |
|
| 1186 |
bool primary_has_mime(const String &p_mime) const; |
| 1187 |
Vector<uint8_t> primary_get_mime(const String &p_mime) const; |
| 1188 |
|
| 1189 |
void primary_set_text(const String &p_text); |
| 1190 |
|
| 1191 |
void commit_surfaces(); |
| 1192 |
|
| 1193 |
|
| 1194 |
int wait_events(int p_timeout = -1); |
| 1195 |
|
| 1196 |
void set_frame(); |
| 1197 |
bool get_reset_frame(); |
| 1198 |
bool wait_frame_suspend_ms(int p_timeout); |
| 1199 |
bool is_fifo_available() const; |
| 1200 |
|
| 1201 |
uint64_t window_get_last_frame_time(DisplayServer::WindowID p_window_id) const; |
| 1202 |
bool window_is_suspended(DisplayServer::WindowID p_window_id) const; |
| 1203 |
bool is_suspended() const; |
| 1204 |
|
| 1205 |
bool window_wait_ready(DisplayServer::WindowID p_window_id, int p_timeout_ms); |
| 1206 |
|
| 1207 |
struct godot_embedding_compositor *get_embedding_compositor(); |
| 1208 |
|
| 1209 |
OS::ProcessID embedded_compositor_get_focused_pid(); |
| 1210 |
|
| 1211 |
Error init(); |
| 1212 |
void destroy(); |
| 1213 |
}; |
| 1214 |
|
| 1215 |
#endif |