Skip to content

Commit

Permalink
Decouple Key from modifiers and apply them to text
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 authored and hecrj committed Feb 20, 2024
1 parent e24b1b6 commit 9600954
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions winit/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,40 @@ pub fn window_event(
}))
}
},
WindowEvent::KeyboardInput {
event:
winit::event::KeyEvent {
logical_key,
state,
text,
location,
..
},
..
} => Some(Event::Keyboard({
WindowEvent::KeyboardInput { event, .. } => Some(Event::Keyboard({
let logical_key = {
#[cfg(not(target_arch = "wasm32"))]
{
use winit::platform::modifier_supplement::KeyEventExtModifierSupplement;
event.key_without_modifiers()
}

#[cfg(target_arch = "wasm32")]
{
// TODO: Fix inconsistent API on Wasm
event.logical_key
}
};

let text = {
#[cfg(not(target_arch = "wasm32"))]
{
use crate::core::SmolStr;
use winit::platform::modifier_supplement::KeyEventExtModifierSupplement;

event.text_with_all_modifiers().map(SmolStr::new)
}

#[cfg(target_arch = "wasm32")]
{
// TODO: Fix inconsistent API on Wasm
event.text
}
};

let winit::event::KeyEvent {
state, location, ..
} = event;
let key = key(logical_key);
let modifiers = self::modifiers(modifiers);

Expand Down

0 comments on commit 9600954

Please sign in to comment.