use it

Junkui Zhang created

Change summary

crates/gpui/src/platform/linux/platform.rs   | 30 +++++++++++----------
crates/gpui/src/platform/linux/x11/client.rs |  6 ++--
2 files changed, 19 insertions(+), 17 deletions(-)

Detailed changes

crates/gpui/src/platform/linux/platform.rs 🔗

@@ -726,13 +726,12 @@ impl KeyboardState {
 #[cfg(any(feature = "wayland", feature = "x11"))]
 impl crate::Keystroke {
     pub(super) fn from_xkb(
-        state: &State,
+        keyboard_state: &KeyboardState,
         mut modifiers: crate::Modifiers,
         keycode: Keycode,
     ) -> Self {
-        let key_utf32 = state.key_get_utf32(keycode);
-        let key_utf8 = state.key_get_utf8(keycode);
-        let key_sym = state.key_get_one_sym(keycode);
+        let key_utf8 = keyboard_state.state.key_get_utf8(keycode);
+        let key_sym = keyboard_state.state.key_get_one_sym(keycode);
 
         let key = match key_sym {
             Keysym::space => "space".to_owned(),
@@ -760,14 +759,17 @@ impl crate::Keystroke {
             Keysym::XF86_New => "new".to_owned(),
             Keysym::XF86_Open => "open".to_owned(),
             Keysym::XF86_Save => "save".to_owned(),
-            _ => {
-                let name = xkb::keysym_get_name(key_sym).to_lowercase();
-                if key_sym.is_keypad_key() {
-                    name.replace("kp_", "")
-                } else {
-                    name
-                }
-            }
+            _ => keyboard_state
+                .mapper
+                .get_key(keycode, modifiers.shift)
+                .unwrap_or_else(|| {
+                    let name = xkb::keysym_get_name(key_sym).to_lowercase();
+                    if key_sym.is_keypad_key() {
+                        name.replace("kp_", "")
+                    } else {
+                        name
+                    }
+                }),
         };
 
         if modifiers.shift {
@@ -780,8 +782,8 @@ impl crate::Keystroke {
         }
 
         // Ignore control characters (and DEL) for the purposes of key_char
-        let key_char =
-            (key_utf32 >= 32 && key_utf32 != 127 && !key_utf8.is_empty()).then_some(key_utf8);
+        let key_char = (!key_utf8.is_empty() && !key_utf8.chars().next().unwrap().is_control())
+            .then_some(key_utf8);
 
         Self {
             modifiers,

crates/gpui/src/platform/linux/x11/client.rs 🔗

@@ -1046,7 +1046,7 @@ impl X11Client {
                         xkb_state.locked_layout,
                     );
                     let mut keystroke =
-                        crate::Keystroke::from_xkb(&state.keyboard_state.state, modifiers, code);
+                        crate::Keystroke::from_xkb(&state.keyboard_state, modifiers, code);
                     let keysym = state.keyboard_state.state.key_get_one_sym(code);
                     if keysym.is_modifier_key() {
                         return Some(());
@@ -1121,7 +1121,7 @@ impl X11Client {
                         xkb_state.locked_layout,
                     );
                     let keystroke =
-                        crate::Keystroke::from_xkb(&state.keyboard_state.state, modifiers, code);
+                        crate::Keystroke::from_xkb(&state.keyboard_state, modifiers, code);
                     let keysym = state.keyboard_state.state.key_get_one_sym(code);
                     if keysym.is_modifier_key() {
                         return Some(());
@@ -1342,7 +1342,7 @@ impl X11Client {
             Event::KeyPress(event) | Event::KeyRelease(event) => {
                 let mut state = self.0.borrow_mut();
                 state.pre_key_char_down = Some(Keystroke::from_xkb(
-                    &state.keyboard_state.state,
+                    &state.keyboard_state,
                     state.modifiers,
                     event.detail.into(),
                 ));