wayland_thread.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. /**************************************************************************/
  2. /* wayland_thread.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef WAYLAND_THREAD_H
  31. #define WAYLAND_THREAD_H
  32. #ifdef WAYLAND_ENABLED
  33. #include "key_mapping_xkb.h"
  34. #ifdef SOWRAP_ENABLED
  35. #include "wayland/dynwrappers/wayland-client-core-so_wrap.h"
  36. #include "wayland/dynwrappers/wayland-cursor-so_wrap.h"
  37. #include "wayland/dynwrappers/wayland-egl-core-so_wrap.h"
  38. #include "xkbcommon-so_wrap.h"
  39. #else
  40. #include <wayland-client-core.h>
  41. #include <wayland-cursor.h>
  42. #include <xkbcommon/xkbcommon.h>
  43. #endif // SOWRAP_ENABLED
  44. // These must go after the Wayland client include to work properly.
  45. #include "wayland/protocol/idle_inhibit.gen.h"
  46. #include "wayland/protocol/primary_selection.gen.h"
  47. // These three protocol headers name wl_pointer method arguments as `pointer`,
  48. // which is the same name as X11's pointer typedef. This trips some very
  49. // annoying shadowing warnings. A `#define` works around this issue.
  50. #define pointer wl_pointer
  51. #include "wayland/protocol/pointer_constraints.gen.h"
  52. #include "wayland/protocol/pointer_gestures.gen.h"
  53. #include "wayland/protocol/relative_pointer.gen.h"
  54. #undef pointer
  55. #include "wayland/protocol/fractional_scale.gen.h"
  56. #include "wayland/protocol/tablet.gen.h"
  57. #include "wayland/protocol/viewporter.gen.h"
  58. #include "wayland/protocol/wayland.gen.h"
  59. #include "wayland/protocol/xdg_activation.gen.h"
  60. #include "wayland/protocol/xdg_decoration.gen.h"
  61. #include "wayland/protocol/xdg_foreign.gen.h"
  62. #include "wayland/protocol/xdg_shell.gen.h"
  63. #ifdef LIBDECOR_ENABLED
  64. #ifdef SOWRAP_ENABLED
  65. #include "dynwrappers/libdecor-so_wrap.h"
  66. #else
  67. #include <libdecor-0/libdecor.h>
  68. #endif // SOWRAP_ENABLED
  69. #endif // LIBDECOR_ENABLED
  70. #include "core/os/thread.h"
  71. #include "servers/display_server.h"
  72. class WaylandThread {
  73. public:
  74. // Messages used for exchanging information between Godot's and Wayland's thread.
  75. class Message : public RefCounted {
  76. public:
  77. Message() {}
  78. virtual ~Message() = default;
  79. };
  80. // Message data for window rect changes.
  81. class WindowRectMessage : public Message {
  82. public:
  83. // NOTE: This is in "scaled" terms. For example, if there's a 1920x1080 rect
  84. // with a scale factor of 2, the actual value of `rect` will be 3840x2160.
  85. Rect2i rect;
  86. };
  87. class WindowEventMessage : public Message {
  88. public:
  89. DisplayServer::WindowEvent event;
  90. };
  91. class InputEventMessage : public Message {
  92. public:
  93. Ref<InputEvent> event;
  94. };
  95. class DropFilesEventMessage : public Message {
  96. public:
  97. Vector<String> files;
  98. };
  99. struct RegistryState {
  100. WaylandThread *wayland_thread;
  101. // Core Wayland globals.
  102. struct wl_shm *wl_shm = nullptr;
  103. uint32_t wl_shm_name = 0;
  104. struct wl_compositor *wl_compositor = nullptr;
  105. uint32_t wl_compositor_name = 0;
  106. struct wl_subcompositor *wl_subcompositor = nullptr;
  107. uint32_t wl_subcompositor_name = 0;
  108. struct wl_data_device_manager *wl_data_device_manager = nullptr;
  109. uint32_t wl_data_device_manager_name = 0;
  110. List<struct wl_output *> wl_outputs;
  111. List<struct wl_seat *> wl_seats;
  112. // xdg-shell globals.
  113. struct xdg_wm_base *xdg_wm_base = nullptr;
  114. uint32_t xdg_wm_base_name = 0;
  115. struct zxdg_exporter_v1 *wl_exporter = nullptr;
  116. uint32_t wl_exporter_name = 0;
  117. // wayland-protocols globals.
  118. struct wp_viewporter *wp_viewporter = nullptr;
  119. uint32_t wp_viewporter_name = 0;
  120. struct wp_fractional_scale_manager_v1 *wp_fractional_scale_manager = nullptr;
  121. uint32_t wp_fractional_scale_manager_name = 0;
  122. struct zxdg_decoration_manager_v1 *xdg_decoration_manager = nullptr;
  123. uint32_t xdg_decoration_manager_name = 0;
  124. struct xdg_activation_v1 *xdg_activation = nullptr;
  125. uint32_t xdg_activation_name = 0;
  126. struct zwp_primary_selection_device_manager_v1 *wp_primary_selection_device_manager = nullptr;
  127. uint32_t wp_primary_selection_device_manager_name = 0;
  128. struct zwp_relative_pointer_manager_v1 *wp_relative_pointer_manager = nullptr;
  129. uint32_t wp_relative_pointer_manager_name = 0;
  130. struct zwp_pointer_constraints_v1 *wp_pointer_constraints = nullptr;
  131. uint32_t wp_pointer_constraints_name = 0;
  132. struct zwp_pointer_gestures_v1 *wp_pointer_gestures = nullptr;
  133. uint32_t wp_pointer_gestures_name = 0;
  134. struct zwp_idle_inhibit_manager_v1 *wp_idle_inhibit_manager = nullptr;
  135. uint32_t wp_idle_inhibit_manager_name = 0;
  136. struct zwp_tablet_manager_v2 *wp_tablet_manager = nullptr;
  137. uint32_t wp_tablet_manager_name = 0;
  138. };
  139. // General Wayland-specific states. Shouldn't be accessed directly.
  140. // TODO: Make private?
  141. struct WindowState {
  142. DisplayServer::WindowID id;
  143. Rect2i rect;
  144. DisplayServer::WindowMode mode = DisplayServer::WINDOW_MODE_WINDOWED;
  145. bool suspended = false;
  146. // These are true by default as it isn't guaranteed that we'll find an
  147. // xdg-shell implementation with wm_capabilities available. If and once we
  148. // receive a wm_capabilities event these will get reset and updated with
  149. // whatever the compositor says.
  150. bool can_minimize = false;
  151. bool can_maximize = false;
  152. bool can_fullscreen = false;
  153. HashSet<struct wl_output *> wl_outputs;
  154. // NOTE: If for whatever reason this callback is destroyed _while_ the event
  155. // thread is still running, it might be a good idea to set its user data to
  156. // `nullptr`. From some initial testing of mine, it looks like it might still
  157. // be called even after being destroyed, pointing to probably invalid window
  158. // data by then and segfaulting hard.
  159. struct wl_callback *frame_callback = nullptr;
  160. struct wl_surface *wl_surface = nullptr;
  161. struct xdg_surface *xdg_surface = nullptr;
  162. struct xdg_toplevel *xdg_toplevel = nullptr;
  163. struct wp_viewport *wp_viewport = nullptr;
  164. struct wp_fractional_scale_v1 *wp_fractional_scale = nullptr;
  165. struct zxdg_exported_v1 *xdg_exported = nullptr;
  166. String exported_handle;
  167. // Currently applied buffer scale.
  168. int buffer_scale = 1;
  169. // Buffer scale must be applied right before rendering but _after_ committing
  170. // everything else or otherwise we might have an inconsistent state (e.g.
  171. // double scale and odd resolution). This flag assists with that; when set,
  172. // on the next frame, we'll commit whatever is set in `buffer_scale`.
  173. bool buffer_scale_changed = false;
  174. // NOTE: The preferred buffer scale is currently only dynamically calculated.
  175. // It can be accessed by calling `window_state_get_preferred_buffer_scale`.
  176. // Override used by the fractional scale add-on object. If less or equal to 0
  177. // (default) then the normal output-based scale is used instead.
  178. double fractional_scale = 0;
  179. // What the compositor is recommending us.
  180. double preferred_fractional_scale = 0;
  181. struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration = nullptr;
  182. struct zwp_idle_inhibitor_v1 *wp_idle_inhibitor = nullptr;
  183. #ifdef LIBDECOR_ENABLED
  184. // If this is null the xdg_* variables must be set and vice-versa. This way we
  185. // can handle this mess gracefully enough to hopefully being able of getting
  186. // rid of this cleanly once we have our own CSDs.
  187. struct libdecor_frame *libdecor_frame = nullptr;
  188. struct libdecor_configuration *pending_libdecor_configuration = nullptr;
  189. #endif
  190. RegistryState *registry;
  191. WaylandThread *wayland_thread;
  192. };
  193. // "High level" Godot-side screen data.
  194. struct ScreenData {
  195. // Geometry data.
  196. Point2i position;
  197. String make;
  198. String model;
  199. Size2i size;
  200. Size2i physical_size;
  201. float refresh_rate = -1;
  202. int scale = 1;
  203. };
  204. struct ScreenState {
  205. uint32_t wl_output_name = 0;
  206. ScreenData pending_data;
  207. ScreenData data;
  208. WaylandThread *wayland_thread;
  209. };
  210. enum class Gesture {
  211. NONE,
  212. MAGNIFY,
  213. };
  214. enum class PointerConstraint {
  215. NONE,
  216. LOCKED,
  217. CONFINED,
  218. };
  219. struct PointerData {
  220. Point2i position;
  221. uint32_t motion_time = 0;
  222. // Relative motion has its own optional event and so needs its own time.
  223. Vector2 relative_motion;
  224. uint32_t relative_motion_time = 0;
  225. BitField<MouseButtonMask> pressed_button_mask;
  226. MouseButton last_button_pressed = MouseButton::NONE;
  227. Point2i last_pressed_position;
  228. // This is needed to check for a new double click every time.
  229. bool double_click_begun = false;
  230. uint32_t button_time = 0;
  231. uint32_t button_serial = 0;
  232. uint32_t scroll_type = WL_POINTER_AXIS_SOURCE_WHEEL;
  233. // The amount "scrolled" in pixels, in each direction.
  234. Vector2 scroll_vector;
  235. // The amount of scroll "clicks" in each direction.
  236. Vector2i discrete_scroll_vector;
  237. uint32_t pinch_scale = 1;
  238. };
  239. struct TabletToolData {
  240. Point2i position;
  241. Vector2 tilt;
  242. uint32_t pressure = 0;
  243. BitField<MouseButtonMask> pressed_button_mask;
  244. MouseButton last_button_pressed = MouseButton::NONE;
  245. Point2i last_pressed_position;
  246. bool double_click_begun = false;
  247. // Note: the protocol doesn't have it (I guess that this isn't really meant to
  248. // be used as a mouse...), but we'll hack one in with the current ticks.
  249. uint64_t button_time = 0;
  250. uint64_t motion_time = 0;
  251. uint32_t proximity_serial = 0;
  252. struct wl_surface *proximal_surface = nullptr;
  253. };
  254. struct TabletToolState {
  255. struct wl_seat *wl_seat = nullptr;
  256. struct wl_surface *last_surface = nullptr;
  257. bool is_eraser = false;
  258. TabletToolData data_pending;
  259. TabletToolData data;
  260. };
  261. struct OfferState {
  262. HashSet<String> mime_types;
  263. };
  264. struct SeatState {
  265. RegistryState *registry = nullptr;
  266. WaylandThread *wayland_thread = nullptr;
  267. struct wl_seat *wl_seat = nullptr;
  268. uint32_t wl_seat_name = 0;
  269. // Pointer.
  270. struct wl_pointer *wl_pointer = nullptr;
  271. uint32_t pointer_enter_serial = 0;
  272. struct wl_surface *pointed_surface = nullptr;
  273. struct wl_surface *last_pointed_surface = nullptr;
  274. struct zwp_relative_pointer_v1 *wp_relative_pointer = nullptr;
  275. struct zwp_locked_pointer_v1 *wp_locked_pointer = nullptr;
  276. struct zwp_confined_pointer_v1 *wp_confined_pointer = nullptr;
  277. struct zwp_pointer_gesture_pinch_v1 *wp_pointer_gesture_pinch = nullptr;
  278. // NOTE: According to the wp_pointer_gestures protocol specification, there
  279. // can be only one active gesture at a time.
  280. Gesture active_gesture = Gesture::NONE;
  281. // Used for delta calculations.
  282. // NOTE: The wp_pointer_gestures protocol keeps track of the total scale of
  283. // the pinch gesture, while godot instead wants its delta.
  284. wl_fixed_t old_pinch_scale = 0;
  285. struct wl_surface *cursor_surface = nullptr;
  286. struct wl_callback *cursor_frame_callback = nullptr;
  287. uint32_t cursor_time_ms = 0;
  288. // This variable is needed to buffer all pointer changes until a
  289. // wl_pointer.frame event, as per Wayland's specification. Everything is
  290. // first set in `data_buffer` and then `data` is set with its contents on
  291. // an input frame event. All methods should generally read from
  292. // `pointer_data` and write to `data_buffer`.
  293. PointerData pointer_data_buffer;
  294. PointerData pointer_data;
  295. // Keyboard.
  296. struct wl_keyboard *wl_keyboard = nullptr;
  297. struct xkb_context *xkb_context = nullptr;
  298. struct xkb_keymap *xkb_keymap = nullptr;
  299. struct xkb_state *xkb_state = nullptr;
  300. const char *keymap_buffer = nullptr;
  301. uint32_t keymap_buffer_size = 0;
  302. xkb_layout_index_t current_layout_index = 0;
  303. int32_t repeat_key_delay_msec = 0;
  304. int32_t repeat_start_delay_msec = 0;
  305. xkb_keycode_t repeating_keycode = XKB_KEYCODE_INVALID;
  306. uint64_t last_repeat_start_msec = 0;
  307. uint64_t last_repeat_msec = 0;
  308. bool shift_pressed = false;
  309. bool ctrl_pressed = false;
  310. bool alt_pressed = false;
  311. bool meta_pressed = false;
  312. uint32_t last_key_pressed_serial = 0;
  313. struct wl_data_device *wl_data_device = nullptr;
  314. // Drag and drop.
  315. struct wl_data_offer *wl_data_offer_dnd = nullptr;
  316. uint32_t dnd_enter_serial = 0;
  317. // Clipboard.
  318. struct wl_data_source *wl_data_source_selection = nullptr;
  319. Vector<uint8_t> selection_data;
  320. struct wl_data_offer *wl_data_offer_selection = nullptr;
  321. // Primary selection.
  322. struct zwp_primary_selection_device_v1 *wp_primary_selection_device = nullptr;
  323. struct zwp_primary_selection_source_v1 *wp_primary_selection_source = nullptr;
  324. Vector<uint8_t> primary_data;
  325. struct zwp_primary_selection_offer_v1 *wp_primary_selection_offer = nullptr;
  326. // Tablet.
  327. struct zwp_tablet_seat_v2 *wp_tablet_seat = nullptr;
  328. List<struct zwp_tablet_tool_v2 *> tablet_tools;
  329. };
  330. struct CustomCursor {
  331. struct wl_buffer *wl_buffer = nullptr;
  332. uint32_t *buffer_data = nullptr;
  333. uint32_t buffer_data_size = 0;
  334. RID rid;
  335. Point2i hotspot;
  336. };
  337. private:
  338. struct ThreadData {
  339. SafeFlag thread_done;
  340. Mutex mutex;
  341. struct wl_display *wl_display = nullptr;
  342. };
  343. // FIXME: Is this the right thing to do?
  344. inline static const char *proxy_tag = "godot";
  345. Thread events_thread;
  346. ThreadData thread_data;
  347. WindowState main_window;
  348. List<Ref<Message>> messages;
  349. String cursor_theme_name;
  350. int unscaled_cursor_size = 24;
  351. // NOTE: Regarding screen scale handling, the cursor cache is currently
  352. // "static", by which I mean that we try to change it as little as possible and
  353. // thus will be as big as the largest screen. This is mainly due to the fact
  354. // that doing it dynamically doesn't look like it's worth it to me currently,
  355. // especially as usually screen scales don't change continuously.
  356. int cursor_scale = 1;
  357. struct wl_cursor_theme *wl_cursor_theme = nullptr;
  358. struct wl_cursor *wl_cursors[DisplayServer::CURSOR_MAX] = {};
  359. HashMap<DisplayServer::CursorShape, CustomCursor> custom_cursors;
  360. struct wl_cursor *current_wl_cursor = nullptr;
  361. struct CustomCursor *current_custom_cursor = nullptr;
  362. DisplayServer::CursorShape last_cursor_shape = DisplayServer::CURSOR_ARROW;
  363. PointerConstraint pointer_constraint = PointerConstraint::NONE;
  364. struct wl_display *wl_display = nullptr;
  365. struct wl_registry *wl_registry = nullptr;
  366. struct wl_seat *wl_seat_current = nullptr;
  367. bool frame = true;
  368. RegistryState registry;
  369. bool initialized = false;
  370. #ifdef LIBDECOR_ENABLED
  371. struct libdecor *libdecor_context = nullptr;
  372. #endif // LIBDECOR_ENABLED
  373. // Main polling method.
  374. static void _poll_events_thread(void *p_data);
  375. // Core Wayland event handlers.
  376. static void _wl_registry_on_global(void *data, struct wl_registry *wl_registry, uint32_t name, const char *interface, uint32_t version);
  377. static void _wl_registry_on_global_remove(void *data, struct wl_registry *wl_registry, uint32_t name);
  378. static void _wl_surface_on_enter(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output);
  379. static void _wl_surface_on_leave(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output);
  380. static void _wl_surface_on_preferred_buffer_scale(void *data, struct wl_surface *wl_surface, int32_t factor);
  381. static void _wl_surface_on_preferred_buffer_transform(void *data, struct wl_surface *wl_surface, uint32_t transform);
  382. static void _frame_wl_callback_on_done(void *data, struct wl_callback *wl_callback, uint32_t callback_data);
  383. 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);
  384. 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);
  385. static void _wl_output_on_done(void *data, struct wl_output *wl_output);
  386. static void _wl_output_on_scale(void *data, struct wl_output *wl_output, int32_t factor);
  387. static void _wl_output_on_name(void *data, struct wl_output *wl_output, const char *name);
  388. static void _wl_output_on_description(void *data, struct wl_output *wl_output, const char *description);
  389. static void _wl_seat_on_capabilities(void *data, struct wl_seat *wl_seat, uint32_t capabilities);
  390. static void _wl_seat_on_name(void *data, struct wl_seat *wl_seat, const char *name);
  391. static void _cursor_frame_callback_on_done(void *data, struct wl_callback *wl_callback, uint32_t time_ms);
  392. 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);
  393. static void _wl_pointer_on_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface);
  394. 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);
  395. 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);
  396. static void _wl_pointer_on_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value);
  397. static void _wl_pointer_on_frame(void *data, struct wl_pointer *wl_pointer);
  398. static void _wl_pointer_on_axis_source(void *data, struct wl_pointer *wl_pointer, uint32_t axis_source);
  399. static void _wl_pointer_on_axis_stop(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis);
  400. static void _wl_pointer_on_axis_discrete(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete);
  401. static void _wl_pointer_on_axis_value120(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t value120);
  402. static void _wl_pointer_on_axis_relative_direction(void *data, struct wl_pointer *wl_pointer, uint32_t axis, uint32_t direction);
  403. static void _wl_keyboard_on_keymap(void *data, struct wl_keyboard *wl_keyboard, uint32_t format, int32_t fd, uint32_t size);
  404. static void _wl_keyboard_on_enter(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys);
  405. static void _wl_keyboard_on_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface);
  406. 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);
  407. 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);
  408. static void _wl_keyboard_on_repeat_info(void *data, struct wl_keyboard *wl_keyboard, int32_t rate, int32_t delay);
  409. static void _wl_data_device_on_data_offer(void *data, struct wl_data_device *wl_data_device, struct wl_data_offer *id);
  410. 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);
  411. static void _wl_data_device_on_leave(void *data, struct wl_data_device *wl_data_device);
  412. 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);
  413. static void _wl_data_device_on_drop(void *data, struct wl_data_device *wl_data_device);
  414. static void _wl_data_device_on_selection(void *data, struct wl_data_device *wl_data_device, struct wl_data_offer *id);
  415. static void _wl_data_offer_on_offer(void *data, struct wl_data_offer *wl_data_offer, const char *mime_type);
  416. static void _wl_data_offer_on_source_actions(void *data, struct wl_data_offer *wl_data_offer, uint32_t source_actions);
  417. static void _wl_data_offer_on_action(void *data, struct wl_data_offer *wl_data_offer, uint32_t dnd_action);
  418. static void _wl_data_source_on_target(void *data, struct wl_data_source *wl_data_source, const char *mime_type);
  419. static void _wl_data_source_on_send(void *data, struct wl_data_source *wl_data_source, const char *mime_type, int32_t fd);
  420. static void _wl_data_source_on_cancelled(void *data, struct wl_data_source *wl_data_source);
  421. static void _wl_data_source_on_dnd_drop_performed(void *data, struct wl_data_source *wl_data_source);
  422. static void _wl_data_source_on_dnd_finished(void *data, struct wl_data_source *wl_data_source);
  423. static void _wl_data_source_on_action(void *data, struct wl_data_source *wl_data_source, uint32_t dnd_action);
  424. // xdg-shell event handlers.
  425. static void _xdg_wm_base_on_ping(void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial);
  426. static void _xdg_surface_on_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial);
  427. static void _xdg_toplevel_on_configure(void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height, struct wl_array *states);
  428. static void _xdg_toplevel_on_close(void *data, struct xdg_toplevel *xdg_toplevel);
  429. static void _xdg_toplevel_on_configure_bounds(void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height);
  430. static void _xdg_toplevel_on_wm_capabilities(void *data, struct xdg_toplevel *xdg_toplevel, struct wl_array *capabilities);
  431. // wayland-protocols event handlers.
  432. static void _wp_fractional_scale_on_preferred_scale(void *data, struct wp_fractional_scale_v1 *wp_fractional_scale_v1, uint32_t scale);
  433. 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);
  434. static void _wp_pointer_gesture_pinch_on_begin(void *data, struct zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1, uint32_t serial, uint32_t time, struct wl_surface *surface, uint32_t fingers);
  435. static void _wp_pointer_gesture_pinch_on_update(void *data, struct zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1, uint32_t time, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t scale, wl_fixed_t rotation);
  436. static void _wp_pointer_gesture_pinch_on_end(void *data, struct zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1, uint32_t serial, uint32_t time, int32_t cancelled);
  437. 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);
  438. 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);
  439. static void _wp_primary_selection_offer_on_offer(void *data, struct zwp_primary_selection_offer_v1 *zwp_primary_selection_offer_v1, const char *mime_type);
  440. 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);
  441. static void _wp_primary_selection_source_on_cancelled(void *data, struct zwp_primary_selection_source_v1 *wp_primary_selection_source_v1);
  442. static void _wp_tablet_seat_on_tablet_added(void *data, struct zwp_tablet_seat_v2 *zwp_tablet_seat_v2, struct zwp_tablet_v2 *id);
  443. static void _wp_tablet_seat_on_tool_added(void *data, struct zwp_tablet_seat_v2 *zwp_tablet_seat_v2, struct zwp_tablet_tool_v2 *id);
  444. static void _wp_tablet_seat_on_pad_added(void *data, struct zwp_tablet_seat_v2 *zwp_tablet_seat_v2, struct zwp_tablet_pad_v2 *id);
  445. static void _wp_tablet_tool_on_type(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, uint32_t tool_type);
  446. static void _wp_tablet_tool_on_hardware_serial(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, uint32_t hardware_serial_hi, uint32_t hardware_serial_lo);
  447. static void _wp_tablet_tool_on_hardware_id_wacom(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, uint32_t hardware_id_hi, uint32_t hardware_id_lo);
  448. static void _wp_tablet_tool_on_capability(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, uint32_t capability);
  449. static void _wp_tablet_tool_on_done(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2);
  450. static void _wp_tablet_tool_on_removed(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2);
  451. static void _wp_tablet_tool_on_proximity_in(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, uint32_t serial, struct zwp_tablet_v2 *tablet, struct wl_surface *surface);
  452. static void _wp_tablet_tool_on_proximity_out(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2);
  453. static void _wp_tablet_tool_on_down(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, uint32_t serial);
  454. static void _wp_tablet_tool_on_up(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2);
  455. static void _wp_tablet_tool_on_motion(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, wl_fixed_t x, wl_fixed_t y);
  456. static void _wp_tablet_tool_on_pressure(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, uint32_t pressure);
  457. static void _wp_tablet_tool_on_distance(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, uint32_t distance);
  458. static void _wp_tablet_tool_on_tilt(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, wl_fixed_t tilt_x, wl_fixed_t tilt_y);
  459. static void _wp_tablet_tool_on_rotation(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, wl_fixed_t degrees);
  460. static void _wp_tablet_tool_on_slider(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, int32_t position);
  461. static void _wp_tablet_tool_on_wheel(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, wl_fixed_t degrees, int32_t clicks);
  462. static void _wp_tablet_tool_on_button(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, uint32_t serial, uint32_t button, uint32_t state);
  463. static void _wp_tablet_tool_on_frame(void *data, struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2, uint32_t time);
  464. static void _xdg_toplevel_decoration_on_configure(void *data, struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration, uint32_t mode);
  465. static void _xdg_exported_on_exported(void *data, zxdg_exported_v1 *exported, const char *handle);
  466. static void _xdg_activation_token_on_done(void *data, struct xdg_activation_token_v1 *xdg_activation_token, const char *token);
  467. // Core Wayland event listeners.
  468. static constexpr struct wl_registry_listener wl_registry_listener = {
  469. .global = _wl_registry_on_global,
  470. .global_remove = _wl_registry_on_global_remove,
  471. };
  472. static constexpr struct wl_surface_listener wl_surface_listener = {
  473. .enter = _wl_surface_on_enter,
  474. .leave = _wl_surface_on_leave,
  475. .preferred_buffer_scale = _wl_surface_on_preferred_buffer_scale,
  476. .preferred_buffer_transform = _wl_surface_on_preferred_buffer_transform,
  477. };
  478. static constexpr struct wl_callback_listener frame_wl_callback_listener {
  479. .done = _frame_wl_callback_on_done,
  480. };
  481. static constexpr struct wl_output_listener wl_output_listener = {
  482. .geometry = _wl_output_on_geometry,
  483. .mode = _wl_output_on_mode,
  484. .done = _wl_output_on_done,
  485. .scale = _wl_output_on_scale,
  486. .name = _wl_output_on_name,
  487. .description = _wl_output_on_description,
  488. };
  489. static constexpr struct wl_seat_listener wl_seat_listener = {
  490. .capabilities = _wl_seat_on_capabilities,
  491. .name = _wl_seat_on_name,
  492. };
  493. static constexpr struct wl_callback_listener cursor_frame_callback_listener {
  494. .done = _cursor_frame_callback_on_done,
  495. };
  496. static constexpr struct wl_pointer_listener wl_pointer_listener = {
  497. .enter = _wl_pointer_on_enter,
  498. .leave = _wl_pointer_on_leave,
  499. .motion = _wl_pointer_on_motion,
  500. .button = _wl_pointer_on_button,
  501. .axis = _wl_pointer_on_axis,
  502. .frame = _wl_pointer_on_frame,
  503. .axis_source = _wl_pointer_on_axis_source,
  504. .axis_stop = _wl_pointer_on_axis_stop,
  505. .axis_discrete = _wl_pointer_on_axis_discrete,
  506. .axis_value120 = _wl_pointer_on_axis_value120,
  507. .axis_relative_direction = _wl_pointer_on_axis_relative_direction,
  508. };
  509. static constexpr struct wl_keyboard_listener wl_keyboard_listener = {
  510. .keymap = _wl_keyboard_on_keymap,
  511. .enter = _wl_keyboard_on_enter,
  512. .leave = _wl_keyboard_on_leave,
  513. .key = _wl_keyboard_on_key,
  514. .modifiers = _wl_keyboard_on_modifiers,
  515. .repeat_info = _wl_keyboard_on_repeat_info,
  516. };
  517. static constexpr struct wl_data_device_listener wl_data_device_listener = {
  518. .data_offer = _wl_data_device_on_data_offer,
  519. .enter = _wl_data_device_on_enter,
  520. .leave = _wl_data_device_on_leave,
  521. .motion = _wl_data_device_on_motion,
  522. .drop = _wl_data_device_on_drop,
  523. .selection = _wl_data_device_on_selection,
  524. };
  525. static constexpr struct wl_data_offer_listener wl_data_offer_listener = {
  526. .offer = _wl_data_offer_on_offer,
  527. .source_actions = _wl_data_offer_on_source_actions,
  528. .action = _wl_data_offer_on_action,
  529. };
  530. static constexpr struct wl_data_source_listener wl_data_source_listener = {
  531. .target = _wl_data_source_on_target,
  532. .send = _wl_data_source_on_send,
  533. .cancelled = _wl_data_source_on_cancelled,
  534. .dnd_drop_performed = _wl_data_source_on_dnd_drop_performed,
  535. .dnd_finished = _wl_data_source_on_dnd_finished,
  536. .action = _wl_data_source_on_action,
  537. };
  538. // xdg-shell event listeners.
  539. static constexpr struct xdg_wm_base_listener xdg_wm_base_listener = {
  540. .ping = _xdg_wm_base_on_ping,
  541. };
  542. static constexpr struct xdg_surface_listener xdg_surface_listener = {
  543. .configure = _xdg_surface_on_configure,
  544. };
  545. static constexpr struct xdg_toplevel_listener xdg_toplevel_listener = {
  546. .configure = _xdg_toplevel_on_configure,
  547. .close = _xdg_toplevel_on_close,
  548. .configure_bounds = _xdg_toplevel_on_configure_bounds,
  549. .wm_capabilities = _xdg_toplevel_on_wm_capabilities,
  550. };
  551. // wayland-protocols event listeners.
  552. static constexpr struct wp_fractional_scale_v1_listener wp_fractional_scale_listener = {
  553. .preferred_scale = _wp_fractional_scale_on_preferred_scale,
  554. };
  555. static constexpr struct zwp_relative_pointer_v1_listener wp_relative_pointer_listener = {
  556. .relative_motion = _wp_relative_pointer_on_relative_motion,
  557. };
  558. static constexpr struct zwp_pointer_gesture_pinch_v1_listener wp_pointer_gesture_pinch_listener = {
  559. .begin = _wp_pointer_gesture_pinch_on_begin,
  560. .update = _wp_pointer_gesture_pinch_on_update,
  561. .end = _wp_pointer_gesture_pinch_on_end,
  562. };
  563. static constexpr struct zwp_primary_selection_device_v1_listener wp_primary_selection_device_listener = {
  564. .data_offer = _wp_primary_selection_device_on_data_offer,
  565. .selection = _wp_primary_selection_device_on_selection,
  566. };
  567. static constexpr struct zwp_primary_selection_offer_v1_listener wp_primary_selection_offer_listener = {
  568. .offer = _wp_primary_selection_offer_on_offer,
  569. };
  570. static constexpr struct zwp_primary_selection_source_v1_listener wp_primary_selection_source_listener = {
  571. .send = _wp_primary_selection_source_on_send,
  572. .cancelled = _wp_primary_selection_source_on_cancelled,
  573. };
  574. static constexpr struct zwp_tablet_seat_v2_listener wp_tablet_seat_listener = {
  575. .tablet_added = _wp_tablet_seat_on_tablet_added,
  576. .tool_added = _wp_tablet_seat_on_tool_added,
  577. .pad_added = _wp_tablet_seat_on_pad_added,
  578. };
  579. static constexpr struct zwp_tablet_tool_v2_listener wp_tablet_tool_listener = {
  580. .type = _wp_tablet_tool_on_type,
  581. .hardware_serial = _wp_tablet_tool_on_hardware_serial,
  582. .hardware_id_wacom = _wp_tablet_tool_on_hardware_id_wacom,
  583. .capability = _wp_tablet_tool_on_capability,
  584. .done = _wp_tablet_tool_on_done,
  585. .removed = _wp_tablet_tool_on_removed,
  586. .proximity_in = _wp_tablet_tool_on_proximity_in,
  587. .proximity_out = _wp_tablet_tool_on_proximity_out,
  588. .down = _wp_tablet_tool_on_down,
  589. .up = _wp_tablet_tool_on_up,
  590. .motion = _wp_tablet_tool_on_motion,
  591. .pressure = _wp_tablet_tool_on_pressure,
  592. .distance = _wp_tablet_tool_on_distance,
  593. .tilt = _wp_tablet_tool_on_tilt,
  594. .rotation = _wp_tablet_tool_on_rotation,
  595. .slider = _wp_tablet_tool_on_slider,
  596. .wheel = _wp_tablet_tool_on_wheel,
  597. .button = _wp_tablet_tool_on_button,
  598. .frame = _wp_tablet_tool_on_frame,
  599. };
  600. static constexpr struct zxdg_exported_v1_listener xdg_exported_listener = {
  601. .handle = _xdg_exported_on_exported
  602. };
  603. static constexpr struct zxdg_toplevel_decoration_v1_listener xdg_toplevel_decoration_listener = {
  604. .configure = _xdg_toplevel_decoration_on_configure,
  605. };
  606. static constexpr struct xdg_activation_token_v1_listener xdg_activation_token_listener = {
  607. .done = _xdg_activation_token_on_done,
  608. };
  609. #ifdef LIBDECOR_ENABLED
  610. // libdecor event handlers.
  611. static void libdecor_on_error(struct libdecor *context, enum libdecor_error error, const char *message);
  612. static void libdecor_frame_on_configure(struct libdecor_frame *frame, struct libdecor_configuration *configuration, void *user_data);
  613. static void libdecor_frame_on_close(struct libdecor_frame *frame, void *user_data);
  614. static void libdecor_frame_on_commit(struct libdecor_frame *frame, void *user_data);
  615. static void libdecor_frame_on_dismiss_popup(struct libdecor_frame *frame, const char *seat_name, void *user_data);
  616. // libdecor event listeners.
  617. static constexpr struct libdecor_interface libdecor_interface = {
  618. .error = libdecor_on_error,
  619. .reserved0 = nullptr,
  620. .reserved1 = nullptr,
  621. .reserved2 = nullptr,
  622. .reserved3 = nullptr,
  623. .reserved4 = nullptr,
  624. .reserved5 = nullptr,
  625. .reserved6 = nullptr,
  626. .reserved7 = nullptr,
  627. .reserved8 = nullptr,
  628. .reserved9 = nullptr,
  629. };
  630. static constexpr struct libdecor_frame_interface libdecor_frame_interface = {
  631. .configure = libdecor_frame_on_configure,
  632. .close = libdecor_frame_on_close,
  633. .commit = libdecor_frame_on_commit,
  634. .dismiss_popup = libdecor_frame_on_dismiss_popup,
  635. .reserved0 = nullptr,
  636. .reserved1 = nullptr,
  637. .reserved2 = nullptr,
  638. .reserved3 = nullptr,
  639. .reserved4 = nullptr,
  640. .reserved5 = nullptr,
  641. .reserved6 = nullptr,
  642. .reserved7 = nullptr,
  643. .reserved8 = nullptr,
  644. .reserved9 = nullptr,
  645. };
  646. #endif // LIBDECOR_ENABLED
  647. static Vector<uint8_t> _read_fd(int fd);
  648. static int _allocate_shm_file(size_t size);
  649. static Vector<uint8_t> _wl_data_offer_read(struct wl_display *wl_display, const char *p_mime, struct wl_data_offer *wl_data_offer);
  650. 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);
  651. static void _seat_state_set_current(WaylandThread::SeatState &p_ss);
  652. static bool _seat_state_configure_key_event(WaylandThread::SeatState &p_seat, Ref<InputEventKey> p_event, xkb_keycode_t p_keycode, bool p_pressed);
  653. static void _wayland_state_update_cursor();
  654. void _set_current_seat(struct wl_seat *p_seat);
  655. bool _load_cursor_theme(int p_cursor_size);
  656. void _update_scale(int p_scale);
  657. public:
  658. Mutex &mutex = thread_data.mutex;
  659. struct wl_display *get_wl_display() const;
  660. // Core Wayland utilities for integrating with our own data structures.
  661. static bool wl_proxy_is_godot(struct wl_proxy *p_proxy);
  662. static void wl_proxy_tag_godot(struct wl_proxy *p_proxy);
  663. static WindowState *wl_surface_get_window_state(struct wl_surface *p_surface);
  664. static ScreenState *wl_output_get_screen_state(struct wl_output *p_output);
  665. static SeatState *wl_seat_get_seat_state(struct wl_seat *p_seat);
  666. static TabletToolState *wp_tablet_tool_get_state(struct zwp_tablet_tool_v2 *p_tool);
  667. static OfferState *wl_data_offer_get_offer_state(struct wl_data_offer *p_offer);
  668. static OfferState *wp_primary_selection_offer_get_offer_state(struct zwp_primary_selection_offer_v1 *p_offer);
  669. void seat_state_unlock_pointer(SeatState *p_ss);
  670. void seat_state_lock_pointer(SeatState *p_ss);
  671. void seat_state_set_hint(SeatState *p_ss, int p_x, int p_y);
  672. void seat_state_confine_pointer(SeatState *p_ss);
  673. static void seat_state_update_cursor(SeatState *p_ss);
  674. void seat_state_echo_keys(SeatState *p_ss);
  675. static int window_state_get_preferred_buffer_scale(WindowState *p_ws);
  676. static double window_state_get_scale_factor(WindowState *p_ws);
  677. static void window_state_update_size(WindowState *p_ws, int p_width, int p_height);
  678. static Vector2i scale_vector2i(const Vector2i &p_vector, double p_amount);
  679. void push_message(Ref<Message> message);
  680. bool has_message();
  681. Ref<Message> pop_message();
  682. void window_create(DisplayServer::WindowID p_window_id, int p_width, int p_height);
  683. struct wl_surface *window_get_wl_surface(DisplayServer::WindowID p_window_id) const;
  684. void window_set_max_size(DisplayServer::WindowID p_window_id, const Size2i &p_size);
  685. void window_set_min_size(DisplayServer::WindowID p_window_id, const Size2i &p_size);
  686. bool window_can_set_mode(DisplayServer::WindowID p_window_id, DisplayServer::WindowMode p_window_mode) const;
  687. void window_try_set_mode(DisplayServer::WindowID p_window_id, DisplayServer::WindowMode p_window_mode);
  688. DisplayServer::WindowMode window_get_mode(DisplayServer::WindowID p_window_id) const;
  689. void window_set_borderless(DisplayServer::WindowID p_window_id, bool p_borderless);
  690. void window_set_title(DisplayServer::WindowID p_window_id, const String &p_title);
  691. void window_set_app_id(DisplayServer::WindowID p_window_id, const String &p_app_id);
  692. bool window_is_focused(DisplayServer::WindowID p_window_id);
  693. // Optional - requires xdg_activation_v1
  694. void window_request_attention(DisplayServer::WindowID p_window_id);
  695. // Optional - require idle_inhibit_unstable_v1
  696. void window_set_idle_inhibition(DisplayServer::WindowID p_window_id, bool p_enable);
  697. bool window_get_idle_inhibition(DisplayServer::WindowID p_window_id) const;
  698. ScreenData screen_get_data(int p_screen) const;
  699. int get_screen_count() const;
  700. void pointer_set_constraint(PointerConstraint p_constraint);
  701. void pointer_set_hint(const Point2i &p_hint);
  702. PointerConstraint pointer_get_constraint() const;
  703. DisplayServer::WindowID pointer_get_pointed_window_id() const;
  704. BitField<MouseButtonMask> pointer_get_button_mask() const;
  705. void cursor_hide();
  706. void cursor_set_shape(DisplayServer::CursorShape p_cursor_shape);
  707. void cursor_set_custom_shape(DisplayServer::CursorShape p_cursor_shape);
  708. void cursor_shape_set_custom_image(DisplayServer::CursorShape p_cursor_shape, Ref<Image> p_image, const Point2i &p_hotspot);
  709. void cursor_shape_clear_custom_image(DisplayServer::CursorShape p_cursor_shape);
  710. int keyboard_get_layout_count() const;
  711. int keyboard_get_current_layout_index() const;
  712. void keyboard_set_current_layout_index(int p_index);
  713. String keyboard_get_layout_name(int p_index) const;
  714. Key keyboard_get_key_from_physical(Key p_key) const;
  715. void keyboard_echo_keys();
  716. bool selection_has_mime(const String &p_mime) const;
  717. Vector<uint8_t> selection_get_mime(const String &p_mime) const;
  718. void selection_set_text(const String &p_text);
  719. // Optional primary support - requires wp_primary_selection_unstable_v1
  720. bool primary_has_mime(const String &p_mime) const;
  721. Vector<uint8_t> primary_get_mime(const String &p_mime) const;
  722. void primary_set_text(const String &p_text);
  723. void set_frame();
  724. bool get_reset_frame();
  725. bool wait_frame_suspend_ms(int p_timeout);
  726. bool is_suspended() const;
  727. Error init();
  728. void destroy();
  729. };
  730. #endif // WAYLAND_ENABLED
  731. #endif // WAYLAND_THREAD_H