Skip to content

Commit

Permalink
Added conditional logging
Browse files Browse the repository at this point in the history
Simplified Ctrl+V trigger
  • Loading branch information
davystrong committed Sep 15, 2021
1 parent 1b6e6a1 commit 4be2d11
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 129 deletions.
109 changes: 1 addition & 108 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "filo-clipboard"
version = "0.2.0"
version = "0.3.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -9,5 +9,4 @@ edition = "2018"
clipboard-win = "4.2.1"
winapi = {version = "0.3.9", features = ["winuser", "std", "impl-default"]}
error-code = "2.3.0"
clap = "3.0.0-beta.4"
rayon = "1.5.1"
clap = "3.0.0-beta.4"
45 changes: 27 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,32 @@ pub fn run(opts: Opts) {
compare_data(&cb_data, last_update, SIMILARITY_THRESHOLD)
})
.unwrap_or(ComparisonResult::Different);
#[cfg(debug_assertions)]
{
if let Some(cb_data) = last_internal_update.as_ref() {
println!("prev_item: {}", get_cb_text(cb_data));
}

if let Some(cb_data) = cb_history.front() {
println!("current_item: {}", get_cb_text(cb_data));
}

println!("New item: {}", get_cb_text(&cb_data));
}

match (prev_item_similarity, current_item_similarity) {
(_, ComparisonResult::Same) | (ComparisonResult::Same, _) => {}
(_, ComparisonResult::Similar) | (ComparisonResult::Similar, _) => {
*cb_history.front_mut().unwrap() = cb_data;
last_internal_update = None;
#[cfg(debug_assertions)]
println!("Updating last element: {}", get_cb_text(&cb_data));
if let Some(cb_history_front) = cb_history.front_mut() {
*cb_history_front = cb_data;
last_internal_update = None;
}
}
(ComparisonResult::Different, ComparisonResult::Different) => {
#[cfg(debug_assertions)]
println!("Appending to history: {}", get_cb_text(&cb_data));
cb_history.push_front(cb_data);
cb_history.truncate(opts.max_history);
last_internal_update = None;
Expand All @@ -197,16 +215,15 @@ pub fn run(opts: Opts) {
winuser::WM_HOTKEY => {
if lp_msg.wParam == 1 {
/*Ctrl + Shift + V*/
#[cfg(debug_assertions)]
dbg!("Ctrl+Shift+V");
fn old_state(v_key: i32) -> u32 {
match is_key_pressed(v_key) {
Ok(false) => winuser::KEYEVENTF_KEYUP,
_ => 0,
}
}

let old_control = old_state(winuser::VK_CONTROL);
let old_v = old_state('V' as i32);

match trigger_keys(
&[
winuser::VK_SHIFT as u16,
Expand All @@ -218,19 +235,11 @@ pub fn run(opts: Opts) {
],
&[
winuser::KEYEVENTF_KEYUP,
if old_control == 0 {
winuser::KEYEVENTF_KEYUP
} else {
0
},
if old_v == 0 {
winuser::KEYEVENTF_KEYUP
} else {
0
},
old_control,
old_v,
old_state(winuser::VK_SHIFT),
winuser::KEYEVENTF_KEYUP,
winuser::KEYEVENTF_KEYUP,
0,
0,
0,
],
) {
Ok(_) => {
Expand Down

0 comments on commit 4be2d11

Please sign in to comment.