|
2 | 2 | //! |
3 | 3 | //! [`winit`]: https://github.com/rust-windowing/winit |
4 | 4 | //! [`iced_runtime`]: https://github.com/iced-rs/iced/tree/0.10/runtime |
| 5 | +use winit::keyboard::SmolStr; |
| 6 | +use winit::platform::modifier_supplement::KeyEventExtModifierSupplement; |
| 7 | + |
5 | 8 | use crate::core::keyboard; |
6 | 9 | use crate::core::mouse; |
7 | 10 | use crate::core::touch; |
@@ -195,51 +198,54 @@ pub fn window_event( |
195 | 198 | })) |
196 | 199 | } |
197 | 200 | }, |
198 | | - WindowEvent::KeyboardInput { |
199 | | - event: |
200 | | - winit::event::KeyEvent { |
201 | | - logical_key, |
202 | | - state, |
203 | | - text, |
204 | | - location, |
205 | | - .. |
206 | | - }, |
207 | | - .. |
208 | | - } => Some(Event::Keyboard({ |
209 | | - let key = key(logical_key); |
210 | | - let modifiers = self::modifiers(modifiers); |
211 | | - |
212 | | - let location = match location { |
213 | | - winit::keyboard::KeyLocation::Standard => { |
214 | | - keyboard::Location::Standard |
215 | | - } |
216 | | - winit::keyboard::KeyLocation::Left => keyboard::Location::Left, |
217 | | - winit::keyboard::KeyLocation::Right => { |
218 | | - keyboard::Location::Right |
219 | | - } |
220 | | - winit::keyboard::KeyLocation::Numpad => { |
221 | | - keyboard::Location::Numpad |
222 | | - } |
223 | | - }; |
224 | | - |
225 | | - match state { |
226 | | - winit::event::ElementState::Pressed => { |
227 | | - keyboard::Event::KeyPressed { |
228 | | - key, |
229 | | - modifiers, |
230 | | - location, |
231 | | - text, |
| 201 | + WindowEvent::KeyboardInput { event, .. } => { |
| 202 | + let text_with_modifiers = |
| 203 | + event.text_with_all_modifiers().map(|t| SmolStr::new(t)); |
| 204 | + let winit::event::KeyEvent { |
| 205 | + logical_key, |
| 206 | + state, |
| 207 | + text: _text, |
| 208 | + location, |
| 209 | + .. |
| 210 | + } = event; |
| 211 | + Some(Event::Keyboard({ |
| 212 | + let key = key(logical_key); |
| 213 | + let modifiers = self::modifiers(modifiers); |
| 214 | + |
| 215 | + let location = match location { |
| 216 | + winit::keyboard::KeyLocation::Standard => { |
| 217 | + keyboard::Location::Standard |
232 | 218 | } |
233 | | - } |
234 | | - winit::event::ElementState::Released => { |
235 | | - keyboard::Event::KeyReleased { |
236 | | - key, |
237 | | - modifiers, |
238 | | - location, |
| 219 | + winit::keyboard::KeyLocation::Left => { |
| 220 | + keyboard::Location::Left |
| 221 | + } |
| 222 | + winit::keyboard::KeyLocation::Right => { |
| 223 | + keyboard::Location::Right |
| 224 | + } |
| 225 | + winit::keyboard::KeyLocation::Numpad => { |
| 226 | + keyboard::Location::Numpad |
| 227 | + } |
| 228 | + }; |
| 229 | + |
| 230 | + match state { |
| 231 | + winit::event::ElementState::Pressed => { |
| 232 | + keyboard::Event::KeyPressed { |
| 233 | + key, |
| 234 | + modifiers, |
| 235 | + location, |
| 236 | + text: text_with_modifiers, |
| 237 | + } |
| 238 | + } |
| 239 | + winit::event::ElementState::Released => { |
| 240 | + keyboard::Event::KeyReleased { |
| 241 | + key, |
| 242 | + modifiers, |
| 243 | + location, |
| 244 | + } |
239 | 245 | } |
240 | 246 | } |
241 | | - } |
242 | | - })), |
| 247 | + })) |
| 248 | + } |
243 | 249 | WindowEvent::ModifiersChanged(new_modifiers) => { |
244 | 250 | Some(Event::Keyboard(keyboard::Event::ModifiersChanged( |
245 | 251 | self::modifiers(new_modifiers.state()), |
|
0 commit comments