mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-27 15:10:53 +03:00
update ashpd
This commit is contained in:
committed by
Ferdinand Schober
parent
27225ed564
commit
9d148804e4
@@ -40,7 +40,9 @@ wayland-protocols-misc = { version = "0.3.1", features = [
|
||||
"client",
|
||||
], optional = true }
|
||||
x11 = { version = "2.21.0", features = ["xlib", "xtest"], optional = true }
|
||||
ashpd = { version = "0.11.0", default-features = false, features = [
|
||||
ashpd = { version = "0.13.0", default-features = false, features = [
|
||||
"remote_desktop",
|
||||
"screencast",
|
||||
"tokio",
|
||||
], optional = true }
|
||||
reis = { version = "0.5.0", features = ["tokio"], optional = true }
|
||||
|
||||
@@ -13,7 +13,7 @@ use tokio::task::JoinHandle;
|
||||
|
||||
use ashpd::desktop::{
|
||||
PersistMode, Session,
|
||||
remote_desktop::{DeviceType, RemoteDesktop},
|
||||
remote_desktop::{DeviceType, RemoteDesktop, SelectDevicesOptions},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
|
||||
@@ -40,15 +40,15 @@ struct Devices {
|
||||
keyboard: Arc<RwLock<Option<(ei::Device, ei::Keyboard)>>>,
|
||||
}
|
||||
|
||||
pub(crate) struct LibeiEmulation<'a> {
|
||||
pub(crate) struct LibeiEmulation {
|
||||
context: ei::Context,
|
||||
conn: event::Connection,
|
||||
devices: Devices,
|
||||
ei_task: JoinHandle<()>,
|
||||
error: Arc<Mutex<Option<EmulationError>>>,
|
||||
libei_error: Arc<AtomicBool>,
|
||||
_remote_desktop: RemoteDesktop<'a>,
|
||||
session: Session<'a, RemoteDesktop<'a>>,
|
||||
_remote_desktop: RemoteDesktop,
|
||||
session: Session<RemoteDesktop>,
|
||||
}
|
||||
|
||||
/// Get the path to the RemoteDesktop token file
|
||||
@@ -84,27 +84,26 @@ fn write_token(token: &str) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_ei_fd<'a>()
|
||||
-> Result<(RemoteDesktop<'a>, Session<'a, RemoteDesktop<'a>>, OwnedFd), ashpd::Error> {
|
||||
async fn get_ei_fd() -> Result<(RemoteDesktop, Session<RemoteDesktop>, OwnedFd), ashpd::Error> {
|
||||
let remote_desktop = RemoteDesktop::new().await?;
|
||||
|
||||
let restore_token = read_token();
|
||||
|
||||
log::debug!("creating session ...");
|
||||
let session = remote_desktop.create_session().await?;
|
||||
let session = remote_desktop.create_session(Default::default()).await?;
|
||||
|
||||
log::debug!("selecting devices ...");
|
||||
remote_desktop
|
||||
.select_devices(
|
||||
&session,
|
||||
DeviceType::Keyboard | DeviceType::Pointer,
|
||||
restore_token.as_deref(),
|
||||
PersistMode::ExplicitlyRevoked,
|
||||
)
|
||||
.await?;
|
||||
let options = SelectDevicesOptions::default()
|
||||
.set_devices(DeviceType::Keyboard | DeviceType::Pointer)
|
||||
.set_persist_mode(PersistMode::ExplicitlyRevoked)
|
||||
.set_restore_token(restore_token.as_deref());
|
||||
remote_desktop.select_devices(&session, options).await?;
|
||||
|
||||
log::info!("requesting permission for input emulation");
|
||||
let start_response = remote_desktop.start(&session, None).await?.response()?;
|
||||
let start_response = remote_desktop
|
||||
.start(&session, None, Default::default())
|
||||
.await?
|
||||
.response()?;
|
||||
|
||||
// The restore token is only valid once, we need to re-save it each time
|
||||
if let Some(token_str) = start_response.restore_token() {
|
||||
@@ -113,11 +112,13 @@ async fn get_ei_fd<'a>()
|
||||
}
|
||||
}
|
||||
|
||||
let fd = remote_desktop.connect_to_eis(&session).await?;
|
||||
let fd = remote_desktop
|
||||
.connect_to_eis(&session, Default::default())
|
||||
.await?;
|
||||
Ok((remote_desktop, session, fd))
|
||||
}
|
||||
|
||||
impl LibeiEmulation<'_> {
|
||||
impl LibeiEmulation {
|
||||
pub(crate) async fn new() -> Result<Self, LibeiEmulationCreationError> {
|
||||
let (_remote_desktop, session, eifd) = get_ei_fd().await?;
|
||||
let stream = UnixStream::from(eifd);
|
||||
@@ -152,14 +153,14 @@ impl LibeiEmulation<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for LibeiEmulation<'_> {
|
||||
impl Drop for LibeiEmulation {
|
||||
fn drop(&mut self) {
|
||||
self.ei_task.abort();
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Emulation for LibeiEmulation<'_> {
|
||||
impl Emulation for LibeiEmulation {
|
||||
async fn consume(
|
||||
&mut self,
|
||||
event: Event,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use ashpd::{
|
||||
desktop::{
|
||||
PersistMode, Session,
|
||||
remote_desktop::{Axis, DeviceType, KeyState, RemoteDesktop},
|
||||
remote_desktop::{
|
||||
Axis, DeviceType, KeyState, NotifyPointerAxisOptions, RemoteDesktop,
|
||||
SelectDevicesOptions,
|
||||
},
|
||||
},
|
||||
zbus::AsyncDrop,
|
||||
};
|
||||
@@ -17,32 +20,31 @@ use crate::error::EmulationError;
|
||||
|
||||
use super::{Emulation, EmulationHandle, error::XdpEmulationCreationError};
|
||||
|
||||
pub(crate) struct DesktopPortalEmulation<'a> {
|
||||
proxy: RemoteDesktop<'a>,
|
||||
session: Session<'a, RemoteDesktop<'a>>,
|
||||
pub(crate) struct DesktopPortalEmulation {
|
||||
proxy: RemoteDesktop,
|
||||
session: Session<RemoteDesktop>,
|
||||
}
|
||||
|
||||
impl<'a> DesktopPortalEmulation<'a> {
|
||||
pub(crate) async fn new() -> Result<DesktopPortalEmulation<'a>, XdpEmulationCreationError> {
|
||||
impl DesktopPortalEmulation {
|
||||
pub(crate) async fn new() -> Result<DesktopPortalEmulation, XdpEmulationCreationError> {
|
||||
log::debug!("connecting to org.freedesktop.portal.RemoteDesktop portal ...");
|
||||
let proxy = RemoteDesktop::new().await?;
|
||||
|
||||
// retry when user presses the cancel button
|
||||
log::debug!("creating session ...");
|
||||
let session = proxy.create_session().await?;
|
||||
let session = proxy.create_session(Default::default()).await?;
|
||||
|
||||
log::debug!("selecting devices ...");
|
||||
proxy
|
||||
.select_devices(
|
||||
&session,
|
||||
DeviceType::Keyboard | DeviceType::Pointer,
|
||||
None,
|
||||
PersistMode::ExplicitlyRevoked,
|
||||
)
|
||||
.await?;
|
||||
let options = SelectDevicesOptions::default()
|
||||
.set_devices(DeviceType::Keyboard | DeviceType::Pointer)
|
||||
.set_persist_mode(PersistMode::ExplicitlyRevoked);
|
||||
proxy.select_devices(&session, options).await?;
|
||||
|
||||
log::info!("requesting permission for input emulation");
|
||||
let _devices = proxy.start(&session, None).await?.response()?;
|
||||
let _devices = proxy
|
||||
.start(&session, None, Default::default())
|
||||
.await?
|
||||
.response()?;
|
||||
|
||||
log::debug!("started session");
|
||||
let session = session;
|
||||
@@ -52,7 +54,7 @@ impl<'a> DesktopPortalEmulation<'a> {
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Emulation for DesktopPortalEmulation<'_> {
|
||||
impl Emulation for DesktopPortalEmulation {
|
||||
async fn consume(
|
||||
&mut self,
|
||||
event: input_event::Event,
|
||||
@@ -62,7 +64,7 @@ impl Emulation for DesktopPortalEmulation<'_> {
|
||||
Pointer(p) => match p {
|
||||
PointerEvent::Motion { time: _, dx, dy } => {
|
||||
self.proxy
|
||||
.notify_pointer_motion(&self.session, dx, dy)
|
||||
.notify_pointer_motion(&self.session, dx, dy, Default::default())
|
||||
.await?;
|
||||
}
|
||||
PointerEvent::Button {
|
||||
@@ -75,7 +77,12 @@ impl Emulation for DesktopPortalEmulation<'_> {
|
||||
_ => KeyState::Pressed,
|
||||
};
|
||||
self.proxy
|
||||
.notify_pointer_button(&self.session, button as i32, state)
|
||||
.notify_pointer_button(
|
||||
&self.session,
|
||||
button as i32,
|
||||
state,
|
||||
Default::default(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
PointerEvent::AxisDiscrete120 { axis, value } => {
|
||||
@@ -84,7 +91,12 @@ impl Emulation for DesktopPortalEmulation<'_> {
|
||||
_ => Axis::Horizontal,
|
||||
};
|
||||
self.proxy
|
||||
.notify_pointer_axis_discrete(&self.session, axis, value / 120)
|
||||
.notify_pointer_axis_discrete(
|
||||
&self.session,
|
||||
axis,
|
||||
value / 120,
|
||||
Default::default(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
PointerEvent::Axis {
|
||||
@@ -101,7 +113,12 @@ impl Emulation for DesktopPortalEmulation<'_> {
|
||||
Axis::Horizontal => (value, 0.),
|
||||
};
|
||||
self.proxy
|
||||
.notify_pointer_axis(&self.session, dx, dy, true)
|
||||
.notify_pointer_axis(
|
||||
&self.session,
|
||||
dx,
|
||||
dy,
|
||||
NotifyPointerAxisOptions::default().set_finish(true),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
},
|
||||
@@ -117,7 +134,12 @@ impl Emulation for DesktopPortalEmulation<'_> {
|
||||
_ => KeyState::Pressed,
|
||||
};
|
||||
self.proxy
|
||||
.notify_keyboard_keycode(&self.session, key as i32, state)
|
||||
.notify_keyboard_keycode(
|
||||
&self.session,
|
||||
key as i32,
|
||||
state,
|
||||
Default::default(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
KeyboardEvent::Modifiers { .. } => {
|
||||
@@ -141,7 +163,7 @@ impl Emulation for DesktopPortalEmulation<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncDrop for DesktopPortalEmulation<'_> {
|
||||
impl AsyncDrop for DesktopPortalEmulation {
|
||||
#[doc = r" Perform the async cleanup."]
|
||||
#[allow(clippy::type_complexity, clippy::type_repetition_in_bounds)]
|
||||
fn async_drop<'async_trait>(
|
||||
|
||||
Reference in New Issue
Block a user