From 73e887bcfb946ec72d21787579721986f99feb8e Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 1 Feb 2024 16:30:08 -0500 Subject: [PATCH] fix(sctk): send key characters --- sctk/src/sctk_event.rs | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/sctk/src/sctk_event.rs b/sctk/src/sctk_event.rs index c01291b5e5..b2fd3dbb65 100755 --- a/sctk/src/sctk_event.rs +++ b/sctk/src/sctk_event.rs @@ -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::{ @@ -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, @@ -580,14 +579,18 @@ 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), }, )) @@ -595,8 +598,10 @@ impl SctkEvent { .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, @@ -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) }