Blender V4.3
GHOST_SystemWayland.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#pragma once
11
12#include "../GHOST_Types.h"
13#include "GHOST_System.hh"
15
16#ifdef WITH_GHOST_WAYLAND_DYNLOAD
18#endif
19#include <wayland-client.h>
20
21#ifdef WITH_GHOST_WAYLAND_LIBDECOR
22# ifdef WITH_GHOST_WAYLAND_DYNLOAD
24# endif
25# include <libdecor.h>
26#endif
27
28#include <mutex>
29#include <string>
30
31#ifdef USE_EVENT_BACKGROUND_THREAD
32# include <atomic>
33# include <thread>
34#endif
35
37
39
40bool ghost_wl_output_own(const struct wl_output *wl_output);
41void ghost_wl_output_tag(struct wl_output *wl_output);
42struct GWL_Output *ghost_wl_output_user_data(struct wl_output *wl_output);
43
55
58
61
62/* Scaling to: translates from WAYLAND into GHOST (viewport local) coordinates.
63 * Scaling from: performs the reverse translation.
64 *
65 * Scaling "to" is used to map WAYLAND location cursor coordinates to GHOST coordinates.
66 * Scaling "from" is used to clamp cursor coordinates in WAYLAND local coordinates. */
67
69wl_fixed_t gwl_window_scale_wl_fixed_to(const GWL_WindowScaleParams &scale_params,
70 wl_fixed_t value);
71wl_fixed_t gwl_window_scale_wl_fixed_from(const GWL_WindowScaleParams &scale_params,
72 wl_fixed_t value);
73
74/* Avoid this where possible as scaling integers often incurs rounding errors.
75 * Scale #wl_fixed_t where possible.
76 *
77 * In general scale by large values where this is less likely to be a problem. */
78
79int gwl_window_scale_int_to(const GWL_WindowScaleParams &scale_params, int value);
80int gwl_window_scale_int_from(const GWL_WindowScaleParams &scale_params, int value);
81
82#define FRACTIONAL_DENOMINATOR 120
83
84#ifdef WITH_GHOST_WAYLAND_DYNLOAD
89bool ghost_wl_dynload_libraries_init();
90void ghost_wl_dynload_libraries_exit();
91#endif
92
93#if defined(WITH_GHOST_WAYLAND_LIBDECOR) && defined(WITH_VULKAN_BACKEND)
97int memfd_create_sealed_for_vulkan_hack(const char *name);
98#endif
99
101
103 struct {
104 wl_output *output = nullptr;
105 } wl;
106
108 struct {
109 struct zxdg_output_v1 *output = nullptr;
111
113
115 int32_t size_native[2] = {0, 0};
117 int32_t size_mm[2] = {0, 0};
118
120 bool has_size_logical = false;
121
125
126 int transform = 0;
127 int scale = 1;
138
139 std::string make;
140 std::string model;
141};
142
144 public:
145 GHOST_SystemWayland(bool background);
147
148 ~GHOST_SystemWayland() override;
149
150 GHOST_TSuccess init() override;
151
152 bool processEvents(bool waitForEvent) override;
153
155
157
158 GHOST_TSuccess getButtons(GHOST_Buttons &buttons) const override;
159
160 char *getClipboard(bool selection) const override;
161
162 void putClipboard(const char *buffer, bool selection) const override;
163
167 GHOST_TSuccess hasClipboardImage() const override;
168
175 uint *getClipboardImage(int *r_width, int *r_height) const override;
176
183 GHOST_TSuccess putClipboardImage(uint *rgba, int width, int height) const override;
184
185 uint8_t getNumDisplays() const override;
186
187 uint64_t getMilliSeconds() const override;
188
190 int32_t &x,
191 int32_t &y) const override;
193 int32_t x,
194 int32_t y) override;
195
196 GHOST_TSuccess getCursorPosition(int32_t &x, int32_t &y) const override;
198
199 void getMainDisplayDimensions(uint32_t &width, uint32_t &height) const override;
200
201 void getAllDisplayDimensions(uint32_t &width, uint32_t &height) const override;
202
204
206
207 GHOST_IWindow *createWindow(const char *title,
208 int32_t left,
209 int32_t top,
210 uint32_t width,
211 uint32_t height,
213 GHOST_GPUSettings gpuSettings,
214 const bool exclusive,
215 const bool is_dialog,
216 const GHOST_IWindow *parentWindow) override;
217
218 GHOST_TCapabilityFlag getCapabilities() const override;
219
220 void setMultitouchGestures(const bool use) override;
221
222 /* WAYLAND utility functions (share window/system logic). */
223
225
227
229 const uint8_t *mask,
230 int sizex,
231 int sizey,
232 int hotX,
233 int hotY,
234 bool canInvertColor);
235
237
239
241
242#ifdef USE_EVENT_BACKGROUND_THREAD
250#endif
251
252 /* WAYLAND direct-data access. */
253
254 struct wl_display *wl_display_get();
255 struct wl_compositor *wl_compositor_get();
256 struct zwp_primary_selection_device_manager_v1 *wp_primary_selection_manager_get();
257 struct xdg_activation_v1 *xdg_activation_manager_get();
258 struct zwp_pointer_gestures_v1 *wp_pointer_gestures_get();
259 struct wp_fractional_scale_manager_v1 *wp_fractional_scale_manager_get();
260 struct wp_viewporter *wp_viewporter_get();
261
262#ifdef WITH_GHOST_WAYLAND_LIBDECOR
263 libdecor *libdecor_context_get();
264#endif
265 struct xdg_wm_base *xdg_decor_shell_get();
266 struct zxdg_decoration_manager_v1 *xdg_decor_manager_get();
267 /* End `xdg_decor`. */
268
269 const std::vector<GWL_Output *> &outputs_get() const;
270
271 struct wl_shm *wl_shm_get() const;
272
274 int32_t x,
275 int32_t y,
276 int32_t w,
277 int32_t h,
278 bool completed) const;
279 void ime_end(const GHOST_WindowWayland *win) const;
280
281 static const char *xdg_app_id_get();
282
283 /* WAYLAND utility functions. */
284
290 uint64_t ms_from_input_time(const uint32_t timestamp_as_uint);
291
297
299 void seat_active_set(const struct GWL_Seat *seat);
300
301 struct wl_seat *wl_seat_active_get_with_input_serial(uint32_t &serial);
302
312 bool output_unref(struct wl_output *wl_output);
313
314 void output_scale_update(GWL_Output *output);
315
322
324 const GHOST_TGrabCursorMode mode_current,
325 int32_t init_grab_xy[2],
326 const GHOST_Rect *wrap_bounds,
327 GHOST_TAxisFlag wrap_axis,
329 const struct GWL_WindowScaleParams &scale_params);
330
331#ifdef WITH_GHOST_WAYLAND_LIBDECOR
332 static bool use_libdecor_runtime();
333#endif
334
335#ifdef USE_EVENT_BACKGROUND_THREAD
336 /* NOTE: allocate mutex so `const` functions can lock the mutex. */
337
340 std::mutex *server_mutex = nullptr;
341
350 std::mutex *timer_mutex = nullptr;
351
352 std::thread::id main_thread_id;
353
354 std::atomic<bool> has_pending_actions_for_window = false;
355#endif
356
357 private:
362 void display_destroy_and_free_all();
363
364 struct GWL_Display *display_;
365};
unsigned int uint
#define wl_display
#define wl_surface
wl_fixed_t gwl_window_scale_wl_fixed_to(const GWL_WindowScaleParams &scale_params, wl_fixed_t value)
wl_fixed_t gwl_window_scale_wl_fixed_from(const GWL_WindowScaleParams &scale_params, wl_fixed_t value)
int gwl_window_scale_int_to(const GWL_WindowScaleParams &scale_params, int value)
void ghost_wl_surface_tag_cursor_pointer(struct wl_surface *wl_surface)
#define FRACTIONAL_DENOMINATOR
bool ghost_wl_output_own(const struct wl_output *wl_output)
bool ghost_wl_surface_own_cursor_tablet(const struct wl_surface *wl_surface)
bool ghost_wl_display_report_error_if_set(wl_display *display)
void ghost_wl_output_tag(struct wl_output *wl_output)
int gwl_window_scale_int_from(const GWL_WindowScaleParams &scale_params, int value)
void ghost_wl_surface_tag_cursor_tablet(struct wl_surface *wl_surface)
bool ghost_wl_surface_own(const struct wl_surface *wl_surface)
bool ghost_wl_surface_own_cursor_pointer(const struct wl_surface *wl_surface)
struct GWL_Output * ghost_wl_output_user_data(struct wl_output *wl_output)
GHOST_WindowWayland * ghost_wl_surface_user_data(struct wl_surface *wl_surface)
void ghost_wl_surface_tag(struct wl_surface *wl_surface)
bool ghost_wl_surface_own_with_null_check(const struct wl_surface *wl_surface)
GHOST_TWindowState
GHOST_TStandardCursor
GHOST_TCapabilityFlag
Definition GHOST_Types.h:96
GHOST_TAxisFlag
GHOST_TSuccess
Definition GHOST_Types.h:87
GHOST_TGrabCursorMode
GHOST_TConsoleWindowState
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
struct zwp_primary_selection_device_manager_v1 * wp_primary_selection_manager_get()
static const char * xdg_app_id_get()
GHOST_TSuccess init() override
GHOST_TSuccess pushEvent_maybe_pending(const GHOST_IEvent *event)
bool window_surface_unref(const wl_surface *wl_surface)
uint64_t getMilliSeconds() const override
GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys &keys) const override
bool window_cursor_grab_set(const GHOST_TGrabCursorMode mode, const GHOST_TGrabCursorMode mode_current, int32_t init_grab_xy[2], const GHOST_Rect *wrap_bounds, GHOST_TAxisFlag wrap_axis, wl_surface *wl_surface, const struct GWL_WindowScaleParams &scale_params)
GHOST_TSuccess cursor_visibility_set(bool visible)
std::thread::id main_thread_id
struct wl_display * wl_display_get()
char * getClipboard(bool selection) const override
GHOST_TSuccess setCursorPosition(int32_t x, int32_t y) override
GHOST_TSuccess cursor_shape_check(GHOST_TStandardCursor cursorShape)
bool cursor_grab_use_software_display_get(const GHOST_TGrabCursorMode mode)
uint64_t ms_from_input_time(const uint32_t timestamp_as_uint)
GHOST_TimerManager * ghost_timer_manager()
uint * getClipboardImage(int *r_width, int *r_height) const override
struct xdg_wm_base * xdg_decor_shell_get()
struct wl_compositor * wl_compositor_get()
struct wp_fractional_scale_manager_v1 * wp_fractional_scale_manager_get()
void setMultitouchGestures(const bool use) override
struct wl_shm * wl_shm_get() const
GHOST_TSuccess getButtons(GHOST_Buttons &buttons) const override
GHOST_TSuccess cursor_shape_set(GHOST_TStandardCursor shape)
const std::vector< GWL_Output * > & outputs_get() const
GHOST_TSuccess disposeContext(GHOST_IContext *context) override
GHOST_IWindow * createWindow(const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_GPUSettings gpuSettings, const bool exclusive, const bool is_dialog, const GHOST_IWindow *parentWindow) override
struct wp_viewporter * wp_viewporter_get()
struct zxdg_decoration_manager_v1 * xdg_decor_manager_get()
struct wl_seat * wl_seat_active_get_with_input_serial(uint32_t &serial)
GHOST_TSuccess cursor_bitmap_get(GHOST_CursorBitmapRef *bitmap)
GHOST_TSuccess cursor_shape_custom_set(const uint8_t *bitmap, const uint8_t *mask, int sizex, int sizey, int hotX, int hotY, bool canInvertColor)
GHOST_TSuccess getCursorPosition(int32_t &x, int32_t &y) const override
void ime_begin(const GHOST_WindowWayland *win, int32_t x, int32_t y, int32_t w, int32_t h, bool completed) const
uint8_t getNumDisplays() const override
bool output_unref(struct wl_output *wl_output)
void putClipboard(const char *buffer, bool selection) const override
void output_scale_update(GWL_Output *output)
GHOST_TCapabilityFlag getCapabilities() const override
std::atomic< bool > has_pending_actions_for_window
bool processEvents(bool waitForEvent) override
void seat_active_set(const struct GWL_Seat *seat)
GHOST_TSuccess getCursorPositionClientRelative(const GHOST_IWindow *window, int32_t &x, int32_t &y) const override
GHOST_TSuccess setCursorPositionClientRelative(GHOST_IWindow *window, int32_t x, int32_t y) override
GHOST_TSuccess hasClipboardImage() const override
bool setConsoleWindowState(GHOST_TConsoleWindowState action) override
void getMainDisplayDimensions(uint32_t &width, uint32_t &height) const override
struct xdg_activation_v1 * xdg_activation_manager_get()
struct zwp_pointer_gestures_v1 * wp_pointer_gestures_get()
void ime_end(const GHOST_WindowWayland *win) const
GHOST_IContext * createOffscreenContext(GHOST_GPUSettings gpuSettings) override
void getAllDisplayDimensions(uint32_t &width, uint32_t &height) const override
GHOST_TSuccess putClipboardImage(uint *rgba, int width, int height) const override
static ulong state[N]
unsigned int uint32_t
Definition stdint.h:80
signed int int32_t
Definition stdint.h:77
unsigned char uint8_t
Definition stdint.h:78
unsigned __int64 uint64_t
Definition stdint.h:90
struct GWL_Output::@1502 wl
int32_t position_logical[2]
struct GWL_Output::@1503 xdg
int32_t size_native[2]
GHOST_SystemWayland * system
int32_t size_logical[2]