From 375daa68c84a2c61585cf28816c58f7f5a07ef5f Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Thu, 9 Jan 2020 12:09:28 +0000 Subject: [PATCH] layout: Make handling presses uniform --- src/layout.rs | 52 ++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/layout.rs b/src/layout.rs index 76f830c1..c01226d5 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -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> = 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>, - 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>, + ) { + 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,