JFLib

plat/linux_x11.rs (Linux)#

Source: lib/plat/linux_x11.rs

linux_x11 -- the X11 display backend: our own X11 protocol client over a Unix socket (no
Xlib / xcb) behind linux_disp::Display
                    [src/plat/linux/x11.inc, x11_wire.s, x11_window.s, x11_present.s,
                     x11_input.s, x11_xi.s, x11_clip.s, x11_dnd.s, x11_popup.s,
                     x11_cursor.s, x11_monitor.s; docs/modules/WINDOWS_PLATFORM.md §4, §9, §10]

  x11_connect() -> backend        $DISPLAY reachable: the backend (the main window is made
                                  by its win_create), None (no message) otherwise
  x11t::*                         the self-test entry points of linuxtest (x11synth,
                                  x11err): events without a server, keysyms, the core
                                  keymap, raw requests, the last X error

The state of the assembly's globals lives in one X11 record (module state, one UI thread):
the backend object is empty and every Display call borrows the record for its duration.
Nothing inside calls back into the plat API that would borrow it again (the refresh
callback is only stored, as on X11 in the assembly), so a re-entrant borrow would be a
bug and panics.  Files:
  linux_x11_wire.rs     connection, authentication, setup, requests, replies, errors
  linux_x11_window.rs   window records, hints, WM messages, DPI, state, events, wait
  linux_x11_present.rs  MIT-SHM (memfd / SysV) or PutImage, per window
  linux_x11_gpu.rs      DRI3 and Present: the GPU's buffers on a window (programs against glibc)
  linux_x11_input.rs    core keyboard / pointer input, keysyms, the core keymap (built into
                        the key table of linux_xkb.rs: xkb_begin / xkb_set_key / xkb_key)
  linux_x11_xi.rs       XInput 2 pens
  linux_x11_clip.rs     CLIPBOARD (INCR both ways, images)
  linux_x11_dnd.rs      XDND 5: drops of every kind into the windows, the app's drags out
  linux_x11_misc.rs     popups (override-redirect), cursors (font / RENDER), monitors (RandR)
  linux_x11_screen.rs   the monitor list, global shortcuts (GrabKey), GetImage of the root,
                        the colour pick (pointer grab), RandR change events

Deviation from the assembly (the Rust API hands the frame over only for the call): the
MIT-SHM segments are whole frames brought up to date from the caller's frame (what each
lacks, linux_x11_present.rs), so repaints (Expose, after a map) read the segment of the
last put; the PutImage fallback keeps a shadow image of the frame, and popups keep a copy
of their pixels -- where the assembly re-read the caller's framebuffer.
  • fn x11_connect() -> Option<Box<dyn Display>> connect to $DISPLAY -> the backend, None when there is no X server [x11_plat_win_create]

mod x11t

the X11 internals linuxtest --test x11synth / x11err drives (x11_event, x11_ks_value, x11_kb_*, g_x11_xkb_on, g_x11_mods, x11_req, x11_sync, g_x11_err_last; the key table is plat::xkb_*)

  • fn event(pkt: &[u8; 32]) one X event packet (32 bytes) through the event handler (x11_event)

  • fn event_bytes(pkt: &[u8]) one X event packet of any length (a GenericEvent: 32 bytes + its extra length) through the event handler (x11_event)

  • fn lock_setup(w: i32, on: bool, abs: &[(u16, [i32; 2], [i32; 2])]) (G7a, plattest --test input) play the pointer lock of window w without a server: held (on) or not; absolute devices (id, range of valuator 0, of valuator 1) for its raw events

  • fn xi_setup(op: u32, atoms: [u32; 3]) XInput 2 without a server: its major opcode and the valuator label atoms ("Abs Pressure", "Abs Tilt X", "Abs Tilt Y"); op 0 turns it off again (g_xi_op, g_xi_atoms)

  • fn xi_parse_devices(reply: &[u8]) -> u32 the pen devices of an XIQueryDevice reply -> pens found (x11_xi_parse_devices)

  • fn pen_devices() -> i32 pens found, -1 = no XInput 2 (x11_pen_devices)

  • fn ks_value(ks: u32) -> u32 a keysym as an xkb.s symbol value (x11_ks_value)

  • fn kb_set_keysyms(ks: &[u32], first: u32, count: u32, per: u32) the core keyboard mapping: per keysyms per keycode from first (x11_kb_set_keysyms)

  • fn kb_set_modmap(kc: &[u8], per: u32) the modifier mapping: 8 modifiers x per keycodes (x11_kb_set_modmap)

  • fn kb_build(group: u32) build the key records of a group (x11_kb_build)

  • fn set_xkb_on(on: bool) XKB on (event state bits 13-14 select the group) (g_x11_xkb_on)

  • fn mods() -> u32 the current MOD_* bits (g_x11_mods)

  • fn req(major: u32, body: &[u8]) -> u32 a raw request: major opcode, body after the 4-byte header -> its sequence number (x11_req; nothing without a connection)

  • fn sync() round trip: every earlier request has been processed (x11_sync)

  • fn err_last() -> u32 the sequence number of the last X error (g_x11_err_last)

  • fn fake_input(typ: u32, detail: u32, x: i32, y: i32) -> bool XTEST FakeInput: 2 / 3 key press / release (detail: keycode), 4 / 5 button press / release, 6 motion to the root point x, y -> false without XTEST or a connection

  • fn focus() -> (u32, u32) the input focus: (window: 0 None, 1 PointerRoot; revert-to) (GetInputFocus)

  • fn set_focus(win: u32, revert: u32) SetInputFocus(window, revert-to) at CurrentTime

  • fn root() -> u32 the root window (0 without a connection)

  • fn roles() -> (u32, u32, u32) the modifier masks of Alt, Num Lock and Super (their roles in the modifier mapping)

  • fn vk_keycodes(vk: u32) -> alloc::vec::Vec<u32> the keycodes (X, evdev + 8) that give vk without modifiers

  • fn image_of(w: i32, r: [i32; 4]) -> Result<crate::screen::Shot, crate::screen::ScreenError> GetImage of window w's rectangle (window px): the capture's path on an own window

mod x11s

the X11 state other plat modules read (plat-shared)

  • fn main_xid() -> u32 the main window's XID (0 = none) (g_x11_win)

  • fn root_property(name: &[u8], atom: &mut u32) -> Option<Vec<u8>> the root window property name (AnyPropertyType, X11_PROP_CHUNK longs) -> the GetProperty reply (see get_property), None without a connection / on an error. atom caches the atom between calls: 0 not asked yet (InternAtom only-if-exists is sent), u32::MAX the name does not exist (lx_icc.s g_icc_atom)

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