Macro wayland_client::global_filter [] [src]

macro_rules! global_filter {
    ($([$interface:ty, $version:expr, $callback:expr]),*) => { ... };
}

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 advertized 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_display::RequestsTrait;
use wayland_client::protocol::{wl_output, wl_seat};

let globals = GlobalManager::new_with_cb(
    display.get_registry().unwrap(),
    global_filter!(
        // Bind all wl_seat with version 4
        [wl_seat::WlSeat, 4, seat_callback],
        // Bind all wl_output with version 1
        [wl_output::WlOutput, 1, output_callback]
    )
);

The supplied callbacks for each global kind must be an instance of a type implementing the Interface<Result<NewProxy<I>, u32>, ()> trait. The argument provided to your callback is a result containing the NewProxy of the newly instanciated global on success. The error case happens if the server advertized a lower version of the global than the one you requested, in which case you are given the version it advertized.

As with all implementations, you can also provide closures for the various callbacks. 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 example is not tested
global_filer!(
    [Interface, version, |new_proxy: Result<NewProxy<_>, _>, ()| {
        ...
    }]
);