mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-17 22:11:28 +03:00
fix drop impl for desktop-portal
This commit is contained in:
@@ -4,10 +4,12 @@ use ashpd::{
|
|||||||
remote_desktop::{Axis, DeviceType, KeyState, RemoteDesktop},
|
remote_desktop::{Axis, DeviceType, KeyState, RemoteDesktop},
|
||||||
ResponseError, Session,
|
ResponseError, Session,
|
||||||
},
|
},
|
||||||
|
zbus::AsyncDrop,
|
||||||
WindowIdentifier,
|
WindowIdentifier,
|
||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
|
use futures::FutureExt;
|
||||||
use input_event::{
|
use input_event::{
|
||||||
Event::{Keyboard, Pointer},
|
Event::{Keyboard, Pointer},
|
||||||
KeyboardEvent, PointerEvent,
|
KeyboardEvent, PointerEvent,
|
||||||
@@ -19,7 +21,7 @@ use super::{error::XdpEmulationCreationError, EmulationHandle, InputEmulation};
|
|||||||
|
|
||||||
pub struct DesktopPortalEmulation<'a> {
|
pub struct DesktopPortalEmulation<'a> {
|
||||||
proxy: RemoteDesktop<'a>,
|
proxy: RemoteDesktop<'a>,
|
||||||
session: Option<Session<'a>>,
|
session: Session<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DesktopPortalEmulation<'a> {
|
impl<'a> DesktopPortalEmulation<'a> {
|
||||||
@@ -53,7 +55,7 @@ impl<'a> DesktopPortalEmulation<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
log::debug!("started session");
|
log::debug!("started session");
|
||||||
let session = Some(session);
|
let session = session;
|
||||||
|
|
||||||
Ok(Self { proxy, session })
|
Ok(Self { proxy, session })
|
||||||
}
|
}
|
||||||
@@ -74,11 +76,7 @@ impl<'a> InputEmulation for DesktopPortalEmulation<'a> {
|
|||||||
relative_y,
|
relative_y,
|
||||||
} => {
|
} => {
|
||||||
self.proxy
|
self.proxy
|
||||||
.notify_pointer_motion(
|
.notify_pointer_motion(&self.session, relative_x, relative_y)
|
||||||
self.session.as_ref().expect("no session"),
|
|
||||||
relative_x,
|
|
||||||
relative_y,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
PointerEvent::Button {
|
PointerEvent::Button {
|
||||||
@@ -91,11 +89,7 @@ impl<'a> InputEmulation for DesktopPortalEmulation<'a> {
|
|||||||
_ => KeyState::Pressed,
|
_ => KeyState::Pressed,
|
||||||
};
|
};
|
||||||
self.proxy
|
self.proxy
|
||||||
.notify_pointer_button(
|
.notify_pointer_button(&self.session, button as i32, state)
|
||||||
self.session.as_ref().expect("no session"),
|
|
||||||
button as i32,
|
|
||||||
state,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
PointerEvent::AxisDiscrete120 { axis, value } => {
|
PointerEvent::AxisDiscrete120 { axis, value } => {
|
||||||
@@ -104,11 +98,7 @@ impl<'a> InputEmulation for DesktopPortalEmulation<'a> {
|
|||||||
_ => Axis::Horizontal,
|
_ => Axis::Horizontal,
|
||||||
};
|
};
|
||||||
self.proxy
|
self.proxy
|
||||||
.notify_pointer_axis_discrete(
|
.notify_pointer_axis_discrete(&self.session, axis, value)
|
||||||
self.session.as_ref().expect("no session"),
|
|
||||||
axis,
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
PointerEvent::Axis {
|
PointerEvent::Axis {
|
||||||
@@ -125,12 +115,7 @@ impl<'a> InputEmulation for DesktopPortalEmulation<'a> {
|
|||||||
Axis::Horizontal => (value, 0.),
|
Axis::Horizontal => (value, 0.),
|
||||||
};
|
};
|
||||||
self.proxy
|
self.proxy
|
||||||
.notify_pointer_axis(
|
.notify_pointer_axis(&self.session, dx, dy, true)
|
||||||
self.session.as_ref().expect("no session"),
|
|
||||||
dx,
|
|
||||||
dy,
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
PointerEvent::Frame {} => {}
|
PointerEvent::Frame {} => {}
|
||||||
@@ -147,11 +132,7 @@ impl<'a> InputEmulation for DesktopPortalEmulation<'a> {
|
|||||||
_ => KeyState::Pressed,
|
_ => KeyState::Pressed,
|
||||||
};
|
};
|
||||||
self.proxy
|
self.proxy
|
||||||
.notify_keyboard_keycode(
|
.notify_keyboard_keycode(&self.session, key as i32, state)
|
||||||
self.session.as_ref().expect("no session"),
|
|
||||||
key as i32,
|
|
||||||
state,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
KeyboardEvent::Modifiers { .. } => {
|
KeyboardEvent::Modifiers { .. } => {
|
||||||
@@ -168,16 +149,21 @@ impl<'a> InputEmulation for DesktopPortalEmulation<'a> {
|
|||||||
async fn destroy(&mut self, _client: EmulationHandle) {}
|
async fn destroy(&mut self, _client: EmulationHandle) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Drop for DesktopPortalEmulation<'a> {
|
impl<'a> AsyncDrop for DesktopPortalEmulation<'a> {
|
||||||
fn drop(&mut self) {
|
#[doc = r" Perform the async cleanup."]
|
||||||
let session = self.session.take().expect("no session");
|
#[must_use]
|
||||||
tokio::runtime::Handle::try_current()
|
#[allow(clippy::type_complexity, clippy::type_repetition_in_bounds)]
|
||||||
.expect("no runtime")
|
fn async_drop<'async_trait>(
|
||||||
.block_on(async move {
|
self,
|
||||||
log::debug!("closing remote desktop session");
|
) -> ::core::pin::Pin<
|
||||||
if let Err(e) = session.close().await {
|
Box<dyn ::core::future::Future<Output = ()> + ::core::marker::Send + 'async_trait>,
|
||||||
log::error!("failed to close remote desktop session: {e}");
|
>
|
||||||
}
|
where
|
||||||
});
|
Self: 'async_trait,
|
||||||
|
{
|
||||||
|
async move {
|
||||||
|
let _ = self.session.close().await;
|
||||||
|
}
|
||||||
|
.boxed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user