Skip to content

Commit c6ec32c

Browse files
committed
Show tap-hold, extras only on QMK
1 parent 84abb39 commit c6ec32c

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

backend/src/layout/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ impl Layout {
195195
}
196196
}
197197

198+
pub fn has_scancode(&self, scancode_name: &str) -> bool {
199+
self.keymap.get(scancode_name).is_some()
200+
}
201+
198202
pub fn f_keys(&self) -> impl Iterator<Item = &str> {
199203
self.default.map.iter().filter_map(|(k, v)| {
200204
if let Some(num) = v[0].strip_prefix('F') {

src/keyboard.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl Keyboard {
283283
}
284284
}
285285

286-
fn layout(&self) -> &Layout {
286+
pub fn layout(&self) -> &Layout {
287287
&self.inner().board.layout()
288288
}
289289

@@ -303,11 +303,6 @@ impl Keyboard {
303303
&self.inner().layer_stack
304304
}
305305

306-
// XXX
307-
pub fn has_scancode(&self, scancode_name: &Keycode) -> bool {
308-
self.layout().scancode_from_name(scancode_name).is_some()
309-
}
310-
311306
pub async fn keymap_set(&self, key_index: usize, layer: usize, scancode_name: &Keycode) {
312307
if let Err(err) = self.board().keys()[key_index]
313308
.set_scancode(layer, scancode_name)

src/picker/mod.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ pub static SCANCODE_LABELS: Lazy<HashMap<String, String>> = Lazy::new(|| {
4040

4141
#[derive(Default)]
4242
pub struct PickerInner {
43-
group_boxes: DerefCell<Vec<PickerGroupBox>>,
43+
stack_switcher: DerefCell<gtk::StackSwitcher>,
44+
basics_group_box: DerefCell<PickerGroupBox>,
45+
extras_group_box: DerefCell<PickerGroupBox>,
4446
keyboard: RefCell<Option<Keyboard>>,
4547
selected: RefCell<Vec<Keycode>>,
4648
shift: Cell<bool>,
@@ -100,8 +102,9 @@ impl ObjectImpl for PickerInner {
100102
..show_all();
101103
};
102104

103-
self.group_boxes
104-
.set(vec![basics_group_box, extras_group_box]);
105+
self.stack_switcher.set(stack_switcher);
106+
self.basics_group_box.set(basics_group_box);
107+
self.extras_group_box.set(extras_group_box);
105108
self.tap_hold.set(tap_hold);
106109
}
107110
}
@@ -156,26 +159,35 @@ impl Picker {
156159
PickerInner::from_instance(self)
157160
}
158161

162+
fn group_boxes(&self) -> [&PickerGroupBox; 2] {
163+
[
164+
&*self.inner().basics_group_box,
165+
&*self.inner().extras_group_box,
166+
]
167+
}
168+
159169
pub(crate) fn set_keyboard(&self, keyboard: Option<Keyboard>) {
160170
if let Some(old_kb) = &*self.inner().keyboard.borrow() {
161171
old_kb.set_picker(None);
162172
}
163173

164174
if let Some(kb) = &keyboard {
165175
// Check that scancode is available for the keyboard
166-
for group_box in self.inner().group_boxes.iter() {
167-
group_box.set_key_visibility(|name| {
168-
kb.has_scancode(&Keycode::Basic(Mods::empty(), name.to_string()))
169-
});
176+
for group_box in self.group_boxes() {
177+
group_box.set_key_visibility(|name| kb.layout().has_scancode(name));
170178
}
179+
let is_qmk = kb.layout().meta.is_qmk;
180+
self.inner().extras_group_box.set_visible(is_qmk);
181+
self.inner().tap_hold.set_visible(is_qmk);
182+
self.inner().stack_switcher.set_visible(is_qmk);
171183
kb.set_picker(Some(&self));
172184
}
173185

174186
*self.inner().keyboard.borrow_mut() = keyboard;
175187
}
176188

177189
pub(crate) fn set_selected(&self, scancode_names: Vec<Keycode>) {
178-
for group_box in self.inner().group_boxes.iter() {
190+
for group_box in self.group_boxes() {
179191
group_box.set_selected(scancode_names.clone());
180192
}
181193
self.inner().tap_hold.set_selected(scancode_names.clone());
@@ -271,7 +283,7 @@ impl Picker {
271283
allow_non_basic = true;
272284
}
273285

274-
for group_box in self.inner().group_boxes.iter() {
286+
for group_box in self.group_boxes() {
275287
group_box.set_key_sensitivity(|name| {
276288
if ["LEFT_SHIFT", "LEFT_ALT", "LEFT_CTRL", "LEFT_SUPER"].contains(&name) {
277289
allow_left_mods

0 commit comments

Comments
 (0)