Path: blob/master/platform/linuxbsd/wayland/wayland_thread.h
10278 views
/**************************************************************************/1/* wayland_thread.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#ifdef WAYLAND_ENABLED3334#include "key_mapping_xkb.h"3536#ifdef SOWRAP_ENABLED37#include "wayland/dynwrappers/wayland-client-core-so_wrap.h"38#include "wayland/dynwrappers/wayland-cursor-so_wrap.h"39#include "wayland/dynwrappers/wayland-egl-core-so_wrap.h"40#include "xkbcommon-so_wrap.h"41#else42#include <wayland-client-core.h>43#include <wayland-cursor.h>44#ifdef GLES3_ENABLED45#include <wayland-egl-core.h>46#endif47#include <xkbcommon/xkbcommon.h>48#endif // SOWRAP_ENABLED4950// These must go after the Wayland client include to work properly.51#include "wayland/protocol/idle_inhibit.gen.h"52#include "wayland/protocol/primary_selection.gen.h"53// These four protocol headers name wl_pointer method arguments as `pointer`,54// which is the same name as X11's pointer typedef. This trips some very55// annoying shadowing warnings. A `#define` works around this issue.56#define pointer wl_pointer57#include "wayland/protocol/cursor_shape.gen.h"58#include "wayland/protocol/pointer_constraints.gen.h"59#include "wayland/protocol/pointer_gestures.gen.h"60#include "wayland/protocol/relative_pointer.gen.h"61#undef pointer62#include "wayland/protocol/fractional_scale.gen.h"63#include "wayland/protocol/tablet.gen.h"64#include "wayland/protocol/text_input.gen.h"65#include "wayland/protocol/viewporter.gen.h"66#include "wayland/protocol/wayland.gen.h"67#include "wayland/protocol/xdg_activation.gen.h"68#include "wayland/protocol/xdg_decoration.gen.h"69#include "wayland/protocol/xdg_foreign_v2.gen.h"70#include "wayland/protocol/xdg_shell.gen.h"71#include "wayland/protocol/xdg_system_bell.gen.h"7273// NOTE: Deprecated.74#include "wayland/protocol/xdg_foreign_v1.gen.h"7576#ifdef LIBDECOR_ENABLED77#ifdef SOWRAP_ENABLED78#include "dynwrappers/libdecor-so_wrap.h"79#else80#include <libdecor.h>81#endif // SOWRAP_ENABLED82#endif // LIBDECOR_ENABLED8384#include "core/os/thread.h"85#include "servers/display_server.h"8687class WaylandThread {88public:89// Messages used for exchanging information between Godot's and Wayland's thread.90class Message : public RefCounted {91GDSOFTCLASS(Message, RefCounted);9293public:94Message() {}95virtual ~Message() = default;96};9798class WindowMessage : public Message {99GDSOFTCLASS(WindowMessage, Message);100101public:102DisplayServer::WindowID id = DisplayServer::INVALID_WINDOW_ID;103};104105// Message data for window rect changes.106class WindowRectMessage : public WindowMessage {107GDSOFTCLASS(WindowRectMessage, WindowMessage);108109public:110// NOTE: This is in "scaled" terms. For example, if there's a 1920x1080 rect111// with a scale factor of 2, the actual value of `rect` will be 3840x2160.112Rect2i rect;113};114115class WindowEventMessage : public WindowMessage {116GDSOFTCLASS(WindowEventMessage, WindowMessage);117118public:119DisplayServer::WindowEvent event;120};121122class InputEventMessage : public Message {123GDSOFTCLASS(InputEventMessage, Message);124125public:126Ref<InputEvent> event;127};128129class DropFilesEventMessage : public WindowMessage {130GDSOFTCLASS(DropFilesEventMessage, WindowMessage);131132public:133Vector<String> files;134};135136class IMEUpdateEventMessage : public WindowMessage {137GDSOFTCLASS(IMEUpdateEventMessage, WindowMessage);138139public:140String text;141Vector2i selection;142};143144class IMECommitEventMessage : public WindowMessage {145GDSOFTCLASS(IMECommitEventMessage, WindowMessage);146147public:148String text;149};150151struct RegistryState {152WaylandThread *wayland_thread;153154// Core Wayland globals.155struct wl_shm *wl_shm = nullptr;156uint32_t wl_shm_name = 0;157158struct wl_compositor *wl_compositor = nullptr;159uint32_t wl_compositor_name = 0;160161struct wl_subcompositor *wl_subcompositor = nullptr;162uint32_t wl_subcompositor_name = 0;163164struct wl_data_device_manager *wl_data_device_manager = nullptr;165uint32_t wl_data_device_manager_name = 0;166167List<struct wl_output *> wl_outputs;168List<struct wl_seat *> wl_seats;169170// xdg-shell globals.171172struct xdg_wm_base *xdg_wm_base = nullptr;173uint32_t xdg_wm_base_name = 0;174175// NOTE: Deprecated.176struct zxdg_exporter_v1 *xdg_exporter_v1 = nullptr;177uint32_t xdg_exporter_v1_name = 0;178179uint32_t xdg_exporter_v2_name = 0;180struct zxdg_exporter_v2 *xdg_exporter_v2 = nullptr;181182// wayland-protocols globals.183184struct wp_viewporter *wp_viewporter = nullptr;185uint32_t wp_viewporter_name = 0;186187struct wp_fractional_scale_manager_v1 *wp_fractional_scale_manager = nullptr;188uint32_t wp_fractional_scale_manager_name = 0;189190struct wp_cursor_shape_manager_v1 *wp_cursor_shape_manager = nullptr;191uint32_t wp_cursor_shape_manager_name = 0;192193struct zxdg_decoration_manager_v1 *xdg_decoration_manager = nullptr;194uint32_t xdg_decoration_manager_name = 0;195196struct xdg_system_bell_v1 *xdg_system_bell = nullptr;197uint32_t xdg_system_bell_name = 0;198199struct xdg_activation_v1 *xdg_activation = nullptr;200uint32_t xdg_activation_name = 0;201202struct zwp_primary_selection_device_manager_v1 *wp_primary_selection_device_manager = nullptr;203uint32_t wp_primary_selection_device_manager_name = 0;204205struct zwp_relative_pointer_manager_v1 *wp_relative_pointer_manager = nullptr;206uint32_t wp_relative_pointer_manager_name = 0;207208struct zwp_pointer_constraints_v1 *wp_pointer_constraints = nullptr;209uint32_t wp_pointer_constraints_name = 0;210211struct zwp_pointer_gestures_v1 *wp_pointer_gestures = nullptr;212uint32_t wp_pointer_gestures_name = 0;213214struct zwp_idle_inhibit_manager_v1 *wp_idle_inhibit_manager = nullptr;215uint32_t wp_idle_inhibit_manager_name = 0;216217struct zwp_tablet_manager_v2 *wp_tablet_manager = nullptr;218uint32_t wp_tablet_manager_name = 0;219220struct zwp_text_input_manager_v3 *wp_text_input_manager = nullptr;221uint32_t wp_text_input_manager_name = 0;222223// We're really not meant to use this one directly but we still need to know224// whether it's available.225uint32_t wp_fifo_manager_name = 0;226};227228// General Wayland-specific states. Shouldn't be accessed directly.229// TODO: Make private?230231struct WindowState {232DisplayServer::WindowID id = DisplayServer::INVALID_WINDOW_ID;233DisplayServer::WindowID parent_id = DisplayServer::INVALID_WINDOW_ID;234235Rect2i rect;236DisplayServer::WindowMode mode = DisplayServer::WINDOW_MODE_WINDOWED;237bool suspended = false;238239// These are true by default as it isn't guaranteed that we'll find an240// xdg-shell implementation with wm_capabilities available. If and once we241// receive a wm_capabilities event these will get reset and updated with242// whatever the compositor says.243bool can_minimize = false;244bool can_maximize = false;245bool can_fullscreen = false;246247HashSet<struct wl_output *> wl_outputs;248249// NOTE: If for whatever reason this callback is destroyed _while_ the event250// thread is still running, it might be a good idea to set its user data to251// `nullptr`. From some initial testing of mine, it looks like it might still252// be called even after being destroyed, pointing to probably invalid window253// data by then and segfaulting hard.254struct wl_callback *frame_callback = nullptr;255uint64_t last_frame_time = 0;256257struct wl_surface *wl_surface = nullptr;258struct xdg_surface *xdg_surface = nullptr;259struct xdg_toplevel *xdg_toplevel = nullptr;260261struct wp_viewport *wp_viewport = nullptr;262struct wp_fractional_scale_v1 *wp_fractional_scale = nullptr;263264// NOTE: Deprecated.265struct zxdg_exported_v1 *xdg_exported_v1 = nullptr;266267struct zxdg_exported_v2 *xdg_exported_v2 = nullptr;268269struct xdg_popup *xdg_popup = nullptr;270271String exported_handle;272273// Currently applied buffer scale.274int buffer_scale = 1;275276// Buffer scale must be applied right before rendering but _after_ committing277// everything else or otherwise we might have an inconsistent state (e.g.278// double scale and odd resolution). This flag assists with that; when set,279// on the next frame, we'll commit whatever is set in `buffer_scale`.280bool buffer_scale_changed = false;281282// NOTE: The preferred buffer scale is currently only dynamically calculated.283// It can be accessed by calling `window_state_get_preferred_buffer_scale`.284285// Override used by the fractional scale add-on object. If less or equal to 0286// (default) then the normal output-based scale is used instead.287double fractional_scale = 0;288289// What the compositor is recommending us.290double preferred_fractional_scale = 0;291292struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration = nullptr;293294struct zwp_idle_inhibitor_v1 *wp_idle_inhibitor = nullptr;295296#ifdef LIBDECOR_ENABLED297// If this is null the xdg_* variables must be set and vice-versa. This way we298// can handle this mess gracefully enough to hopefully being able of getting299// rid of this cleanly once we have our own CSDs.300struct libdecor_frame *libdecor_frame = nullptr;301struct libdecor_configuration *pending_libdecor_configuration = nullptr;302#endif303304RegistryState *registry;305WaylandThread *wayland_thread;306};307308// "High level" Godot-side screen data.309struct ScreenData {310// Geometry data.311Point2i position;312313String make;314String model;315316Size2i size;317Size2i physical_size;318319float refresh_rate = -1;320int scale = 1;321};322323struct ScreenState {324uint32_t wl_output_name = 0;325326ScreenData pending_data;327ScreenData data;328329WaylandThread *wayland_thread;330};331332enum class Gesture {333NONE,334MAGNIFY,335};336337enum class PointerConstraint {338NONE,339LOCKED,340CONFINED,341};342343struct PointerData {344Point2 position;345uint32_t motion_time = 0;346347// Relative motion has its own optional event and so needs its own time.348Vector2 relative_motion;349uint32_t relative_motion_time = 0;350351BitField<MouseButtonMask> pressed_button_mask = MouseButtonMask::NONE;352353MouseButton last_button_pressed = MouseButton::NONE;354Point2 last_pressed_position;355356DisplayServer::WindowID pointed_id = DisplayServer::INVALID_WINDOW_ID;357DisplayServer::WindowID last_pointed_id = DisplayServer::INVALID_WINDOW_ID;358359// This is needed to check for a new double click every time.360bool double_click_begun = false;361362uint32_t button_time = 0;363uint32_t button_serial = 0;364365uint32_t scroll_type = WL_POINTER_AXIS_SOURCE_WHEEL;366367// The amount "scrolled" in pixels, in each direction.368Vector2 scroll_vector;369370// The amount of scroll "clicks" in each direction, in fractions of 120.371Vector2i discrete_scroll_vector_120;372373uint32_t pinch_scale = 1;374};375376struct TabletToolData {377Point2 position;378Vector2 tilt;379uint32_t pressure = 0;380381BitField<MouseButtonMask> pressed_button_mask = MouseButtonMask::NONE;382383MouseButton last_button_pressed = MouseButton::NONE;384Point2 last_pressed_position;385386bool double_click_begun = false;387388uint64_t button_time = 0;389uint64_t motion_time = 0;390391DisplayServer::WindowID proximal_id = DisplayServer::INVALID_WINDOW_ID;392DisplayServer::WindowID last_proximal_id = DisplayServer::INVALID_WINDOW_ID;393uint32_t proximity_serial = 0;394};395396struct TabletToolState {397struct wl_seat *wl_seat = nullptr;398399bool is_eraser = false;400401TabletToolData data_pending;402TabletToolData data;403};404405struct OfferState {406HashSet<String> mime_types;407};408409struct SeatState {410RegistryState *registry = nullptr;411412WaylandThread *wayland_thread = nullptr;413414struct wl_seat *wl_seat = nullptr;415uint32_t wl_seat_name = 0;416417// Pointer.418struct wl_pointer *wl_pointer = nullptr;419420uint32_t pointer_enter_serial = 0;421422struct wp_cursor_shape_device_v1 *wp_cursor_shape_device = nullptr;423424struct zwp_relative_pointer_v1 *wp_relative_pointer = nullptr;425struct zwp_locked_pointer_v1 *wp_locked_pointer = nullptr;426struct zwp_confined_pointer_v1 *wp_confined_pointer = nullptr;427428struct zwp_pointer_gesture_pinch_v1 *wp_pointer_gesture_pinch = nullptr;429430// NOTE: According to the wp_pointer_gestures protocol specification, there431// can be only one active gesture at a time.432Gesture active_gesture = Gesture::NONE;433434// Used for delta calculations.435// NOTE: The wp_pointer_gestures protocol keeps track of the total scale of436// the pinch gesture, while godot instead wants its delta.437wl_fixed_t old_pinch_scale = 0;438439struct wl_surface *cursor_surface = nullptr;440struct wl_callback *cursor_frame_callback = nullptr;441uint32_t cursor_time_ms = 0;442443// This variable is needed to buffer all pointer changes until a444// wl_pointer.frame event, as per Wayland's specification. Everything is445// first set in `data_buffer` and then `data` is set with its contents on446// an input frame event. All methods should generally read from447// `pointer_data` and write to `data_buffer`.448PointerData pointer_data_buffer;449PointerData pointer_data;450451// Keyboard.452struct wl_keyboard *wl_keyboard = nullptr;453454// For key events.455DisplayServer::WindowID focused_id = DisplayServer::INVALID_WINDOW_ID;456457struct xkb_context *xkb_context = nullptr;458struct xkb_keymap *xkb_keymap = nullptr;459struct xkb_state *xkb_state = nullptr;460461const char *keymap_buffer = nullptr;462uint32_t keymap_buffer_size = 0;463464HashMap<xkb_keycode_t, Key> pressed_keycodes;465466xkb_layout_index_t current_layout_index = 0;467468int32_t repeat_key_delay_msec = 0;469int32_t repeat_start_delay_msec = 0;470471xkb_keycode_t repeating_keycode = XKB_KEYCODE_INVALID;472uint64_t last_repeat_start_msec = 0;473uint64_t last_repeat_msec = 0;474475bool shift_pressed = false;476bool ctrl_pressed = false;477bool alt_pressed = false;478bool meta_pressed = false;479480uint32_t last_key_pressed_serial = 0;481482struct wl_data_device *wl_data_device = nullptr;483484// Drag and drop.485DisplayServer::WindowID dnd_id = DisplayServer::INVALID_WINDOW_ID;486struct wl_data_offer *wl_data_offer_dnd = nullptr;487uint32_t dnd_enter_serial = 0;488489// Clipboard.490struct wl_data_source *wl_data_source_selection = nullptr;491Vector<uint8_t> selection_data;492493struct wl_data_offer *wl_data_offer_selection = nullptr;494495// Primary selection.496struct zwp_primary_selection_device_v1 *wp_primary_selection_device = nullptr;497498struct zwp_primary_selection_source_v1 *wp_primary_selection_source = nullptr;499Vector<uint8_t> primary_data;500501struct zwp_primary_selection_offer_v1 *wp_primary_selection_offer = nullptr;502503// Tablet.504struct zwp_tablet_seat_v2 *wp_tablet_seat = nullptr;505506List<struct zwp_tablet_tool_v2 *> tablet_tools;507508// IME.509struct zwp_text_input_v3 *wp_text_input = nullptr;510DisplayServer::WindowID ime_window_id = DisplayServer::INVALID_WINDOW_ID;511bool ime_enabled = false;512bool ime_active = false;513String ime_text;514String ime_text_commit;515Vector2i ime_cursor;516Rect2i ime_rect;517};518519struct CustomCursor {520struct wl_buffer *wl_buffer = nullptr;521uint32_t *buffer_data = nullptr;522uint32_t buffer_data_size = 0;523524Point2i hotspot;525};526527private:528struct ThreadData {529SafeFlag thread_done;530Mutex mutex;531532struct wl_display *wl_display = nullptr;533};534535// FIXME: Is this the right thing to do?536inline static const char *proxy_tag = "godot";537538Thread events_thread;539ThreadData thread_data;540541HashMap<DisplayServer::WindowID, WindowState> windows;542543List<Ref<Message>> messages;544545String cursor_theme_name;546int unscaled_cursor_size = 24;547548// NOTE: Regarding screen scale handling, the cursor cache is currently549// "static", by which I mean that we try to change it as little as possible and550// thus will be as big as the largest screen. This is mainly due to the fact551// that doing it dynamically doesn't look like it's worth it to me currently,552// especially as usually screen scales don't change continuously.553int cursor_scale = 1;554555// Use cursor-shape-v1 protocol if the compositor supports it.556wp_cursor_shape_device_v1_shape standard_cursors[DisplayServer::CURSOR_MAX] = {557wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT, //CURSOR_ARROW558wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT, //CURSOR_IBEAM559wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_POINTER, //CURSOR_POINTING_HAND560wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CROSSHAIR, //CURSOR_CROSS561wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_WAIT, //CURSOR_WAIT562wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_PROGRESS, //CURSOR_BUSY563wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_GRAB, //CURSOR_DRAG564wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_GRABBING, //CURSOR_CAN_DROP565wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NO_DROP, //CURSOR_FORBIDDEN566wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NS_RESIZE, //CURSOR_VSIZE567wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_EW_RESIZE, //CURSOR_HSIZE568wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NESW_RESIZE, //CURSOR_BDIAGSIZE569wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NWSE_RESIZE, //CURSOR_FDIAGSIZE570wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_MOVE, //CURSOR_MOVE571wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ROW_RESIZE, //CURSOR_VSPLIT572wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_COL_RESIZE, //CURSOR_HSPLIT573wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_HELP, //CURSOR_HELP574};575576// Fallback to reading $XCURSOR and system themes if the compositor does not.577struct wl_cursor_theme *wl_cursor_theme = nullptr;578struct wl_cursor *wl_cursors[DisplayServer::CURSOR_MAX] = {};579580// User-defined cursor overrides. Take precedence over standard and wl cursors.581HashMap<DisplayServer::CursorShape, CustomCursor> custom_cursors;582583DisplayServer::CursorShape cursor_shape = DisplayServer::CURSOR_ARROW;584bool cursor_visible = true;585586PointerConstraint pointer_constraint = PointerConstraint::NONE;587588struct wl_display *wl_display = nullptr;589struct wl_registry *wl_registry = nullptr;590591struct wl_seat *wl_seat_current = nullptr;592593bool frame = true;594595RegistryState registry;596597bool initialized = false;598599#ifdef LIBDECOR_ENABLED600struct libdecor *libdecor_context = nullptr;601#endif // LIBDECOR_ENABLED602603// Main polling method.604static void _poll_events_thread(void *p_data);605606// Core Wayland event handlers.607static void _wl_registry_on_global(void *data, struct wl_registry *wl_registry, uint32_t name, const char *interface, uint32_t version);608static void _wl_registry_on_global_remove(void *data, struct wl_registry *wl_registry, uint32_t name);609610static void _wl_surface_on_enter(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output);611static void _wl_surface_on_leave(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output);612static void _wl_surface_on_preferred_buffer_scale(void *data, struct wl_surface *wl_surface, int32_t factor);613static void _wl_surface_on_preferred_buffer_transform(void *data, struct wl_surface *wl_surface, uint32_t transform);614615static void _frame_wl_callback_on_done(void *data, struct wl_callback *wl_callback, uint32_t callback_data);616617static 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);618static void _wl_output_on_mode(void *data, struct wl_output *wl_output, uint32_t flags, int32_t width, int32_t height, int32_t refresh);619static void _wl_output_on_done(void *data, struct wl_output *wl_output);620static void _wl_output_on_scale(void *data, struct wl_output *wl_output, int32_t factor);621static void _wl_output_on_name(void *data, struct wl_output *wl_output, const char *name);622static void _wl_output_on_description(void *data, struct wl_output *wl_output, const char *description);623624static void _wl_seat_on_capabilities(void *data, struct wl_seat *wl_seat, uint32_t capabilities);625static void _wl_seat_on_name(void *data, struct wl_seat *wl_seat, const char *name);626627static void _cursor_frame_callback_on_done(void *data, struct wl_callback *wl_callback, uint32_t time_ms);628629static 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);630static void _wl_pointer_on_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface);631static 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);632static void _wl_pointer_on_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state);633static void _wl_pointer_on_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value);634static void _wl_pointer_on_frame(void *data, struct wl_pointer *wl_pointer);635static void _wl_pointer_on_axis_source(void *data, struct wl_pointer *wl_pointer, uint32_t axis_source);636static void _wl_pointer_on_axis_stop(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis);637static void _wl_pointer_on_axis_discrete(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete);638static void _wl_pointer_on_axis_value120(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t value120);639static void _wl_pointer_on_axis_relative_direction(void *data, struct wl_pointer *wl_pointer, uint32_t axis, uint32_t direction);640641static void _wl_keyboard_on_keymap(void *data, struct wl_keyboard *wl_keyboard, uint32_t format, int32_t fd, uint32_t size);642static void _wl_keyboard_on_enter(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys);643static void _wl_keyboard_on_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface);644static void _wl_keyboard_on_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state);645static 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);646static void _wl_keyboard_on_repeat_info(void *data, struct wl_keyboard *wl_keyboard, int32_t rate, int32_t delay);647648static void _wl_data_device_on_data_offer(void *data, struct wl_data_device *wl_data_device, struct wl_data_offer *id);649static 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);650static void _wl_data_device_on_leave(void *data, struct wl_data_device *wl_data_device);651static 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);652static void _wl_data_device_on_drop(void *data, struct wl_data_device *wl_data_device);653static void _wl_data_device_on_selection(void *data, struct wl_data_device *wl_data_device, struct wl_data_offer *id);654655static void _wl_data_offer_on_offer(void *data, struct wl_data_offer *wl_data_offer, const char *mime_type);656static void _wl_data_offer_on_source_actions(void *data, struct wl_data_offer *wl_data_offer, uint32_t source_actions);657static void _wl_data_offer_on_action(void *data, struct wl_data_offer *wl_data_offer, uint32_t dnd_action);658659static void _wl_data_source_on_target(void *data, struct wl_data_source *wl_data_source, const char *mime_type);660static void _wl_data_source_on_send(void *data, struct wl_data_source *wl_data_source, const char *mime_type, int32_t fd);661static void _wl_data_source_on_cancelled(void *data, struct wl_data_source *wl_data_source);662static void _wl_data_source_on_dnd_drop_performed(void *data, struct wl_data_source *wl_data_source);663static void _wl_data_source_on_dnd_finished(void *data, struct wl_data_source *wl_data_source);664static void _wl_data_source_on_action(void *data, struct wl_data_source *wl_data_source, uint32_t dnd_action);665666// xdg-shell event handlers.667static void _xdg_wm_base_on_ping(void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial);668669static void _xdg_surface_on_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial);670671static void _xdg_toplevel_on_configure(void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height, struct wl_array *states);672static void _xdg_toplevel_on_close(void *data, struct xdg_toplevel *xdg_toplevel);673static void _xdg_toplevel_on_configure_bounds(void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height);674static void _xdg_toplevel_on_wm_capabilities(void *data, struct xdg_toplevel *xdg_toplevel, struct wl_array *capabilities);675676static void _xdg_popup_on_configure(void *data, struct xdg_popup *xdg_popup, int32_t x, int32_t y, int32_t width, int32_t height);677static void _xdg_popup_on_popup_done(void *data, struct xdg_popup *xdg_popup);678static void _xdg_popup_on_repositioned(void *data, struct xdg_popup *xdg_popup, uint32_t token);679680// wayland-protocols event handlers.681static void _wp_fractional_scale_on_preferred_scale(void *data, struct wp_fractional_scale_v1 *wp_fractional_scale_v1, uint32_t scale);682683static 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);684685static 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);686static 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);687static 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);688689static 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);690static 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);691692static void _wp_primary_selection_offer_on_offer(void *data, struct zwp_primary_selection_offer_v1 *wp_primary_selection_offer_v1, const char *mime_type);693694static 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);695static void _wp_primary_selection_source_on_cancelled(void *data, struct zwp_primary_selection_source_v1 *wp_primary_selection_source_v1);696697static void _wp_tablet_seat_on_tablet_added(void *data, struct zwp_tablet_seat_v2 *wp_tablet_seat_v2, struct zwp_tablet_v2 *id);698static void _wp_tablet_seat_on_tool_added(void *data, struct zwp_tablet_seat_v2 *wp_tablet_seat_v2, struct zwp_tablet_tool_v2 *id);699static void _wp_tablet_seat_on_pad_added(void *data, struct zwp_tablet_seat_v2 *wp_tablet_seat_v2, struct zwp_tablet_pad_v2 *id);700701static void _wp_tablet_tool_on_type(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t tool_type);702static 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);703static 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);704static void _wp_tablet_tool_on_capability(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t capability);705static void _wp_tablet_tool_on_done(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2);706static void _wp_tablet_tool_on_removed(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2);707static 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);708static void _wp_tablet_tool_on_proximity_out(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2);709static void _wp_tablet_tool_on_down(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t serial);710static void _wp_tablet_tool_on_up(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2);711static 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);712static void _wp_tablet_tool_on_pressure(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t pressure);713static void _wp_tablet_tool_on_distance(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t distance);714static 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);715static void _wp_tablet_tool_on_rotation(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, wl_fixed_t degrees);716static void _wp_tablet_tool_on_slider(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, int32_t position);717static void _wp_tablet_tool_on_wheel(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, wl_fixed_t degrees, int32_t clicks);718static 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);719static void _wp_tablet_tool_on_frame(void *data, struct zwp_tablet_tool_v2 *wp_tablet_tool_v2, uint32_t time);720721static void _wp_text_input_on_enter(void *data, struct zwp_text_input_v3 *wp_text_input_v3, struct wl_surface *surface);722static void _wp_text_input_on_leave(void *data, struct zwp_text_input_v3 *wp_text_input_v3, struct wl_surface *surface);723static 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);724static void _wp_text_input_on_commit_string(void *data, struct zwp_text_input_v3 *wp_text_input_v3, const char *text);725static 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);726static void _wp_text_input_on_done(void *data, struct zwp_text_input_v3 *wp_text_input_v3, uint32_t serial);727728static void _xdg_toplevel_decoration_on_configure(void *data, struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration, uint32_t mode);729730// NOTE: Deprecated.731static void _xdg_exported_v1_on_handle(void *data, zxdg_exported_v1 *exported, const char *handle);732733static void _xdg_exported_v2_on_handle(void *data, zxdg_exported_v2 *exported, const char *handle);734735static void _xdg_activation_token_on_done(void *data, struct xdg_activation_token_v1 *xdg_activation_token, const char *token);736737// Core Wayland event listeners.738static constexpr struct wl_registry_listener wl_registry_listener = {739.global = _wl_registry_on_global,740.global_remove = _wl_registry_on_global_remove,741};742743static constexpr struct wl_surface_listener wl_surface_listener = {744.enter = _wl_surface_on_enter,745.leave = _wl_surface_on_leave,746.preferred_buffer_scale = _wl_surface_on_preferred_buffer_scale,747.preferred_buffer_transform = _wl_surface_on_preferred_buffer_transform,748};749750static constexpr struct wl_callback_listener frame_wl_callback_listener = {751.done = _frame_wl_callback_on_done,752};753754static constexpr struct wl_output_listener wl_output_listener = {755.geometry = _wl_output_on_geometry,756.mode = _wl_output_on_mode,757.done = _wl_output_on_done,758.scale = _wl_output_on_scale,759.name = _wl_output_on_name,760.description = _wl_output_on_description,761};762763static constexpr struct wl_seat_listener wl_seat_listener = {764.capabilities = _wl_seat_on_capabilities,765.name = _wl_seat_on_name,766};767768static constexpr struct wl_callback_listener cursor_frame_callback_listener = {769.done = _cursor_frame_callback_on_done,770};771772static constexpr struct wl_pointer_listener wl_pointer_listener = {773.enter = _wl_pointer_on_enter,774.leave = _wl_pointer_on_leave,775.motion = _wl_pointer_on_motion,776.button = _wl_pointer_on_button,777.axis = _wl_pointer_on_axis,778.frame = _wl_pointer_on_frame,779.axis_source = _wl_pointer_on_axis_source,780.axis_stop = _wl_pointer_on_axis_stop,781.axis_discrete = _wl_pointer_on_axis_discrete,782.axis_value120 = _wl_pointer_on_axis_value120,783.axis_relative_direction = _wl_pointer_on_axis_relative_direction,784};785786static constexpr struct wl_keyboard_listener wl_keyboard_listener = {787.keymap = _wl_keyboard_on_keymap,788.enter = _wl_keyboard_on_enter,789.leave = _wl_keyboard_on_leave,790.key = _wl_keyboard_on_key,791.modifiers = _wl_keyboard_on_modifiers,792.repeat_info = _wl_keyboard_on_repeat_info,793};794795static constexpr struct wl_data_device_listener wl_data_device_listener = {796.data_offer = _wl_data_device_on_data_offer,797.enter = _wl_data_device_on_enter,798.leave = _wl_data_device_on_leave,799.motion = _wl_data_device_on_motion,800.drop = _wl_data_device_on_drop,801.selection = _wl_data_device_on_selection,802};803804static constexpr struct wl_data_offer_listener wl_data_offer_listener = {805.offer = _wl_data_offer_on_offer,806.source_actions = _wl_data_offer_on_source_actions,807.action = _wl_data_offer_on_action,808};809810static constexpr struct wl_data_source_listener wl_data_source_listener = {811.target = _wl_data_source_on_target,812.send = _wl_data_source_on_send,813.cancelled = _wl_data_source_on_cancelled,814.dnd_drop_performed = _wl_data_source_on_dnd_drop_performed,815.dnd_finished = _wl_data_source_on_dnd_finished,816.action = _wl_data_source_on_action,817};818819// xdg-shell event listeners.820static constexpr struct xdg_wm_base_listener xdg_wm_base_listener = {821.ping = _xdg_wm_base_on_ping,822};823824static constexpr struct xdg_surface_listener xdg_surface_listener = {825.configure = _xdg_surface_on_configure,826};827828static constexpr struct xdg_toplevel_listener xdg_toplevel_listener = {829.configure = _xdg_toplevel_on_configure,830.close = _xdg_toplevel_on_close,831.configure_bounds = _xdg_toplevel_on_configure_bounds,832.wm_capabilities = _xdg_toplevel_on_wm_capabilities,833};834835static constexpr struct xdg_popup_listener xdg_popup_listener = {836.configure = _xdg_popup_on_configure,837.popup_done = _xdg_popup_on_popup_done,838.repositioned = _xdg_popup_on_repositioned,839};840841// wayland-protocols event listeners.842static constexpr struct wp_fractional_scale_v1_listener wp_fractional_scale_listener = {843.preferred_scale = _wp_fractional_scale_on_preferred_scale,844};845846static constexpr struct zwp_relative_pointer_v1_listener wp_relative_pointer_listener = {847.relative_motion = _wp_relative_pointer_on_relative_motion,848};849850static constexpr struct zwp_pointer_gesture_pinch_v1_listener wp_pointer_gesture_pinch_listener = {851.begin = _wp_pointer_gesture_pinch_on_begin,852.update = _wp_pointer_gesture_pinch_on_update,853.end = _wp_pointer_gesture_pinch_on_end,854};855856static constexpr struct zwp_primary_selection_device_v1_listener wp_primary_selection_device_listener = {857.data_offer = _wp_primary_selection_device_on_data_offer,858.selection = _wp_primary_selection_device_on_selection,859};860861static constexpr struct zwp_primary_selection_offer_v1_listener wp_primary_selection_offer_listener = {862.offer = _wp_primary_selection_offer_on_offer,863};864865static constexpr struct zwp_primary_selection_source_v1_listener wp_primary_selection_source_listener = {866.send = _wp_primary_selection_source_on_send,867.cancelled = _wp_primary_selection_source_on_cancelled,868};869870static constexpr struct zwp_tablet_seat_v2_listener wp_tablet_seat_listener = {871.tablet_added = _wp_tablet_seat_on_tablet_added,872.tool_added = _wp_tablet_seat_on_tool_added,873.pad_added = _wp_tablet_seat_on_pad_added,874};875876static constexpr struct zwp_tablet_tool_v2_listener wp_tablet_tool_listener = {877.type = _wp_tablet_tool_on_type,878.hardware_serial = _wp_tablet_tool_on_hardware_serial,879.hardware_id_wacom = _wp_tablet_tool_on_hardware_id_wacom,880.capability = _wp_tablet_tool_on_capability,881.done = _wp_tablet_tool_on_done,882.removed = _wp_tablet_tool_on_removed,883.proximity_in = _wp_tablet_tool_on_proximity_in,884.proximity_out = _wp_tablet_tool_on_proximity_out,885.down = _wp_tablet_tool_on_down,886.up = _wp_tablet_tool_on_up,887.motion = _wp_tablet_tool_on_motion,888.pressure = _wp_tablet_tool_on_pressure,889.distance = _wp_tablet_tool_on_distance,890.tilt = _wp_tablet_tool_on_tilt,891.rotation = _wp_tablet_tool_on_rotation,892.slider = _wp_tablet_tool_on_slider,893.wheel = _wp_tablet_tool_on_wheel,894.button = _wp_tablet_tool_on_button,895.frame = _wp_tablet_tool_on_frame,896};897898static constexpr struct zwp_text_input_v3_listener wp_text_input_listener = {899.enter = _wp_text_input_on_enter,900.leave = _wp_text_input_on_leave,901.preedit_string = _wp_text_input_on_preedit_string,902.commit_string = _wp_text_input_on_commit_string,903.delete_surrounding_text = _wp_text_input_on_delete_surrounding_text,904.done = _wp_text_input_on_done,905};906907// NOTE: Deprecated.908static constexpr struct zxdg_exported_v1_listener xdg_exported_v1_listener = {909.handle = _xdg_exported_v1_on_handle,910};911912static constexpr struct zxdg_exported_v2_listener xdg_exported_v2_listener = {913.handle = _xdg_exported_v2_on_handle,914};915916static constexpr struct zxdg_toplevel_decoration_v1_listener xdg_toplevel_decoration_listener = {917.configure = _xdg_toplevel_decoration_on_configure,918};919920static constexpr struct xdg_activation_token_v1_listener xdg_activation_token_listener = {921.done = _xdg_activation_token_on_done,922};923924#ifdef LIBDECOR_ENABLED925// libdecor event handlers.926static void libdecor_on_error(struct libdecor *context, enum libdecor_error error, const char *message);927928static void libdecor_frame_on_configure(struct libdecor_frame *frame, struct libdecor_configuration *configuration, void *user_data);929930static void libdecor_frame_on_close(struct libdecor_frame *frame, void *user_data);931932static void libdecor_frame_on_commit(struct libdecor_frame *frame, void *user_data);933934static void libdecor_frame_on_dismiss_popup(struct libdecor_frame *frame, const char *seat_name, void *user_data);935936// libdecor event listeners.937static constexpr struct libdecor_interface libdecor_interface = {938.error = libdecor_on_error,939.reserved0 = nullptr,940.reserved1 = nullptr,941.reserved2 = nullptr,942.reserved3 = nullptr,943.reserved4 = nullptr,944.reserved5 = nullptr,945.reserved6 = nullptr,946.reserved7 = nullptr,947.reserved8 = nullptr,948.reserved9 = nullptr,949};950951static constexpr struct libdecor_frame_interface libdecor_frame_interface = {952.configure = libdecor_frame_on_configure,953.close = libdecor_frame_on_close,954.commit = libdecor_frame_on_commit,955.dismiss_popup = libdecor_frame_on_dismiss_popup,956.reserved0 = nullptr,957.reserved1 = nullptr,958.reserved2 = nullptr,959.reserved3 = nullptr,960.reserved4 = nullptr,961.reserved5 = nullptr,962.reserved6 = nullptr,963.reserved7 = nullptr,964.reserved8 = nullptr,965.reserved9 = nullptr,966};967#endif // LIBDECOR_ENABLED968969static Vector<uint8_t> _read_fd(int fd);970static int _allocate_shm_file(size_t size);971972static Vector<uint8_t> _wl_data_offer_read(struct wl_display *wl_display, const char *p_mime, struct wl_data_offer *wl_data_offer);973static 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);974975static void _seat_state_set_current(WaylandThread::SeatState &p_ss);976static Ref<InputEventKey> _seat_state_get_key_event(SeatState *p_ss, xkb_keycode_t p_keycode, bool p_pressed);977static Ref<InputEventKey> _seat_state_get_unstuck_key_event(SeatState *p_ss, xkb_keycode_t p_keycode, bool p_pressed, Key p_key);978979static void _wayland_state_update_cursor();980981void _set_current_seat(struct wl_seat *p_seat);982983bool _load_cursor_theme(int p_cursor_size);984985void _update_scale(int p_scale);986987public:988Mutex &mutex = thread_data.mutex;989990struct wl_display *get_wl_display() const;991992// Core Wayland utilities for integrating with our own data structures.993static bool wl_proxy_is_godot(struct wl_proxy *p_proxy);994static void wl_proxy_tag_godot(struct wl_proxy *p_proxy);995996static WindowState *wl_surface_get_window_state(struct wl_surface *p_surface);997static ScreenState *wl_output_get_screen_state(struct wl_output *p_output);998static SeatState *wl_seat_get_seat_state(struct wl_seat *p_seat);999static TabletToolState *wp_tablet_tool_get_state(struct zwp_tablet_tool_v2 *p_tool);1000static OfferState *wl_data_offer_get_offer_state(struct wl_data_offer *p_offer);10011002static OfferState *wp_primary_selection_offer_get_offer_state(struct zwp_primary_selection_offer_v1 *p_offer);10031004void seat_state_unlock_pointer(SeatState *p_ss);1005void seat_state_lock_pointer(SeatState *p_ss);1006void seat_state_set_hint(SeatState *p_ss, int p_x, int p_y);1007void seat_state_confine_pointer(SeatState *p_ss);10081009static void seat_state_update_cursor(SeatState *p_ss);10101011void seat_state_echo_keys(SeatState *p_ss);10121013static int window_state_get_preferred_buffer_scale(WindowState *p_ws);1014static double window_state_get_scale_factor(WindowState *p_ws);1015static void window_state_update_size(WindowState *p_ws, int p_width, int p_height);10161017static Vector2i scale_vector2i(const Vector2i &p_vector, double p_amount);10181019void push_message(Ref<Message> message);1020bool has_message();1021Ref<Message> pop_message();10221023void beep() const;10241025void window_create(DisplayServer::WindowID p_window_id, int p_width, int p_height);1026void window_create_popup(DisplayServer::WindowID p_window_id, DisplayServer::WindowID p_parent_id, Rect2i p_rect);1027void window_destroy(DisplayServer::WindowID p_window_Id);10281029void window_set_parent(DisplayServer::WindowID p_window_id, DisplayServer::WindowID p_parent_id);10301031struct wl_surface *window_get_wl_surface(DisplayServer::WindowID p_window_id) const;1032WindowState *window_get_state(DisplayServer::WindowID p_window_id);10331034void window_start_resize(DisplayServer::WindowResizeEdge p_edge, DisplayServer::WindowID p_window);10351036void window_set_max_size(DisplayServer::WindowID p_window_id, const Size2i &p_size);1037void window_set_min_size(DisplayServer::WindowID p_window_id, const Size2i &p_size);10381039bool window_can_set_mode(DisplayServer::WindowID p_window_id, DisplayServer::WindowMode p_window_mode) const;1040void window_try_set_mode(DisplayServer::WindowID p_window_id, DisplayServer::WindowMode p_window_mode);1041DisplayServer::WindowMode window_get_mode(DisplayServer::WindowID p_window_id) const;10421043void window_set_borderless(DisplayServer::WindowID p_window_id, bool p_borderless);1044void window_set_title(DisplayServer::WindowID p_window_id, const String &p_title);1045void window_set_app_id(DisplayServer::WindowID p_window_id, const String &p_app_id);10461047bool window_is_focused(DisplayServer::WindowID p_window_id);10481049// Optional - requires xdg_activation_v11050void window_request_attention(DisplayServer::WindowID p_window_id);10511052void window_start_drag(DisplayServer::WindowID p_window_id);10531054// Optional - require idle_inhibit_unstable_v11055void window_set_idle_inhibition(DisplayServer::WindowID p_window_id, bool p_enable);1056bool window_get_idle_inhibition(DisplayServer::WindowID p_window_id) const;10571058ScreenData screen_get_data(int p_screen) const;1059int get_screen_count() const;10601061void pointer_set_constraint(PointerConstraint p_constraint);1062void pointer_set_hint(const Point2i &p_hint);1063PointerConstraint pointer_get_constraint() const;1064DisplayServer::WindowID pointer_get_pointed_window_id() const;1065DisplayServer::WindowID pointer_get_last_pointed_window_id() const;1066BitField<MouseButtonMask> pointer_get_button_mask() const;10671068void cursor_set_visible(bool p_visible);1069void cursor_set_shape(DisplayServer::CursorShape p_cursor_shape);10701071void cursor_set_custom_shape(DisplayServer::CursorShape p_cursor_shape);1072void cursor_shape_set_custom_image(DisplayServer::CursorShape p_cursor_shape, Ref<Image> p_image, const Point2i &p_hotspot);1073void cursor_shape_clear_custom_image(DisplayServer::CursorShape p_cursor_shape);10741075void window_set_ime_active(const bool p_active, DisplayServer::WindowID p_window_id);1076void window_set_ime_position(const Point2i &p_pos, DisplayServer::WindowID p_window_id);10771078int keyboard_get_layout_count() const;1079int keyboard_get_current_layout_index() const;1080void keyboard_set_current_layout_index(int p_index);1081String keyboard_get_layout_name(int p_index) const;10821083Key keyboard_get_key_from_physical(Key p_key) const;10841085void keyboard_echo_keys();10861087bool selection_has_mime(const String &p_mime) const;1088Vector<uint8_t> selection_get_mime(const String &p_mime) const;10891090void selection_set_text(const String &p_text);10911092// Optional primary support - requires wp_primary_selection_unstable_v11093bool primary_has_mime(const String &p_mime) const;1094Vector<uint8_t> primary_get_mime(const String &p_mime) const;10951096void primary_set_text(const String &p_text);10971098void commit_surfaces();10991100void set_frame();1101bool get_reset_frame();1102bool wait_frame_suspend_ms(int p_timeout);1103bool is_fifo_available() const;11041105uint64_t window_get_last_frame_time(DisplayServer::WindowID p_window_id) const;1106bool window_is_suspended(DisplayServer::WindowID p_window_id) const;1107bool is_suspended() const;11081109Error init();1110void destroy();1111};11121113#endif // WAYLAND_ENABLED111411151116