Desktop: Fix Windows build (#3522)
* fix win build * fix mac * Change window button colors to match Windows colors --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
parent
9d26c040e9
commit
11e2882cb2
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ pub(crate) mod menu {
|
|||
widgets
|
||||
.into_iter()
|
||||
.map(|widget| {
|
||||
let text_button = match &widget.widget {
|
||||
let text_button = match widget.widget.as_ref() {
|
||||
Widget::TextButton(text_button) => text_button,
|
||||
_ => panic!("Menu bar layout top-level widgets are supposed to be text buttons"),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
}
|
||||
|
||||
&:hover {
|
||||
background: var(--color-6-lowergray);
|
||||
background: #2d2d2d;
|
||||
|
||||
svg {
|
||||
fill: var(--color-f-white);
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
}
|
||||
|
||||
&:last-of-type:hover {
|
||||
background: #e81123;
|
||||
background: #c42b1c;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
Loading…
Reference in New Issue