metal: enable keyboard LEDs
This commit is contained in:
parent
0e51b9469b
commit
11c10fde70
14 changed files with 188 additions and 22 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use {
|
||||
crate::utils::{oserror::OsError, vecset::VecSet},
|
||||
kbvm::Components,
|
||||
crate::utils::{event_listener::EventSource, oserror::OsError, vecset::VecSet},
|
||||
kbvm::{Components, state_machine::Event},
|
||||
std::{
|
||||
cell::{Ref, RefCell},
|
||||
rc::Rc,
|
||||
|
|
@ -25,6 +25,11 @@ pub struct KeyboardState {
|
|||
pub xwayland_map: KeymapFd,
|
||||
pub pressed_keys: VecSet<u32>,
|
||||
pub mods: Components,
|
||||
pub mods_changed: EventSource<dyn ModifiersListener>,
|
||||
}
|
||||
|
||||
pub trait ModifiersListener {
|
||||
fn locked_mods(&self, mods: &Components);
|
||||
}
|
||||
|
||||
pub trait DynKeyboardState {
|
||||
|
|
@ -37,6 +42,23 @@ impl DynKeyboardState for RefCell<KeyboardState> {
|
|||
}
|
||||
}
|
||||
|
||||
impl KeyboardState {
|
||||
pub fn apply_event(&mut self, event: Event) -> bool {
|
||||
let locked_mods = self.mods.mods_locked;
|
||||
let changed = self.mods.apply_event(event);
|
||||
if locked_mods != self.mods.mods_locked {
|
||||
self.dispatch_locked_mods_listeners();
|
||||
}
|
||||
changed
|
||||
}
|
||||
|
||||
pub fn dispatch_locked_mods_listeners(&self) {
|
||||
for listener in self.mods_changed.iter() {
|
||||
listener.locked_mods(&self.mods);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct KeymapFd {
|
||||
pub map: Rc<OwnedFd>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue