11use futures:: SinkExt ;
22use wayland_client:: {
33 delegate_noop,
4+ globals:: { registry_queue_init, GlobalListContents } ,
45 protocol:: {
56 wl_output:: { self , WlOutput } ,
67 wl_registry,
78 } ,
89 Connection , Dispatch , Proxy ,
910} ;
1011
11- use wayland_protocols:: xdg:: xdg_output:: zv1:: client:: zxdg_output_manager_v1:: ZxdgOutputManagerV1 ;
12+ use wayland_protocols:: xdg:: xdg_output:: zv1:: client:: {
13+ zxdg_output_manager_v1:: ZxdgOutputManagerV1 , zxdg_output_v1,
14+ } ;
15+
16+ #[ derive( Debug ) ]
17+ struct BaseState ;
18+
19+ // so interesting, it is just need to invoke once, it just used to get the globals
20+ impl Dispatch < wl_registry:: WlRegistry , GlobalListContents > for BaseState {
21+ fn event (
22+ _state : & mut Self ,
23+ _proxy : & wl_registry:: WlRegistry ,
24+ _event : <wl_registry:: WlRegistry as wayland_client:: Proxy >:: Event ,
25+ _data : & GlobalListContents ,
26+ _conn : & Connection ,
27+ _qh : & wayland_client:: QueueHandle < Self > ,
28+ ) {
29+ }
30+ }
1231
1332#[ derive( Debug , Default ) ]
1433struct SubscribeState {
1534 events : Vec < WaylandEvents > ,
35+ padding_wloutputs : Vec < wl_output:: WlOutput > ,
1636}
1737
1838impl Dispatch < wl_registry:: WlRegistry , ( ) > for SubscribeState {
@@ -32,35 +52,65 @@ impl Dispatch<wl_registry::WlRegistry, ()> for SubscribeState {
3252 } => {
3353 if interface == wl_output:: WlOutput :: interface ( ) . name {
3454 let output = proxy. bind :: < wl_output:: WlOutput , _ , _ > ( name, version, qh, ( ) ) ;
35- state. events . push ( WaylandEvents :: OutputInsert ( output) ) ;
55+ state. padding_wloutputs . push ( output) ;
3656 }
3757 }
3858 wl_registry:: Event :: GlobalRemove { .. } => { }
3959 _ => unreachable ! ( ) ,
4060 }
4161 }
4262}
63+ impl Dispatch < zxdg_output_v1:: ZxdgOutputV1 , ( ) > for SubscribeState {
64+ fn event (
65+ state : & mut Self ,
66+ _proxy : & zxdg_output_v1:: ZxdgOutputV1 ,
67+ event : <zxdg_output_v1:: ZxdgOutputV1 as Proxy >:: Event ,
68+ _data : & ( ) ,
69+ _conn : & Connection ,
70+ _qhandle : & wayland_client:: QueueHandle < Self > ,
71+ ) {
72+ if let zxdg_output_v1:: Event :: Name { name } = event {
73+ state. events . push ( WaylandEvents :: OutputInsert ( name) ) ;
74+ }
75+ }
76+ }
4377delegate_noop ! ( SubscribeState : ignore WlOutput ) ; // output is need to place layer_shell, although here
4478delegate_noop ! ( SubscribeState : ignore ZxdgOutputManagerV1 ) ;
4579
4680#[ derive( Debug , Clone ) ]
4781pub enum WaylandEvents {
48- OutputInsert ( wl_output :: WlOutput ) ,
82+ OutputInsert ( String ) ,
4983}
5084
5185pub fn listen ( ) -> iced:: Subscription < WaylandEvents > {
5286 iced:: Subscription :: run ( || {
5387 iced:: stream:: channel ( 100 , |mut output| async move {
5488 let connection = Connection :: connect_to_env ( ) . unwrap ( ) ;
89+ let ( globals, _) = registry_queue_init :: < BaseState > ( & connection) . unwrap ( ) ; // We just need the
90+ // global, the
91+ // event_queue is
92+ // not needed, we
93+ // do not need
94+ // BaseState after
95+
5596 let mut state = SubscribeState :: default ( ) ;
5697
5798 let mut event_queue = connection. new_event_queue :: < SubscribeState > ( ) ;
5899 let qhandle = event_queue. handle ( ) ;
59100 let display = connection. display ( ) ;
60101
102+ let xdg_output_manager = globals
103+ . bind :: < ZxdgOutputManagerV1 , _ , _ > ( & qhandle, 1 ..=3 , ( ) )
104+ . unwrap ( ) ; // b
61105 display. get_registry ( & qhandle, ( ) ) ;
62106 loop {
63107 event_queue. blocking_dispatch ( & mut state) . unwrap ( ) ;
108+ let mut current_outputs = vec ! [ ] ;
109+ std:: mem:: swap ( & mut current_outputs, & mut state. padding_wloutputs ) ;
110+ for output in current_outputs {
111+ xdg_output_manager. get_xdg_output ( & output, & qhandle, ( ) ) ;
112+ }
113+
64114 let mut current_events = vec ! [ ] ;
65115 std:: mem:: swap ( & mut current_events, & mut state. events ) ;
66116 for event in current_events {
0 commit comments