1+ #![ feature( default_field_values) ]
2+
13use anyhow:: { Context , Result } ;
24use clap:: Parser ;
35use evdev:: {
46 uinput:: VirtualDevice , Device , EventType , RelativeAxisCode ,
57} ;
6- use log:: { error, info} ;
8+ use log:: { debug , error, info} ;
79use std:: path:: PathBuf ;
810
911#[ derive( Parser , Debug ) ]
@@ -18,6 +20,21 @@ struct Args {
1820 debug : bool ,
1921}
2022
23+ struct AnxiousParams {
24+ // Base sensitivity
25+ base_sens : i32 = 1 ,
26+ // Max sensitivity multiplier before clipping
27+ max_sens : i32 = 50 ,
28+ // How much acceleration to apply (higher = more acceleration)
29+ accel : i32 = 2 ,
30+ // Threshold for acceleration to apply
31+ threshold : i32 = 10 ,
32+ // Input scale factor
33+ in_scale : i32 = 1 ,
34+ // Output scale factor
35+ out_scale : i32 = 1 ,
36+ }
37+
2138fn main ( ) -> Result < ( ) > {
2239 let args = Args :: parse ( ) ;
2340
@@ -27,6 +44,9 @@ fn main() -> Result<()> {
2744
2845 info ! ( "Starting anxious scroll daemon" ) ;
2946
47+ // Initialize anxious parameters
48+ let anxious_params = AnxiousParams { .. } ;
49+
3050 // Find the physical mouse device
3151 let mut physical_device = find_mouse_device ( args. device ) ?;
3252 info ! ( "Found physical mouse: {}" , physical_device. name( ) . unwrap_or( "Unknown" ) ) ;
@@ -47,7 +67,7 @@ fn main() -> Result<()> {
4767
4868 // Main event loop - pass through all events
4969 info ! ( "Starting event pass-through loop..." ) ;
50- run_pass_through_loop ( & mut physical_device, & mut virtual_device) ?;
70+ run_pass_through_loop ( & mut physical_device, & mut virtual_device, & anxious_params ) ?;
5171
5272 Ok ( ( ) )
5373}
@@ -103,18 +123,41 @@ fn create_virtual_mouse(physical_device: &Device) -> Result<VirtualDevice> {
103123 Ok ( builder. build ( ) ?)
104124}
105125
106- fn run_pass_through_loop ( physical_device : & mut Device , virtual_device : & mut VirtualDevice ) -> Result < ( ) > {
126+ #[ inline( always) ]
127+ fn apply_anxious_scroll ( value : i32 , anxious_params : & AnxiousParams ) -> i32 {
128+ value
129+ }
130+
131+ fn run_pass_through_loop ( physical_device : & mut Device , virtual_device : & mut VirtualDevice , anxious_params : & AnxiousParams ) -> Result < ( ) > {
107132 loop {
108133 match physical_device. fetch_events ( ) {
109134 Ok ( events) => {
110135 // Process events in batches to handle high-resolution scroll coordination
111136 let mut event_batch = Vec :: new ( ) ;
112137
113138 for event in events {
114- // For now, pass through all events unchanged
115- // In Phase 2, we'll add scroll acceleration logic here
116- event_batch. push ( event) ;
139+ if event. event_type ( ) == EventType :: RELATIVE && event. code ( ) == RelativeAxisCode :: REL_WHEEL_HI_RES . 0 {
140+ // Create a new event with modified value (example: double the scroll amount)
141+ let modified_value = apply_anxious_scroll ( event. value ( ) , anxious_params) ;
142+ // new_now() is not necessary here as the kernel will update the time field
143+ // when it emits the events to any programs reading the event "file".
144+ let modified_event = evdev:: InputEvent :: new (
145+ event. event_type ( ) . 0 ,
146+ event. code ( ) ,
147+ modified_value
148+ ) ;
149+ event_batch. push ( modified_event) ;
150+ debug ! ( "Modified scroll event: {:?}" , modified_event) ;
151+ }
152+ else if event. event_type ( ) == EventType :: RELATIVE && event. code ( ) == RelativeAxisCode :: REL_WHEEL . 0 {
153+ // Drop event
154+ continue ;
155+ } else {
156+ // Pass through all other events unchanged
157+ event_batch. push ( event) ;
158+ }
117159 }
160+ debug ! ( "Processed {} events in batch" , event_batch. len( ) ) ;
118161
119162 // Emit all events in the batch together
120163 if !event_batch. is_empty ( ) {
0 commit comments