From 56385f79c79325b63eaff8870d3b3457f19a8d8e Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Tue, 18 Jun 2024 13:11:36 +0200 Subject: [PATCH] fix(core/mercury): disallow swipes when touch starts too close to an edge of the display --- .../embed/rust/src/ui/component/swipe_detect.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/core/embed/rust/src/ui/component/swipe_detect.rs b/core/embed/rust/src/ui/component/swipe_detect.rs index 88c6d6924..f827c55d6 100644 --- a/core/embed/rust/src/ui/component/swipe_detect.rs +++ b/core/embed/rust/src/ui/component/swipe_detect.rs @@ -181,6 +181,21 @@ impl SwipeDetect { Self::MIN_TRIGGER } + fn is_lockable(&self, dir: SwipeDirection) -> bool { + let Some(origin) = self.origin else { + return false; + }; + + let min_distance = self.min_trigger() as i16; + + match dir { + SwipeDirection::Up => origin.y > min_distance, + SwipeDirection::Down => origin.y < (screen().height() - min_distance), + SwipeDirection::Left => origin.x > min_distance, + SwipeDirection::Right => origin.x < (screen().width() - min_distance), + } + } + fn progress(&self, val: u16) -> u16 { ((val as f32 / Self::DISTANCE as f32) * Self::PROGRESS_MAX as f32) as u16 } @@ -236,7 +251,7 @@ impl SwipeDetect { let mut res = None; for dir in SwipeDirection::iter() { let progress = config.progress(dir, ofs, self.min_lock()); - if progress > 0 { + if progress > 0 && self.is_lockable(dir) { self.locked = Some(dir); res = Some(SwipeDetectMsg::Start(dir)); break;