Skip to content

Commit f4608a6

Browse files
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
1 parent 8cebde7 commit f4608a6

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

desktop/src/cef/consts.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ pub(crate) const RESOURCE_DOMAIN: &str = "resources";
55

66
pub(crate) const SCROLL_LINE_HEIGHT: usize = 40;
77
pub(crate) const SCROLL_LINE_WIDTH: usize = 40;
8+
9+
#[cfg(target_os = "linux")]
810
pub(crate) const SCROLL_SPEED_X: f32 = 3.0;
11+
#[cfg(target_os = "linux")]
912
pub(crate) const SCROLL_SPEED_Y: f32 = 3.0;
1013

14+
#[cfg(not(target_os = "linux"))]
15+
pub(crate) const SCROLL_SPEED_X: f32 = 1.0;
16+
#[cfg(not(target_os = "linux"))]
17+
pub(crate) const SCROLL_SPEED_Y: f32 = 1.0;
18+
1119
pub(crate) const PINCH_ZOOM_SPEED: f64 = 300.0;
1220

1321
pub(crate) const MULTICLICK_TIMEOUT: Duration = Duration::from_millis(500);

desktop/src/cef/context/singlethreaded.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ impl CefContext for SingleThreadedCefContext {
2828
let host = self.browser.host().unwrap();
2929
host.set_zoom_level(view_info.zoom());
3030
host.was_resized();
31+
32+
// Fix for CEF not updating the view after resize on windows and mac
33+
// TODO: remove once https://github.com/chromiumembedded/cef/issues/3822 is fixed
34+
#[cfg(any(target_os = "windows", target_os = "macos"))]
35+
host.invalidate(cef::PaintElementType::default());
3136
}
3237

3338
fn send_web_message(&self, message: Vec<u8>) {

desktop/src/cef/input.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ use super::consts::{PINCH_ZOOM_SPEED, SCROLL_LINE_HEIGHT, SCROLL_LINE_WIDTH, SCR
1313
pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputState, event: &WindowEvent) {
1414
match event {
1515
WindowEvent::PointerMoved { position, .. } | WindowEvent::PointerEntered { position, .. } => {
16-
input_state.cursor_move(position);
16+
if !input_state.cursor_move(position) {
17+
return;
18+
}
1719

1820
let Some(host) = browser.host() else { return };
1921
host.send_mouse_move_event(Some(&input_state.into()), 0);
2022
}
2123
WindowEvent::PointerLeft { position, .. } => {
2224
if let Some(position) = position {
23-
input_state.cursor_move(position);
25+
let _ = input_state.cursor_move(position);
2426
}
2527

2628
let Some(host) = browser.host() else { return };

desktop/src/cef/input/state.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ impl InputState {
1717
self.modifiers = *modifiers;
1818
}
1919

20-
pub(crate) fn cursor_move(&mut self, position: &PhysicalPosition<f64>) {
21-
self.mouse_position = position.into();
20+
pub(crate) fn cursor_move(&mut self, position: &PhysicalPosition<f64>) -> bool {
21+
let new = position.into();
22+
if self.mouse_position == new {
23+
return false;
24+
}
25+
self.mouse_position = new;
26+
true
2227
}
2328

2429
pub(crate) fn mouse_input(&mut self, button: &MouseButton, state: &ElementState) -> ClickCount {
@@ -59,7 +64,7 @@ impl From<&mut InputState> for MouseEvent {
5964
}
6065
}
6166

62-
#[derive(Default, Clone, Copy)]
67+
#[derive(Default, Clone, Copy, Eq, PartialEq)]
6368
pub(crate) struct MousePosition {
6469
x: usize,
6570
y: usize,

0 commit comments

Comments
 (0)