improve libei error handling

This commit is contained in:
Ferdinand Schober
2024-07-10 09:32:21 +02:00
parent 110b37e26e
commit 89ca9c3c0b
2 changed files with 38 additions and 27 deletions

View File

@@ -43,6 +43,9 @@ pub enum CaptureError {
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))] #[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
#[error(transparent)] #[error(transparent)]
Portal(#[from] ashpd::Error), Portal(#[from] ashpd::Error),
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
#[error("libei disconnected - reason: `{0}`")]
Disconnected(String),
} }
#[derive(Debug, Error)] #[derive(Debug, Error)]

View File

@@ -192,7 +192,10 @@ async fn libei_event_handler(
.map_err(ReisConvertEventStreamError::from)?; .map_err(ReisConvertEventStreamError::from)?;
log::trace!("from ei: {ei_event:?}"); log::trace!("from ei: {ei_event:?}");
let client = current_client.get(); let client = current_client.get();
handle_ei_event(ei_event, client, &context, &event_tx).await?; if !handle_ei_event(ei_event, client, &context, &event_tx).await? {
/* close requested */
break Ok(());
}
} }
} }
@@ -403,7 +406,7 @@ async fn handle_ei_event(
current_client: Option<CaptureHandle>, current_client: Option<CaptureHandle>,
context: &ei::Context, context: &ei::Context,
event_tx: &Sender<(CaptureHandle, Event)>, event_tx: &Sender<(CaptureHandle, Event)>,
) -> Result<(), CaptureError> { ) -> Result<bool, CaptureError> {
match ei_event { match ei_event {
EiEvent::SeatAdded(s) => { EiEvent::SeatAdded(s) => {
s.seat.bind_capabilities(&[ s.seat.bind_capabilities(&[
@@ -429,10 +432,11 @@ async fn handle_ei_event(
group: mods.group, group: mods.group,
}; };
if let Some(current_client) = current_client { if let Some(current_client) = current_client {
event_tx if event_tx
.send((current_client, Event::Keyboard(modifier_event))) .send((current_client, Event::Keyboard(modifier_event)))
.await .await.is_err() {
.map_err(|_| CaptureError::EndOfStream)?; return Ok(false);
}
} }
} }
EiEvent::Frame(_) => {} EiEvent::Frame(_) => {}
@@ -449,10 +453,11 @@ async fn handle_ei_event(
dy: motion.dy as f64, dy: motion.dy as f64,
}; };
if let Some(current_client) = current_client { if let Some(current_client) = current_client {
event_tx if event_tx
.send((current_client, Event::Pointer(motion_event))) .send((current_client, Event::Pointer(motion_event)))
.await .await.is_err() {
.map_err(|_| CaptureError::EndOfStream)?; return Ok(false);
}
} }
} }
EiEvent::PointerMotionAbsolute(_) => {} EiEvent::PointerMotionAbsolute(_) => {}
@@ -466,10 +471,11 @@ async fn handle_ei_event(
}, },
}; };
if let Some(current_client) = current_client { if let Some(current_client) = current_client {
event_tx if event_tx
.send((current_client, Event::Pointer(button_event))) .send((current_client, Event::Pointer(button_event)))
.await .await.is_err() {
.map_err(|_| CaptureError::EndOfStream)?; return Ok(false);
}
} }
} }
EiEvent::ScrollDelta(delta) => { EiEvent::ScrollDelta(delta) => {
@@ -490,10 +496,11 @@ async fn handle_ei_event(
}); });
} }
for event in events { for event in events {
event_tx if event_tx
.send((handle, Event::Pointer(event))) .send((handle, Event::Pointer(event)))
.await .await.is_err() {
.map_err(|_| CaptureError::EndOfStream)?; return Ok(false);
}
} }
} }
} }
@@ -506,10 +513,11 @@ async fn handle_ei_event(
value: scroll.discrete_dy, value: scroll.discrete_dy,
}; };
if let Some(current_client) = current_client { if let Some(current_client) = current_client {
event_tx if event_tx
.send((current_client, Event::Pointer(event))) .send((current_client, Event::Pointer(event)))
.await .await.is_err() {
.map_err(|_| CaptureError::EndOfStream)?; return Ok(false);
}
} }
} }
if scroll.discrete_dx != 0 { if scroll.discrete_dx != 0 {
@@ -518,10 +526,11 @@ async fn handle_ei_event(
value: scroll.discrete_dx, value: scroll.discrete_dx,
}; };
if let Some(current_client) = current_client { if let Some(current_client) = current_client {
event_tx if event_tx
.send((current_client, Event::Pointer(event))) .send((current_client, Event::Pointer(event)))
.await .await.is_err() {
.map_err(|_| CaptureError::EndOfStream)?; return Ok(false);
}
} }
}; };
} }
@@ -535,20 +544,19 @@ async fn handle_ei_event(
time: key.time as u32, time: key.time as u32,
}; };
if let Some(current_client) = current_client { if let Some(current_client) = current_client {
event_tx if event_tx
.send((current_client, Event::Keyboard(key_event))) .send((current_client, Event::Keyboard(key_event)))
.await .await.is_err() {
.map_err(|_| CaptureError::EndOfStream)?; return Ok(false);
}
} }
} }
EiEvent::TouchDown(_) => {} EiEvent::TouchDown(_) => {}
EiEvent::TouchUp(_) => {} EiEvent::TouchUp(_) => {}
EiEvent::TouchMotion(_) => {} EiEvent::TouchMotion(_) => {}
EiEvent::Disconnected(d) => { EiEvent::Disconnected(d) => return Err(CaptureError::Disconnected(format!("{:?}", d.reason))),
log::error!("disconnect: {d:?}");
}
} }
Ok(()) Ok(true)
} }
impl<'a> LanMouseInputCapture for LibeiInputCapture<'a> { impl<'a> LanMouseInputCapture for LibeiInputCapture<'a> {