Desktop: Resize issue mitigation, scroll speed adjustment and duplicate pointer move event filtering (#3424)

* mitigate resizing issue on mac and windows

* adjust scroll speed for mac and win

* fixup

* filter out duplicate mouse move events
This commit is contained in:
Timon 2025-11-27 17:18:52 +01:00 committed by GitHub
parent 8cebde76e2
commit f4608a6e40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 5 deletions

View File

@ -5,9 +5,17 @@ pub(crate) const RESOURCE_DOMAIN: &str = "resources";
pub(crate) const SCROLL_LINE_HEIGHT: usize = 40;
pub(crate) const SCROLL_LINE_WIDTH: usize = 40;
#[cfg(target_os = "linux")]
pub(crate) const SCROLL_SPEED_X: f32 = 3.0;
#[cfg(target_os = "linux")]
pub(crate) const SCROLL_SPEED_Y: f32 = 3.0;
#[cfg(not(target_os = "linux"))]
pub(crate) const SCROLL_SPEED_X: f32 = 1.0;
#[cfg(not(target_os = "linux"))]
pub(crate) const SCROLL_SPEED_Y: f32 = 1.0;
pub(crate) const PINCH_ZOOM_SPEED: f64 = 300.0;
pub(crate) const MULTICLICK_TIMEOUT: Duration = Duration::from_millis(500);

View File

@ -28,6 +28,11 @@ impl CefContext for SingleThreadedCefContext {
let host = self.browser.host().unwrap();
host.set_zoom_level(view_info.zoom());
host.was_resized();
// Fix for CEF not updating the view after resize on windows and mac
// TODO: remove once https://github.com/chromiumembedded/cef/issues/3822 is fixed
#[cfg(any(target_os = "windows", target_os = "macos"))]
host.invalidate(cef::PaintElementType::default());
}
fn send_web_message(&self, message: Vec<u8>) {

View File

@ -13,14 +13,16 @@ use super::consts::{PINCH_ZOOM_SPEED, SCROLL_LINE_HEIGHT, SCROLL_LINE_WIDTH, SCR
pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputState, event: &WindowEvent) {
match event {
WindowEvent::PointerMoved { position, .. } | WindowEvent::PointerEntered { position, .. } => {
input_state.cursor_move(position);
if !input_state.cursor_move(position) {
return;
}
let Some(host) = browser.host() else { return };
host.send_mouse_move_event(Some(&input_state.into()), 0);
}
WindowEvent::PointerLeft { position, .. } => {
if let Some(position) = position {
input_state.cursor_move(position);
let _ = input_state.cursor_move(position);
}
let Some(host) = browser.host() else { return };

View File

@ -17,8 +17,13 @@ impl InputState {
self.modifiers = *modifiers;
}
pub(crate) fn cursor_move(&mut self, position: &PhysicalPosition<f64>) {
self.mouse_position = position.into();
pub(crate) fn cursor_move(&mut self, position: &PhysicalPosition<f64>) -> bool {
let new = position.into();
if self.mouse_position == new {
return false;
}
self.mouse_position = new;
true
}
pub(crate) fn mouse_input(&mut self, button: &MouseButton, state: &ElementState) -> ClickCount {
@ -59,7 +64,7 @@ impl From<&mut InputState> for MouseEvent {
}
}
#[derive(Default, Clone, Copy)]
#[derive(Default, Clone, Copy, Eq, PartialEq)]
pub(crate) struct MousePosition {
x: usize,
y: usize,