Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/ironrdp-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub mod output_channel;
pub mod rail;
pub mod rdp;

#[cfg(all(windows, feature = "clipboard"))]
#[cfg(all(any(windows, target_os = "linux"), feature = "clipboard"))]
mod clipboard;

mod ws;
31 changes: 28 additions & 3 deletions crates/ironrdp-client/src/rdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,14 +790,21 @@ impl RdpClient {
// ── Clipboard initialisation (compile-time gated) ─────────────────────
//
// On Windows the WinClipboard object must outlive the entire connection loop, so we
// keep it alive via `_win_clipboard`. On non-Windows a StubClipboard backend is used
// and its ownership can be released immediately after the factory is extracted.
// keep it alive via `_win_clipboard`; the same goes for LinuxClipboard and
// `_linux_clipboard`. Elsewhere a StubClipboard backend is used and its ownership can be
// released immediately after the factory is extracted.
#[cfg(all(windows, feature = "clipboard"))]
#[expect(
clippy::collection_is_never_read,
reason = "binding owns the Windows clipboard so it stays alive for the connection's lifetime"
)]
let _win_clipboard;
#[cfg(all(target_os = "linux", feature = "clipboard"))]
#[expect(
clippy::collection_is_never_read,
reason = "binding owns the Linux clipboard so it stays alive for the connection's lifetime"
)]
let mut _linux_clipboard = None;

#[cfg(feature = "clipboard")]
let cliprdr_factory: Option<Box<dyn CliprdrBackendFactory + Send>>;
Expand Down Expand Up @@ -852,7 +859,25 @@ impl RdpClient {
}
}

#[cfg(not(windows))]
#[cfg(target_os = "linux")]
{
use crate::clipboard::ClientClipboardMessageProxy;
use ironrdp_cliprdr_native::{LinuxClipboard, StubClipboard};
match LinuxClipboard::new(ClientClipboardMessageProxy::new(self.input_event_sender.clone())) {
Ok(clipboard) => {
cliprdr_factory = Some(clipboard.backend_factory());
_linux_clipboard = Some(clipboard);
}
Err(error) => {
// Without a desktop clipboard there is nothing to bridge, and the
// session is still useful, so this is not a connection failure.
warn!(%error, "OS clipboard unavailable; clipboard redirection is off for this session");
cliprdr_factory = Some(StubClipboard::new().backend_factory());
}
}
}

#[cfg(not(any(windows, target_os = "linux")))]
{
use ironrdp_cliprdr_native::StubClipboard;
let stub = StubClipboard::new();
Expand Down
13 changes: 13 additions & 0 deletions crates/ironrdp-cliprdr-native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ authors.workspace = true
keywords.workspace = true
categories.workspace = true

[features]
# Exposes internals to the integration tests in ironrdp-testsuite-core.
__test = ["dep:visibility"]

[lib]
doctest = false
test = false
Expand All @@ -21,6 +25,15 @@ ironrdp-cliprdr = { path = "../ironrdp-cliprdr", version = "0.7" } # public
ironrdp-core = { path = "../ironrdp-core", version = "0.2" }
tracing = { version = "0.1", features = ["log"] }

[target.'cfg(target_os = "linux")'.dependencies]
nix = { version = "0.31", features = ["fs", "poll"] }
visibility = { version = "0.1", optional = true }
wayland-client = "0.31"
wayland-protocols = { version = "0.32", features = ["client", "staging"] }
wayland-protocols-wlr = { version = "0.3", features = ["client"] }
x11rb = { version = "0.13", features = ["xfixes"] }
ironrdp-cliprdr-format = { path = "../ironrdp-cliprdr-format", version = "0.2" }

Comment thread
AKolenda marked this conversation as resolved.
[target.'cfg(windows)'.dependencies]
windows = { version = "0.62", features = [
"Win32_Foundation",
Expand Down
30 changes: 29 additions & 1 deletion crates/ironrdp-cliprdr-native/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
# IronRDP CLIPRDR native backends

Native CLIPRDR backend implementations. Currently only Windows is supported.
Native CLIPRDR backend implementations: Windows (`WinClipboard`) and Linux desktops over X11 and Wayland (`LinuxClipboard`, text and images).

This crate is part of the [IronRDP] project.

[IronRDP]: https://github.com/Devolutions/IronRDP

## Linux

`LinuxClipboard` uses the shared `data_control` client for Wayland compositors offering `ext-data-control-v1` or `wlr-data-control-unstable-v1`.
When data-control is unavailable, including on GNOME, it falls back to X11/XWayland through XFixes and selection ownership.
A desktop without either clipboard service uses the client's stub backend.

Both backends react to selection changes and advertise remote formats without fetching their contents.
Text (`CF_UNICODETEXT`) and images (`CF_DIB`/`CF_DIBV5`, converted to/from PNG by `ironrdp-cliprdr-format`) are requested only when an application pastes.
Local clipboard content is read only when the peer requests it.
File clipboard transfer and HTML are not supported.

Only one Format Data Request is outstanding at a time, because responses do not identify their request.
A paste times out after five seconds, but its outstanding request is retained until the late response is drained.
If the peer never replies, new remote pastes fail until the clipboard channel is reinitialized; this prevents stale content from being mistaken for a newer copy.
Selection changes cancel older paste waiters, and the existing `ironrdp_cliprdr::loop_detector` detects content echoed by clipboard managers.

The clipboard workers bound data transfers and pending pastes.
X11 transfers use INCR for large content and separate requestor windows so late selection responses cannot complete newer reads.

State-machine tests run in the normal CI suite with `cargo test -p ironrdp-testsuite-core cliprdr_native`.
Three additional integration tests require a dedicated X11 display; the interoperability test also requires `xclip`:

```sh
DISPLAY=:N cargo test -p ironrdp-testsuite-core cliprdr_native::linux::x11_ -- --ignored --test-threads=1
```

Use a private display such as Xvfb for these tests, because they replace its clipboard selection.
Loading
Loading