Fix double arrow keys

This commit is contained in:
Timon Schelling
2025-11-13 19:08:43 +01:00
parent 9cababc75a
commit feae93590b
3 changed files with 13 additions and 6 deletions
+9 -1
View File
@@ -70,7 +70,7 @@ pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputStat
key_event.type_ = match (event.state, &event.logical_key) { key_event.type_ = match (event.state, &event.logical_key) {
(ElementState::Pressed, winit::keyboard::Key::Character(_)) => cef_key_event_type_t::KEYEVENT_CHAR, (ElementState::Pressed, winit::keyboard::Key::Character(_)) => cef_key_event_type_t::KEYEVENT_CHAR,
(ElementState::Pressed, _) => cef_key_event_type_t::KEYEVENT_KEYDOWN, (ElementState::Pressed, _) => cef_key_event_type_t::KEYEVENT_RAWKEYDOWN,
(ElementState::Released, _) => cef_key_event_type_t::KEYEVENT_KEYUP, (ElementState::Released, _) => cef_key_event_type_t::KEYEVENT_KEYUP,
} }
.into(); .into();
@@ -87,6 +87,14 @@ pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputStat
key_event.character = key_to_char(&event.logical_key) as u16; key_event.character = key_to_char(&event.logical_key) as u16;
key_event.unmodified_character = key_to_char(&event.key_without_modifiers) as u16; key_event.unmodified_character = key_to_char(&event.key_without_modifiers) as u16;
#[cfg(target_os = "macos")] // See https://www.magpcss.org/ceforum/viewtopic.php?start=10&t=11650
if key_event.character == 0
&& key_event.unmodified_character == 0
&& let Some(text) = &event.text_with_all_modifiers
{
key_event.character = text.chars().next().unwrap_or_default() as u16;
}
host.send_key_event(Some(&key_event)); host.send_key_event(Some(&key_event));
fn key_to_char(key: &winit::keyboard::Key) -> char { fn key_to_char(key: &winit::keyboard::Key) -> char {
+2 -2
View File
@@ -49,10 +49,10 @@ impl ToVKBits for winit::keyboard::NamedKey {
(0x5B, Meta), (0x5B, Meta),
(0x0D, Enter), (0x0D, Enter),
(0x09, Tab), (0x09, Tab),
(0x28, ArrowDown),
(0x25, ArrowLeft), (0x25, ArrowLeft),
(0x27, ArrowRight),
(0x26, ArrowUp), (0x26, ArrowUp),
(0x27, ArrowRight),
(0x28, ArrowDown),
(0x23, End), (0x23, End),
(0x24, Home), (0x24, Home),
(0x22, PageDown), (0x22, PageDown),
+2 -3
View File
@@ -1,5 +1,5 @@
use winit::event_loop::ActiveEventLoop; use winit::event_loop::ActiveEventLoop;
use winit::platform::macos::{OptionAsAlt, WindowAttributesMacOS}; use winit::platform::macos::WindowAttributesMacOS;
use winit::window::{Window, WindowAttributes}; use winit::window::{Window, WindowAttributes};
use crate::consts::APP_NAME; use crate::consts::APP_NAME;
@@ -15,8 +15,7 @@ impl super::NativeWindow for NativeWindowImpl {
let mac_window = WindowAttributesMacOS::default() let mac_window = WindowAttributesMacOS::default()
.with_titlebar_transparent(true) .with_titlebar_transparent(true)
.with_fullsize_content_view(true) .with_fullsize_content_view(true)
.with_title_hidden(true) .with_title_hidden(true);
.with_option_as_alt(OptionAsAlt::OnlyLeft);
attributes.with_platform_attributes(Box::new(mac_window)) attributes.with_platform_attributes(Box::new(mac_window))
} }