core: button: emit key presses as text when available
This commit is contained in:
parent
399ab9deba
commit
fc829a96c4
2 changed files with 28 additions and 4 deletions
|
|
@ -6,7 +6,10 @@
|
|||
use crate::core::Display;
|
||||
use crate::core::Graphics;
|
||||
use crate::core::Layout;
|
||||
use crate::core::Part;
|
||||
use crate::core::layout::Key;
|
||||
use crate::core::layout::MOD_ALT;
|
||||
use crate::core::layout::MOD_CTRL;
|
||||
use crate::core::layout::MODIFIERS_MAX;
|
||||
use std::collections::VecDeque;
|
||||
use std::convert::TryInto;
|
||||
|
|
@ -459,6 +462,23 @@ impl<D: Display, K: Keyboard> Button<D, K> {
|
|||
Self::draw(draw, &self.gfx, &self.layout, Some(key), &self.modifiers);
|
||||
}
|
||||
|
||||
fn emit(kbd: &mut K, part: &Part, modifiers: &[ModState])
|
||||
{
|
||||
let ctrl_pressed = modifiers[MOD_CTRL - 1] != ModState::Released;
|
||||
let alt_pressed = modifiers[MOD_ALT - 1] != ModState::Released;
|
||||
let mods_pressed = ctrl_pressed || alt_pressed;
|
||||
|
||||
if part.key_available() && mods_pressed {
|
||||
kbd.press(part.sym());
|
||||
kbd.release(part.sym());
|
||||
} else if part.text_available() {
|
||||
kbd.text(part.text());
|
||||
} else if part.key_available() {
|
||||
kbd.press(part.sym());
|
||||
kbd.release(part.sym());
|
||||
}
|
||||
}
|
||||
|
||||
fn is_normal_key_pressed(&self) -> bool
|
||||
{
|
||||
for id in &self.timers {
|
||||
|
|
@ -548,8 +568,7 @@ impl<D: Display, K: Keyboard> Button<D, K> {
|
|||
|
||||
let modifier = key.parts[press.part].modifier_id();
|
||||
if modifier == 0 {
|
||||
self.kbd.press(key.parts[press.part].sym());
|
||||
self.kbd.release(key.parts[press.part].sym());
|
||||
Self::emit(&mut self.kbd, &key.parts[press.part], &self.modifiers);
|
||||
}
|
||||
|
||||
let draw = self.release_mod(modifier);
|
||||
|
|
@ -596,8 +615,7 @@ impl<D: Display, K: Keyboard> Button<D, K> {
|
|||
if modifier != 0 {
|
||||
draw = draw + self.lock_mod(modifier);
|
||||
} else {
|
||||
self.kbd.press(key.parts[press.part].sym());
|
||||
self.kbd.release(key.parts[press.part].sym());
|
||||
Self::emit(&mut self.kbd, &key.parts[press.part], &self.modifiers);
|
||||
|
||||
press.timer += self.repeat;
|
||||
self.timers.push_back(id);
|
||||
|
|
|
|||
|
|
@ -355,6 +355,12 @@ impl Part {
|
|||
self.val.0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn text(&self) -> &str
|
||||
{
|
||||
&self.val.1
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn press(&mut self)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue