Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
windows: Remove null terminator from keyboard ID (#41785)
Antal Szabó71f1f3728d22
diff --git a/crates/gpui/src/platform/windows/keyboard.rs b/crates/gpui/src/platform/windows/keyboard.rsindex 7a8478d5910..cd0c1da1056 100644--- a/crates/gpui/src/platform/windows/keyboard.rs+++ b/crates/gpui/src/platform/windows/keyboard.rs@@ -9,7 +9,6 @@ use windows::Win32::UI::{},WindowsAndMessaging::KL_NAMELENGTH,};-use windows_core::HSTRING;use crate::{KeybindingKeystroke, Keystroke, Modifiers, PlatformKeyboardLayout, PlatformKeyboardMapper,@@ -93,14 +92,13 @@ impl PlatformKeyboardMapper for WindowsKeyboardMapper {impl WindowsKeyboardLayout {pub(crate) fn new() -> Result<Self> {- let mut buffer = [0u16; KL_NAMELENGTH as usize];+ let mut buffer = [0u16; KL_NAMELENGTH as usize]; // KL_NAMELENGTH includes the null terminatorunsafe { GetKeyboardLayoutNameW(&mut buffer)? };- let id = HSTRING::from_wide(&buffer).to_string();+ let id = String::from_utf16_lossy(&buffer[..buffer.len() - 1]); // Remove the null terminatorlet entry = windows_registry::LOCAL_MACHINE.open(format!(- "System\\CurrentControlSet\\Control\\Keyboard Layouts\\{}",- id+ "System\\CurrentControlSet\\Control\\Keyboard Layouts\\{id}"))?;- let name = entry.get_hstring("Layout Text")?.to_string();+ let name = entry.get_string("Layout Text")?;Ok(Self { id, name })}@@ -135,6 +133,7 @@ impl WindowsKeyboardLayout {b"0405" | // Czechb"040E" | // Hungarianb"0424" | // Slovenian+ b"041A" | // Croatianb"041B" | // Slovakb"0418" // Romanian)