Macro xcb::atoms_struct

source ·
macro_rules! atoms_struct {
    (
        $(#[$outer:meta])*
        $vis:vis struct $Atoms:ident {
            $(
                $(#[$fmeta:meta])* $fvis:vis $field:ident => $name:tt $( only_if_exists = $only_if_exists:expr)?,
            )*
        }
    ) => { ... };
}
Expand description

An helper macro that generate a struct of atoms.

The struct provide a constructor intern_all that takes a Connection as parameter, interns all the atoms and return xcb::Result<[struct name]>. intern_all takes advantage of XCB asynchronous design by sending all the x::InternAtom requests before starting to wait for the first reply. Fields that refer to atoms not existing in the server are set to x::ATOM_NONE (i.e. only_if_exists is always set to true).

Both the struct and each field can receive visibility attributes.

§Example

xcb::atoms_struct! {
    #[derive(Copy, Clone, Debug)]
    pub(crate) struct Atoms {
        pub wm_protocols    => b"WM_PROTOCOLS",
        pub wm_del_window   => b"WM_DELETE_WINDOW",
        /// Supported EWMH hints
        pub net_supported  => b"_NET_SUPPORTED",

        // You can also explicitly set the `only_if_exists` argument when interning
        // each atom with the following syntax (the default is `true`):
        pub custom_atom    => b"MY_CUSTOM_ATOM" only_if_exists = false,
    }
}

fn main() -> xcb::Result<()> {
    // ...
    let atoms = Atoms::intern_all(&conn)?;

    conn.check_request(conn.send_request_checked(&x::ChangeProperty {
        mode: x::PropMode::Replace,
        window,
        property: atoms.wm_protocols,
        r#type: x::ATOM_ATOM,
        data: &[atoms.wm_del_window],
    }))?;
    // ...
}