| 1 |
# ASHPD |
| 2 |
|
| 3 |
[](https://docs.rs/ashpd/) [](https://crates.io/crates/ashpd)  |
| 4 |
|
| 5 |
ASHPD, acronym of Aperture Science Handheld Portal Device is a Rust & [zbus](https://github.com/z-galaxy/zbus) wrapper of |
| 6 |
the XDG portals DBus interfaces. The library aims to provide an easy way to |
| 7 |
interact with the various portals defined per the [specifications](https://flatpak.github.io/xdg-desktop-portal/docs/). |
| 8 |
It provides an alternative to the C library [https://github.com/flatpak/libportal](https://github.com/flatpak/libportal) |
| 9 |
|
| 10 |
## Examples |
| 11 |
|
| 12 |
Ask the compositor to pick a color |
| 13 |
|
| 14 |
```rust,no_run |
| 15 |
use ashpd::desktop::Color; |
| 16 |
|
| 17 |
async fn run() -> ashpd::Result<()> { |
| 18 |
let color = Color::pick().send().await?.response()?; |
| 19 |
println!("({}, {}, {})", color.red(), color.green(), color.blue()); |
| 20 |
Ok(()) |
| 21 |
} |
| 22 |
``` |
| 23 |
|
| 24 |
Start a PipeWire stream from the user's camera |
| 25 |
|
| 26 |
```rust,no_run |
| 27 |
use ashpd::desktop::camera::Camera; |
| 28 |
|
| 29 |
pub async fn run() -> ashpd::Result<()> { |
| 30 |
let camera = Camera::new().await?; |
| 31 |
if camera.is_present().await? { |
| 32 |
camera.request_access(Default::default()).await?; |
| 33 |
let remote_fd = camera.open_pipe_wire_remote(Default::default()).await?; |
| 34 |
// pass the remote fd to GStreamer for example |
| 35 |
} |
| 36 |
Ok(()) |
| 37 |
} |
| 38 |
``` |
| 39 |
|
| 40 |
## Optional features |
| 41 |
|
| 42 |
| Feature | Description | Default | |
| 43 |
| --- | ----------- | ------- | |
| 44 |
| tracing | Record various debug information using the `tracing` library | No | |
| 45 |
| tokio | Enable tokio runtime on zbus dependency | Yes | |
| 46 |
| async-io | Enable the use of the async-io crates, compatible with runtimes such smol or glib | No | |
| 47 |
| backend | *unstable* Enables APIs useful for writing portals implementations | No | |
| 48 |
| glib | Make all the enums derive `glib::Enum`. Flags are not supported yet | No | |
| 49 |
| gtk4 | Implement `From<Color>` for [`gdk4::RGBA`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gdk4/struct.RGBA.html) Provides `WindowIdentifier::from_native` that takes a [`IsA<gtk4::Native>`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Native.html) | No | |
| 50 |
| gtk4_wayland |Provides `WindowIdentifier::from_native` that takes a [`IsA<gtk4::Native>`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Native.html) with Wayland backend support only | No | |
| 51 |
| gtk4_x11 |Provides `WindowIdentifier::from_native` that takes a [`IsA<gtk4::Native>`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Native.html) with X11 backend support only | No | |
| 52 |
| pipewire | Provides `ashpd::desktop::camera::pipewire_streams` that helps you retrieve the various camera streams associated with the retrieved file descriptor| No | |
| 53 |
| raw_handle | Provides `WindowIdentifier::from_raw_handle` and `WindowIdentifier::as_raw_handle` for [raw-window-handle](https://lib.rs/crates/raw-window-handle) crate | No | |
| 54 |
| wayland | Provides `WindowIdentifier::from_wayland` for [wayland-client](https://lib.rs/crates/wayland-client) crate | No | |
| 55 |
| backend | Enables portal backend implementation supoport | No | |
| 56 |
|
| 57 |
## Demo |
| 58 |
|
| 59 |
The library comes with a [demo](./demo/client) built using the [GTK 4 Rust bindings](https://gtk-rs.org/gtk4-rs) 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. |
| 60 |
|
| 61 |
<a href="https://flathub.org/apps/details/com.belmoussaoui.ashpd.demo"> |
| 62 |
<img src="https://flathub.org/api/badge?svg&locale=en&light" width="190px" /> |
| 63 |
</a> |
| 64 |
|
| 65 |
## Backend demo |
| 66 |
|
| 67 |
The library also comes with a [backend demo](./demo/backend/README.md) that exemplifies how to implement [a portal backend](https://flatpak.github.io/xdg-desktop-portal/docs/impl-dbus-interfaces.html). |