Skip to content

Commit 289c02c

Browse files
committed
improv: Have Layout as member of Keyboard
Will allow adding more to `Layout` without increasingly many members of `Keyboard`.
1 parent 717b401 commit 289c02c

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/application/keyboard.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ pub struct KeyboardInner {
2222
action_group: DerefCell<gio::SimpleActionGroup>,
2323
board: DerefCell<DaemonBoard>,
2424
board_name: DerefCell<String>,
25-
default_layout: DerefCell<KeyMap>,
26-
keymap: DerefCell<HashMap<String, u16>>,
2725
keys: DerefCell<Rc<[Key]>>,
26+
layout: DerefCell<Layout>,
2827
page: Cell<Page>,
2928
picker: RefCell<WeakRef<Picker>>,
3029
selected: Cell<Option<usize>>,
@@ -251,8 +250,7 @@ impl Keyboard {
251250
keyboard.inner().keys.set(keys.into_boxed_slice().into());
252251
keyboard.inner().board.set(board);
253252
keyboard.inner().board_name.set(board_name.to_string());
254-
keyboard.inner().keymap.set(layout.keymap);
255-
keyboard.inner().default_layout.set(layout.default);
253+
keyboard.inner().layout.set(layout);
256254

257255
let color_button = KeyboardColorButton::new(keyboard.board().clone());
258256
keyboard.inner().color_button_bin.add(&color_button);
@@ -324,12 +322,8 @@ impl Keyboard {
324322
}
325323
}
326324

327-
fn keymap(&self) -> &HashMap<String, u16> {
328-
&self.inner().keymap
329-
}
330-
331-
fn default_layout(&self) -> &KeyMap {
332-
&self.inner().default_layout
325+
fn layout(&self) -> &Layout {
326+
&self.inner().layout
333327
}
334328

335329
fn window(&self) -> Option<gtk::Window> {
@@ -353,7 +347,7 @@ impl Keyboard {
353347
}
354348

355349
pub fn has_scancode(&self, scancode_name: &str) -> bool {
356-
self.keymap().contains_key(scancode_name)
350+
self.layout().keymap.contains_key(scancode_name)
357351
}
358352

359353
pub fn keys(&self) -> &Rc<[Key]> {
@@ -363,7 +357,7 @@ impl Keyboard {
363357
pub fn keymap_set(&self, key_index: usize, layer: usize, scancode_name: &str) {
364358
let k = &self.keys()[key_index];
365359
let mut found = false;
366-
if let Some(scancode) = self.keymap().get(scancode_name) {
360+
if let Some(scancode) = self.layout().keymap.get(scancode_name) {
367361
k.scancodes.borrow_mut()[layer] = (*scancode, scancode_name.to_string());
368362
found = true;
369363
}
@@ -493,7 +487,7 @@ impl Keyboard {
493487
}
494488

495489
fn reset(&self) {
496-
self.import_keymap(self.default_layout());
490+
self.import_keymap(&self.layout().default);
497491
}
498492

499493
fn add_pages(&self) {

0 commit comments

Comments
 (0)