Blender V5.0
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
9
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(bool use_window_frame);
90void ghost_wl_dynload_libraries_exit();
91#endif
92
93struct GWL_Output {
94
96 struct {
97 wl_output *output = nullptr;
98 } wl;
99
101 struct {
102 struct zxdg_output_v1 *output = nullptr;
104
106
113 int32_t size_native[2] = {0, 0};
115 int32_t size_mm[2] = {0, 0};
116
126 bool has_size_logical = false;
127
131
132 int transform = 0;
133 int scale = 1;
144
145 std::string make;
146 std::string model;
147};
148
150 public:
151 GHOST_SystemWayland(bool background);
153
154 ~GHOST_SystemWayland() override;
155
156 GHOST_TSuccess init() override;
157
158 bool processEvents(bool waitForEvent) override;
159
161
163
164 GHOST_TSuccess getButtons(GHOST_Buttons &buttons) const override;
165
166 char *getClipboard(bool selection) const override;
167
168 void putClipboard(const char *buffer, bool selection) const override;
169
173 GHOST_TSuccess hasClipboardImage() const override;
174
181 uint *getClipboardImage(int *r_width, int *r_height) const override;
182
189 GHOST_TSuccess putClipboardImage(uint *rgba, int width, int height) const override;
190
191 uint8_t getNumDisplays() const override;
192
193 uint64_t getMilliSeconds() const override;
194
196 int32_t &x,
197 int32_t &y) const override;
199 int32_t x,
200 int32_t y) override;
201
204
205 uint32_t getCursorPreferredLogicalSize() const override;
206
207 void getMainDisplayDimensions(uint32_t &width, uint32_t &height) const override;
208
209 void getAllDisplayDimensions(uint32_t &width, uint32_t &height) const override;
210
212
214
215 GHOST_IWindow *createWindow(const char *title,
217 int32_t top,
218 uint32_t width,
219 uint32_t height,
221 GHOST_GPUSettings gpu_settings,
222 const bool exclusive,
223 const bool is_dialog,
224 const GHOST_IWindow *parent_window) override;
225
226 GHOST_TCapabilityFlag getCapabilities() const override;
227
228 void setMultitouchGestures(const bool use) override;
229
230 /* WAYLAND utility functions (share window/system logic). */
231
233
235
237
239
241
243
244#ifdef USE_EVENT_BACKGROUND_THREAD
252#endif
253
254 /* WAYLAND direct-data access. */
255
256 struct wl_display *wl_display_get();
257 struct wl_compositor *wl_compositor_get();
258 struct zwp_primary_selection_device_manager_v1 *wp_primary_selection_manager_get();
259 struct xdg_activation_v1 *xdg_activation_manager_get();
260 struct zwp_pointer_gestures_v1 *wp_pointer_gestures_get();
261 struct wp_fractional_scale_manager_v1 *wp_fractional_scale_manager_get();
262 struct wp_viewporter *wp_viewporter_get();
263
264#ifdef WITH_GHOST_WAYLAND_LIBDECOR
265 libdecor *libdecor_context_get();
266#endif
267 struct xdg_wm_base *xdg_decor_shell_get();
268 struct zxdg_decoration_manager_v1 *xdg_decor_manager_get();
269 /* End `xdg_decor`. */
270
271 const std::vector<GWL_Output *> &outputs_get() const;
272
273 struct wl_shm *wl_shm_get() const;
274
276 int32_t x,
277 int32_t y,
278 int32_t w,
279 int32_t h,
280 bool completed) const;
281 void ime_end(const GHOST_WindowWayland *win) const;
282
284
285 static const char *xdg_app_id_get();
286
287 /* WAYLAND utility functions. */
288
294 uint64_t ms_from_input_time(const uint32_t timestamp_as_uint);
295
301
303 void seat_active_set(const struct GWL_Seat *seat);
304
305 struct wl_seat *wl_seat_active_get_with_input_serial(uint32_t &serial);
306
316 bool output_unref(struct wl_output *wl_output);
317
319
326
328 const GHOST_TGrabCursorMode mode_current,
329 int32_t init_grab_xy[2],
330 const GHOST_Rect *wrap_bounds,
331 GHOST_TAxisFlag wrap_axis,
333 const struct GWL_WindowScaleParams &scale_params);
334
335#ifdef WITH_GHOST_WAYLAND_LIBDECOR
336 static bool use_libdecor_runtime();
337#endif
338
339#ifdef USE_EVENT_BACKGROUND_THREAD
340 /* NOTE: allocate mutex so `const` functions can lock the mutex. */
341
344 std::mutex *server_mutex = nullptr;
345
354 std::mutex *timer_mutex = nullptr;
355
356 std::thread::id main_thread_id;
357
358 std::atomic<bool> has_pending_actions_for_window = false;
359#endif
360
361 private:
366 void display_destroy_and_free_all();
367
368 struct GWL_Display *display_;
369};
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
GHOST_TAxisFlag
GHOST_TSuccess
Definition GHOST_Types.h:57
GHOST_TGrabCursorMode
GHOST_TConsoleWindowState
return true
unsigned long long int uint64_t
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_IContext * createOffscreenContext(GHOST_GPUSettings gpu_settings) 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_SystemWayland(bool background)
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()
GHOST_IWindow * createWindow(const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_GPUSettings gpu_settings, const bool exclusive, const bool is_dialog, const GHOST_IWindow *parent_window) override
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
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 GHOST_CursorGenerator &cg)
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 cursor_shape_check(GHOST_TStandardCursor cursor_shape)
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()
uint32_t getCursorPreferredLogicalSize() const override
struct zwp_pointer_gestures_v1 * wp_pointer_gestures_get()
void ime_end(const GHOST_WindowWayland *win) const
void getAllDisplayDimensions(uint32_t &width, uint32_t &height) const override
GHOST_TSuccess putClipboardImage(uint *rgba, int width, int height) const override
uint top
#define output
static ulong state[N]
static int left
struct GWL_Output::@200364346014063304064377215311155007053341370217 xdg
int32_t position_logical[2]
int32_t size_native[2]
GHOST_SystemWayland * system
struct GWL_Output::@375117327175370011033050254040132177200107056211 wl
wl_output * output
int32_t size_logical[2]