diff --git a/input-capture/src/libei.rs b/input-capture/src/libei.rs index 5a19d27..9517fb0 100644 --- a/input-capture/src/libei.rs +++ b/input-capture/src/libei.rs @@ -53,17 +53,13 @@ enum CaptureEvent { Destroy(CaptureHandle), } -/// events that do not necessitate restarting the capture session -#[derive(Clone, Copy, Debug)] -struct ReleaseCaptureEvent; - #[allow(dead_code)] pub struct LibeiInputCapture<'a> { input_capture: Pin>>, capture_task: JoinHandle>, event_rx: Receiver<(CaptureHandle, Event)>, notify_capture: Sender, - notify_capture_session: Sender, + notify_release: Arc, cancellation_token: CancellationToken, } @@ -214,14 +210,14 @@ impl<'a> LibeiInputCapture<'a> { let (event_tx, event_rx) = mpsc::channel(1); let (notify_capture, notify_rx) = mpsc::channel(1); - let (notify_capture_session, notify_session_rx) = mpsc::channel(1); + let notify_release = Arc::new(Notify::new()); let cancellation_token = CancellationToken::new(); let capture = do_capture( input_capture_ptr, notify_rx, - notify_session_rx, + notify_release.clone(), first_session, event_tx, cancellation_token.clone(), @@ -233,7 +229,7 @@ impl<'a> LibeiInputCapture<'a> { event_rx, capture_task, notify_capture, - notify_capture_session, + notify_release, cancellation_token, }; @@ -244,7 +240,7 @@ impl<'a> LibeiInputCapture<'a> { async fn do_capture<'a>( input_capture: *const InputCapture<'a>, mut capture_event: Receiver, - mut release_capture_channel: Receiver, + notify_release: Arc, session: Option<(Session<'a>, BitFlags)>, event_tx: Sender<(CaptureHandle, Event)>, cancellation_token: CancellationToken, @@ -293,7 +289,7 @@ async fn do_capture<'a>( &event_tx, &mut active_clients, &mut next_barrier_id, - &mut release_capture_channel, + ¬ify_release, cancel_session.clone(), cancel_update.clone(), ); @@ -337,7 +333,7 @@ async fn do_capture_session( event_tx: &Sender<(CaptureHandle, Event)>, active_clients: &mut Vec<(CaptureHandle, Position)>, next_barrier_id: &mut u32, - capture_session_event: &mut Receiver, + notify_release: &Notify, cancel_session: CancellationToken, cancel_update: CancellationToken, ) -> Result<(), CaptureError> { @@ -400,21 +396,33 @@ async fn do_capture_session( event_tx.send((client, Event::Enter())).await.expect("no channel"); tokio::select! { - _ = capture_session_event.recv() => {}, /* capture release */ + _ = notify_release.notified() => { /* capture release */ + log::debug!("release session requested"); + }, _ = release_session.notified() => { /* release session */ + log::debug!("ei devices changed"); ei_devices_changed = true; }, - _ = cancel_session.cancelled() => break, /* kill session notify */ + _ = cancel_session.cancelled() => { /* kill session notify */ + log::debug!("session cancel requested"); + break + }, } release_capture(input_capture, session, activated, client, active_clients).await?; } - _ = capture_session_event.recv() => {}, /* capture release -> we are not capturing anyway, so ignore */ + _ = notify_release.notified() => { /* capture release -> we are not capturing anyway, so ignore */ + log::debug!("release session requested"); + }, _ = release_session.notified() => { /* release session */ + log::debug!("ei devices changed"); ei_devices_changed = true; }, - _ = cancel_session.cancelled() => break, /* kill session notify */ + _ = cancel_session.cancelled() => { /* kill session notify */ + log::debug!("session cancel requested"); + break + }, } if ei_devices_changed { /* for whatever reason, GNOME seems to kill the session @@ -664,7 +672,7 @@ impl<'a> LanMouseInputCapture for LibeiInputCapture<'a> { } async fn release(&mut self) -> Result<(), CaptureError> { - let _ = self.notify_capture_session.send(ReleaseCaptureEvent).await; + self.notify_release.notify_one(); Ok(()) } diff --git a/src/server/capture_task.rs b/src/server/capture_task.rs index f8edebf..2bbb4c0 100644 --- a/src/server/capture_task.rs +++ b/src/server/capture_task.rs @@ -123,15 +123,15 @@ async fn do_capture( .await; // FIXME DUPLICATES - let clients = server - .client_manager - .borrow() - .get_client_states() - .map(|(h, (c, _))| (h, c.pos)) - .collect::>(); - for (handle, pos) in clients { - capture.create(handle, pos.into()).await?; - } + // let clients = server + // .client_manager + // .borrow() + // .get_client_states() + // .map(|(h, (c, _))| (h, c.pos)) + // .collect::>(); + // for (handle, pos) in clients { + // capture.create(handle, pos.into()).await?; + // } let mut pressed_keys = HashSet::new(); loop { diff --git a/src/server/emulation_task.rs b/src/server/emulation_task.rs index 30fba4c..a3c7670 100644 --- a/src/server/emulation_task.rs +++ b/src/server/emulation_task.rs @@ -129,17 +129,17 @@ async fn do_emulation( .send(FrontendEvent::EmulationStatus(Status::Enabled)) .await; - // FIMXE DUPLICATES + // FIXME DUPLICATES // add clients - let clients = server - .client_manager - .borrow() - .get_client_states() - .map(|(h, _)| h) - .collect::>(); - for handle in clients { - emulation.create(handle).await; - } + // let clients = server + // .client_manager + // .borrow() + // .get_client_states() + // .map(|(h, _)| h) + // .collect::>(); + // for handle in clients { + // emulation.create(handle).await; + // } let mut last_ignored = None; loop {