11use 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
58use 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
8791impl 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 {
379387pub struct RiverStatus ;
380388
381389impl 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}
0 commit comments