std1.0.0-beta-7 SafeC docs

Module gui::gui_wayland

#include <std/gui/gui_wayland.h> source

GUI: the Wayland backend (Linux).

A complete struct GuiBackend (gui_backend.h) on the Wayland protocol. Nothing is linked: libwayland-client.so.0 is dlopen()ed on first use, together with libxkbcommon.so.0 (keymaps, UTF-8 text, dead keys) and libwayland-cursor.so.0 (cursor themes) when they are installed, so the same binary still runs, through X11, on a system without Wayland.

Which backend a Linux program uses is decided at its first window (or first clipboard/clock call):

SAFEC_GUI_BACKEND=wayland   Wayland (fails cleanly if there is none)
SAFEC_GUI_BACKEND=x11       X11 (on a Wayland desktop: through Xwayland)
SAFEC_GUI_BACKEND=headless  the in-memory backend (gui_headless.h)
unset / anything else       Wayland if $WAYLAND_DISPLAY is set, the
                            library loads and the compositor answers;
                            X11 otherwise.

A program can also force it with gui_use_wayland() before its first window.

What it does (the protocol objects in parentheses):

windows      xdg-shell toplevels (xdg_wm_base, xdg_surface,
             xdg_toplevel), any number of them, each its own surface.
             Title, app id ($SAFEC_GUI_APP_ID, else the program's
             name), min/max size, close button, compositor-driven
             resizes (tiling, maximize) arrive as GUI_EVENT_RESIZE.
presenting   wl_shm buffers, double-buffered (a third or fourth one
             only while the compositor still holds both), damage-only
             copies, throttled by frame callbacks: a present while the
             previous frame is still pending is coalesced into the next
             frame. A GPU presenter (gui_gl.h) replaces all of this
             with EGL.
HiDPI        wp_fractional_scale_v1 + wp_viewporter (e.g. 1.25 or 1.5
             — the buffer is exactly the surface's size in device
             pixels), else wl_surface.preferred_buffer_scale, else the
             scale of the outputs the window is on; GUI_EVENT_SCALE
             when it changes. $SAFEC_GUI_SCALE overrides it.
decorations  server-side via zxdg_decoration_manager_v1 when the
             compositor offers it (sway, KDE, wlroots compositors,
             Weston >= 14). Without it (GNOME's Mutter, older Weston)
             windows have NO decorations: std/gui draws no client-side
             title bar — put your own close/move controls in the UI if
             you target those compositors. decorated = 0 asks for none.
input        wl_seat: pointer (enter/leave, motion, buttons, wheel —
             high-resolution value120 / discrete steps / smooth
             scrolling), keyboard (xkbcommon keymaps from the
             compositor, Shift/Ctrl/Alt/Super, dead keys and compose
             sequences, client-side key repeat at the compositor's
             rate). Without libxkbcommon keys are mapped as a US
             layout. Seats that gain or lose devices are followed.
cursors      wp_cursor_shape_v1 when offered, else the XCursor theme
             ($XCURSOR_THEME / $XCURSOR_SIZE) through libwayland-cursor.
clipboard    wl_data_device text selection (UTF-8; reads wait up to a
             second for the other client). Setting it needs a recent
             input event's serial — like every Wayland client, a
             program can only take the clipboard while it has focus.

Not available on Wayland by design: window positions (set_position() is ignored and pos_x()/pos_y() stay GUI_POS_DEFAULT unless set), raising or focusing a window (focus() is a no-op), and always-on-top (topmost is ignored).

Verified against real compositors (tests/stdlib/wayland/run.sh: sway headless with grim/wtype/wlrctl, and Weston headless).

Functions

gui_wayland_backendThe Wayland backend's table; null on a target without Wayland support (anything but Linux).
gui_wayland_available1 if libwayland-client loads and a compositor accepts the connection (connects on the first call; the connection is then the backend's).
gui_use_waylandInstalls the Wayland backend (gui_set_backend) if it is available. Returns 0, changing nothing, if it isn't or a window already exists.