Remove unused KeycodeSource (#34403)

Conrad Irwin created

Release Notes:

- N/A

Change summary

crates/gpui/src/platform/linux/platform.rs       | 117 ++++++++----------
crates/gpui/src/platform/linux/wayland/client.rs |  20 --
crates/gpui/src/platform/linux/x11/client.rs     |   9 
3 files changed, 59 insertions(+), 87 deletions(-)

Detailed changes

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

@@ -707,69 +707,57 @@ pub(super) fn log_cursor_icon_warning(message: impl std::fmt::Display) {
 }
 
 #[cfg(any(feature = "wayland", feature = "x11"))]
-pub(crate) enum KeycodeSource {
-    X11,
-    Wayland,
-}
-
-#[cfg(any(feature = "wayland", feature = "x11"))]
-impl KeycodeSource {
-    fn guess_ascii(&self, keycode: Keycode, shift: bool) -> Option<char> {
-        // For historical reasons, X11 adds 8 to keycodes.
-        // Wayland doesn't, but by this point, our own Wayland client
-        // has added 8 for X11 compatibility.
-        let raw = keycode.raw() - 8;
-        let c = match (raw, shift) {
-            (16, _) => 'q',
-            (17, _) => 'w',
-            (18, _) => 'e',
-            (19, _) => 'r',
-            (20, _) => 't',
-            (21, _) => 'y',
-            (22, _) => 'u',
-            (23, _) => 'i',
-            (24, _) => 'o',
-            (25, _) => 'p',
-            (26, false) => '[',
-            (26, true) => '{',
-            (27, false) => ']',
-            (27, true) => '}',
-            (30, _) => 'a',
-            (31, _) => 's',
-            (32, _) => 'd',
-            (33, _) => 'f',
-            (34, _) => 'g',
-            (35, _) => 'h',
-            (36, _) => 'j',
-            (37, _) => 'k',
-            (38, _) => 'l',
-            (39, false) => ';',
-            (39, true) => ':',
-            (40, false) => '\'',
-            (40, true) => '"',
-            (41, false) => '`',
-            (41, true) => '~',
-            (43, false) => '\\',
-            (43, true) => '|',
-            (44, _) => 'z',
-            (45, _) => 'x',
-            (46, _) => 'c',
-            (47, _) => 'v',
-            (48, _) => 'b',
-            (49, _) => 'n',
-            (50, _) => 'm',
-            (51, false) => ',',
-            (51, true) => '>',
-            (52, false) => '.',
-            (52, true) => '<',
-            (53, false) => '/',
-            (53, true) => '?',
-
-            _ => return None,
-        };
-
-        Some(c)
-    }
+fn guess_ascii(keycode: Keycode, shift: bool) -> Option<char> {
+    let c = match (keycode.raw(), shift) {
+        (24, _) => 'q',
+        (25, _) => 'w',
+        (26, _) => 'e',
+        (27, _) => 'r',
+        (28, _) => 't',
+        (29, _) => 'y',
+        (30, _) => 'u',
+        (31, _) => 'i',
+        (32, _) => 'o',
+        (33, _) => 'p',
+        (34, false) => '[',
+        (34, true) => '{',
+        (35, false) => ']',
+        (35, true) => '}',
+        (38, _) => 'a',
+        (39, _) => 's',
+        (40, _) => 'd',
+        (41, _) => 'f',
+        (42, _) => 'g',
+        (43, _) => 'h',
+        (44, _) => 'j',
+        (45, _) => 'k',
+        (46, _) => 'l',
+        (47, false) => ';',
+        (47, true) => ':',
+        (48, false) => '\'',
+        (48, true) => '"',
+        (49, false) => '`',
+        (49, true) => '~',
+        (51, false) => '\\',
+        (51, true) => '|',
+        (52, _) => 'z',
+        (53, _) => 'x',
+        (54, _) => 'c',
+        (55, _) => 'v',
+        (56, _) => 'b',
+        (57, _) => 'n',
+        (58, _) => 'm',
+        (59, false) => ',',
+        (59, true) => '>',
+        (60, false) => '.',
+        (60, true) => '<',
+        (61, false) => '/',
+        (61, true) => '?',
+
+        _ => return None,
+    };
+
+    Some(c)
 }
 
 #[cfg(any(feature = "wayland", feature = "x11"))]
@@ -778,7 +766,6 @@ impl crate::Keystroke {
         state: &State,
         mut modifiers: crate::Modifiers,
         keycode: Keycode,
-        source: KeycodeSource,
     ) -> Self {
         let key_utf32 = state.key_get_utf32(keycode);
         let key_utf8 = state.key_get_utf8(keycode);
@@ -840,7 +827,7 @@ impl crate::Keystroke {
                 let name = xkb::keysym_get_name(key_sym).to_lowercase();
                 if key_sym.is_keypad_key() {
                     name.replace("kp_", "")
-                } else if let Some(key_en) = source.guess_ascii(keycode, modifiers.shift) {
+                } else if let Some(key_en) = guess_ascii(keycode, modifiers.shift) {
                     String::from(key_en)
                 } else {
                     name

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

@@ -69,6 +69,7 @@ use super::{
     window::{ImeInput, WaylandWindowStatePtr},
 };
 
+use crate::platform::{PlatformWindow, blade::BladeContext};
 use crate::{
     AnyWindowHandle, Bounds, Capslock, CursorStyle, DOUBLE_CLICK_INTERVAL, DevicePixels, DisplayId,
     FileDropEvent, ForegroundExecutor, KeyDownEvent, KeyUpEvent, Keystroke, LinuxCommon,
@@ -77,10 +78,6 @@ use crate::{
     PlatformInput, PlatformKeyboardLayout, Point, SCROLL_LINES, ScaledPixels, ScrollDelta,
     ScrollWheelEvent, Size, TouchPhase, WindowParams, point, px, size,
 };
-use crate::{
-    KeycodeSource,
-    platform::{PlatformWindow, blade::BladeContext},
-};
 use crate::{
     SharedString,
     platform::linux::{
@@ -1296,12 +1293,8 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClientStatePtr {
 
                 match key_state {
                     wl_keyboard::KeyState::Pressed if !keysym.is_modifier_key() => {
-                        let mut keystroke = Keystroke::from_xkb(
-                            &keymap_state,
-                            state.modifiers,
-                            keycode,
-                            KeycodeSource::Wayland,
-                        );
+                        let mut keystroke =
+                            Keystroke::from_xkb(&keymap_state, state.modifiers, keycode);
                         if let Some(mut compose) = state.compose_state.take() {
                             compose.feed(keysym);
                             match compose.status() {
@@ -1386,12 +1379,7 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClientStatePtr {
                     }
                     wl_keyboard::KeyState::Released if !keysym.is_modifier_key() => {
                         let input = PlatformInput::KeyUp(KeyUpEvent {
-                            keystroke: Keystroke::from_xkb(
-                                keymap_state,
-                                state.modifiers,
-                                keycode,
-                                KeycodeSource::Wayland,
-                            ),
+                            keystroke: Keystroke::from_xkb(keymap_state, state.modifiers, keycode),
                         });
 
                         if state.repeat.current_keycode == Some(keycode) {

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

@@ -1,4 +1,4 @@
-use crate::{Capslock, KeycodeSource, xcb_flush};
+use crate::{Capslock, xcb_flush};
 use core::str;
 use std::{
     cell::RefCell,
@@ -1034,8 +1034,7 @@ impl X11Client {
                         xkb_state.latched_layout,
                         xkb_state.locked_layout,
                     );
-                    let mut keystroke =
-                        crate::Keystroke::from_xkb(&state.xkb, modifiers, code, KeycodeSource::X11);
+                    let mut keystroke = crate::Keystroke::from_xkb(&state.xkb, modifiers, code);
                     let keysym = state.xkb.key_get_one_sym(code);
                     if keysym.is_modifier_key() {
                         return Some(());
@@ -1103,8 +1102,7 @@ impl X11Client {
                         xkb_state.latched_layout,
                         xkb_state.locked_layout,
                     );
-                    let keystroke =
-                        crate::Keystroke::from_xkb(&state.xkb, modifiers, code, KeycodeSource::X11);
+                    let keystroke = crate::Keystroke::from_xkb(&state.xkb, modifiers, code);
                     let keysym = state.xkb.key_get_one_sym(code);
                     if keysym.is_modifier_key() {
                         return Some(());
@@ -1328,7 +1326,6 @@ impl X11Client {
                     &state.xkb,
                     state.modifiers,
                     event.detail.into(),
-                    KeycodeSource::X11,
                 ));
                 let (mut ximc, mut xim_handler) = state.take_xim()?;
                 drop(state);