JFLib

plat/linux_portal.rs (Linux)#

Source: lib/plat/linux_portal.rs

linux_portal -- xdg-desktop-portal over a minimal D-Bus client (raw socket, SASL EXTERNAL,
little-endian marshalling): the file dialog, OpenURI / OpenDirectory, Print
                                                           [src/plat/linux/portal.s]

  file_dialog(flags, path, exts) -> (1 chosen / 0 cancelled / -1 no portal, index of the
       chosen extension entry).  Same contract as on Windows (win_filedlg.rs): flags FD_SAVE
       | index << FD_EXT_SHIFT (FD_FOLDER: OpenFile with "directory", portal version 3),
       path in / out (UTF-8, '/'; at most PATH_CAP - 1 bytes out),
       exts ["png=PNG-Bild", "jpg;jpeg=JPEG-Bild"] (an empty entry ends the list).
  open_url(url) -> 0 / -1         a web page in the default application: OpenURI.OpenURI;
                                  jfgui_OPEN_DRYRUN=1 only prints it
  open_folder(path) -> 0 / -1     show a folder / a file in the file manager:
       OpenURI.OpenDirectory with an O_PATH descriptor (SCM_RIGHTS), fallback
       OpenURI.OpenURI("file://...").  The Response is awaited for OF_WAIT ms (the window
       keeps being serviced): code 0 -> 0, 1 / 2 -> -1; without an answer by then the
       request stays alive on its connection until the next call and 0 is returned.  No
       bus / no portal / no such path -> -1.  jfgui_OPEN_DRYRUN=1: printed, nothing sent.
  (crate) portal_print_prepare / portal_print_send / portal_print_end  org.freedesktop.portal
       .Print for linux_print.rs (PreparePrint with the job's paper / orientation, the page
       setup of the answer; Print with the PDF as a descriptor)

The dialogs belong to the portal's process.  While one is open the display keeps being
serviced (wait); input events of that time are dropped, window events (resize, close,
focus, dpi, paint) are kept and queued again afterwards.

State: the assembly's globals (receive buffer, body / message builders, token, request
path, ...) are one Bus record (module state, UI thread only).  Messages are byte-identical
to the assembly's (serials, field order, padding, token "jfgui<n>").
/// file_dialog: the path capacity (FD_PATH of ui_filedlg.s)
PATH_CAP: usize = 1040
  • fn file_dialog(flags: u32, path: &mut String, exts: &[&str]) -> (i32, u32) the portal's FileChooser (see the file header) [plat_file_dialog]

  • fn open_folder(path: &str) -> i32 show a folder / a file in the file manager (OpenURI.OpenDirectory) -> 0 / -1 [plat_open_folder]

  • fn open_url(url: &str) -> i32 a web page in the default application (OpenURI.OpenURI) -> 0 / -1 [plat_open_url]

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