gpui: Introduce PlatformKeyboardLayout
trait for human-friendly keyboard layout names (#29049)
This PR adds a new `PlatformKeyboardLayout` trait with two methods: `id(&self) -> &str` and `name(&self) -> &str`. The `id()` method returns a unique identifier for the keyboard layout, while `name()` provides a human-readable name. This distinction is especially important on Windows, where the `id` and `name` can be quite different. For example, the French layout has an `id` of `0000040C`, which is not human-readable, whereas the `name` would simply be `French`. Currently, the existing `keyboard_layout()` method returns what's essentially the same as `id()` in this new design. This PR implements the `name()` method for both Windows and macOS. On Linux, for now, `name()` still returns the same value as `id()`. Release Notes: - N/A
This commit is contained in:
parent
0454e7a22e
commit
f0ef3110d3
16 changed files with 197 additions and 68 deletions
|
@ -59,9 +59,10 @@ use crate::platform::{
|
|||
};
|
||||
use crate::{
|
||||
AnyWindowHandle, Bounds, ClipboardItem, CursorStyle, DisplayId, FileDropEvent, Keystroke,
|
||||
Modifiers, ModifiersChangedEvent, MouseButton, Pixels, Platform, PlatformDisplay,
|
||||
PlatformInput, Point, RequestFrameOptions, ScaledPixels, ScreenCaptureSource, ScrollDelta,
|
||||
Size, TouchPhase, WindowParams, X11Window, modifiers_from_xinput_info, point, px,
|
||||
LinuxKeyboardLayout, Modifiers, ModifiersChangedEvent, MouseButton, Pixels, Platform,
|
||||
PlatformDisplay, PlatformInput, PlatformKeyboardLayout, Point, RequestFrameOptions,
|
||||
ScaledPixels, ScreenCaptureSource, ScrollDelta, Size, TouchPhase, WindowParams, X11Window,
|
||||
modifiers_from_xinput_info, point, px,
|
||||
};
|
||||
|
||||
/// Value for DeviceId parameters which selects all devices.
|
||||
|
@ -1282,14 +1283,16 @@ impl LinuxClient for X11Client {
|
|||
f(&mut self.0.borrow_mut().common)
|
||||
}
|
||||
|
||||
fn keyboard_layout(&self) -> String {
|
||||
fn keyboard_layout(&self) -> Box<dyn PlatformKeyboardLayout> {
|
||||
let state = self.0.borrow();
|
||||
let layout_idx = state.xkb.serialize_layout(STATE_LAYOUT_EFFECTIVE);
|
||||
state
|
||||
.xkb
|
||||
.get_keymap()
|
||||
.layout_get_name(layout_idx)
|
||||
.to_string()
|
||||
Box::new(LinuxKeyboardLayout::new(
|
||||
state
|
||||
.xkb
|
||||
.get_keymap()
|
||||
.layout_get_name(layout_idx)
|
||||
.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue