Skip to content

Commit

Permalink
fix(sctk): send key characters
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Feb 1, 2024
1 parent 32a0efc commit 73e887b
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions sctk/src/sctk_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ use iced_futures::core::event::{
use iced_runtime::{
command::platform_specific::wayland::data_device::DndIcon,
core::{event::wayland, keyboard, mouse, window, Point},
keyboard::{
key::{self, Named},
Key, Location,
},
keyboard::{Key, Location},
window::Id as SurfaceId,
};
use sctk::{
Expand Down Expand Up @@ -567,8 +564,10 @@ impl SctkEvent {
)])
.collect(),
KeyboardEventVariant::Press(ke) => {
let (key, location) =
keysym_to_vkey_location(ke.keysym.raw());
let (key, location) = keysym_to_vkey_location(
ke.keysym.raw(),
ke.utf8.as_deref(),
);
Some(iced_runtime::core::Event::Keyboard(
keyboard::Event::KeyPressed {
key: key,
Expand All @@ -580,23 +579,29 @@ impl SctkEvent {
.into_iter()
.collect()
}
KeyboardEventVariant::Repeat(ke) => {
KeyboardEventVariant::Repeat(KeyEvent {
raw_code,
utf8,
..
}) => {
let (key, location) =
keysym_to_vkey_location(ke.keysym.raw());
keysym_to_vkey_location(raw_code, utf8.as_deref());
Some(iced_runtime::core::Event::Keyboard(
keyboard::Event::KeyPressed {
key: key,
location: location,
text: ke.utf8.map(|s| s.into()),
text: utf8.map(|s| s.into()),
modifiers: modifiers_to_native(*modifiers),
},
))
.into_iter()
.collect()
}
KeyboardEventVariant::Release(ke) => {
let (k, location) =
keysym_to_vkey_location(ke.keysym.raw());
let (k, location) = keysym_to_vkey_location(
ke.keysym.raw(),
ke.utf8.as_deref(),
);
Some(iced_runtime::core::Event::Keyboard(
keyboard::Event::KeyReleased {
key: k,
Expand Down Expand Up @@ -942,8 +947,12 @@ impl SctkEvent {
}
}

fn keysym_to_vkey_location(keysym: u32) -> (Key, Location) {
let key = keysym_to_key(keysym);
fn keysym_to_vkey_location(keysym: u32, utf8: Option<&str>) -> (Key, Location) {
let key = if let Some(utf8) = utf8 {
Key::Character(utf8.into())
} else {
keysym_to_key(keysym)
};
let location = keymap::keysym_location(keysym);
(key, location)
}

0 comments on commit 73e887b

Please sign in to comment.