1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
//! # Examples
//!
//! ```rust,no_run
//! use ashpd::{
//! desktop::{
//! remote_desktop::{DeviceType, KeyState, RemoteDesktop},
//! PersistMode,
//! },
//! WindowIdentifier,
//! };
//!
//! async fn run() -> ashpd::Result<()> {
//! let proxy = RemoteDesktop::new().await?;
//! let session = proxy.create_session().await?;
//! proxy
//! .select_devices(
//! &session,
//! DeviceType::Keyboard | DeviceType::Pointer,
//! None,
//! PersistMode::DoNot,
//! )
//! .await?;
//!
//! let response = proxy
//! .start(&session, &WindowIdentifier::default())
//! .await?
//! .response()?;
//! println!("{:#?}", response.devices());
//!
//! // 13 for Enter key code
//! proxy
//! .notify_keyboard_keycode(&session, 13, KeyState::Pressed)
//! .await?;
//!
//! Ok(())
//! }
//! ```
//!
//! You can also use the Remote Desktop portal with the ScreenCast one. In order
//! to do so, you need to call
//! [`Screencast::select_sources()`][select_sources]
//! on the session created with
//! [`RemoteDesktop::create_session()`][create_session]
//!
//! ```rust,no_run
//! use ashpd::{
//! desktop::{
//! remote_desktop::{DeviceType, KeyState, RemoteDesktop},
//! screencast::{CursorMode, Screencast, SourceType},
//! PersistMode,
//! },
//! WindowIdentifier,
//! };
//!
//! async fn run() -> ashpd::Result<()> {
//! let remote_desktop = RemoteDesktop::new().await?;
//! let screencast = Screencast::new().await?;
//! let identifier = WindowIdentifier::default();
//! let session = remote_desktop.create_session().await?;
//!
//! remote_desktop
//! .select_devices(
//! &session,
//! DeviceType::Keyboard | DeviceType::Pointer,
//! None,
//! PersistMode::DoNot,
//! )
//! .await?;
//! screencast
//! .select_sources(
//! &session,
//! CursorMode::Metadata,
//! SourceType::Monitor | SourceType::Window,
//! true,
//! None,
//! PersistMode::DoNot,
//! )
//! .await?;
//!
//! let response = remote_desktop
//! .start(&session, &identifier)
//! .await?
//! .response()?;
//! println!("{:#?}", response.devices());
//! println!("{:#?}", response.streams());
//!
//! // 13 for Enter key code
//! remote_desktop
//! .notify_keyboard_keycode(&session, 13, KeyState::Pressed)
//! .await?;
//!
//! Ok(())
//! }
//! ```
//! [select_sources]: crate::desktop::screencast::Screencast::select_sources
//! [create_session]: crate::desktop::remote_desktop::RemoteDesktop::create_session
use std::{collections::HashMap, os::fd::OwnedFd};
use enumflags2::{bitflags, BitFlags};
use futures_util::TryFutureExt;
use serde_repr::{Deserialize_repr, Serialize_repr};
use zbus::zvariant::{self, DeserializeDict, SerializeDict, Type, Value};
use super::{
screencast::Stream, session::SessionPortal, HandleToken, PersistMode, Request, Session,
};
use crate::{desktop::session::CreateSessionResponse, proxy::Proxy, Error, WindowIdentifier};
#[cfg_attr(feature = "glib", derive(glib::Enum))]
#[cfg_attr(feature = "glib", enum_type(name = "AshpdKeyState"))]
#[derive(Serialize_repr, Deserialize_repr, Copy, Clone, PartialEq, Eq, Debug, Type)]
#[doc(alias = "XdpKeyState")]
/// The keyboard key state.
#[repr(u32)]
pub enum KeyState {
#[doc(alias = "XDP_KEY_PRESSED")]
/// The key is pressed.
Pressed = 1,
#[doc(alias = "XDP_KEY_RELEASED")]
/// The key is released..
Released = 0,
}
#[bitflags]
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Eq, Debug, Clone, Copy, Type)]
#[repr(u32)]
#[doc(alias = "XdpDeviceType")]
/// A bit flag for the available devices.
pub enum DeviceType {
#[doc(alias = "XDP_DEVICE_KEYBOARD")]
/// A keyboard.
Keyboard,
#[doc(alias = "XDP_DEVICE_POINTER")]
/// A mouse pointer.
Pointer,
#[doc(alias = "XDP_DEVICE_TOUCHSCREEN")]
/// A touchscreen
Touchscreen,
}
#[cfg_attr(feature = "glib", derive(glib::Enum))]
#[cfg_attr(feature = "glib", enum_type(name = "AshpdAxis"))]
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Eq, Debug, Clone, Copy, Type)]
#[doc(alias = "XdpDiscreteAxis")]
#[repr(u32)]
/// The available axis.
pub enum Axis {
#[doc(alias = "XDP_AXIS_VERTICAL_SCROLL")]
/// Vertical axis.
Vertical = 0,
#[doc(alias = "XDP_AXIS_HORIZONTAL_SCROLL")]
/// Horizontal axis.
Horizontal = 1,
}
#[derive(SerializeDict, Type, Debug, Default)]
/// Specified options for a [`RemoteDesktop::create_session`] request.
#[zvariant(signature = "dict")]
struct CreateRemoteOptions {
/// A string that will be used as the last element of the handle.
handle_token: HandleToken,
/// A string that will be used as the last element of the session handle.
session_handle_token: HandleToken,
}
#[derive(SerializeDict, Type, Debug, Default)]
/// Specified options for a [`RemoteDesktop::select_devices`] request.
#[zvariant(signature = "dict")]
struct SelectDevicesOptions {
/// A string that will be used as the last element of the handle.
handle_token: HandleToken,
/// The device types to request remote controlling of. Default is all.
types: Option<BitFlags<DeviceType>>,
restore_token: Option<String>,
persist_mode: Option<PersistMode>,
}
impl SelectDevicesOptions {
/// Sets the device types to request remote controlling of.
pub fn types(mut self, types: impl Into<Option<BitFlags<DeviceType>>>) -> Self {
self.types = types.into();
self
}
pub fn persist_mode(mut self, persist_mode: impl Into<Option<PersistMode>>) -> Self {
self.persist_mode = persist_mode.into();
self
}
pub fn restore_token<'a>(mut self, token: impl Into<Option<&'a str>>) -> Self {
self.restore_token = token.into().map(ToOwned::to_owned);
self
}
}
#[derive(SerializeDict, Type, Debug, Default)]
/// Specified options for a [`RemoteDesktop::start`] request.
#[zvariant(signature = "dict")]
struct StartRemoteOptions {
/// A string that will be used as the last element of the handle.
handle_token: HandleToken,
}
#[derive(DeserializeDict, Type, Debug, Default)]
/// A response to a [`RemoteDesktop::select_devices`] request.
#[zvariant(signature = "dict")]
pub struct SelectedDevices {
devices: BitFlags<DeviceType>,
streams: Option<Vec<Stream>>,
restore_token: Option<String>,
}
impl SelectedDevices {
/// The selected devices.
pub fn devices(&self) -> BitFlags<DeviceType> {
self.devices
}
/// The selected streams if a ScreenCast portal is used on the same session
pub fn streams(&self) -> Option<&[Stream]> {
self.streams.as_deref()
}
/// The session restore token.
pub fn restore_token(&self) -> Option<&str> {
self.restore_token.as_deref()
}
}
/// The interface lets sandboxed applications create remote desktop sessions.
///
/// Wrapper of the DBus interface: [`org.freedesktop.portal.RemoteDesktop`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html).
#[derive(Debug)]
#[doc(alias = "org.freedesktop.portal.RemoteDesktop")]
pub struct RemoteDesktop<'a>(Proxy<'a>);
impl<'a> RemoteDesktop<'a> {
/// Create a new instance of [`RemoteDesktop`].
pub async fn new() -> Result<RemoteDesktop<'a>, Error> {
let proxy = Proxy::new_desktop("org.freedesktop.portal.RemoteDesktop").await?;
Ok(Self(proxy))
}
/// Create a remote desktop session.
/// A remote desktop session is used to allow remote controlling a desktop
/// session. It can also be used together with a screen cast session.
///
/// # Specifications
///
/// See also [`CreateSession`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-createsession).
#[doc(alias = "CreateSession")]
#[doc(alias = "xdp_portal_create_remote_desktop_session")]
pub async fn create_session(&self) -> Result<Session<'a, Self>, Error> {
let options = CreateRemoteOptions::default();
let (request, proxy) = futures_util::try_join!(
self.0
.request::<CreateSessionResponse>(&options.handle_token, "CreateSession", &options)
.into_future(),
Session::from_unique_name(&options.session_handle_token).into_future()
)?;
assert_eq!(proxy.path(), &request.response()?.session_handle.as_ref());
Ok(proxy)
}
/// Select input devices to remote control.
///
/// # Arguments
///
/// * `session` - A [`Session`], created with
/// [`create_session()`][`RemoteDesktop::create_session`].
/// * `types` - The device types to request remote controlling of.
///
/// # Specifications
///
/// See also [`SelectDevices`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-selectdevices).
#[doc(alias = "SelectDevices")]
pub async fn select_devices(
&self,
session: &Session<'_, Self>,
types: BitFlags<DeviceType>,
restore_token: Option<&str>,
persist_mode: PersistMode,
) -> Result<Request<()>, Error> {
let options = SelectDevicesOptions::default()
.types(types)
.persist_mode(persist_mode)
.restore_token(restore_token);
self.0
.empty_request(&options.handle_token, "SelectDevices", &(session, &options))
.await
}
/// Start the remote desktop session.
///
/// This will typically result in the portal presenting a dialog letting
/// the user select what to share, including devices and optionally screen
/// content if screen cast sources was selected.
///
/// # Arguments
///
/// * `session` - A [`Session`], created with
/// [`create_session()`][`RemoteDesktop::create_session`].
/// * `identifier` - The application window identifier.
///
/// # Specifications
///
/// See also [`Start`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-start).
#[doc(alias = "Start")]
pub async fn start(
&self,
session: &Session<'_, Self>,
identifier: &WindowIdentifier,
) -> Result<Request<SelectedDevices>, Error> {
let options = StartRemoteOptions::default();
self.0
.request(
&options.handle_token,
"Start",
&(session, &identifier, &options),
)
.await
}
/// Notify keyboard code.
///
/// **Note** only works if [`DeviceType::Keyboard`] access was provided
/// after starting the session.
///
/// # Arguments
///
/// * `session` - A [`Session`], created with
/// [`create_session()`][`RemoteDesktop::create_session`].
/// * `keycode` - Keyboard code that was pressed or released.
/// * `state` - The new state of the keyboard code.
///
/// # Specifications
///
/// See also [`NotifyKeyboardKeycode`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-notifykeyboardkeycode).
#[doc(alias = "NotifyKeyboardKeycode")]
pub async fn notify_keyboard_keycode(
&self,
session: &Session<'_, Self>,
keycode: i32,
state: KeyState,
) -> Result<(), Error> {
// The `notify` methods don't take any options for now
// see https://github.com/flatpak/xdg-desktop-portal/blob/master/src/remote-desktop.c#L723
let options: HashMap<&str, Value<'_>> = HashMap::new();
self.0
.call("NotifyKeyboardKeycode", &(session, options, keycode, state))
.await
}
/// Notify keyboard symbol.
///
/// **Note** only works if [`DeviceType::Keyboard`] access was provided
/// after starting the session.
///
/// # Arguments
///
/// * `session` - A [`Session`], created with
/// [`create_session()`][`RemoteDesktop::create_session`].
/// * `keysym` - Keyboard symbol that was pressed or released.
/// * `state` - The new state of the keyboard code.
///
/// # Specifications
///
/// See also [`NotifyKeyboardKeysym`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-notifykeyboardkeysym).
#[doc(alias = "NotifyKeyboardKeysym")]
pub async fn notify_keyboard_keysym(
&self,
session: &Session<'_, Self>,
keysym: i32,
state: KeyState,
) -> Result<(), Error> {
// The `notify` methods don't take any options for now
// see https://github.com/flatpak/xdg-desktop-portal/blob/master/src/remote-desktop.c#L723
let options: HashMap<&str, Value<'_>> = HashMap::new();
self.0
.call("NotifyKeyboardKeysym", &(session, options, keysym, state))
.await
}
/// Notify about a new touch up event.
///
/// **Note** only works if [`DeviceType::Touchscreen`] access was provided
/// after starting the session.
///
/// # Arguments
///
/// * `session` - A [`Session`], created with
/// [`create_session()`][`RemoteDesktop::create_session`].
/// * `slot` - Touch slot where touch point appeared.
///
/// # Specifications
///
/// See also [`NotifyTouchUp`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-notifytouchup).
#[doc(alias = "NotifyTouchUp")]
pub async fn notify_touch_up(
&self,
session: &Session<'_, Self>,
slot: u32,
) -> Result<(), Error> {
// The `notify` methods don't take any options for now
// see https://github.com/flatpak/xdg-desktop-portal/blob/master/src/remote-desktop.c#L723
let options: HashMap<&str, Value<'_>> = HashMap::new();
self.0
.call("NotifyTouchUp", &(session, options, slot))
.await
}
/// Notify about a new touch down event.
/// The (x, y) position represents the new touch point position in the
/// streams logical coordinate space.
///
/// **Note** only works if [`DeviceType::Touchscreen`] access was provided
/// after starting the session.
///
/// # Arguments
///
/// * `session` - A [`Session`], created with
/// [`create_session()`][`RemoteDesktop::create_session`].
/// * `stream` - The PipeWire stream node the coordinate is relative to.
/// * `slot` - Touch slot where touch point appeared.
/// * `x` - Touch down x coordinate.
/// * `y` - Touch down y coordinate.
///
/// # Specifications
///
/// See also [`NotifyTouchDown`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-notifytouchdown).
#[doc(alias = "NotifyTouchDown")]
pub async fn notify_touch_down(
&self,
session: &Session<'_, Self>,
stream: u32,
slot: u32,
x: f64,
y: f64,
) -> Result<(), Error> {
// The `notify` methods don't take any options for now
// see https://github.com/flatpak/xdg-desktop-portal/blob/master/src/remote-desktop.c#L723
let options: HashMap<&str, Value<'_>> = HashMap::new();
self.0
.call("NotifyTouchDown", &(session, options, stream, slot, x, y))
.await
}
/// Notify about a new touch motion event.
/// The (x, y) position represents where the touch point position in the
/// streams logical coordinate space moved.
///
/// **Note** only works if [`DeviceType::Touchscreen`] access was provided
/// after starting the session.
///
/// # Arguments
///
/// * `session` - A [`Session`], created with
/// [`create_session()`][`RemoteDesktop::create_session`].
/// * `stream` - The PipeWire stream node the coordinate is relative to.
/// * `slot` - Touch slot where touch point appeared.
/// * `x` - Touch motion x coordinate.
/// * `y` - Touch motion y coordinate.
///
/// # Specifications
///
/// See also [`NotifyTouchMotion`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-notifytouchmotion).
#[doc(alias = "NotifyTouchMotion")]
pub async fn notify_touch_motion(
&self,
session: &Session<'_, Self>,
stream: u32,
slot: u32,
x: f64,
y: f64,
) -> Result<(), Error> {
// The `notify` methods don't take any options for now
// see https://github.com/flatpak/xdg-desktop-portal/blob/master/src/remote-desktop.c#L723
let options: HashMap<&str, Value<'_>> = HashMap::new();
self.0
.call("NotifyTouchMotion", &(session, options, stream, slot, x, y))
.await
}
/// Notify about a new absolute pointer motion event.
/// The (x, y) position represents the new pointer position in the streams
/// logical coordinate space.
///
/// # Arguments
///
/// * `session` - A [`Session`], created with
/// [`create_session()`][`RemoteDesktop::create_session`].
/// * `stream` - The PipeWire stream node the coordinate is relative to.
/// * `x` - Pointer motion x coordinate.
/// * `y` - Pointer motion y coordinate.
///
/// # Specifications
///
/// See also [`NotifyPointerMotionAbsolute`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-notifypointermotionabsolute).
#[doc(alias = "NotifyPointerMotionAbsolute")]
pub async fn notify_pointer_motion_absolute(
&self,
session: &Session<'_, Self>,
stream: u32,
x: f64,
y: f64,
) -> Result<(), Error> {
// The `notify` methods don't take any options for now
// see https://github.com/flatpak/xdg-desktop-portal/blob/master/src/remote-desktop.c#L723
let options: HashMap<&str, Value<'_>> = HashMap::new();
self.0
.call(
"NotifyPointerMotionAbsolute",
&(session, options, stream, x, y),
)
.await
}
/// Notify about a new relative pointer motion event.
/// The (dx, dy) vector represents the new pointer position in the streams
/// logical coordinate space.
///
/// # Arguments
///
/// * `session` - A [`Session`], created with
/// [`create_session()`][`RemoteDesktop::create_session`].
/// * `dx` - Relative movement on the x axis.
/// * `dy` - Relative movement on the y axis.
///
/// # Specifications
///
/// See also [`NotifyPointerMotion`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-notifypointermotion).
#[doc(alias = "NotifyPointerMotion")]
pub async fn notify_pointer_motion(
&self,
session: &Session<'_, Self>,
dx: f64,
dy: f64,
) -> Result<(), Error> {
// The `notify` methods don't take any options for now
// see https://github.com/flatpak/xdg-desktop-portal/blob/master/src/remote-desktop.c#L723
let options: HashMap<&str, Value<'_>> = HashMap::new();
self.0
.call("NotifyPointerMotion", &(session, options, dx, dy))
.await
}
/// Notify pointer button.
/// The pointer button is encoded according to Linux Evdev button codes.
///
///
/// **Note** only works if [`DeviceType::Pointer`] access was provided after
/// starting the session.
///
/// # Arguments
///
/// * `session` - A [`Session`], created with
/// [`create_session()`][`RemoteDesktop::create_session`].
/// * `button` - The pointer button was pressed or released.
/// * `state` - The new state of the keyboard code.
///
/// # Specifications
///
/// See also [`NotifyPointerButton`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-notifypointerbutton).
#[doc(alias = "NotifyPointerButton")]
pub async fn notify_pointer_button(
&self,
session: &Session<'_, Self>,
button: i32,
state: KeyState,
) -> Result<(), Error> {
// The `notify` methods don't take any options for now
// see https://github.com/flatpak/xdg-desktop-portal/blob/master/src/remote-desktop.c#L723
let options: HashMap<&str, Value<'_>> = HashMap::new();
self.0
.call("NotifyPointerButton", &(session, options, button, state))
.await
}
/// Notify pointer axis discrete.
///
/// **Note** only works if [`DeviceType::Pointer`] access was provided after
/// starting the session.
///
/// # Arguments
///
/// * `session` - A [`Session`], created with
/// [`create_session()`][`RemoteDesktop::create_session`].
/// * `axis` - The axis that was scrolled.
///
/// # Specifications
///
/// See also [`NotifyPointerAxisDiscrete`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-notifypointeraxisdiscrete).
#[doc(alias = "NotifyPointerAxisDiscrete")]
pub async fn notify_pointer_axis_discrete(
&self,
session: &Session<'_, Self>,
axis: Axis,
steps: i32,
) -> Result<(), Error> {
// The `notify` methods don't take any options for now
// see https://github.com/flatpak/xdg-desktop-portal/blob/master/src/remote-desktop.c#L723
let options: HashMap<&str, Value<'_>> = HashMap::new();
self.0
.call(
"NotifyPointerAxisDiscrete",
&(session, options, axis, steps),
)
.await
}
/// Notify pointer axis.
/// The axis movement from a "smooth scroll" device, such as a touchpad.
/// When applicable, the size of the motion delta should be equivalent to
/// the motion vector of a pointer motion done using the same advice.
///
///
/// **Note** only works if [`DeviceType::Pointer`] access was provided after
/// starting the session.
///
/// # Arguments
///
/// * `session` - A [`Session`], created with
/// [`create_session()`][`RemoteDesktop::create_session`].
/// * `dx` - Relative axis movement on the x axis.
/// * `dy` - Relative axis movement on the y axis.
/// * `finish` - Whether it is the last axis event.
///
/// # Specifications
///
/// See also [`NotifyPointerAxis`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-notifypointeraxis).
#[doc(alias = "NotifyPointerAxis")]
pub async fn notify_pointer_axis(
&self,
session: &Session<'_, Self>,
dx: f64,
dy: f64,
finish: bool,
) -> Result<(), Error> {
// see https://github.com/flatpak/xdg-desktop-portal/blob/master/src/remote-desktop.c#L911
let mut options: HashMap<&str, Value<'_>> = HashMap::new();
options.insert("finish", Value::Bool(finish));
self.0
.call("NotifyPointerAxis", &(session, options, dx, dy))
.await
}
/// Connect to EIS.
///
/// **Note** only succeeds if called after [`RemoteDesktop::start`].
///
/// Requires RemoteDesktop version 2.
///
/// # Arguments
///
/// * `session` - A [`Session`], created with
/// [`create_session()`][`RemoteDesktop::create_session`].
///
/// # Required version
///
/// The method requires the 2nd version implementation of the portal and
/// would fail with [`Error::RequiresVersion`] otherwise.
///
/// # Specifications
///
/// See also [`ConnectToEIS`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-connecttoeis).
#[doc(alias = "ConnectToEIS")]
pub async fn connect_to_eis(&self, session: &Session<'_, Self>) -> Result<OwnedFd, Error> {
// `ConnectToEIS` doesn't take any options for now
// see https://github.com/flatpak/xdg-desktop-portal/blob/master/src/remote-desktop.c#L1464
let options: HashMap<&str, Value<'_>> = HashMap::new();
let fd = self
.0
.call_versioned::<zvariant::OwnedFd>("ConnectToEIS", &(session, options), 2)
.await?;
Ok(fd.into())
}
/// Available source types.
///
/// # Specifications
///
/// See also [`AvailableDeviceTypes`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html#org-freedesktop-portal-remotedesktop-availabledevicetypes).
#[doc(alias = "AvailableDeviceTypes")]
pub async fn available_device_types(&self) -> Result<BitFlags<DeviceType>, Error> {
self.0.property("AvailableDeviceTypes").await
}
}
impl<'a> std::ops::Deref for RemoteDesktop<'a> {
type Target = zbus::Proxy<'a>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl SessionPortal for RemoteDesktop<'_> {}