core: layout: store keysym availability
This commit is contained in:
parent
adf71ed2c8
commit
c152dc8468
2 changed files with 42 additions and 5 deletions
|
|
@ -204,6 +204,12 @@ impl<D: Display, K: Keyboard> Button<D, K> {
|
|||
&self.modifiers
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn update_keys_supported(&mut self)
|
||||
{
|
||||
self.layout.update_keys_supported(&self.kbd)
|
||||
}
|
||||
|
||||
pub fn next_time(&self) -> Option<Instant>
|
||||
{
|
||||
let id = *self.timers.front()?;
|
||||
|
|
@ -229,7 +235,7 @@ impl<D: Display, K: Keyboard> Button<D, K> {
|
|||
}
|
||||
|
||||
if old == ModState::Released || new == ModState::Released {
|
||||
self.layout.update_modifiers(&self.modifiers);
|
||||
self.layout.update_modifiers(&self.kbd, &self.modifiers);
|
||||
if Layout::is_keysym_modifier(modifier) {
|
||||
self.kbd.change_layout(&self.layout);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
* Copyright (c) 2024, Richard Acayan. All rights reserved.
|
||||
*/
|
||||
|
||||
use crate::core::Keyboard;
|
||||
use crate::core::button::ModState;
|
||||
use crate::core::expat;
|
||||
use std::cmp::Ordering;
|
||||
|
|
@ -68,9 +69,10 @@ impl KeyValue {
|
|||
|
||||
pub struct Part {
|
||||
orig: KeyValue,
|
||||
|
||||
val: KeyValue,
|
||||
|
||||
key_avail: bool,
|
||||
|
||||
presses: u32,
|
||||
}
|
||||
|
||||
|
|
@ -304,6 +306,8 @@ impl Part {
|
|||
orig,
|
||||
val,
|
||||
|
||||
key_avail: false,
|
||||
|
||||
presses: 0,
|
||||
}
|
||||
}
|
||||
|
|
@ -332,6 +336,18 @@ impl Part {
|
|||
self.presses
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn key_available(&self) -> bool
|
||||
{
|
||||
self.key_avail
|
||||
}
|
||||
|
||||
fn update_keys_supported<K: Keyboard>(&mut self, kbd: &K)
|
||||
{
|
||||
let key_supp = kbd.key_supported(self.val.0);
|
||||
self.key_avail = self.val.0 != Keysym::NoSymbol && key_supp;
|
||||
}
|
||||
|
||||
pub fn modifier_id(&self) -> usize
|
||||
{
|
||||
match self.val.0 {
|
||||
|
|
@ -343,7 +359,9 @@ impl Part {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn update_modifiers(&mut self, mod_state: &[ModState])
|
||||
pub fn update_modifiers<K: Keyboard>(&mut self,
|
||||
kbd: &K,
|
||||
mod_state: &[ModState])
|
||||
{
|
||||
let mut val = self.orig.clone();
|
||||
|
||||
|
|
@ -357,6 +375,8 @@ impl Part {
|
|||
val = Self::modify_shift_label(&val);
|
||||
}
|
||||
|
||||
let key_supp = kbd.key_supported(self.val.0);
|
||||
self.key_avail = self.val.0 != Keysym::NoSymbol && key_supp;
|
||||
self.val = val;
|
||||
}
|
||||
|
||||
|
|
@ -653,12 +673,23 @@ impl Layout {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn update_modifiers(&mut self, mod_state: &[ModState])
|
||||
pub fn update_modifiers<K: Keyboard>(&mut self, kbd: &K, mod_state: &[ModState])
|
||||
{
|
||||
for row in self.rows.iter_mut() {
|
||||
for key in row.iter_mut() {
|
||||
for part in key.parts.iter_mut() {
|
||||
part.update_modifiers(mod_state);
|
||||
part.update_modifiers(kbd, mod_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_keys_supported<K: Keyboard>(&mut self, kbd: &K)
|
||||
{
|
||||
for row in self.rows.iter_mut() {
|
||||
for key in row.iter_mut() {
|
||||
for part in key.parts.iter_mut() {
|
||||
part.update_keys_supported(kbd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue