File tree Expand file tree Collapse file tree 3 files changed +15
-8
lines changed Expand file tree Collapse file tree 3 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ impl Key {
89
89
debug ! ( " Scancode: {:04X}" , scancode) ;
90
90
debug ! (
91
91
" Scancode Name: {:?}" ,
92
- board. layout( ) . scancode_names . get ( & scancode)
92
+ board. layout( ) . scancode_to_name ( scancode)
93
93
) ;
94
94
95
95
scancodes. push ( Cell :: new ( scancode) ) ;
@@ -145,7 +145,7 @@ impl Key {
145
145
pub fn get_scancode ( & self , layer : usize ) -> Option < ( u16 , String ) > {
146
146
let board = self . board ( ) ;
147
147
let scancode = self . scancodes . get ( layer) ?. get ( ) ;
148
- let scancode_name = match board. layout ( ) . scancode_names . get ( & scancode) {
148
+ let scancode_name = match board. layout ( ) . scancode_to_name ( scancode) {
149
149
Some ( some) => some. to_string ( ) ,
150
150
None => String :: new ( ) ,
151
151
} ;
@@ -154,10 +154,9 @@ impl Key {
154
154
155
155
pub fn set_scancode ( & self , layer : usize , scancode_name : & str ) -> Result < ( ) , String > {
156
156
let board = self . board ( ) ;
157
- let scancode = * board
157
+ let scancode = board
158
158
. layout ( )
159
- . keymap
160
- . get ( scancode_name)
159
+ . scancode_from_name ( scancode_name)
161
160
. ok_or_else ( || format ! ( "Unable to find scancode '{}'" , scancode_name) ) ?;
162
161
board. 0 . daemon . keymap_set (
163
162
board. 0 . board ,
Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ use crate::KeyMap;
10
10
pub struct Layout {
11
11
pub meta : Meta ,
12
12
pub default : KeyMap ,
13
- pub keymap : HashMap < String , u16 > ,
14
- pub scancode_names : HashMap < u16 , String > ,
13
+ keymap : HashMap < String , u16 > ,
14
+ scancode_names : HashMap < u16 , String > ,
15
15
pub ( crate ) physical : Vec < PhysicalLayoutKey > ,
16
16
pub ( crate ) layout : HashMap < String , ( u8 , u8 ) > ,
17
17
pub ( crate ) leds : HashMap < String , Vec < u8 > > ,
@@ -133,6 +133,14 @@ impl Layout {
133
133
} ,
134
134
)
135
135
}
136
+
137
+ pub fn scancode_to_name ( & self , scancode : u16 ) -> Option < & str > {
138
+ self . scancode_names . get ( & scancode) . map ( String :: as_str)
139
+ }
140
+
141
+ pub fn scancode_from_name ( & self , name : & str ) -> Option < u16 > {
142
+ self . keymap . get ( name) . copied ( )
143
+ }
136
144
}
137
145
138
146
fn parse_keymap_json ( keymap_json : & str ) -> ( HashMap < String , u16 > , HashMap < u16 , String > ) {
Original file line number Diff line number Diff line change @@ -237,7 +237,7 @@ impl Keyboard {
237
237
}
238
238
239
239
pub fn has_scancode ( & self , scancode_name : & str ) -> bool {
240
- self . layout ( ) . keymap . contains_key ( scancode_name)
240
+ self . layout ( ) . scancode_from_name ( scancode_name) . is_some ( )
241
241
}
242
242
243
243
pub fn keymap_set ( & self , key_index : usize , layer : usize , scancode_name : & str ) {
You can’t perform that action at this time.
0 commit comments