mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-22 04:30:54 +03:00
allow cancelling session creation
This commit is contained in:
@@ -156,7 +156,6 @@ pub async fn create(
|
||||
Backend::Windows,
|
||||
#[cfg(target_os = "macos")]
|
||||
Backend::MacOs,
|
||||
Backend::Dummy,
|
||||
] {
|
||||
match create_backend(backend).await {
|
||||
Ok(b) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use ashpd::{
|
||||
desktop::{
|
||||
input_capture::{Activated, Barrier, BarrierID, Capabilities, InputCapture, Region, Zones},
|
||||
ResponseError, Session,
|
||||
Session,
|
||||
},
|
||||
enumflags2::BitFlags,
|
||||
};
|
||||
@@ -140,21 +140,12 @@ async fn create_session<'a>(
|
||||
input_capture: &'a InputCapture<'a>,
|
||||
) -> std::result::Result<(Session<'a>, BitFlags<Capabilities>), ashpd::Error> {
|
||||
log::debug!("creating input capture session");
|
||||
let (session, capabilities) = loop {
|
||||
match input_capture
|
||||
.create_session(
|
||||
&ashpd::WindowIdentifier::default(),
|
||||
Capabilities::Keyboard | Capabilities::Pointer | Capabilities::Touchscreen,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(s) => break s,
|
||||
Err(ashpd::Error::Response(ResponseError::Cancelled)) => continue,
|
||||
o => o?,
|
||||
};
|
||||
};
|
||||
log::debug!("capabilities: {capabilities:?}");
|
||||
Ok((session, capabilities))
|
||||
input_capture
|
||||
.create_session(
|
||||
&ashpd::WindowIdentifier::default(),
|
||||
Capabilities::Keyboard | Capabilities::Pointer | Capabilities::Touchscreen,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn connect_to_eis(
|
||||
|
||||
@@ -99,7 +99,14 @@ async fn do_capture(
|
||||
frontend_tx: &Sender<FrontendEvent>,
|
||||
release_bind: &[scancode::Linux],
|
||||
) -> Result<(), LanMouseCaptureError> {
|
||||
let mut capture = input_capture::create(backend).await?;
|
||||
/* allow cancelling capture request */
|
||||
let mut capture = tokio::select! {
|
||||
r = input_capture::create(backend) => {
|
||||
r?
|
||||
},
|
||||
_ = server.cancelled() => return Ok(()),
|
||||
};
|
||||
|
||||
let _ = frontend_tx
|
||||
.send(FrontendEvent::CaptureStatus(Status::Enabled))
|
||||
.await;
|
||||
|
||||
@@ -109,7 +109,12 @@ async fn do_emulation(
|
||||
) -> Result<(), LanMouseEmulationError> {
|
||||
let backend = backend.map(|b| b.into());
|
||||
log::info!("creating input emulation...");
|
||||
let mut emulation = input_emulation::create(backend).await?;
|
||||
let mut emulation = tokio::select! {
|
||||
r = input_emulation::create(backend) => {
|
||||
r?
|
||||
}
|
||||
_ = server.cancelled() => return Ok(()),
|
||||
};
|
||||
let _ = frontend_tx
|
||||
.send(FrontendEvent::EmulationStatus(Status::Enabled))
|
||||
.await;
|
||||
|
||||
Reference in New Issue
Block a user