layout: Make handling presses uniform

This commit is contained in:
Dorota Czaplejewicz
2020-01-09 12:09:28 +00:00
parent 34db364a62
commit 375daa68c8

View File

@ -332,11 +332,12 @@ pub mod c {
.map(|place| place.button.state.clone())
};
if let Some(mut state) = state {
layout.press_key(
if let Some(state) = state {
seat::handle_press_key(
layout,
&VirtualKeyboard(virtual_keyboard),
&mut state,
Timestamp(time),
&state,
);
// maybe TODO: draw on the display buffer here
drawing::queue_redraw(ui_keyboard);
@ -379,7 +380,7 @@ pub mod c {
)})
};
if let Some((mut state, _button, _view_position)) = button_info {
if let Some((state, _button, _view_position)) = button_info {
let mut found = false;
for wrapped_key in pressed {
let key: &Rc<RefCell<KeyState>> = wrapped_key.borrow();
@ -397,7 +398,12 @@ pub mod c {
}
}
if !found {
layout.press_key(&virtual_keyboard, &mut state, time);
seat::handle_press_key(
layout,
&virtual_keyboard,
time,
&state,
);
// maybe TODO: draw on the display buffer here
}
} else {
@ -653,24 +659,6 @@ impl Layout {
}
}
fn press_key(
&mut self,
virtual_keyboard: &VirtualKeyboard,
rckey: &mut Rc<RefCell<KeyState>>,
time: Timestamp,
) {
if !self.pressed_keys.insert(::util::Pointer(rckey.clone())) {
eprintln!("Warning: key {:?} was already pressed", rckey);
}
let mut key = rckey.borrow_mut();
virtual_keyboard.switch(
&key.keycodes,
PressType::Pressed,
time,
);
key.pressed = PressType::Pressed;
}
/// Calculates size without margins
fn calculate_inner_size(&self) -> Size {
Size {
@ -864,6 +852,24 @@ mod seat {
}
}
pub fn handle_press_key(
layout: &mut Layout,
virtual_keyboard: &VirtualKeyboard,
time: Timestamp,
rckey: &Rc<RefCell<KeyState>>,
) {
if !layout.pressed_keys.insert(::util::Pointer(rckey.clone())) {
eprintln!("Warning: key {:?} was already pressed", rckey);
}
let mut key = rckey.borrow_mut();
virtual_keyboard.switch(
&key.keycodes,
PressType::Pressed,
time,
);
key.pressed = PressType::Pressed;
}
pub fn handle_release_key(
layout: &mut Layout,
virtual_keyboard: &VirtualKeyboard,