Skip to content

Commit

Permalink
fix(winit): pass text with modifiers in event
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Feb 6, 2024
1 parent 9499727 commit a83d381
Showing 1 changed file with 48 additions and 42 deletions.
90 changes: 48 additions & 42 deletions winit/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
//!
//! [`winit`]: https://github.com/rust-windowing/winit
//! [`iced_runtime`]: https://github.com/iced-rs/iced/tree/0.10/runtime
use winit::keyboard::SmolStr;
use winit::platform::modifier_supplement::KeyEventExtModifierSupplement;

Check failure on line 6 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / web

unresolved import `winit::platform::modifier_supplement`

Check failure on line 6 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / wasm

unresolved import `winit::platform::modifier_supplement`

Check failure on line 6 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / web

unresolved import `winit::platform::modifier_supplement`

Check failure on line 6 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / wasm

unresolved import `winit::platform::modifier_supplement`

use crate::core::keyboard;
use crate::core::mouse;
use crate::core::touch;
Expand Down Expand Up @@ -195,51 +198,54 @@ pub fn window_event(
}))
}
},
WindowEvent::KeyboardInput {
event:
winit::event::KeyEvent {
logical_key,
state,
text,
location,
..
},
..
} => Some(Event::Keyboard({
let key = key(logical_key);
let modifiers = self::modifiers(modifiers);

let location = match location {
winit::keyboard::KeyLocation::Standard => {
keyboard::Location::Standard
}
winit::keyboard::KeyLocation::Left => keyboard::Location::Left,
winit::keyboard::KeyLocation::Right => {
keyboard::Location::Right
}
winit::keyboard::KeyLocation::Numpad => {
keyboard::Location::Numpad
}
};

match state {
winit::event::ElementState::Pressed => {
keyboard::Event::KeyPressed {
key,
modifiers,
location,
text,
WindowEvent::KeyboardInput { event, .. } => {
let text_with_modifiers =
event.text_with_all_modifiers().map(|t| SmolStr::new(t));

Check failure on line 203 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / web

no method named `text_with_all_modifiers` found for struct `KeyEvent` in the current scope

Check failure on line 203 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / wasm

no method named `text_with_all_modifiers` found for struct `KeyEvent` in the current scope

Check failure on line 203 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / web

no method named `text_with_all_modifiers` found for struct `KeyEvent` in the current scope

Check failure on line 203 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / wasm

no method named `text_with_all_modifiers` found for struct `KeyEvent` in the current scope
let winit::event::KeyEvent {
logical_key,
state,
text: _text,
location,
..
} = event;
Some(Event::Keyboard({
let key = key(logical_key);
let modifiers = self::modifiers(modifiers);

let location = match location {
winit::keyboard::KeyLocation::Standard => {
keyboard::Location::Standard
}
}
winit::event::ElementState::Released => {
keyboard::Event::KeyReleased {
key,
modifiers,
location,
winit::keyboard::KeyLocation::Left => {
keyboard::Location::Left
}
winit::keyboard::KeyLocation::Right => {
keyboard::Location::Right
}
winit::keyboard::KeyLocation::Numpad => {
keyboard::Location::Numpad
}
};

match state {
winit::event::ElementState::Pressed => {
keyboard::Event::KeyPressed {
key,
modifiers,
location,
text: text_with_modifiers,
}
}
winit::event::ElementState::Released => {
keyboard::Event::KeyReleased {
key,
modifiers,
location,
}
}
}
}
})),
}))
}
WindowEvent::ModifiersChanged(new_modifiers) => {
Some(Event::Keyboard(keyboard::Event::ModifiersChanged(
self::modifiers(new_modifiers.state()),
Expand Down

0 comments on commit a83d381

Please sign in to comment.