pub fn new_with_cb<F>(display: &wl_display::WlDisplay, mut callback: F) -> GlobalManager
    where
        F: FnMut(GlobalEvent, wl_registry::WlRegistry) + 'static,
    {
        let inner = Arc::new(Mutex::new(Inner { list: Vec::new() }));
        let inner_clone = inner.clone();

        let registry = display
            .get_registry(|registry| {
                registry.implement_closure(
                    move |msg, proxy| {
                        let mut inner = inner.lock().unwrap();
                        let inner = &mut *inner;
                        match msg {
                            wl_registry::Event::Global {
                                name,
                                interface,
                                version,
                            } => {
                                inner.list.push((name, interface.clone(), version));
                                callback(
                                    GlobalEvent::New {
                                        id: name,
                                        interface,
                                        version,
                                    },
                                    proxy,
                                    );
                            }
                            wl_registry::Event::GlobalRemove { name } => {
                                if let Some((i, _)) =
                                    inner.list.iter().enumerate().find(|&(_, &(n, _, _))| n == name)
                                    {
                                        let (id, interface, _) = inner.list.swap_remove(i);
                                        callback(
                                            GlobalEvent::Removed {
                                                id,
                                                interface,
                                            },
                                            proxy,
                                            );
                                    } else {
                                        panic!(
                                            "Wayland protocol error: the server removed non-existing global \"{}\".",
                                            name
                                        );
                                    }
                            },
                            _ => {}
                        }
                    },
                    (),
                )
            })
            .expect("Attempted to create a GlobalManager from a dead display.");

        GlobalManager {
            inner: inner_clone,
            registry,
        }
    }
/// Create a global manager handling a registry with a callback
///
/// This global manager will track globals as a simple one, but will
/// also forward the registry events to your callback.
///
/// This can be used if you want to handle specially certain globals, but want
/// to use the default mechanism for the rest.
///
/// In order to use `GlobalManager` from a different thread than the one `display` was created
/// on, wrap the `display` to an `EventQueue` on the appropriate thread using
/// `Proxy::make_wrapper()` before calling this function.
Create a global manager handling a registry with a callback
This global manager will track globals as a simple one, but will
also forward the registry events to your callback.

This can be used if you want to handle specially certain globals, but want
to use the default mechanism for the rest.


Create a global manager handling a registry with a callback This global manager will track globals as a simple one but will also forward the registry events to your callback . This can be used if you want to handle specially certain globals but want to use the default mechanism for the rest .
pub fn new_with_cb<F>(display: &wl_display::WlDisplay, mut callback: F) -> GlobalManager
    where
        F: FnMut(GlobalEvent, wl_registry::WlRegistry) + 'static,
    {
        let inner = Arc::new(Mutex::new(Inner { list: Vec::new() }));
        let inner_clone = inner.clone();
        let registry = display
            .get_registry(|registry| {
                registry.implement_closure(
                    move |msg, proxy| {
                        let mut inner = inner.lock().unwrap();
                        let inner = &mut *inner;
                        match msg {
                            wl_registry::Event::Global {
                                name,
                                interface,
                                version,
                            } => {
                                inner.list.push((name, interface.clone(), version));
                                callback(
                                    GlobalEvent::New {
                                        id: name,
                                        interface,
                                        version,
                                    },
                                    proxy,
                                    );
                            }
                            wl_registry::Event::GlobalRemove { name } => {
                                if let Some((i, _)) =
                                    inner.list.iter().enumerate().find(|&(_, &(n, _, _))| n == name)
                                    {
                                        let (id, interface, _) = inner.list.swap_remove(i);
                                        callback(
                                            GlobalEvent::Removed {
                                                id,
                                                interface,
                                            },
                                            proxy,
                                            );
                                    } else {
                                        panic!(
                                            "Wayland protocol error: the server removed non-existing global \"{}\".",
                                            name
                                        );
                                    }
                            },
                            _ => {}
                        }
                    },
                    (),
                )
            })
            .expect("Attempted to create a GlobalManager from a dead display.");
        GlobalManager {
            inner: inner_clone,
            registry,
        }
    }
pub fn new_with_cb < F > ( display : & wl_display :: WlDisplay , mut callback : F ) -> GlobalManager where F : FnMut ( GlobalEvent , wl_registry :: WlRegistry ) + ' static , { let inner = Arc :: new ( Mutex :: new ( Inner { list : Vec :: new ( ) } ) ) ; let inner_clone = inner . clone ( ) ; let registry = display . get_registry ( | registry | { registry . implement_closure ( move | msg , proxy | { let mut inner = inner . lock ( ) . unwrap ( ) ; let inner = & mut * inner ; match msg { wl_registry :: Event :: Global { name , interface , version , } => { inner . list . push ( ( name , interface . clone ( ) , version ) ) ; callback ( GlobalEvent :: New { id : name , interface , version , } , proxy , ) ; } wl_registry :: Event :: GlobalRemove { name } => { if let Some ( ( i , _ ) ) = inner . list . iter ( ) . enumerate ( ) . find ( | & ( _ , & ( n , _ , _ ) ) | n == name ) { let ( id , interface , _ ) = inner . list . swap_remove ( i ) ; callback ( GlobalEvent :: Removed { id , interface , } , proxy , ) ; } else { panic ! ( " \" \" " name ) ; } } , _ => { } } } , ( ) , ) } ) . expect ( " " ) ; GlobalManager { inner : inner_clone , registry , } }
Create a global manager handling a registry with a callback
This global manager will track globals as a simple one, but will
also forward the registry events to your callback.
Create a global manager handling a registry with a callback This global manager will track globals as a simple one but will also forward the registry events to your callback .
display
&wl_display::WlDisplay
callback
F
display
&wl_display::WlDisplay
callback
F