gpui: Refactor PlatformKeyboardLayout (#29653)

Release Notes:

- N/A
This commit is contained in:
张小白 2025-04-30 16:17:26 +08:00 committed by GitHub
parent edda386827
commit 074b6965e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 131 additions and 106 deletions

View file

@ -1,5 +1,5 @@
use super::{
BoolExt,
BoolExt, MacKeyboardLayout,
attributed_string::{NSAttributedString, NSMutableAttributedString},
events::key_to_native,
is_macos_version_at_least, renderer, screen_capture,
@ -1579,45 +1579,6 @@ impl UTType {
}
}
struct MacKeyboardLayout {
id: String,
name: String,
}
impl PlatformKeyboardLayout for MacKeyboardLayout {
fn id(&self) -> &str {
&self.id
}
fn name(&self) -> &str {
&self.name
}
}
impl MacKeyboardLayout {
fn new() -> Self {
unsafe {
let current_keyboard = TISCopyCurrentKeyboardLayoutInputSource();
let id: *mut Object = TISGetInputSourceProperty(
current_keyboard,
kTISPropertyInputSourceID as *const c_void,
);
let id: *const std::os::raw::c_char = msg_send![id, UTF8String];
let id = CStr::from_ptr(id).to_str().unwrap().to_string();
let name: *mut Object = TISGetInputSourceProperty(
current_keyboard,
kTISPropertyLocalizedName as *const c_void,
);
let name: *const std::os::raw::c_char = msg_send![name, UTF8String];
let name = CStr::from_ptr(name).to_str().unwrap().to_string();
Self { id, name }
}
}
}
#[cfg(test)]
mod tests {
use crate::ClipboardItem;