kiwmi/src/input/manager.rs

49 lines
1.3 KiB
Rust
Raw Normal View History

2019-01-25 10:47:04 +01:00
use crate::{
input::{Keyboard, Pointer},
CompositorState,
};
use log::debug;
2019-01-11 09:14:59 +01:00
use wlroots::{
compositor,
2019-01-25 10:47:04 +01:00
input::{self, keyboard, pointer},
with_handles,
2019-01-11 09:14:59 +01:00
};
pub fn manager() -> input::manager::Builder {
2019-01-25 10:47:04 +01:00
input::manager::Builder::default()
.keyboard_added(keyboard_added)
.pointer_added(pointer_added)
2019-01-11 09:14:59 +01:00
}
fn keyboard_added(
2019-01-25 10:47:04 +01:00
compositor_handle: compositor::Handle,
keyboard_handle: keyboard::Handle,
2019-01-11 09:14:59 +01:00
) -> Option<Box<keyboard::Handler>> {
2019-01-25 10:47:04 +01:00
debug!("Keyboard added");
with_handles!([(compositor: {compositor_handle})] => {
let compositor_state: &mut CompositorState = compositor.data.downcast_mut().unwrap();
compositor_state.keyboards.push(keyboard_handle);
})
.unwrap();
2019-01-11 09:14:59 +01:00
Some(Box::new(Keyboard))
}
2019-01-25 10:47:04 +01:00
fn pointer_added(
compositor_handle: compositor::Handle,
pointer_handle: pointer::Handle,
) -> Option<Box<pointer::Handler>> {
debug!("Pointer added");
with_handles!([(compositor: {compositor_handle}), (pointer: {pointer_handle})] => {
let compositor_state: &mut CompositorState = compositor.downcast();
compositor_state.cursor_handle
.run(|cursor| cursor.attach_input_device(pointer.input_device()))
.unwrap();
})
.unwrap();
Some(Box::new(Pointer))
}