fix win build

This commit is contained in:
Timon Schelling 2025-12-22 18:52:31 +00:00
parent 9d26c040e9
commit 59ec2884d2
2 changed files with 16 additions and 32 deletions

View file

@ -1,7 +1,6 @@
use cef::sys::{cef_event_flags_t, cef_key_event_type_t, cef_mouse_button_type_t};
use cef::sys::{cef_key_event_type_t, cef_mouse_button_type_t};
use cef::{Browser, ImplBrowser, ImplBrowserHost, KeyEvent, MouseEvent};
use winit::event::{ButtonSource, ElementState, MouseButton, MouseScrollDelta, WindowEvent};
use winit::keyboard::Key;
mod keymap;
use keymap::{ToCharRepresentation, ToNativeKeycode, ToVKBits};
@ -70,6 +69,8 @@ pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputStat
WindowEvent::KeyboardInput { device_id: _, event, is_synthetic: _ } => {
let Some(host) = browser.host() else { return };
input_state.modifiers_apply_key_event(&event.logical_key, &event.state);
let mut key_event = KeyEvent {
type_: match (event.state, &event.logical_key) {
(ElementState::Pressed, winit::keyboard::Key::Character(_)) => cef_key_event_type_t::KEYEVENT_CHAR,
@ -82,35 +83,6 @@ pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputStat
key_event.modifiers = input_state.cef_modifiers(&event.location, event.repeat).into();
match (&event.logical_key, event.state) {
(Key::Named(winit::keyboard::NamedKey::Control), ElementState::Pressed) => {
key_event.modifiers |= cef_event_flags_t::EVENTFLAG_CONTROL_DOWN.0;
}
(Key::Named(winit::keyboard::NamedKey::Control), ElementState::Released) => {
key_event.modifiers &= !(cef_event_flags_t::EVENTFLAG_CONTROL_DOWN.0);
}
(Key::Named(winit::keyboard::NamedKey::Shift), ElementState::Pressed) => {
key_event.modifiers |= cef_event_flags_t::EVENTFLAG_SHIFT_DOWN.0;
}
(Key::Named(winit::keyboard::NamedKey::Shift), ElementState::Released) => {
key_event.modifiers &= !(cef_event_flags_t::EVENTFLAG_SHIFT_DOWN.0);
}
(Key::Named(winit::keyboard::NamedKey::Alt), ElementState::Pressed) => {
key_event.modifiers |= cef_event_flags_t::EVENTFLAG_ALT_DOWN.0;
}
(Key::Named(winit::keyboard::NamedKey::Alt), ElementState::Released) => {
key_event.modifiers &= !(cef_event_flags_t::EVENTFLAG_ALT_DOWN.0);
}
(Key::Named(winit::keyboard::NamedKey::Meta), ElementState::Pressed) => {
key_event.modifiers |= cef_event_flags_t::EVENTFLAG_COMMAND_DOWN.0;
}
(Key::Named(winit::keyboard::NamedKey::Meta), ElementState::Released) => {
key_event.modifiers &= !(cef_event_flags_t::EVENTFLAG_COMMAND_DOWN.0);
}
_ => {}
}
key_event.windows_key_code = match &event.logical_key {
winit::keyboard::Key::Named(named) => named.to_vk_bits(),
winit::keyboard::Key::Character(char) => char.chars().next().unwrap_or_default().to_vk_bits(),

View file

@ -3,7 +3,7 @@ use cef::sys::cef_event_flags_t;
use std::time::Instant;
use winit::dpi::PhysicalPosition;
use winit::event::{ElementState, MouseButton};
use winit::keyboard::{KeyLocation, ModifiersState};
use winit::keyboard::{Key, KeyLocation, ModifiersState, NamedKey};
use crate::cef::consts::{MULTICLICK_ALLOWED_TRAVEL, MULTICLICK_TIMEOUT};
@ -19,6 +19,18 @@ impl InputState {
self.modifiers = *modifiers;
}
pub(crate) fn modifiers_apply_key_event(&mut self, key: &Key, state: &ElementState) {
let bits = match key {
Key::Named(NamedKey::Shift) => ModifiersState::SHIFT,
Key::Named(NamedKey::Control) => ModifiersState::CONTROL,
Key::Named(NamedKey::Alt) => ModifiersState::ALT,
Key::Named(NamedKey::Meta) => ModifiersState::META,
_ => return,
};
let is_pressed = matches!(state, ElementState::Pressed);
self.modifiers.set(bits, is_pressed);
}
pub(crate) fn cursor_move(&mut self, position: &PhysicalPosition<f64>) -> bool {
let new = position.into();
if self.mouse_position == new {