implemented max_delays.

This commit is contained in:
Schrottkatze 2022-07-11 12:03:53 +02:00
parent d8c8a7606e
commit 5e0936b827

View file

@ -50,7 +50,7 @@ fn main() {
Box::new(io::stdout()) Box::new(io::stdout())
}; };
event_loop(display, recorded_display, screen, stop_key, outfile, args.ignore_delay_capturing); event_loop(display, recorded_display, screen, stop_key, outfile, args.ignore_delay_capturing, args.max_delay);
display.close(); display.close();
} }
@ -89,7 +89,7 @@ fn get_stop_key(display: XDisplay) -> Keycode {
stop_key stop_key
} }
fn event_loop(display: XDisplay, recordeddpy: XDisplay, screen: i32, stop_key: Keycode, mut outfile: Box<dyn Write>, ignore_delay_capturing: bool) { fn event_loop(display: XDisplay, recordeddpy: XDisplay, screen: i32, stop_key: Keycode, mut outfile: Box<dyn Write>, ignore_delay_capturing: bool, max_delay: Option<u64>) {
// let root = display.get_root_window(screen); // let root = display.get_root_window(screen);
let protocol_ranges = unsafe { XRecordAllocRange() }; let protocol_ranges = unsafe { XRecordAllocRange() };
@ -112,6 +112,7 @@ fn event_loop(display: XDisplay, recordeddpy: XDisplay, screen: i32, stop_key: K
x: pointer_pos.0 as i16, x: pointer_pos.0 as i16,
y: pointer_pos.1 as i16, y: pointer_pos.1 as i16,
ignore_delay_capturing, ignore_delay_capturing,
max_delay,
no_keypress_yet: true, no_keypress_yet: true,
last_event: 0, last_event: 0,
moving: false, moving: false,
@ -141,6 +142,7 @@ pub struct EvCallbackData {
x: i16, x: i16,
y: i16, y: i16,
ignore_delay_capturing: bool, ignore_delay_capturing: bool,
max_delay: Option<u64>,
no_keypress_yet: bool, no_keypress_yet: bool,
last_event: u64, last_event: u64,
moving: bool, moving: bool,
@ -198,7 +200,10 @@ unsafe extern "C" fn ev_callback(closure: *mut c_char, intercept_data: *mut XRec
} }
if !data.ignore_delay_capturing && (intercept_data.server_time - data.last_event) != 0 { if !data.ignore_delay_capturing && (intercept_data.server_time - data.last_event) != 0 {
writeln!(&mut data.outfile,"Delay {}", intercept_data.server_time - data.last_event) writeln!(&mut data.outfile,"Delay {}", if let Some(max_delay) = data.max_delay {
let delay_res = intercept_data.server_time - data.last_event;
if delay_res > max_delay { max_delay } else { delay_res }
} else { intercept_data.server_time - data.last_event })
.expect("Failed to write to outfile."); .expect("Failed to write to outfile.");
data.last_event = intercept_data.server_time; data.last_event = intercept_data.server_time;
} }
@ -221,7 +226,10 @@ unsafe extern "C" fn ev_callback(closure: *mut c_char, intercept_data: *mut XRec
let bc: u8 = *((intercept_data.data as usize + 1) as *const u8); let bc: u8 = *((intercept_data.data as usize + 1) as *const u8);
if !data.ignore_delay_capturing && (intercept_data.server_time - data.last_event) != 0 { if !data.ignore_delay_capturing && (intercept_data.server_time - data.last_event) != 0 {
writeln!(&mut data.outfile,"Delay {}", intercept_data.server_time - data.last_event) writeln!(&mut data.outfile,"Delay {}", if let Some(max_delay) = data.max_delay {
let delay_res = intercept_data.server_time - data.last_event;
if delay_res > max_delay { max_delay } else { delay_res }
} else { intercept_data.server_time - data.last_event })
.expect("Failed to write to outfile."); .expect("Failed to write to outfile.");
data.last_event = intercept_data.server_time; data.last_event = intercept_data.server_time;
} }