Skip to content

Commit 2fb7755

Browse files
committed
Distinguish basic from non-basic keycodes
1 parent d309fc3 commit 2fb7755

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

backend/src/layout/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use once_cell::sync::Lazy;
12
use std::{collections::HashMap, fs, path::Path};
23

34
mod meta;
@@ -61,6 +62,14 @@ macro_rules! keyboards {
6162
// Calls the `keyboards!` macro
6263
include!(concat!(env!("OUT_DIR"), "/keyboards.rs"));
6364

65+
pub fn is_qmk_basic(name: &str) -> bool {
66+
static QMK_KEYMAP: Lazy<HashMap<String, u16>> =
67+
Lazy::new(|| parse_keymap_json(layout_data("system76/launch_1").unwrap().2).0);
68+
QMK_KEYMAP
69+
.get(name)
70+
.map_or(false, |scancode| *scancode <= 0xff)
71+
}
72+
6473
impl Layout {
6574
pub fn from_data(
6675
meta_json: &str,

src/picker/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::{
1313
};
1414

1515
use crate::Keyboard;
16-
use backend::{DerefCell, Keycode, Mods};
16+
use backend::{is_qmk_basic, DerefCell, Keycode, Mods};
1717

1818
mod picker_group;
1919
mod picker_group_box;
@@ -271,7 +271,6 @@ impl Picker {
271271
}
272272

273273
for group_box in self.inner().group_boxes.iter() {
274-
// TODO: What to allow?
275274
group_box.set_key_sensitivity(|name| {
276275
if ["LEFT_SHIFT", "LEFT_ALT", "LEFT_CTRL", "LEFT_SUPER"].contains(&name) {
277276
allow_left_mods
@@ -280,10 +279,11 @@ impl Picker {
280279
allow_right_mods
281280
} else if basic_keycode.as_deref() == Some(name) && !keycode_mods.is_empty() {
282281
true
283-
} else {
282+
} else if is_qmk_basic(name) {
284283
allow_basic
284+
} else {
285+
allow_non_basic
285286
}
286-
// XXX non-basic?
287287
});
288288
}
289289
}

src/picker/tap_hold.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use once_cell::sync::Lazy;
99
use std::cell::{Cell, RefCell};
1010

1111
use super::{picker_group_box::PickerGroupBox, PickerKey, SCANCODE_LABELS};
12-
use backend::{DerefCell, Keycode, Mods};
12+
use backend::{is_qmk_basic, DerefCell, Keycode, Mods};
1313

1414
#[derive(Clone, Copy)]
1515
enum Hold {
@@ -67,16 +67,14 @@ impl ObjectImpl for TapHoldInner {
6767
fn constructed(&self, widget: &Self::Type) {
6868
self.parent_constructed(widget);
6969

70-
let layout = backend::Layout::from_board("system76/launch_1").unwrap();
71-
7270
let picker_group_box = cascade! {
7371
PickerGroupBox::new("basics");
7472
..connect_key_pressed(clone!(@weak widget => move |name, _shift| {
7573
*widget.inner().keycode.borrow_mut() = Some(name);
7674
widget.update();
7775
}));
7876
// Correct?
79-
..set_key_visibility(|name| layout.scancode_from_name(&Keycode::Basic(Mods::empty(), name.to_string())).map_or(false, |code| code <= 0xff));
77+
..set_key_visibility(|name| is_qmk_basic(name));
8078
};
8179

8280
let modifier_button_box = cascade! {

0 commit comments

Comments
 (0)