Desktop: Mac fix keyboard input (#3371)

* add browser debug port env

* mac use option as alt

* fix cef texture double sRGB conversion by using cef-rs fork with fix

* fix keyboard input on mac

* add missing frontend messages

* fixup

* fix keyboard input mac

* dbg

* re implement keyboard mapping

Co-authored-by: csmoe <csmoe@msn.com>

* Fix double arrow keys

* try fix for non mac

* test

* Revert "test"

This reverts commit c7cde9c597.

* fix mac

* some cleanup

* fix zoom in shortcut on mac introduced in #3377

* disable menu shortcut display

* fixup
This commit is contained in:
Timon
2025-11-17 11:51:59 +00:00
committed by GitHub
co-authored by csmoe
parent 181c30bc0a
commit e751979e5c
14 changed files with 365 additions and 383 deletions
+28 -10
View File
@@ -1,23 +1,44 @@
pub trait ToNativeKeycode {
use winit::keyboard::{Key, NamedKey, PhysicalKey};
pub(crate) trait ToCharRepresentation {
fn to_char_representation(&self) -> char;
}
impl ToCharRepresentation for Key {
fn to_char_representation(&self) -> char {
match self {
Key::Named(named) => match named {
NamedKey::Tab => '\t',
NamedKey::Enter => '\r',
NamedKey::Backspace => '\x08',
NamedKey::Escape => '\x1b',
_ => '\0',
},
Key::Character(char) => char.chars().next().unwrap_or_default(),
_ => '\0',
}
}
}
pub(crate) trait ToNativeKeycode {
fn to_native_keycode(&self) -> i32;
}
impl ToNativeKeycode for winit::keyboard::PhysicalKey {
impl ToNativeKeycode for PhysicalKey {
fn to_native_keycode(&self) -> i32 {
use winit::platform::scancode::PhysicalKeyExtScancode;
#[cfg(target_os = "linux")]
{
self.to_scancode().map(|evdev| (evdev + 8) as i32).unwrap_or(0)
self.to_scancode().map(|evdev| (evdev + 8) as i32).unwrap_or_default()
}
#[cfg(any(target_os = "macos", target_os = "windows"))]
{
self.to_scancode().map(|c| c as i32).unwrap_or(0)
self.to_scancode().map(|c| c as i32).unwrap_or_default()
}
}
}
// Windows Virtual keyboard binary representation
pub(crate) trait ToVKBits {
fn to_vk_bits(&self) -> i32;
}
@@ -32,10 +53,8 @@ macro_rules! map_enum {
}
};
}
impl ToVKBits for winit::keyboard::NamedKey {
fn to_vk_bits(&self) -> i32 {
use winit::keyboard::NamedKey;
map_enum!(
self,
NamedKey,
@@ -49,10 +68,10 @@ impl ToVKBits for winit::keyboard::NamedKey {
(0x5B, Meta),
(0x0D, Enter),
(0x09, Tab),
(0x28, ArrowDown),
(0x25, ArrowLeft),
(0x27, ArrowRight),
(0x26, ArrowUp),
(0x27, ArrowRight),
(0x28, ArrowDown),
(0x23, End),
(0x24, Home),
(0x22, PageDown),
@@ -152,7 +171,6 @@ macro_rules! map {
}
};
}
impl ToVKBits for char {
fn to_vk_bits(&self) -> i32 {
map!(