Blender V5.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
9
10#pragma once
11
12#include "../GHOST_Types.hh"
13#include "GHOST_System.hh"
15
16#ifdef WITH_GHOST_WAYLAND_DYNLOAD
18#endif
19#include <wayland-client.h>
20
21#include <mutex>
22#include <span>
23#include <string>
24
25#ifdef USE_EVENT_BACKGROUND_THREAD
26# include <atomic>
27# include <thread>
28#endif
29
30#ifdef WITH_GHOST_DBUS
32# include <atomic>
33# include <memory>
34#endif
35
37#ifdef WITH_GHOST_DBUS
38struct GWL_DBusEvent;
39#endif
40
42
47struct wl_buffer *ghost_wl_buffer_create_transparent_pixel(struct wl_shm *shm);
48
49bool ghost_wl_output_own(const struct wl_output *wl_output);
50void ghost_wl_output_tag(struct wl_output *wl_output);
51struct GWL_Output *ghost_wl_output_user_data(struct wl_output *wl_output);
52
64
67
70
71#ifdef WITH_GHOST_CSD
77bool ghost_wl_surface_own_csd_margin(const struct wl_surface *wl_surface);
78void ghost_wl_surface_tag_csd_margin(struct wl_surface *wl_surface);
79#endif
80
81/* Scaling to: translates from WAYLAND into GHOST (viewport local) coordinates.
82 * Scaling from: performs the reverse translation.
83 *
84 * Scaling "to" is used to map WAYLAND location cursor coordinates to GHOST coordinates.
85 * Scaling "from" is used to clamp cursor coordinates in WAYLAND local coordinates. */
86
88wl_fixed_t gwl_window_scale_wl_fixed_to(const GWL_WindowScaleParams &scale_params,
89 wl_fixed_t value);
90wl_fixed_t gwl_window_scale_wl_fixed_from(const GWL_WindowScaleParams &scale_params,
91 wl_fixed_t value);
92
93/* Avoid this where possible as scaling integers often incurs rounding errors.
94 * Scale #wl_fixed_t where possible.
95 *
96 * In general scale by large values where this is less likely to be a problem. */
97
98int gwl_window_scale_int_to(const GWL_WindowScaleParams &scale_params, int value);
99int gwl_window_scale_int_from(const GWL_WindowScaleParams &scale_params, int value);
100
106 int logical_size,
107 int *r_buffer_scale);
108
109#define FRACTIONAL_DENOMINATOR 120
110
117 Other = 0,
120};
121
122#ifdef WITH_GHOST_WAYLAND_DYNLOAD
126bool ghost_wl_dynload_libraries_init();
127void ghost_wl_dynload_libraries_exit();
128#endif
129
131
133 struct {
134 wl_output *output = nullptr;
135 } wl;
136
138 struct {
139 struct zxdg_output_v1 *output = nullptr;
141
143
150 int32_t size_native[2] = {0, 0};
152 int32_t size_mm[2] = {0, 0};
153
163 bool has_size_logical = false;
164
168
169 int transform = 0;
170 int scale = 1;
181
182 std::string make;
183 std::string model;
184};
185
186#ifdef WITH_GHOST_DBUS
193struct GHOST_SystemDBusSettings {
195 std::atomic<uint32_t> color_scheme = -1;
196};
197#endif /* WITH_GHOST_DBUS */
198
200 public:
201 GHOST_SystemWayland(bool background);
203
204 ~GHOST_SystemWayland() override;
205
206 GHOST_TSuccess init() override;
207
208 bool processEvents(bool waitForEvent) override;
209
211
213
214 GHOST_TSuccess getButtons(GHOST_Buttons &buttons) const override;
215
216 char *getClipboard(bool selection) const override;
217
218 void putClipboard(const char *buffer, bool selection) const override;
219
223 GHOST_TSuccess hasClipboardImage() const override;
224
231 uint *getClipboardImage(int *r_width, int *r_height) const override;
232
239 GHOST_TSuccess putClipboardImage(uint *rgba, int width, int height) const override;
240
241 uint8_t getNumDisplays() const override;
242
243 uint64_t getMilliSeconds() const override;
244
246 int32_t &x,
247 int32_t &y) const override;
249 int32_t x,
250 int32_t y) override;
251
254
255 uint32_t getCursorPreferredLogicalSize() const override;
256
257 void getMainDisplayDimensions(uint32_t &width, uint32_t &height) const override;
258
259 void getAllDisplayDimensions(uint32_t &width, uint32_t &height) const override;
260
262
264
265 GHOST_IWindow *createWindow(const char *title,
266 int32_t left,
267 int32_t top,
268 uint32_t width,
269 uint32_t height,
271 GHOST_GPUSettings gpu_settings,
272 const bool exclusive,
273 const bool is_dialog,
274 const GHOST_IWindow *parent_window) override;
275
276 GHOST_TCapabilityFlag getCapabilities() const override;
277
278 void setMultitouchGestures(const bool use) override;
279
280 /* WAYLAND utility functions (share window/system logic). */
281
283
285
287
289
291
293
301
302 void xdg_toplevel_icon_update(GHOST_WindowWayland *window, struct xdg_toplevel *toplevel);
303
304 /* WAYLAND direct-data access. */
305
306 struct wl_display *wl_display_get();
307 struct wl_compositor *wl_compositor_get();
308 struct wl_subcompositor *wl_subcompositor_get();
309 struct zwp_primary_selection_device_manager_v1 *wp_primary_selection_manager_get();
310 struct xdg_activation_v1 *xdg_activation_manager_get();
311 struct zwp_pointer_gestures_v1 *wp_pointer_gestures_get();
312 struct wp_fractional_scale_manager_v1 *wp_fractional_scale_manager_get();
313 struct wp_viewporter *wp_viewporter_get();
314 struct wp_color_manager_v1 *wp_color_manager_get();
315 struct wl_event_queue *wp_color_manager_queue_get();
316
319
320 struct xdg_wm_base *xdg_decor_shell_get();
321 struct zxdg_decoration_manager_v1 *xdg_decor_manager_get();
322 /* End `xdg_decor`. */
323
324 const std::span<GWL_Output *const> outputs_get() const;
325
326 struct wl_shm *wl_shm_get() const;
327
329 int32_t x,
330 int32_t y,
331 int32_t w,
332 int32_t h,
333 bool completed) const;
334 void ime_end(const GHOST_WindowWayland *win) const;
335
336 bool use_window_frame_get() const;
337 bool use_window_frame_csd_get() const;
338
339 int preferences_cursor_size_get() const;
340#ifdef WITH_GHOST_CSD
341 const GHOST_CSD_Layout &preferences_csd_button_layout_get() const;
342#endif
343
344 static const char *xdg_app_id_get();
345
346 /* WAYLAND utility functions. */
347
353 uint64_t ms_from_input_time(const uint32_t timestamp_as_uint);
354
359 GHOST_TSuccess pushEvent_maybe_pending(std::unique_ptr<const GHOST_IEvent> event);
360
362 void seat_active_set(const struct GWL_Seat *seat);
363
364 struct wl_seat *wl_seat_active_get_with_input_serial(uint32_t &serial);
365
375 bool output_unref(struct wl_output *wl_output);
376
378
385
387 const GHOST_TGrabCursorMode mode_current,
388 int32_t init_grab_xy[2],
389 const GHOST_Rect *wrap_bounds,
390 GHOST_TAxisFlag wrap_axis,
392 const struct GWL_WindowScaleParams &scale_params,
393 const GHOST_TDrawingContextType context_type);
394
395#ifdef USE_EVENT_BACKGROUND_THREAD
396 /* NOTE: allocate mutex so `const` functions can lock the mutex. */
397
400 std::mutex *server_mutex = nullptr;
401
410 std::mutex *timer_mutex = nullptr;
411
412 std::thread::id main_thread_id;
413
414 std::atomic<bool> has_pending_actions_for_window = false;
415#endif
416
417 private:
422 void display_destroy_and_free_all();
423
424#ifdef WITH_GHOST_DBUS
426 void dbus_watcher_start(bool watch_cursor_size);
428 void dbus_event_push(GWL_DBusEvent dbus_event);
430 void dbus_events_handle_pending();
436 void dbus_event_handle(const GWL_DBusEvent &dbus_event);
437#endif /* WITH_GHOST_DBUS */
438
439 struct GWL_Display *display_;
440
441#ifdef WITH_GHOST_DBUS
442 std::unique_ptr<GHOST_SystemDBusUnix> dbus_watcher_;
443 GHOST_SystemDBusSettings dbus_;
444#endif
445};
#define wl_display
#define wl_surface
bool ghost_wl_surface_own(const wl_surface *wl_surface)
void ghost_wl_output_tag(wl_output *wl_output)
GHOST_WindowWayland * ghost_wl_surface_user_data(wl_surface *wl_surface)
void ghost_wl_surface_tag_cursor_tablet(wl_surface *wl_surface)
bool ghost_wl_surface_own_cursor_tablet(const wl_surface *wl_surface)
GWL_Output * ghost_wl_output_user_data(wl_output *wl_output)
void ghost_wl_surface_tag(wl_surface *wl_surface)
bool ghost_wl_display_report_error_if_set(wl_display *display)
void ghost_wl_surface_tag_cursor_pointer(wl_surface *wl_surface)
bool ghost_wl_output_own(const wl_output *wl_output)
bool ghost_wl_surface_own_cursor_pointer(const wl_surface *wl_surface)
wl_buffer * ghost_wl_buffer_create_transparent_pixel(wl_shm *shm)
bool ghost_wl_surface_own_with_null_check(const wl_surface *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)
#define FRACTIONAL_DENOMINATOR
int gwl_window_scale_buffer_size_to(const GWL_WindowScaleParams &scale_params, int logical_size, int *r_buffer_scale)
int gwl_window_scale_int_from(const GWL_WindowScaleParams &scale_params, int value)
GWL_CurrentDesktopType
GHOST_TWindowState
GHOST_TStandardCursor
GHOST_TCapabilityFlag
GHOST_TAxisFlag
GHOST_TDrawingContextType
GHOST_TSuccess
GHOST_TGrabCursorMode
GHOST_TConsoleWindowState
void init()
unsigned long long int uint64_t
#define output
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()
bool supports_color_manager_extended_srgb_linear() const
struct wl_event_queue * wp_color_manager_queue_get()
void xdg_toplevel_icon_update(GHOST_WindowWayland *window, struct xdg_toplevel *toplevel)
bool supports_color_manager_feature_windows_scrgb() const
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
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_TimerManager * key_repeat_timer_manager()
GHOST_SystemWayland(bool background)
const std::span< GWL_Output *const > outputs_get() const
bool cursor_grab_use_software_display_get(const GHOST_TGrabCursorMode mode)
uint64_t ms_from_input_time(const uint32_t timestamp_as_uint)
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()
struct wl_subcompositor * wl_subcompositor_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)
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 pushEvent_maybe_pending(std::unique_ptr< const GHOST_IEvent > event)
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
struct wp_color_manager_v1 * wp_color_manager_get()
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, const GHOST_TDrawingContextType context_type)
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
const int state
struct zxdg_output_v1 * output
struct GWL_Output::@371061212041022101244377303143126301040355372254 wl
int32_t position_logical[2]
struct GWL_Output::@365164314301162002323105114026146113150233044062 xdg
int32_t size_native[2]
GHOST_SystemWayland * system
int32_t size_logical[2]