@@ -8,6 +8,29 @@ use std::time::Duration;
88
99use crate :: device:: DeviceModel ;
1010
11+ #[ derive( Debug , Clone ) ]
12+ pub enum TriggerCorner {
13+ UpperRight ,
14+ UpperLeft ,
15+ LowerRight ,
16+ LowerLeft ,
17+ }
18+
19+ impl TriggerCorner {
20+ pub fn from_string ( s : & str ) -> Result < Self > {
21+ match s. to_lowercase ( ) . as_str ( ) {
22+ "ur" | "upper-right" => Ok ( TriggerCorner :: UpperRight ) ,
23+ "ul" | "upper-left" => Ok ( TriggerCorner :: UpperLeft ) ,
24+ "lr" | "lower-right" => Ok ( TriggerCorner :: LowerRight ) ,
25+ "ll" | "lower-left" => Ok ( TriggerCorner :: LowerLeft ) ,
26+ _ => Err ( anyhow:: anyhow!(
27+ "Invalid trigger corner: {}. Use UR, UL, LR, LL, upper-right, upper-left, lower-right, or lower-left" ,
28+ s
29+ ) ) ,
30+ }
31+ }
32+ }
33+
1134// Output dimensions remain the same for both devices
1235const VIRTUAL_WIDTH : u16 = 768 ;
1336const VIRTUAL_HEIGHT : u16 = 1024 ;
@@ -26,10 +49,11 @@ const ABS_MT_PRESSURE: u16 = 58;
2649pub struct Touch {
2750 device : Option < Device > ,
2851 device_model : DeviceModel ,
52+ trigger_corner : TriggerCorner ,
2953}
3054
3155impl Touch {
32- pub fn new ( no_touch : bool ) -> Self {
56+ pub fn new ( no_touch : bool , trigger_corner : TriggerCorner ) -> Self {
3357 let device_model = DeviceModel :: detect ( ) ;
3458 info ! ( "Touch using device model: {}" , device_model. name( ) ) ;
3559
@@ -41,7 +65,11 @@ impl Touch {
4165
4266 let device = if no_touch { None } else { Some ( Device :: open ( device_path) . unwrap ( ) ) } ;
4367
44- Self { device, device_model }
68+ Self {
69+ device,
70+ device_model,
71+ trigger_corner,
72+ }
4573 }
4674
4775 pub fn wait_for_trigger ( & mut self ) -> Result < ( ) > {
@@ -67,7 +95,7 @@ impl Touch {
6795 if event. code ( ) == ABS_MT_TRACKING_ID && event. value ( ) == -1 {
6896 let ( x, y) = self . input_to_virtual ( ( position_x, position_y) ) ;
6997 debug ! ( "Touch release detected at ({}, {}) normalized ({}, {})" , position_x, position_y, x, y) ;
70- if x > 700 && y < 50 {
98+ if self . is_in_trigger_zone ( x , y ) {
7199 debug ! ( "Touch release in target zone!" ) ;
72100 return Ok ( ( ) ) ;
73101 }
@@ -133,6 +161,17 @@ impl Touch {
133161 Ok ( ( ) )
134162 }
135163
164+ fn is_in_trigger_zone ( & self , x : i32 , y : i32 ) -> bool {
165+ const CORNER_SIZE : i32 = 68 ; // Size of the trigger zone (68x68 pixels)
166+
167+ match self . trigger_corner {
168+ TriggerCorner :: UpperRight => x > VIRTUAL_WIDTH as i32 - CORNER_SIZE && y < CORNER_SIZE ,
169+ TriggerCorner :: UpperLeft => x < CORNER_SIZE && y < CORNER_SIZE ,
170+ TriggerCorner :: LowerRight => x > VIRTUAL_WIDTH as i32 - CORNER_SIZE && y > VIRTUAL_HEIGHT as i32 - CORNER_SIZE ,
171+ TriggerCorner :: LowerLeft => x < CORNER_SIZE && y > VIRTUAL_HEIGHT as i32 - CORNER_SIZE ,
172+ }
173+ }
174+
136175 fn screen_width ( & self ) -> u32 {
137176 match self . device_model {
138177 DeviceModel :: Remarkable2 => 1404 ,
0 commit comments