#ifndef PLATFORM_LINUX_WAYLAND_H #define PLATFORM_LINUX_WAYLAND_H // NOTE: no shm buffers here (unlike loo). vulkan owns presenting: vkCreateWaylandSurfaceKHR // only needs the wl_display and wl_surface, the driver attaches and commits buffers itself. typedef struct WaylandState WaylandState; struct WaylandState { //- globals struct wl_display *display; struct wl_registry *registry; struct wl_compositor *compositor; struct xdg_wm_base *xdg_wm_base; struct zwlr_layer_shell_v1 *layer_shell; struct wl_seat *seat; struct wp_cursor_shape_manager_v1 *cursor_shape_manager; struct zxdg_decoration_manager_v1 *decoration_manager; struct wl_data_device_manager *data_device_manager; u32 compositor_version; u32 layer_shell_version; //- surface struct wl_surface *surface; struct xdg_surface *xdg_surface; struct xdg_toplevel *xdg_toplevel; struct zwlr_layer_surface_v1 *layer_surface; struct zxdg_toplevel_decoration_v1 *decoration; b32 is_layer; b32 maximized; b32 suspended; // xdg-shell v6: compositor says we're not visible (niri: other workspace) //- frame pacing // NOTE: we only draw when the compositor asked for a frame (wl_surface.frame). a window that // is scrolled away or on another workspace gets no callbacks, so we simply stop drawing // instead of blocking inside vkQueuePresentKHR. struct wl_callback *frame_callback; u64 last_frame_done_ns; // when the compositor last consumed a frame u64 frame_requested_ns; // when we asked for the pending callback. unanswered for long = hidden //- input struct wl_keyboard *keyboard; struct wl_pointer *pointer; struct wp_cursor_shape_device_v1 *cursor_shape_device; struct xkb_context *xkb_context; struct xkb_keymap *xkb_keymap; struct xkb_state *xkb_state; PlatformInput input; u32 last_button_serial; // needed for xdg_toplevel.move u32 pointer_serial; // last enter, needed to change the cursor shape u32 cursor; // PlatformCursor currently shown //- drag and drop (files, text/uri-list) struct wl_data_device *data_device; struct wl_data_offer *pending_offer; // newest offer, its mime types are still arriving b32 pending_offer_uri; // pending_offer offered text/uri-list struct wl_data_offer *drag_offer; // the offer of the drag over our surface b32 drag_offer_uri; f32 drag_x; f32 drag_y; //- clipboard (wl_data_device selection) struct wl_data_offer *pending_offer_text_offer; // pending_offer had a text mime b32 pending_offer_text; struct wl_data_offer *selection_offer; // what the compositor says is on the clipboard now b32 selection_offer_text; char selection_mime[48]; struct wl_data_source *clip_source; // our own selection, while we own it char *clip_data; // malloc'd, what we serve on send u64 clip_size; b32 clip_pending; // set by platform_clipboard_set, applied by the pump u32 input_serial; // last key / button serial, set_selection needs one // key repeat, wayland leaves it to the client s32 repeat_rate; // per second, 0 = off s32 repeat_delay_ms; u32 repeat_key; // evdev keycode, 0 = nothing held u64 repeat_next_ns; //- size u32 width; // logical u32 height; u32 scale; // integer buffer scale b32 resized; b32 configured; b32 should_close; }; // NOTE: fills window->wayland, false when there is no wayland display (the caller tries x11) internal b32 wayland_window_open(PlatformWindow *window, WindowParams params); // NOTE: blocks up to timeout_ms (-1 forever) for wayland events or extra_fd becoming readable. // fills input. false once the window should close. internal b32 wayland_window_pump(PlatformWindow *window, PlatformInput *input, s64 timeout_ns, int *extra_fds, u32 extra_count, u32 *ready_mask); internal void wayland_window_size(PlatformWindow *window, u32 *width, u32 *height, u32 *scale); internal b32 wayland_window_take_resized(PlatformWindow *window); internal void wayland_window_close(PlatformWindow *window); internal void wayland_window_begin_move(PlatformWindow *window); internal void wayland_window_toggle_maximized(PlatformWindow *window); internal void wayland_window_request_frame(PlatformWindow *window); // call right before presenting internal void wayland_window_cancel_frame(PlatformWindow *window); // the present didn't happen internal b32 wayland_window_frame_ready(PlatformWindow *window); internal void wayland_window_set_cursor(PlatformWindow *window, PlatformCursor cursor); internal void wayland_clipboard_set(PlatformWindow *window, const char *data, u64 size); internal String8 wayland_clipboard_get(PlatformWindow *window, Arena *arena); #endif // PLATFORM_LINUX_WAYLAND_H