Expand description
XDG Desktop Portal integration for Wayland screen capture and input control
This library provides a high-level Rust interface to the XDG Desktop Portal, specifically the ScreenCast, RemoteDesktop, and Clipboard interfaces. It enables applications to capture screen content via PipeWire and inject input events on Wayland compositors.
§Features
- Screen capture: Capture monitor or window content through PipeWire streams
- Input injection: Send keyboard and mouse events to the desktop
- Clipboard integration: Portal-based clipboard for remote desktop scenarios
- Multi-monitor support: Handle multiple displays simultaneously
- Flexible configuration: Builder pattern and struct literals for Portal options
- Typed errors: Handle different failure modes appropriately
§Requirements
This library requires:
- A Wayland compositor (e.g., GNOME, KDE Plasma, Sway)
xdg-desktop-portalinstalled and running- A portal backend for your compositor (e.g.,
xdg-desktop-portal-gnome) - PipeWire for video streaming
§Quick Start
use lamco_portal::{PortalManager, PortalConfig};
// Create portal manager with default config
let manager = PortalManager::with_default().await?;
// Create a session (triggers permission dialog)
let (session, restore_token) = manager.create_session("my-session".to_string(), None).await?;
// Access PipeWire file descriptor for video capture
let fd = session.pipewire_fd();
let streams = session.streams();
println!("Capturing {} streams on PipeWire FD {}", streams.len(), fd);§Configuration
Customize Portal behavior using PortalConfig:
use lamco_portal::{PortalManager, PortalConfig};
use ashpd::desktop::screencast::CursorMode;
use ashpd::desktop::PersistMode;
let config = PortalConfig::builder()
.cursor_mode(CursorMode::Embedded) // Embed cursor in video
.persist_mode(PersistMode::Application) // Remember permission
.build();
let manager = PortalManager::new(config).await?;§Input Injection
Send keyboard and mouse events through the RemoteDesktop portal:
// Move mouse to absolute position
manager.remote_desktop()
.notify_pointer_motion_absolute(
session.ashpd_session(),
0, // stream index
100.0, // x position
200.0, // y position
)
.await?;
// Click mouse button
manager.remote_desktop()
.notify_pointer_button(
session.ashpd_session(),
1, // button 1 (left)
true, // pressed
)
.await?;§Error Handling
The library uses typed errors via PortalError:
match manager.create_session("my-session".to_string(), None).await {
Ok((session, _token)) => {
println!("Session created successfully");
}
Err(PortalError::PermissionDenied) => {
eprintln!("User denied permission in dialog");
}
Err(PortalError::PortalNotAvailable) => {
eprintln!("Portal not installed - install xdg-desktop-portal");
}
Err(e) => {
eprintln!("Other error: {}", e);
}
}§Platform Notes
- GNOME: Works out of the box with
xdg-desktop-portal-gnome - KDE Plasma: Use
xdg-desktop-portal-kde - wlroots (Sway, etc.): Use
xdg-desktop-portal-wlr - X11: Not supported - Wayland only
§Security
This library triggers system permission dialogs. Users must explicitly grant:
- Screen capture access (which monitors/windows to share)
- Input injection access (keyboard/mouse control)
- Clipboard access (if using clipboard features)
Permissions can be remembered per-application using ashpd::desktop::PersistMode::Application.
Re-exports§
pub use clipboard::ClipboardManager;pub use config::PortalConfig;pub use config::PortalConfigBuilder;pub use error::PortalError;pub use error::Result;pub use remote_desktop::RemoteDesktopManager;pub use screencast::ScreenCastManager;pub use clipboard_sink::PortalClipboardSink;clipboard-sinkpub use dbus_clipboard::DbusClipboardBridge;dbus-clipboardpub use dbus_clipboard::DbusClipboardEvent;dbus-clipboardpub use session::PortalSessionHandle;pub use session::SourceType;pub use session::StreamInfo;
Modules§
- clipboard
- Portal Clipboard Integration
- clipboard_
sink clipboard-sink - ClipboardSink implementation for Portal clipboard
- config
- Configuration types for Portal operations
- dbus_
clipboard dbus-clipboard - D-Bus clipboard bridge for GNOME fallback.
- error
- Error types for Portal operations
- remote_
desktop - RemoteDesktop portal integration
- screencast
- ScreenCast portal integration
- session
- Portal session management
Structs§
- Portal
Manager - Portal manager coordinates all portal interactions