[−][src]Macro wayland_client::global_filter
Convenience macro to create a GlobalManager
callback
This macro aims to simplify the specific but common case of
providing a callback to the GlobalManager
that needs to
auto-bind all advertised instances of some specific globals
whenever they happen. Typically, your application will likely
want to keep track of all wl_seat
and wl_output
globals
to be able to correctly react to user input and their different
monitors.
The output of this macro is a closure, that can be given to
GlobalManager::new_with_cb
as the callback argument.
Example use is typically:
use wayland_client::GlobalManager; use wayland_client::protocol::{wl_output, wl_seat}; let globals = GlobalManager::new_with_cb( &display.attach(event_queue.token()), global_filter!( // Bind all wl_seat with version 4 [wl_seat::WlSeat, 4, seat_implementor], // Bind all wl_output with version 1 [wl_output::WlOutput, 1, output_implementor] ) );
The supplied callbacks for each global kind must be an instance of a type
implementing the GlobalImplementor<I>
trait. The argument provided to your
callback is a Main
handle of the newly instantiated global, and you should assign it
to a filter in this callback if you plan to do so.. The error case happens if the server
advertised a lower version of the global than the one you requested, in which case you
are given the version it advertised in the error method, if you want to handle it graciously.
You can also provide closures for the various callbacks, in this case the errors will be ignored. However, due to a lack of capability of rustc's inference, you'll likely need to add some type annotation to your closure, typically something like this:
global_filter!( [Interface, version, |proxy: Main<_>, dispatch_data| { /* Setup the global as required */ }] );