From 6a46610632fa01cb8ce7726597af59ed0048e29a Mon Sep 17 00:00:00 2001 From: richerfu <32590310+richerfu@users.noreply.github.com> Date: Mon, 17 Nov 2025 14:56:20 +0800 Subject: [PATCH] feat(core): add keyboard for ohos --- winit-core/src/keyboard.rs | 17 +++++++++++++++-- winit/src/changelog/unreleased.md | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/winit-core/src/keyboard.rs b/winit-core/src/keyboard.rs index af92c430a..f686e3a3a 100644 --- a/winit-core/src/keyboard.rs +++ b/winit-core/src/keyboard.rs @@ -29,11 +29,13 @@ pub enum NativeKeyCode { Windows(u16), /// An XKB "keycode". Xkb(u32), + /// An OpenHarmony "scancode". + Ohos(u32), } impl std::fmt::Debug for NativeKeyCode { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - use NativeKeyCode::{Android, MacOS, Unidentified, Windows, Xkb}; + use NativeKeyCode::{Android, MacOS, Ohos, Unidentified, Windows, Xkb}; let mut debug_tuple; match self { Unidentified => { @@ -55,6 +57,10 @@ impl std::fmt::Debug for NativeKeyCode { debug_tuple = f.debug_tuple("Xkb"); debug_tuple.field(&format_args!("0x{code:04X}")); }, + Ohos(code) => { + debug_tuple = f.debug_tuple("OpenHarmony"); + debug_tuple.field(&format_args!("0x{code:04X}")); + }, } debug_tuple.finish() } @@ -85,11 +91,13 @@ pub enum NativeKey { Xkb(u32), /// A "key value string". Web(SmolStr), + /// An OpenHarmony "keycode", which is similar to a "virtual-key code" on Windows. + Ohos(u32), } impl std::fmt::Debug for NativeKey { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - use NativeKey::{Android, MacOS, Unidentified, Web, Windows, Xkb}; + use NativeKey::{Android, MacOS, Ohos, Unidentified, Web, Windows, Xkb}; let mut debug_tuple; match self { Unidentified => { @@ -115,6 +123,10 @@ impl std::fmt::Debug for NativeKey { debug_tuple = f.debug_tuple("Web"); debug_tuple.field(code); }, + Ohos(code) => { + debug_tuple = f.debug_tuple("OpenHarmony"); + debug_tuple.field(code); + }, } debug_tuple.finish() } @@ -129,6 +141,7 @@ impl From for NativeKey { NativeKeyCode::MacOS(x) => NativeKey::MacOS(x), NativeKeyCode::Windows(x) => NativeKey::Windows(x), NativeKeyCode::Xkb(x) => NativeKey::Xkb(x), + NativeKeyCode::Ohos(x) => NativeKey::Ohos(x), } } } diff --git a/winit/src/changelog/unreleased.md b/winit/src/changelog/unreleased.md index f3a0f6d2c..02015c38c 100644 --- a/winit/src/changelog/unreleased.md +++ b/winit/src/changelog/unreleased.md @@ -39,3 +39,7 @@ The migration guide could reference other migration examples in the current changelog entry. ## Unreleased + +### Added + +- Add `keyboard` support for OpenHarmony. \ No newline at end of file