JFLib

plat/linux_wl.rs (Linux)#

Source: lib/plat/linux_wl.rs

linux_wl -- the Wayland display backend behind linux_disp::Display
                                    [src/plat/linux/wl_window.s, wl_wire.s, wl_present.s, ...]

  wl_connect() -> the backend, None when no compositor answers ($WAYLAND_DISPLAY in
       $XDG_RUNTIME_DIR, /run/user/UID, /mnt/wslg/runtime-dir)
  test hooks for linuxtest (synthetic events, no compositor needed): wl_test_event,
       wl_test_setup, wl_input_service, wl_cursor_image, wl_cursor_render, wl_test_protoerr,
       wl_test_roundtrip (a compositor or tools/wlproxy/wlinject.py)
  xkb_* (linux_xkb.rs): the keymap of the Wayland keyboard, also used by X11

The modules follow the assembly files:
  linux_wl_wire.rs     connection, object table, marshalling, fd passing, dispatch,
                       roundtrips, fatal errors, the jfgui_WLDEBUG trace   [wl_wire.s]
  linux_wl_proto.rs    interface descriptors (event tables) and requests    [wl_proto.s]
  linux_wl_window.rs   globals, xdg toplevels, configure, scale, commands, the wait loop
                                                                            [wl_window.s]
  linux_wl_present.rs  wl_shm buffers, damage, frame callbacks            [wl_present.s]
  linux_wl_input.rs    wl_seat pointer / keyboard, key repeat               [wl_input.s]
  linux_wl_tablet.rs   zwp_tablet_v2 pens                                  [wl_tablet.s]
  linux_wl_popup.rs    xdg_popup windows                                    [wl_popup.s]
  linux_wl_clip.rs     wl_data_device: clipboard both ways, drag and drop in and out
                                                                            [wl_clip.s]
  linux_wl_cursor.rs   cursor-shape protocol, own cursor images, custom cursors [wl_cursor.s]
  linux_wl_act.rs      xdg-activation: the launcher's token, raising and restoring windows
  linux_wl_gpu.rs      zwp_linux_dmabuf_v1: the GPU's buffers on a surface (programs against glibc)

State: the assembly's globals are one record (Wl) owned by this module, created on the
first use (the synthetic tests use it without a connection).  Every entry point (the
Display methods, the hooks) borrows it once for its whole call and passes `&mut Wl` down
to the event handlers; a nested borrow (re-entry) panics instead of aliasing.  Only the
UI thread calls in; wake() from other threads goes through the eventfd of linux_thread.
  • fn wl_connect() -> Option<Box<dyn Display>> connect to the compositor -> the backend, None when there is no Wayland display (quiet unless jfgui_BACKEND=wayland forces it) [wl_connect]

  • fn wl_test_event(iface: &str, event: &str, args: &[u64]) -> bool call the handler of event event ("enter", "key", ...) of interface iface ("wl_pointer", "wl_keyboard", ...) with decoded arguments (object id 1, udata 0), as linuxtest --test synth does -> false when there is no such event [hcall]

  • fn wl_test_event_u(iface: &str, event: &str, args: &[u64], udata: u64) -> bool (main agent) wl_test_event with the handler's udata (a tablet tool's slot ...), as plattest --test pen does [tcall in apps/plattest/src/pen.s]

  • fn wl_test_lock(w: i32) (G7a, plattest --test input) play a pointer lock of window w without a compositor: its zwp_locked_pointer_v1 and zwp_relative_pointer_v1 are object 1 (the id of wl_test_event's events), the request Pending until a "locked" event; the protocols count as there

  • fn wl_test_scale(s120: i32) (main agent) the pointer scale while there is no window (g_wl_s120, 120ths) alone

  • fn wl_test_setup(s120: i32, seat_ver: u32) the pointer scale while there is no window (g_wl_s120, 120ths) and the seat version the handlers assume (g_wl_seat_ver)

  • fn wl_input_service(now: u64) -> u64 key repeat at now (time_us) -> the next repeat deadline, u64::MAX = none [wl_input_service]

  • fn wl_cursor_image(shape: u32) -> Option<(u32, u32, u32, u32, &'static [u8])> the built-in cursor image of a CUR_* shape: (width, height, hot x, hot y, rows of 'X' black / 'o' white / '.' transparent) [wl_cursor_image]

  • fn wl_cursor_render(dst: &mut [u32], shape: u32, s: u32) expand a cursor image into ARGB pixels (S x S blocks, rows of width * S pixels) [wl_cursor_render]

  • fn wl_test_roundtrip() -> i32 a wl_display.sync round trip: the events that arrive before its answer are dispatched first (linuxtest --test burst: a burst of keys while it waits) -> 0 ok / -1 timeout

  • fn wl_test_presented(w: i32) -> Option<(i32, i32, Vec<u8>)> the pixels of window w's last committed buffer -- what the compositor shows -- as (w, h, rows of w * 4 bytes B, G, R, x); None while damage waits (linuxtest --test pcheck)

  • fn wl_test_protoerr() attach a buffer id that does not exist to the main window's surface: the compositor answers with wl_display.error, which ends the process (linuxtest --test protoerr)

Source: docs/API.md in the JFLib repository.