[−][src]Attribute Macro wlroots_dehandle::wlroots_dehandle
#[wlroots_dehandle]
Attribute to automatically call the run
method on handles with the
remaining block of code.
The name of the variable you want to use as the upgraded handle should be provided as an argument to the attribute. It does not need to be the same as the handle variable.
The syntax in the code should be use $handle as $upgraded_handle
.
E.g the variable in the code that stores the handle should go on the
left and the variable you used in the attribute declaration should
go on the right.
Panics
If the handle is invalid (e.g. default constructed, or is a dangling
handle) then your code will panic!
.
If this is undesirable, please use the non-proc macro with_handles!
.
Example
ⓘThis example is not tested
impl InputManagerHandler for InputManager { #[wlroots_dehandle(compositor, keyboard, seat)] fn keyboard_added(&mut self, compositor_handle: CompositorHandle, keyboard: KeyboardHandle) -> Option<Box<Keyboard Handler>> { { use compositor_handle as compositor; use keyboard as keyboard; let server: &mut ::Server = compositor.into(); server.keyboards.push(keyboard.weak_reference()); // Now that we have at least one keyboard, update the seat capabilities. let server_seat = &server.seat.seat; use server_seat as seat; let mut capabilities = seat.capabilities(); capabilities.insert(Capability::Keyboard); seat.set_capabilities(capabilities); seat.set_keyboard(keyboard.input_device()); } // Due to some weird closure inference rules, this has to be outside // of the above block. Some(Box::new(::Keyboard)) } }