plat/linux_disp.rs (Linux)#
Source: lib/plat/linux_disp.rs
linux_disp -- display backend dispatch on Linux: Wayland (linux_wl*.rs) or X11 (linux_x11*.rs)
[src/plat/linux/disp.s, lx_popup.s]
The display-dependent functions go through the backend object (trait Display). The
first win_create (the main window, owner PW_NOOWNER) picks the backend:
jfgui_BACKEND=wayland | x11 forces one (only the first letter counts, like disp.s)
WAYLAND_DISPLAY set Wayland first, then X11 if DISPLAY is set
only DISPLAY set X11 first, then Wayland (default socket)
neither Wayland (default socket), else an error
When no backend can open its main window the process ends with exit code 1 and a
message (as disp.s). Before that the minimum size of window 0 and the refresh callback
are remembered and handed to the chosen backend. wait() without a backend (headless
runs) sleeps until its deadline or a wake() (lx_wait_nodisp).
The trait is the contract between the two backend agents and with Windows (win_api.rs has
the same free functions): change it only together and say so in the report.
plat-x11 (R4): the backend choice follows disp.s exactly (first letter of
jfgui_BACKEND, the fallback order, exit 1 when every backend fails, the Wayland
backend's "quiet" flag: disp_wl_quiet()); Display::pen_devices (default -1) was added
for plat_pen_devices; cursor_dpi without a display answers the dpi (pre_cdpi); the
headless wait is lx_wait_nodisp (wake fd, E_WAKE).
BK_NONE: u32 = 0
BK_WAYLAND: u32 = 1
BK_X11: u32 = 2
trait Display: Senda display backend (window-indexed; see the free functions below for the semantics)fn ime_pos(&mut self,_x:i32,_y:i32,_h:i32)fn win_create(&mut self, title: &str, w_dip: i32, h_dip: i32, flags: u32, owner: i32, x: i32, y: i32) -> i32fn win_destroy(&mut self, w: i32)fn win_show(&mut self, w: i32, mode: u32)fn win_activate(&mut self, w: i32)fn win_enable(&mut self, w: i32, on: bool)fn win_set_rect(&mut self, w: i32, x: i32, y: i32, cw: i32, ch: i32)fn win_get_rect(&mut self, w: i32) -> Option<[i32; 4]>fn win_work_area(&mut self, w: i32) -> Option<[i32; 4]>fn win_set_title(&mut self, w: i32, title: &str)fn win_state(&mut self, w: i32) -> u32fn win_cmd(&mut self, w: i32, cmd: u32)fn win_begin_move(&mut self, w: i32)fn win_begin_resize(&mut self, w: i32, edges: u32)fn win_show_menu(&mut self, _w: i32, _x: i32, _y: i32)the window manager's window menu at x, y (px of the window) on a button press; default none (X11)fn win_size(&mut self, w: i32) -> (i32, i32)fn win_dpi(&mut self, w: i32) -> i32fn win_set_min_size(&mut self, w: i32, w_dip: i32, h_dip: i32)fn win_present(&mut self, w: i32, f: &Frame, rects: Option<&[[i32; 4]]>)fn win_set_cursor(&mut self, w: i32, shape: u32)fn set_refresh(&mut self, f: Option<fn()>)fn wait(&mut self, deadline_us: u64) -> u32fn popup(&mut self, slot: u32, owner: i32, rect: Option<[i32; 4]>, f: Option<&Frame>)fn popup_anchor(&mut self, _slot: u32, _anchor: [i32; 4], _kind: u32, _nat: [i32; 2])(§6) how the next popup() of the slot hangs at its anchor -- a backend that places popups itself (Wayland) builds its positioner from it; the others show them where popup() saysfn popup_placed(&mut self, _slot: u32) -> Option<[i32; 2]>where the backend put the slot's popup when it is not where the UI asked (Wayland)fn cursor_create(&mut self, px: &[u8], w: i32, h: i32, hot_x: i32, hot_y: i32, dpi: i32) -> i32fn cursor_destroy(&mut self, id: i32)fn cursor_dpi(&mut self, dpi: i32) -> i32fn cursor_probe(&mut self, _shape: u32, _dpi: i32) -> (u64, i32)(tests) the cursor shown for shape at dpi and the width of a drawn onefn clip_set(&mut self, fmt: u32, data: &[u8]) -> boolfn clip_set_many(&mut self, entries: &[(u32, &[u8])]) -> boolfn clip_get(&mut self, fmt: u32) -> Option<Vec<u8>>fn clip_has(&mut self, fmt: u32) -> boolfn pen_devices(&mut self) -> i32pens / pen tablets the backend sees, -1 = unknown (plat_pen_devices: wl_pen_devices / x11_pen_devices) -- plat-x11: added with a default, the Wayland backend overrides itfn drag_start(&mut self, _data: crate::DragData) -> booldrag data out of the app (dnd.rs drag_start; the left button is held) -> started; E_DRAG_END follows -- added with a default for the drag and drop work (X11, Wayland)fn pointer_lock(&mut self, w: i32, on: bool) -> crate::PointerLock(G7a) lock the pointer to window w (on) or let it go -> the state now (plock.rs: the backend calls plock_set); default: Unsupported
fn disp_backend() -> u320 none, 1 Wayland, 2 X11fn disp_wl_quiet() -> bool(disp.s g_wl_quiet) the Wayland backend is being tried without jfgui_BACKEND=wayland: it should fail without messages (X11 may follow)fn win_create(title: &str, w_dip: i32, h_dip: i32, flags: u32, owner: i32, x: i32, y: i32) -> i32see win_api.rs (Windows) for the semantics of every functionfn win_destroy(w: i32)fn win_show(w: i32, mode: u32)fn win_activate(w: i32)fn win_enable(w: i32, on: bool)fn win_set_rect(w: i32, x: i32, y: i32, cw: i32, ch: i32)fn win_get_rect(w: i32) -> Option<[i32; 4]>fn win_work_area(w: i32) -> Option<[i32; 4]>fn win_set_title(w: i32, title: &str)fn win_state(w: i32) -> u32fn win_cmd(w: i32, cmd: u32)fn win_begin_move(w: i32)fn win_begin_resize(w: i32, edges: u32)fn win_size(w: i32) -> (i32, i32)fn win_dpi(w: i32) -> i32fn win_set_min_size(w: i32, w_dip: i32, h_dip: i32)fn win_present(w: i32, f: &Frame, rects: Option<&[[i32; 4]]>)show the frame's dirty rectangles (x, y, w, h; None = all) in window w; pixels outside them must be what the last present of w showed (linux_x11_present.rs, linux_wl_present.rs)fn win_set_cursor(w: i32, shape: u32)fn win_hit_hook(f: Option<fn(i32, i32, i32) -> u32>)stored: the compositor needs no hit tests, the Wayland backend asks it for the click activation of child windows (disp_hit)fn win_move_hook(f: Option<fn(i32, &mut [i32; 4])>)stored: the window manager or compositor moves toplevels and does not ask; the Wayland backend snaps the child windows it moves itself (disp_moving)fn set_refresh(f: Option<fn()>)fn wait(deadline_us: u64) -> u32pump the display until an event is queued or the deadline passes (0 = poll, u64::MAX = forever); without a display (headless) sleep until the deadline or a wake() [lx_wait_nodisp]. (G7a) While pads are watched, their nodes are read when their time comes (pad.rs pad_wait)fn popup(slot: u32, owner: i32, rect: Option<[i32; 4]>, f: Option<&Frame>)show / move / present popup slotslotover windowowner(rect None hides it) [lx_popup.s]fn popup_anchor(slot: u32, anchor: [i32; 4], kind: u32, nat: [i32; 2])(§6) how the next popup() of slotslothangs at its anchor: anchor x, y, w, h and the popup's natural place x, y (owner px), PA_* kind. Wayland builds the xdg_positioner from it (the compositor flips / slides the popup to keep it on screen); X11 places it as asked.fn popup_placed(slot: u32) -> Option<[i32; 2]>(§6) where the platform put popup slotslot(owner px) when that is not its natural place (Wayland: the compositor's configure); None: where the UI asked, or not known yetfn cursor_create(px: &[u8], w: i32, h: i32, hot_x: i32, hot_y: i32, dpi: i32) -> i32fn cursor_destroy(id: i32)fn cursor_dpi(dpi: i32) -> i32the dpi to draw a cursor for a window of this dpi (no display yet: the dpi itself)fn cursor_probe(shape: u32, dpi: i32) -> (u64, i32)(tests, E3) the cursor shown for shape (CUR_*) in a window of this dpi: its id (X11: the Cursor; 0 without a display or on Wayland) and, for a drawn one (cursor_art), its width in px (0: a system cursor or cursor_fallback's)fn clip_set(fmt: u32, data: &[u8]) -> boolfn clip_set_many(entries: &[(u32, &[u8])]) -> boolPublish distinct TEXT/HTML/RTF/DOCX representations of one selection.fn clip_get(fmt: u32) -> Option<Vec<u8>>fn clip_has(fmt: u32) -> boolfn ime_pos(x: i32, y: i32, h: i32)Forward caret position to backends with text-input support.fn theme() -> i320 light, 1 dark, -1 unknown: jfgui_THEME=light|dark wins, then GTK_THEME "Name:dark" or "Name-dark", then the settings portal's answer at the last sys_settings (color-scheme; GNOME's "Default" is light; unknown before the first, e.g. in headless runs) [plat_theme]fn pen_devices() -> i32pens / pen tablets of the display backend (-1 = unknown or no display) [plat_pen_devices]fn home() -> Option<String>$HOME (or "/") [plat_home]fn drives() -> Vec<String>the root "/" [plat_drives]fn spawn_self(args: &[&str]) -> i32fork; the child execs /proc/self/exe with argv[0], the arguments (at most 31) and the current environment (exit 127 when that fails) -> 0 / -1 [plat_spawn_self]fn restart_self(args: &[&str]) -> i32like spawn_self, but the program file now at this process's path: after an update put a new file there, /proc/self/exe still names the old one ("PATH (deleted)") -> 0 / -1