Remove unused KeycodeSource (#34403)

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2025-07-14 11:03:16 -06:00 committed by GitHub
parent eca36c502e
commit 45d0686129
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 57 additions and 85 deletions

View file

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

View file

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

View file

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