From c4130d12ee3f9e13b531da18d2285ea1a34a65b0 Mon Sep 17 00:00:00 2001 From: Timon Schelling Date: Wed, 24 Sep 2025 01:01:39 +0000 Subject: [PATCH 1/5] fix multiclick --- desktop/src/cef/input.rs | 80 ++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/desktop/src/cef/input.rs b/desktop/src/cef/input.rs index 6b0badad56..1899aaa278 100644 --- a/desktop/src/cef/input.rs +++ b/desktop/src/cef/input.rs @@ -33,7 +33,7 @@ pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputStat } }; - let cef_click_count = input_state.mouse_input(mouse_button, state).into(); + let cef_click_count = input_state.mouse_input(mouse_button, state); let cef_mouse_up = match state { ElementState::Pressed => 0, ElementState::Released => 1, @@ -46,7 +46,7 @@ pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputStat }; let Some(host) = browser.host() else { return }; - host.send_mouse_click_event(Some(&input_state.into()), cef_button, cef_mouse_up, cef_click_count); + host.send_mouse_click_event(Some(&input_state.into()), cef_button, cef_mouse_up, cef_click_count as i32); } WindowEvent::MouseWheel { delta, phase: _, device_id: _, .. } => { let mouse_event = input_state.into(); @@ -149,7 +149,7 @@ impl InputState { self.mouse_position = position.into(); } - fn mouse_input(&mut self, button: &MouseButton, state: &ElementState) -> ClickCount { + fn mouse_input(&mut self, button: &MouseButton, state: &ElementState) -> u32 { self.mouse_state.update(button, state); self.mouse_click_tracker.input(button, state, &self.mouse_position) } @@ -233,24 +233,27 @@ struct ClickTracker { right: Option, } impl ClickTracker { - fn input(&mut self, button: &MouseButton, state: &ElementState, position: &MousePosition) -> ClickCount { + fn input(&mut self, button: &MouseButton, state: &ElementState, position: &MousePosition) -> u32 { let record = match button { MouseButton::Left => &mut self.left, MouseButton::Right => &mut self.right, MouseButton::Middle => &mut self.middle, - _ => return ClickCount::Single, + _ => return 1, }; let now = Instant::now(); - let Some(record) = record else { + if record.is_none() { *record = Some(ClickRecord { time: now, position: position.clone(), - down_count: ClickCount::Single, - up_count: ClickCount::Single, + down_count: 0, + up_count: 0, }); - return ClickCount::Single; + } + + let Some(record) = record else { + return 1; }; let dx = position.x.abs_diff(record.position.x); @@ -258,41 +261,28 @@ impl ClickTracker { let within_dist = dx <= MULTICLICK_ALLOWED_TRAVEL && dy <= MULTICLICK_ALLOWED_TRAVEL; let within_time = now.saturating_duration_since(record.time) <= MULTICLICK_TIMEOUT; - let count = if within_time && within_dist { ClickCount::Double } else { ClickCount::Single }; - - *record = match state { - ElementState::Pressed => ClickRecord { - time: now, - position: position.clone(), - down_count: count.clone(), - up_count: record.up_count.clone(), - }, - ElementState::Released => ClickRecord { - time: now, - position: position.clone(), - down_count: record.down_count.clone(), - up_count: count.clone(), - }, - }; - count - } -} + record.time = now; + record.position = position.clone(); -#[derive(Clone)] -enum ClickCount { - Single, - Double, -} -impl Default for ClickCount { - fn default() -> Self { - Self::Single - } -} -impl From for i32 { - fn from(count: ClickCount) -> i32 { - match count { - ClickCount::Single => 1, - ClickCount::Double => 2, + match state { + ElementState::Pressed if within_time && within_dist => { + record.down_count += 1; + record.down_count + } + ElementState::Released if within_time && within_dist => { + record.up_count += 1; + record.up_count + } + ElementState::Pressed => { + record.down_count = 1; + record.up_count = 0; + 1 + } + ElementState::Released => { + record.down_count = 0; + record.up_count = 1; + 1 + } } } } @@ -300,8 +290,8 @@ impl From for i32 { struct ClickRecord { time: Instant, position: MousePosition, - down_count: ClickCount, - up_count: ClickCount, + down_count: u32, + up_count: u32, } struct CefModifiers(u32); From 7870434cef1afc4fab43edc02c87802c3b859e7b Mon Sep 17 00:00:00 2001 From: Timon Schelling Date: Thu, 25 Sep 2025 08:54:26 +0000 Subject: [PATCH 2/5] Revert "fix multiclick" This reverts commit c4130d12ee3f9e13b531da18d2285ea1a34a65b0. --- desktop/src/cef/input.rs | 80 ++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/desktop/src/cef/input.rs b/desktop/src/cef/input.rs index 1899aaa278..6b0badad56 100644 --- a/desktop/src/cef/input.rs +++ b/desktop/src/cef/input.rs @@ -33,7 +33,7 @@ pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputStat } }; - let cef_click_count = input_state.mouse_input(mouse_button, state); + let cef_click_count = input_state.mouse_input(mouse_button, state).into(); let cef_mouse_up = match state { ElementState::Pressed => 0, ElementState::Released => 1, @@ -46,7 +46,7 @@ pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputStat }; let Some(host) = browser.host() else { return }; - host.send_mouse_click_event(Some(&input_state.into()), cef_button, cef_mouse_up, cef_click_count as i32); + host.send_mouse_click_event(Some(&input_state.into()), cef_button, cef_mouse_up, cef_click_count); } WindowEvent::MouseWheel { delta, phase: _, device_id: _, .. } => { let mouse_event = input_state.into(); @@ -149,7 +149,7 @@ impl InputState { self.mouse_position = position.into(); } - fn mouse_input(&mut self, button: &MouseButton, state: &ElementState) -> u32 { + fn mouse_input(&mut self, button: &MouseButton, state: &ElementState) -> ClickCount { self.mouse_state.update(button, state); self.mouse_click_tracker.input(button, state, &self.mouse_position) } @@ -233,27 +233,24 @@ struct ClickTracker { right: Option, } impl ClickTracker { - fn input(&mut self, button: &MouseButton, state: &ElementState, position: &MousePosition) -> u32 { + fn input(&mut self, button: &MouseButton, state: &ElementState, position: &MousePosition) -> ClickCount { let record = match button { MouseButton::Left => &mut self.left, MouseButton::Right => &mut self.right, MouseButton::Middle => &mut self.middle, - _ => return 1, + _ => return ClickCount::Single, }; let now = Instant::now(); - if record.is_none() { + let Some(record) = record else { *record = Some(ClickRecord { time: now, position: position.clone(), - down_count: 0, - up_count: 0, + down_count: ClickCount::Single, + up_count: ClickCount::Single, }); - } - - let Some(record) = record else { - return 1; + return ClickCount::Single; }; let dx = position.x.abs_diff(record.position.x); @@ -261,28 +258,41 @@ impl ClickTracker { let within_dist = dx <= MULTICLICK_ALLOWED_TRAVEL && dy <= MULTICLICK_ALLOWED_TRAVEL; let within_time = now.saturating_duration_since(record.time) <= MULTICLICK_TIMEOUT; - record.time = now; - record.position = position.clone(); + let count = if within_time && within_dist { ClickCount::Double } else { ClickCount::Single }; - match state { - ElementState::Pressed if within_time && within_dist => { - record.down_count += 1; - record.down_count - } - ElementState::Released if within_time && within_dist => { - record.up_count += 1; - record.up_count - } - ElementState::Pressed => { - record.down_count = 1; - record.up_count = 0; - 1 - } - ElementState::Released => { - record.down_count = 0; - record.up_count = 1; - 1 - } + *record = match state { + ElementState::Pressed => ClickRecord { + time: now, + position: position.clone(), + down_count: count.clone(), + up_count: record.up_count.clone(), + }, + ElementState::Released => ClickRecord { + time: now, + position: position.clone(), + down_count: record.down_count.clone(), + up_count: count.clone(), + }, + }; + count + } +} + +#[derive(Clone)] +enum ClickCount { + Single, + Double, +} +impl Default for ClickCount { + fn default() -> Self { + Self::Single + } +} +impl From for i32 { + fn from(count: ClickCount) -> i32 { + match count { + ClickCount::Single => 1, + ClickCount::Double => 2, } } } @@ -290,8 +300,8 @@ impl ClickTracker { struct ClickRecord { time: Instant, position: MousePosition, - down_count: u32, - up_count: u32, + down_count: ClickCount, + up_count: ClickCount, } struct CefModifiers(u32); From c3f791243a55d6643d4b7501b6fcc6aab17c81ff Mon Sep 17 00:00:00 2001 From: Timon Schelling Date: Thu, 25 Sep 2025 09:04:28 +0000 Subject: [PATCH 3/5] try another way --- desktop/src/cef/input.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/desktop/src/cef/input.rs b/desktop/src/cef/input.rs index 6b0badad56..6bdab986af 100644 --- a/desktop/src/cef/input.rs +++ b/desktop/src/cef/input.rs @@ -253,6 +253,28 @@ impl ClickTracker { return ClickCount::Single; }; + match state { + ElementState::Pressed if record.down_count == ClickCount::Double => { + *record = ClickRecord { + time: now, + position: position.clone(), + down_count: ClickCount::Single, + up_count: record.up_count.clone(), + }; + return ClickCount::Single; + } + ElementState::Released if record.up_count == ClickCount::Double => { + *record = ClickRecord { + time: now, + position: position.clone(), + down_count: record.down_count.clone(), + up_count: ClickCount::Single, + }; + return ClickCount::Single; + } + _ => {} + } + let dx = position.x.abs_diff(record.position.x); let dy = position.y.abs_diff(record.position.y); let within_dist = dx <= MULTICLICK_ALLOWED_TRAVEL && dy <= MULTICLICK_ALLOWED_TRAVEL; @@ -278,7 +300,7 @@ impl ClickTracker { } } -#[derive(Clone)] +#[derive(Clone, PartialEq)] enum ClickCount { Single, Double, From b88bb2a5776454f8062e8f403babbfcd67377341 Mon Sep 17 00:00:00 2001 From: Timon Schelling Date: Thu, 25 Sep 2025 11:47:58 +0000 Subject: [PATCH 4/5] use copy --- desktop/src/cef/input.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/desktop/src/cef/input.rs b/desktop/src/cef/input.rs index 6bdab986af..9fdc3dd866 100644 --- a/desktop/src/cef/input.rs +++ b/desktop/src/cef/input.rs @@ -259,7 +259,7 @@ impl ClickTracker { time: now, position: position.clone(), down_count: ClickCount::Single, - up_count: record.up_count.clone(), + up_count: record.up_count, }; return ClickCount::Single; } @@ -267,7 +267,7 @@ impl ClickTracker { *record = ClickRecord { time: now, position: position.clone(), - down_count: record.down_count.clone(), + down_count: record.down_count, up_count: ClickCount::Single, }; return ClickCount::Single; @@ -286,21 +286,21 @@ impl ClickTracker { ElementState::Pressed => ClickRecord { time: now, position: position.clone(), - down_count: count.clone(), - up_count: record.up_count.clone(), + down_count: count, + up_count: record.up_count, }, ElementState::Released => ClickRecord { time: now, position: position.clone(), - down_count: record.down_count.clone(), - up_count: count.clone(), + down_count: record.down_count, + up_count: count, }, }; count } } -#[derive(Clone, PartialEq)] +#[derive(Clone, Copy, PartialEq)] enum ClickCount { Single, Double, From bd774e726552b82f73e017b3c670d275ca043187 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Thu, 25 Sep 2025 14:26:40 +0200 Subject: [PATCH 5/5] Use struct initializer syntax fror click tracker (#3226) --- desktop/src/cef/input.rs | 61 +++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/desktop/src/cef/input.rs b/desktop/src/cef/input.rs index 9fdc3dd866..5e5abab058 100644 --- a/desktop/src/cef/input.rs +++ b/desktop/src/cef/input.rs @@ -151,7 +151,7 @@ impl InputState { fn mouse_input(&mut self, button: &MouseButton, state: &ElementState) -> ClickCount { self.mouse_state.update(button, state); - self.mouse_click_tracker.input(button, state, &self.mouse_position) + self.mouse_click_tracker.input(button, state, self.mouse_position) } fn cef_modifiers(&self, location: &winit::keyboard::KeyLocation, is_repeat: bool) -> CefModifiers { @@ -187,7 +187,7 @@ impl From<&mut InputState> for MouseEvent { } } -#[derive(Default, Clone)] +#[derive(Default, Clone, Copy)] pub(crate) struct MousePosition { x: usize, y: usize, @@ -233,7 +233,7 @@ struct ClickTracker { right: Option, } impl ClickTracker { - fn input(&mut self, button: &MouseButton, state: &ElementState, position: &MousePosition) -> ClickCount { + fn input(&mut self, button: &MouseButton, state: &ElementState, position: MousePosition) -> ClickCount { let record = match button { MouseButton::Left => &mut self.left, MouseButton::Right => &mut self.right, @@ -241,34 +241,27 @@ impl ClickTracker { _ => return ClickCount::Single, }; - let now = Instant::now(); - let Some(record) = record else { - *record = Some(ClickRecord { - time: now, - position: position.clone(), - down_count: ClickCount::Single, - up_count: ClickCount::Single, - }); + *record = Some(ClickRecord { position, ..Default::default() }); return ClickCount::Single; }; + let now = Instant::now(); + record.time = now; + record.position = position; + match state { ElementState::Pressed if record.down_count == ClickCount::Double => { *record = ClickRecord { - time: now, - position: position.clone(), down_count: ClickCount::Single, - up_count: record.up_count, + ..*record }; return ClickCount::Single; } ElementState::Released if record.up_count == ClickCount::Double => { *record = ClickRecord { - time: now, - position: position.clone(), - down_count: record.down_count, up_count: ClickCount::Single, + ..*record }; return ClickCount::Single; } @@ -283,33 +276,19 @@ impl ClickTracker { let count = if within_time && within_dist { ClickCount::Double } else { ClickCount::Single }; *record = match state { - ElementState::Pressed => ClickRecord { - time: now, - position: position.clone(), - down_count: count, - up_count: record.up_count, - }, - ElementState::Released => ClickRecord { - time: now, - position: position.clone(), - down_count: record.down_count, - up_count: count, - }, + ElementState::Pressed => ClickRecord { down_count: count, ..*record }, + ElementState::Released => ClickRecord { up_count: count, ..*record }, }; count } } -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Default)] enum ClickCount { + #[default] Single, Double, } -impl Default for ClickCount { - fn default() -> Self { - Self::Single - } -} impl From for i32 { fn from(count: ClickCount) -> i32 { match count { @@ -319,6 +298,7 @@ impl From for i32 { } } +#[derive(Clone, Copy)] struct ClickRecord { time: Instant, position: MousePosition, @@ -326,6 +306,17 @@ struct ClickRecord { up_count: ClickCount, } +impl Default for ClickRecord { + fn default() -> Self { + Self { + time: Instant::now(), + position: Default::default(), + down_count: Default::default(), + up_count: Default::default(), + } + } +} + struct CefModifiers(u32); impl CefModifiers { fn new(input_state: &InputState, location: &winit::keyboard::KeyLocation, is_repeat: bool) -> Self {