Home

Awesome

ASHPD

docs crates.io CI

ASHPD, acronym of Aperture Science Handheld Portal Device is a Rust & zbus wrapper of the XDG portals DBus interfaces. The library aims to provide an easy way to interact with the various portals defined per the specifications. It provides an alternative to the C library https://github.com/flatpak/libportal

Examples

Ask the compositor to pick a color

use ashpd::desktop::Color;

async fn run() -> ashpd::Result<()> {
    let color = Color::pick().send().await?.response()?;
    println!("({}, {}, {})", color.red(), color.green(), color.blue());
    Ok(())
}

Start a PipeWire stream from the user's camera

use ashpd::desktop::camera::Camera;

pub async fn run() -> ashpd::Result<()> {
    let camera = Camera::new().await?;
    if camera.is_present().await? {
        camera.request_access().await?;
        let remote_fd = camera.open_pipe_wire_remote().await?;
        // pass the remote fd to GStreamer for example
    }
    Ok(())
}

Optional features

FeatureDescriptionDefault
tracingRecord various debug information using the tracing libraryNo
tokioEnable tokio runtime on zbus dependencyYes
async-stdEnable the use of the async-std runtimeNo
backendunstable Enables APIs useful for writing portals implementationsNo
glibMake all the enums derive glib::Enum. Flags are not supported yetNo
gtk4Implement From<Color> for gdk4::RGBA Provides WindowIdentifier::from_native that takes a IsA<gtk4::Native>No
gtk4_waylandProvides WindowIdentifier::from_native that takes a IsA<gtk4::Native> with Wayland backend support onlyNo
gtk4_x11Provides WindowIdentifier::from_native that takes a IsA<gtk4::Native> with X11 backend support onlyNo
pipewireProvides ashpd::desktop::camera::pipewire_streams that helps you retrieve the various camera streams associated with the retrieved file descriptorNo
raw_handleProvides WindowIdentifier::from_raw_handle and WindowIdentifier::as_raw_handle for raw-window-handle crateNo
waylandProvides WindowIdentifier::from_wayland for wayland-client crateNo

Demo

The library comes with a demo built using the GTK 4 Rust bindings and previews most of the portals. It is meant as a test case for the portals (from a distributor perspective) and as a way for the developers to see which portals exists and how to integrate them into their application using ASHPD.

<a href="https://flathub.org/apps/details/com.belmoussaoui.ashpd.demo"> <img src="https://flathub.org/assets/badges/flathub-badge-i-en.png" width="190px" /> </a>