|
1 | 1 | //! Finnish/Swedish keyboard support
|
2 | 2 |
|
3 |
| -use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers, PhysicalKeyboard}; |
| 3 | +use crate::{ |
| 4 | + DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers, PhysicalKeyboard, QUO, SLS, |
| 5 | +}; |
4 | 6 |
|
5 | 7 | /// A standard Finnish/Swedish 102-key (or 105-key including Windows keys) keyboard.
|
6 | 8 | ///
|
7 | 9 | /// Has a 2-row high Enter key, with Oem5 next to the left shift (ISO format).
|
8 | 10 | pub struct FiSe105Key;
|
9 | 11 |
|
10 | 12 | impl KeyboardLayout for FiSe105Key {
|
| 13 | + #[rustfmt::skip] |
11 | 14 | fn map_keycode(
|
12 | 15 | &self,
|
13 | 16 | keycode: KeyCode,
|
14 | 17 | modifiers: &Modifiers,
|
15 | 18 | handle_ctrl: HandleControl,
|
16 | 19 | ) -> DecodedKey {
|
17 |
| - let map_to_unicode = handle_ctrl == HandleControl::MapLettersToUnicode; |
18 |
| - let fallback = super::Us104Key; |
19 | 20 | match keycode {
|
20 | 21 | // ========= Row 2 (the numbers) =========
|
21 |
| - KeyCode::Oem8 => { |
22 |
| - if modifiers.is_shifted() { |
23 |
| - DecodedKey::Unicode('½') |
24 |
| - } else { |
25 |
| - DecodedKey::Unicode('§') |
26 |
| - } |
27 |
| - } |
28 |
| - KeyCode::Key2 => { |
29 |
| - if modifiers.is_shifted() { |
30 |
| - DecodedKey::Unicode('"') |
31 |
| - } else if modifiers.is_altgr() { |
32 |
| - DecodedKey::Unicode('@') |
33 |
| - } else { |
34 |
| - DecodedKey::Unicode('2') |
35 |
| - } |
36 |
| - } |
37 |
| - KeyCode::Key3 => { |
38 |
| - if modifiers.is_shifted() { |
39 |
| - DecodedKey::Unicode('#') |
40 |
| - } else if modifiers.is_altgr() { |
41 |
| - DecodedKey::Unicode('£') |
42 |
| - } else { |
43 |
| - DecodedKey::Unicode('3') |
44 |
| - } |
45 |
| - } |
46 |
| - KeyCode::Key4 => { |
47 |
| - if modifiers.is_shifted() { |
48 |
| - DecodedKey::Unicode('¤') |
49 |
| - } else if modifiers.is_altgr() { |
50 |
| - DecodedKey::Unicode('$') |
51 |
| - } else { |
52 |
| - DecodedKey::Unicode('4') |
53 |
| - } |
54 |
| - } |
55 |
| - KeyCode::Key5 => { |
56 |
| - if modifiers.is_shifted() { |
57 |
| - DecodedKey::Unicode('%') |
58 |
| - } else if modifiers.is_altgr() { |
59 |
| - DecodedKey::Unicode('€') |
60 |
| - } else { |
61 |
| - DecodedKey::Unicode('5') |
62 |
| - } |
63 |
| - } |
64 |
| - KeyCode::Key6 => { |
65 |
| - if modifiers.is_shifted() { |
66 |
| - DecodedKey::Unicode('&') |
67 |
| - } else { |
68 |
| - DecodedKey::Unicode('6') |
69 |
| - } |
70 |
| - } |
71 |
| - KeyCode::Key7 => { |
72 |
| - if modifiers.is_shifted() { |
73 |
| - DecodedKey::Unicode('/') |
74 |
| - } else if modifiers.is_altgr() { |
75 |
| - DecodedKey::Unicode('{') |
76 |
| - } else { |
77 |
| - DecodedKey::Unicode('7') |
78 |
| - } |
79 |
| - } |
80 |
| - KeyCode::Key8 => { |
81 |
| - if modifiers.is_shifted() { |
82 |
| - DecodedKey::Unicode('(') |
83 |
| - } else if modifiers.is_altgr() { |
84 |
| - DecodedKey::Unicode('[') |
85 |
| - } else { |
86 |
| - DecodedKey::Unicode('8') |
87 |
| - } |
88 |
| - } |
89 |
| - KeyCode::Key9 => { |
90 |
| - if modifiers.is_shifted() { |
91 |
| - DecodedKey::Unicode(')') |
92 |
| - } else if modifiers.is_altgr() { |
93 |
| - DecodedKey::Unicode(']') |
94 |
| - } else { |
95 |
| - DecodedKey::Unicode('9') |
96 |
| - } |
97 |
| - } |
98 |
| - KeyCode::Key0 => { |
99 |
| - if modifiers.is_shifted() { |
100 |
| - DecodedKey::Unicode('=') |
101 |
| - } else if modifiers.is_altgr() { |
102 |
| - DecodedKey::Unicode('}') |
103 |
| - } else { |
104 |
| - DecodedKey::Unicode('0') |
105 |
| - } |
106 |
| - } |
107 |
| - KeyCode::OemMinus => { |
108 |
| - if modifiers.is_shifted() { |
109 |
| - DecodedKey::Unicode('?') |
110 |
| - } else if modifiers.is_altgr() { |
111 |
| - DecodedKey::Unicode('\\') |
112 |
| - } else { |
113 |
| - DecodedKey::Unicode('+') |
114 |
| - } |
115 |
| - } |
116 |
| - KeyCode::OemPlus => { |
117 |
| - if modifiers.is_shifted() { |
118 |
| - DecodedKey::Unicode('`') |
119 |
| - } else { |
120 |
| - DecodedKey::Unicode('´') |
121 |
| - } |
122 |
| - } |
| 22 | + KeyCode::Oem8 => modifiers.handle_shift('§', '½'), |
| 23 | + KeyCode::Key2 => modifiers.handle_altsh('2', '"', '@'), |
| 24 | + KeyCode::Key3 => modifiers.handle_altsh('3', '#', '£'), |
| 25 | + KeyCode::Key4 => modifiers.handle_altsh('4', '¤', '$'), |
| 26 | + KeyCode::Key5 => modifiers.handle_altsh('5', '%', '€'), |
| 27 | + KeyCode::Key6 => modifiers.handle_shift('6', '&'), |
| 28 | + KeyCode::Key7 => modifiers.handle_altsh('7', '/', '{'), |
| 29 | + KeyCode::Key8 => modifiers.handle_altsh('8', '(', '['), |
| 30 | + KeyCode::Key9 => modifiers.handle_altsh('9', ')', ']'), |
| 31 | + KeyCode::Key0 => modifiers.handle_altsh('0', '=', '}'), |
| 32 | + KeyCode::OemMinus => modifiers.handle_altsh('+', '?', SLS), |
| 33 | + KeyCode::OemPlus => modifiers.handle_shift('´', '`'), |
123 | 34 | // ========= Row 3 (QWERTY) =========
|
124 |
| - KeyCode::E => { |
125 |
| - if map_to_unicode && modifiers.is_ctrl() { |
126 |
| - DecodedKey::Unicode('\u{0005}') |
127 |
| - } else if modifiers.is_altgr() { |
128 |
| - DecodedKey::Unicode('€') |
129 |
| - } else if modifiers.is_caps() { |
130 |
| - DecodedKey::Unicode('E') |
131 |
| - } else { |
132 |
| - DecodedKey::Unicode('e') |
133 |
| - } |
134 |
| - } |
135 |
| - KeyCode::Oem4 => { |
136 |
| - if modifiers.is_caps() { |
137 |
| - DecodedKey::Unicode('Å') |
138 |
| - } else { |
139 |
| - DecodedKey::Unicode('å') |
140 |
| - } |
141 |
| - } |
142 |
| - KeyCode::Oem6 => { |
143 |
| - if modifiers.is_shifted() { |
144 |
| - DecodedKey::Unicode('^') |
145 |
| - } else if modifiers.is_altgr() { |
146 |
| - DecodedKey::Unicode('~') |
147 |
| - } else { |
148 |
| - DecodedKey::Unicode('¨') |
149 |
| - } |
150 |
| - } |
| 35 | + KeyCode::E => modifiers.handle_alalt('E', '€', '€', handle_ctrl), |
| 36 | + KeyCode::Oem4 => modifiers.handle_accen('å', 'Å'), |
| 37 | + KeyCode::Oem6 => modifiers.handle_altsh('¨', '^', '~'), |
151 | 38 | // ========= Row 4 (ASDF) =========
|
152 |
| - KeyCode::Oem1 => { |
153 |
| - if modifiers.is_caps() { |
154 |
| - DecodedKey::Unicode('Ö') |
155 |
| - } else { |
156 |
| - DecodedKey::Unicode('ö') |
157 |
| - } |
158 |
| - } |
159 |
| - KeyCode::Oem3 => { |
160 |
| - if modifiers.is_caps() { |
161 |
| - DecodedKey::Unicode('Ä') |
162 |
| - } else { |
163 |
| - DecodedKey::Unicode('ä') |
164 |
| - } |
165 |
| - } |
166 |
| - KeyCode::Oem7 => { |
167 |
| - if modifiers.is_shifted() { |
168 |
| - DecodedKey::Unicode('*') |
169 |
| - } else { |
170 |
| - DecodedKey::Unicode('\'') |
171 |
| - } |
172 |
| - } |
| 39 | + KeyCode::Oem1 => modifiers.handle_accen('ö', 'Ö'), |
| 40 | + KeyCode::Oem3 => modifiers.handle_accen('ä', 'Ä'), |
| 41 | + KeyCode::Oem7 => modifiers.handle_shift(QUO, '*'), |
173 | 42 | // ========= Row 5 (ZXCV) =========
|
174 |
| - KeyCode::Oem5 => { |
175 |
| - if modifiers.is_shifted() { |
176 |
| - DecodedKey::Unicode('>') |
177 |
| - } else if modifiers.is_altgr() { |
178 |
| - DecodedKey::Unicode('|') |
179 |
| - } else { |
180 |
| - DecodedKey::Unicode('<') |
181 |
| - } |
182 |
| - } |
183 |
| - KeyCode::M => { |
184 |
| - if map_to_unicode && modifiers.is_ctrl() { |
185 |
| - DecodedKey::Unicode('\u{000D}') |
186 |
| - } else if modifiers.is_altgr() { |
187 |
| - DecodedKey::Unicode('µ') |
188 |
| - } else if modifiers.is_caps() { |
189 |
| - DecodedKey::Unicode('M') |
190 |
| - } else { |
191 |
| - DecodedKey::Unicode('m') |
192 |
| - } |
193 |
| - } |
194 |
| - KeyCode::OemComma => { |
195 |
| - if modifiers.is_shifted() { |
196 |
| - DecodedKey::Unicode(';') |
197 |
| - } else { |
198 |
| - DecodedKey::Unicode(',') |
199 |
| - } |
200 |
| - } |
201 |
| - KeyCode::OemPeriod => { |
202 |
| - if modifiers.is_shifted() { |
203 |
| - DecodedKey::Unicode(':') |
204 |
| - } else { |
205 |
| - DecodedKey::Unicode('.') |
206 |
| - } |
207 |
| - } |
208 |
| - KeyCode::Oem2 => { |
209 |
| - if modifiers.is_shifted() { |
210 |
| - DecodedKey::Unicode('_') |
211 |
| - } else { |
212 |
| - DecodedKey::Unicode('-') |
213 |
| - } |
214 |
| - } |
| 43 | + KeyCode::Oem5 => modifiers.handle_altsh('<', '>', '|'), |
| 44 | + KeyCode::M => modifiers.handle_alalt('M', 'µ', 'µ', handle_ctrl), |
| 45 | + KeyCode::OemComma => modifiers.handle_shift(',', ';'), |
| 46 | + KeyCode::OemPeriod => modifiers.handle_shift('.', ':'), |
| 47 | + KeyCode::Oem2 => modifiers.handle_shift('-', '_'), |
215 | 48 | // ========= Row 6 (modifers and space bar) =========
|
216 |
| - KeyCode::NumpadPeriod => { |
217 |
| - if modifiers.numlock { |
218 |
| - DecodedKey::Unicode(',') |
219 |
| - } else { |
220 |
| - fallback.map_keycode(keycode, modifiers, handle_ctrl) |
221 |
| - } |
222 |
| - } |
223 |
| - e => fallback.map_keycode(e, modifiers, handle_ctrl), |
| 49 | + KeyCode::NumpadPeriod if modifiers.numlock => DecodedKey::Unicode(','), |
| 50 | + e => super::Us104Key.map_keycode(e, modifiers, handle_ctrl), |
224 | 51 | }
|
225 | 52 | }
|
226 | 53 |
|
|
0 commit comments