From c152dc84682f1db6c0b30a50a22dcddd1be6e08c Mon Sep 17 00:00:00 2001 From: Richard Acayan Date: Sun, 4 Aug 2024 21:47:24 -0400 Subject: [PATCH] core: layout: store keysym availability --- src/core/button.rs | 8 +++++++- src/core/layout.rs | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/core/button.rs b/src/core/button.rs index 43f0412..dde5b4c 100644 --- a/src/core/button.rs +++ b/src/core/button.rs @@ -204,6 +204,12 @@ impl Button { &self.modifiers } + #[inline(always)] + pub fn update_keys_supported(&mut self) + { + self.layout.update_keys_supported(&self.kbd) + } + pub fn next_time(&self) -> Option { let id = *self.timers.front()?; @@ -229,7 +235,7 @@ impl Button { } 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); } diff --git a/src/core/layout.rs b/src/core/layout.rs index 44671ae..02de32d 100644 --- a/src/core/layout.rs +++ b/src/core/layout.rs @@ -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(&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(&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(&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(&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); } } }