Skip to content

Commit 85220c2

Browse files
authored
Merge pull request #24 from typester/feature/ready
wait server process until wayland status is ready
2 parents dce8052 + 976facd commit 85220c2

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/river.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::collections::{HashMap, HashSet};
22

3-
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
3+
use tokio::sync::{
4+
mpsc::{self, UnboundedReceiver, UnboundedSender},
5+
oneshot,
6+
};
47

58
use wayland_client::protocol::{
69
wl_output::{self, WlOutput},
@@ -82,10 +85,11 @@ struct State {
8285
tx: UnboundedSender<Event>,
8386
output_info: HashMap<u32, OutputInfo>,
8487
output_status_owner: HashMap<u32, ObjectId>,
88+
ready: Option<oneshot::Sender<()>>,
8589
}
8690

8791
impl State {
88-
fn new(tx: UnboundedSender<Event>) -> Self {
92+
fn new(tx: UnboundedSender<Event>, ready: oneshot::Sender<()>) -> Self {
8993
Self {
9094
outputs: HashMap::new(),
9195
seats: HashMap::new(),
@@ -95,6 +99,7 @@ impl State {
9599
tx,
96100
output_info: HashMap::new(),
97101
output_status_owner: HashMap::new(),
102+
ready: Some(ready),
98103
}
99104
}
100105

@@ -205,6 +210,9 @@ impl Dispatch<WlRegistry, ()> for State {
205210
registry.bind::<ZriverStatusManagerV1, _, _>(name, version.min(4), qh, ());
206211
state.manager = Some(mgr);
207212
state.create_status_for_all(qh);
213+
if let Some(sender) = state.ready.take() {
214+
let _ = sender.send(());
215+
}
208216
}
209217
_ => {}
210218
},
@@ -379,11 +387,13 @@ impl State {
379387
pub struct RiverStatus;
380388

381389
impl RiverStatus {
382-
pub fn subscribe() -> Result<UnboundedReceiver<Event>, Box<dyn std::error::Error>> {
390+
pub fn subscribe()
391+
-> Result<(UnboundedReceiver<Event>, oneshot::Receiver<()>), Box<dyn std::error::Error>> {
383392
let conn = Connection::connect_to_env()?;
384393
let (tx, rx) = mpsc::unbounded_channel();
394+
let (ready_tx, ready_rx) = oneshot::channel();
385395

386-
let mut state = State::new(tx);
396+
let mut state = State::new(tx, ready_tx);
387397
let mut event_queue: EventQueue<State> = conn.new_event_queue();
388398
let qh = event_queue.handle();
389399

@@ -401,6 +411,6 @@ impl RiverStatus {
401411
}
402412
});
403413

404-
Ok(rx)
414+
Ok((rx, ready_rx))
405415
}
406416
}

src/server.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ pub async fn run(listen: ListenTarget) -> Result<()> {
2828
.finish();
2929

3030
info!("connecting to river status stream");
31-
let mut river_rx = river::RiverStatus::subscribe().map_err(|e| anyhow!(e.to_string()))?;
31+
let (mut river_rx, river_ready) =
32+
river::RiverStatus::subscribe().map_err(|e| anyhow!(e.to_string()))?;
33+
river_ready
34+
.await
35+
.map_err(|e| anyhow!("river status initialization failed: {}", e))?;
3236
info!("river status stream connected");
3337
let tx_for_events = tx.clone();
3438
let state_for_events = river_state.clone();

0 commit comments

Comments
 (0)