@@ -5,10 +5,13 @@ use wayland_client as wlc;
55use wayland_client:: protocol:: wl_registry;
66use wayland_protocols:: xdg_shell:: client:: xdg_wm_base;
77
8+ type GlobalEventConsumer = dyn Fn ( & wlc:: GlobalEvent , & wlc:: Attached < wl_registry:: WlRegistry > , & wlc:: DispatchData )
9+ + ' static ;
10+
811#[ derive( Clone ) ]
912pub struct GlobalEventSubscription {
1013 id : u64 ,
11- sub : std:: sync:: Arc < dyn GlobalEventConsumer > ,
14+ sub : std:: sync:: Arc < GlobalEventConsumer > ,
1215}
1316
1417impl GlobalEventSubscription {
@@ -18,22 +21,20 @@ impl GlobalEventSubscription {
1821 }
1922}
2023
21- impl GlobalEventConsumer for GlobalEventSubscription {
24+ impl GlobalEventSubscription {
2225 fn consume (
2326 & self ,
2427 event : & wlc:: GlobalEvent ,
2528 registry : & wlc:: Attached < wl_registry:: WlRegistry > ,
2629 ctx : & wlc:: DispatchData ,
2730 ) {
28- self . sub . consume ( event, registry, ctx)
31+ ( self . sub ) ( event, registry, ctx)
2932 }
3033}
3134
3235impl < X > From < X > for GlobalEventSubscription
3336where
34- X : Fn ( & wlc:: GlobalEvent , & wlc:: Attached < wl_registry:: WlRegistry > , & wlc:: DispatchData )
35- + GlobalEventConsumer
36- + ' static ,
37+ X : Fn ( & wlc:: GlobalEvent , & wlc:: Attached < wl_registry:: WlRegistry > , & wlc:: DispatchData ) + ' static ,
3738{
3839 fn from ( closure : X ) -> Self {
3940 Self {
@@ -43,34 +44,11 @@ where
4344 }
4445}
4546
46- impl < X > GlobalEventConsumer for X
47- where
48- X : Fn ( & wlc:: GlobalEvent , & wlc:: Attached < wl_registry:: WlRegistry > , & wlc:: DispatchData ) + ' static ,
49- {
50- fn consume (
51- & self ,
52- event : & wlc:: GlobalEvent ,
53- registry : & wlc:: Attached < wl_registry:: WlRegistry > ,
54- ctx : & wlc:: DispatchData ,
55- ) {
56- self ( event, registry, ctx)
57- }
58- }
59-
6047pub trait GlobalEventDispatch {
6148 fn subscribe ( & self , sub : impl Into < GlobalEventSubscription > ) -> GlobalEventSubscription ;
6249 fn release ( & self , s : & GlobalEventSubscription ) ;
6350}
6451
65- pub trait GlobalEventConsumer {
66- fn consume (
67- & self ,
68- event : & wlc:: GlobalEvent ,
69- registry : & wlc:: Attached < wl_registry:: WlRegistry > ,
70- ctx : & wlc:: DispatchData ,
71- ) ;
72- }
73-
7452pub ( super ) struct Dispatcher {
7553 incr : crate :: Counter ,
7654 subscriptions : std:: cell:: RefCell < BTreeMap < u64 , GlobalEventSubscription > > ,
@@ -85,18 +63,16 @@ impl Default for Dispatcher {
8563 }
8664}
8765
88- impl GlobalEventConsumer for Dispatcher {
66+ impl Dispatcher {
8967 fn consume (
9068 & self ,
9169 event : & wlc:: GlobalEvent ,
9270 registry : & wlc:: Attached < wl_registry:: WlRegistry > ,
9371 ctx : & wlc:: DispatchData ,
9472 ) {
95- // tracing::info!("global event initiated {:?} {:?}", registry, event);
9673 for ( _, sub) in self . subscriptions . borrow ( ) . iter ( ) {
9774 sub. consume ( event, registry, ctx) ;
9875 }
99- // tracing::info!("global event completed {:?} {:?}", registry, event);
10076 }
10177}
10278
@@ -120,12 +96,6 @@ pub(super) struct Environment {
12096 dispatcher : std:: sync:: Arc < Dispatcher > ,
12197}
12298
123- // because we have the global environment we need to mark these as safe/send.
124- // strictly speaking we should probably guard the access to the various fields
125- // behind a mutex, but in practice we are not actually accessing across threads.
126- unsafe impl Sync for Environment { }
127- unsafe impl Send for Environment { }
128-
12999impl GlobalEventDispatch for Environment {
130100 fn subscribe ( & self , sub : impl Into < GlobalEventSubscription > ) -> GlobalEventSubscription {
131101 self . dispatcher . subscribe ( sub)
0 commit comments